Remove duplicate of configmap (#1206)

* also change the name of the generated cm
This commit is contained in:
Hang Yan
2019-12-26 08:53:41 +08:00
committed by GitHub
parent 4cbe106351
commit 73ec0abab2
7 changed files with 231 additions and 29 deletions
+24
View File
@@ -581,6 +581,30 @@ func (k *Kubernetes) SortServicesFirst(objs *[]runtime.Object) {
*objs = ret
}
// RemoveDupObjects remove objects that are dups...eg. configmaps from env.
// since we know for sure that the duplication can only happends on ConfigMap, so
// this code will looks like this for now.
func (k *Kubernetes) RemoveDupObjects(objs *[]runtime.Object) {
var result []runtime.Object
exist := map[string]bool{}
for _, obj := range *objs {
if us, ok := obj.(*api.ConfigMap); ok {
k := us.GroupVersionKind().String() + us.GetNamespace() + us.GetName()
if exist[k] {
log.Debugf("Remove duplicate configmap: %s", us.GetName())
continue
} else {
result = append(result, obj)
exist[k] = true
}
} else {
result = append(result, obj)
}
}
*objs = result
}
// SortedKeys Ensure the kubernetes objects are in a consistent order
func SortedKeys(komposeObject kobject.KomposeObject) []string {
var sortedKeys []string
+3 -2
View File
@@ -250,7 +250,7 @@ func (k *Kubernetes) InitConfigMapForEnv(name string, service kobject.ServiceCon
APIVersion: "v1",
},
ObjectMeta: api.ObjectMeta{
Name: name + "-" + envName,
Name: envName,
Labels: transformer.ConfigLabels(name + "-" + envName),
},
Data: envs,
@@ -835,7 +835,7 @@ func (k *Kubernetes) ConfigEnvs(name string, service kobject.ServiceConfig, opt
ValueFrom: &api.EnvVarSource{
ConfigMapKeyRef: &api.ConfigMapKeySelector{
LocalObjectReference: api.LocalObjectReference{
Name: name + "-" + envName,
Name: envName,
},
Key: k,
}},
@@ -1097,6 +1097,7 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
// sort all object so Services are first
k.SortServicesFirst(&allobjects)
k.RemoveDupObjects(&allobjects)
return allobjects, nil
}