mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
enable preserving order with generatorOptions
This commit is contained in:
@@ -64,7 +64,7 @@ func determineFieldOrder() []string {
|
|||||||
"PatchesJson6902",
|
"PatchesJson6902",
|
||||||
"ConfigMapGenerator",
|
"ConfigMapGenerator",
|
||||||
"SecretGenerator",
|
"SecretGenerator",
|
||||||
// "GeneratorOptions",
|
"GeneratorOptions",
|
||||||
"Vars",
|
"Vars",
|
||||||
"ImageTags",
|
"ImageTags",
|
||||||
}
|
}
|
||||||
@@ -91,12 +91,6 @@ func determineFieldOrder() []string {
|
|||||||
result = append(result, n)
|
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
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +275,7 @@ func marshalField(field string, kustomization *types.Kustomization) ([]byte, err
|
|||||||
r := reflect.ValueOf(*kustomization)
|
r := reflect.ValueOf(*kustomization)
|
||||||
v := r.FieldByName(strings.Title(field))
|
v := r.FieldByName(strings.Title(field))
|
||||||
|
|
||||||
if !v.IsValid() || v.Len() == 0 {
|
if !v.IsValid() || isEmpty(v) {
|
||||||
return []byte{}, nil
|
return []byte{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,3 +286,11 @@ func marshalField(field string, kustomization *types.Kustomization) ([]byte, err
|
|||||||
|
|
||||||
return yaml.Marshal(k)
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func TestFieldOrder(t *testing.T) {
|
|||||||
"PatchesJson6902",
|
"PatchesJson6902",
|
||||||
"ConfigMapGenerator",
|
"ConfigMapGenerator",
|
||||||
"SecretGenerator",
|
"SecretGenerator",
|
||||||
// "GeneratorOptions",
|
"GeneratorOptions",
|
||||||
"Vars",
|
"Vars",
|
||||||
"ImageTags",
|
"ImageTags",
|
||||||
}
|
}
|
||||||
@@ -219,6 +219,9 @@ BASES:
|
|||||||
patchesStrategicMerge:
|
patchesStrategicMerge:
|
||||||
- service.yaml
|
- service.yaml
|
||||||
- pod.yaml
|
- pod.yaml
|
||||||
|
# generator options
|
||||||
|
generatorOptions:
|
||||||
|
disableHash: true
|
||||||
`)
|
`)
|
||||||
|
|
||||||
expected := []byte(`
|
expected := []byte(`
|
||||||
@@ -254,6 +257,9 @@ bases:
|
|||||||
patchesStrategicMerge:
|
patchesStrategicMerge:
|
||||||
- service.yaml
|
- service.yaml
|
||||||
- pod.yaml
|
- pod.yaml
|
||||||
|
# generator options
|
||||||
|
generatorOptions:
|
||||||
|
disableHash: true
|
||||||
`)
|
`)
|
||||||
fSys := fs.MakeFakeFS()
|
fSys := fs.MakeFakeFS()
|
||||||
fSys.WriteTestKustomizationWith(kustomizationContentWithComments)
|
fSys.WriteTestKustomizationWith(kustomizationContentWithComments)
|
||||||
|
|||||||
Reference in New Issue
Block a user