Merge pull request #496 from Liujingfang1/master

enable preserving order with generatorOptions
This commit is contained in:
k8s-ci-robot
2018-10-22 16:13:01 -07:00
committed by GitHub
2 changed files with 17 additions and 9 deletions

View File

@@ -64,7 +64,7 @@ func determineFieldOrder() []string {
"PatchesJson6902",
"ConfigMapGenerator",
"SecretGenerator",
// "GeneratorOptions",
"GeneratorOptions",
"Vars",
"ImageTags",
}
@@ -91,12 +91,6 @@ func determineFieldOrder() []string {
result = append(result, n)
}
}
// TODO fix GeneratorOptions.
for k := range m {
if !m[k] && k != "GeneratorOptions" {
log.Fatalf("We're ignoring field '%s'", k)
}
}
return result
}
@@ -281,7 +275,7 @@ func marshalField(field string, kustomization *types.Kustomization) ([]byte, err
r := reflect.ValueOf(*kustomization)
v := r.FieldByName(strings.Title(field))
if !v.IsValid() || v.Len() == 0 {
if !v.IsValid() || isEmpty(v) {
return []byte{}, nil
}
@@ -292,3 +286,11 @@ func marshalField(field string, kustomization *types.Kustomization) ([]byte, err
return yaml.Marshal(k)
}
func isEmpty(v reflect.Value) bool {
// If v is a pointer type
if v.Type().Kind() == reflect.Ptr {
return v.IsNil()
}
return v.Len() == 0
}

View File

@@ -40,7 +40,7 @@ func TestFieldOrder(t *testing.T) {
"PatchesJson6902",
"ConfigMapGenerator",
"SecretGenerator",
// "GeneratorOptions",
"GeneratorOptions",
"Vars",
"ImageTags",
}
@@ -219,6 +219,9 @@ BASES:
patchesStrategicMerge:
- service.yaml
- pod.yaml
# generator options
generatorOptions:
disableHash: true
`)
expected := []byte(`
@@ -254,6 +257,9 @@ bases:
patchesStrategicMerge:
- service.yaml
- pod.yaml
# generator options
generatorOptions:
disableHash: true
`)
fSys := fs.MakeFakeFS()
fSys.WriteTestKustomizationWith(kustomizationContentWithComments)