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"
secret "k8s.libre.sh/objects/secret"
parameters "k8s.libre.sh/parameters"
)
type Dependency interface {
GetParameters() parameters.Interface
// GetSecretParameters() *parameters.Settings
// GetConfigParameters() *parameters.Settings
SetDefaults(i Instance)
}
GetSecretMeta() Meta
GetConfigMapMeta() Meta
GetParameters() parameters.Interface
// GetSecretParameters() *parameters.Settings
// GetConfigParameters() *parameters.Settings
// GetSecret() secret.Mutate
// GetConfigMap() configmap.Mutate
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
func InitParametersFromSettings(s Settings, p parameters.Interface) {
secretRefs := p.GetSecretRefs()
configRefs := p.GetConfigRefs()
for _, param := range *p.GetParameters() {
if len(param.MountType) == 0 {
param.MountType = parameters.MountFrom
if len(param.ValueFrom.Ref) == 0 {
if param.Type == parameters.SecretParameter {
secretRefs = append(secretRefs, s.GetMeta().GetName())
}
configRefs = append(configRefs, s.GetMeta().GetName())
}
}
if len(param.Type) == 0 {
param.Type = parameters.ConfigParameter
}
}
p.SetConfigRefs(Unique(configRefs))
p.SetSecretRefs(Unique(secretRefs))
}
func Unique(stringSlice []string) []string {
keys := make(map[string]bool)
list := []string{}
for _, entry := range stringSlice {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}
cm := &configmap.ConfigMap{
ObjectMeta: &meta.ObjectMeta{},
}
secret := &secret.Secret{
ObjectMeta: &meta.ObjectMeta{},
}
SetObjectMeta(s.GetMeta(), cm.ObjectMeta)
SetObjectMeta(s.GetMeta(), secret.ObjectMeta)
// TODO REPLACE BY GET SECRET PARAMETERS & GET CONFIG PARAMETERS
for _, p := range *params.GetParameters() {
// TODO check not mountLiteral ??
if p.Type == parameters.SecretParameter && len(p.Value) > 0 {
secret.Parameters = append(secret.Parameters, p)
if p.Type == parameters.ConfigParameter && len(p.Value) > 0 {
cm.Parameters = append(cm.Parameters, p)
if len(cm.Parameters) > 0 {
// cm.Parameters = cmParameters
if len(secret.Parameters) > 0 {
// secret.Parameters = secretParameters