Skip to content
settings.go 1.83 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 (
Timothee Gosselin's avatar
Timothee Gosselin committed
	"fmt"

Timothee Gosselin's avatar
Timothee Gosselin committed
	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
Timothee Gosselin's avatar
Timothee Gosselin committed
	GetParameters() *parameters.Settings
Timothee Gosselin's avatar
Timothee Gosselin committed
	SetDefaults(i Instance)
}

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

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

Timothee Gosselin's avatar
Timothee Gosselin committed
	// TODO REPLACE BY SETOBJECTMETA FUNCTION TO AVOID USING meta.ObjectMeta
Timothee Gosselin's avatar
Timothee Gosselin committed
	cm.ObjectMeta = s.GetMeta().(*meta.ObjectMeta)
	secret.ObjectMeta = s.GetMeta().(*meta.ObjectMeta)

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

Timothee Gosselin's avatar
Timothee Gosselin committed
	// TODO REPLACE BY GETSECRETSECRETPARAMETERS & GETCONFIGPARAMETERS
Timothee Gosselin's avatar
Timothee Gosselin committed
	params := s.GetParameters()
Timothee Gosselin's avatar
Timothee Gosselin committed
	for _, p := range *params.Parameters {
		fmt.Println(p)
		if p.Type == parameters.SecretParameter && len(p.Value) > 0 {
Timothee Gosselin's avatar
Timothee Gosselin committed
			secretParameters = append(secretParameters, p)
		}
Timothee Gosselin's avatar
Timothee Gosselin committed
		if p.Type == parameters.ConfigParameter && len(p.Value) > 0 {
			cmParameters = append(cmParameters, p)
		}
Timothee Gosselin's avatar
Timothee Gosselin committed
	}

Timothee Gosselin's avatar
Timothee Gosselin committed
	// TODO IMPROVE
Timothee Gosselin's avatar
Timothee Gosselin committed
	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
}