Skip to content
settings.go 1.57 KiB
Newer Older
Timothee Gosselin's avatar
Timothee Gosselin committed
/*

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package instance

import (
	meta "k8s.libre.sh/meta"
	configmap "k8s.libre.sh/objects/configmap"
	secret "k8s.libre.sh/objects/secret"
	parameters "k8s.libre.sh/parameters"
)

type Settings interface {
	GetMeta() Meta
	GetParameters() parameters.Parameters
	SetDefaults(i Instance)
}

func GetObjects(s Settings) map[int]Object {

	cm := &configmap.ConfigMap{}
	secret := &secret.Secret{}
	objs := make(map[int]Object)

	cm.ObjectMeta = s.GetMeta().(*meta.ObjectMeta)
	secret.ObjectMeta = s.GetMeta().(*meta.ObjectMeta)

	cmParameters := parameters.Parameters{}
	secretParameters := parameters.Parameters{}

	params := s.GetParameters()
	for _, p := range params {
Timothee Gosselin's avatar
Timothee Gosselin committed
		if p.Type == parameters.SecretParameter && len(p.Value) == 0 {
Timothee Gosselin's avatar
Timothee Gosselin committed
			secretParameters = append(secretParameters, p)
		}

		cmParameters = append(cmParameters, p)
	}

	if len(cmParameters) > 0 {
		cm.Parameters = cmParameters
		objs[0] = cm
	}

	if len(secretParameters) > 0 {
		secret.Parameters = secretParameters
		if objs[0] == nil {
			objs[0] = secret

		} else {
			objs[1] = secret
		}
	}

	return objs
}