Newer
Older
/*
Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.gnu.org/licenses/agpl-3.0.html
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 settings
import (
"k8s.libre.sh/application/settings/parameters"
)
func OrderByResourceRef(s *ConfigSpec) (secrets, configMaps map[string]parameters.Parameters) {
secrets = make(map[string]parameters.Parameters)
configMaps = make(map[string]parameters.Parameters)
for _, source := range s.Sources {
if source.Type == "secret" {
secrets[source.Ref] = parameters.Parameters{}
} else if source.Type == "configmap" {
configMaps[source.Ref] = parameters.Parameters{}
}
}
// Then we get the sources that are provided for each parameters and will need a transformation
for _, p := range *s.Parameters {
// TOFIX only refType ? by default secret ?
if len(p.ValueFrom.Ref) > 0 && (p.Type == parameters.SecretParameter || p.RefType == "secret") {
// TODO add a warning, if secret given a source and in valuefrom only keys in valuefrom will be fetched
secrets[p.ValueFrom.Ref] = append(secrets[p.ValueFrom.Ref], p)
}
if len(p.ValueFrom.Ref) > 0 && (p.Type == parameters.ConfigParameter || p.RefType == "configmap") {
42
43
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
configMaps[p.ValueFrom.Ref] = append(configMaps[p.ValueFrom.Ref], p)
}
}
return secrets, configMaps
}
/*
func OrderBySourceTypeAndRef(s *ConfigSpec) (orderedParams map[string]map[string]parameters.Parameters) {
// We order the parameters by secret and configmap sources
// First we get the sources provided that should be mounted untouched
// paramsByResourceName = make(map[string]parameters.Parameters)
orderedParams = make(map[string]map[string]parameters.Parameters)
orderedParams["secret"] = make(map[string]parameters.Parameters)
orderedParams["configmap"] = make(map[string]parameters.Parameters)
orderedParams["field"] = make(map[string]parameters.Parameters)
orderedParams["templateValue"] = make(map[string]parameters.Parameters)
for _, ref := range s.SecretRefs {
orderedParams["secret"][ref] = parameters.Parameters{}
}
for _, ref := range s.ConfigRefs {
orderedParams["configmap"][ref] = parameters.Parameters{}
}
// Then we get the sources that are provided for each parameters and will need a transformation
for _, p := range *s.Parameters {
if len(p.ValueFrom.Ref) > 0 {
orderedParams[string(p.Type)][p.ValueFrom.Ref] = append(orderedParams[string(p.Type)][p.ValueFrom.Ref], p)
}
}
return orderedParams
}
*/
func AppendSourceIfUnique(sources []Source, source Source) []Source {
if len(sources) == 0 {
return append(sources, source)
}
for _, ele := range sources {
if ele == source {
return sources
}
}
return append(sources, source)
}