Newer
Older
/*
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
SetDefaults(i Instance)
}
func GetObjects(s Settings) map[int]Object {
cm := &configmap.ConfigMap{}
secret := &secret.Secret{}
objs := make(map[int]Object)
// TODO REPLACE BY SETOBJECTMETA FUNCTION TO AVOID USING meta.ObjectMeta
cm.ObjectMeta = s.GetMeta().(*meta.ObjectMeta)
secret.ObjectMeta = s.GetMeta().(*meta.ObjectMeta)
cmParameters := parameters.Parameters{}
secretParameters := parameters.Parameters{}
// TODO REPLACE BY GETSECRETSECRETPARAMETERS & GETCONFIGPARAMETERS
for _, p := range *params.Parameters {
fmt.Println(p)
if p.Type == parameters.SecretParameter && len(p.Value) > 0 {
if p.Type == parameters.ConfigParameter && len(p.Value) > 0 {
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
}