Merge pull request #4733 from koba1t/feat/add_edit-fix_for_patchesStrategicMerge_to_patches

add `edit fix` for patchesStrategicMerge to patches
This commit is contained in:
Kubernetes Prow Robot
2022-10-21 14:57:57 -07:00
committed by GitHub
3 changed files with 320 additions and 62 deletions

View File

@@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"sigs.k8s.io/kustomize/kyaml/filesys"
"sigs.k8s.io/yaml"
)
@@ -217,11 +218,25 @@ func (k *Kustomization) FixKustomizationPostUnmarshalling() {
// FixKustomizationPreMarshalling fixes things
// that should occur after the kustomization file
// has been processed.
func (k *Kustomization) FixKustomizationPreMarshalling() error {
func (k *Kustomization) FixKustomizationPreMarshalling(fSys filesys.FileSystem) error {
// PatchesJson6902 should be under the Patches field.
k.Patches = append(k.Patches, k.PatchesJson6902...)
k.PatchesJson6902 = nil
if k.PatchesStrategicMerge != nil {
for _, patchStrategicMerge := range k.PatchesStrategicMerge {
// check this patch is file path select.
if _, err := fSys.ReadFile(string(patchStrategicMerge)); err == nil {
// path patch
k.Patches = append(k.Patches, Patch{Path: string(patchStrategicMerge)})
} else {
// inline string patch
k.Patches = append(k.Patches, Patch{Patch: string(patchStrategicMerge)})
}
}
k.PatchesStrategicMerge = nil
}
// this fix is not in FixKustomizationPostUnmarshalling because
// it will break some commands like `create` and `add`. those
// commands depend on 'commonLabels' field