From 45893b258899b5adaada80a29e59770afcdf3143 Mon Sep 17 00:00:00 2001 From: Eyob Tefera Date: Mon, 10 Aug 2020 17:57:39 +0000 Subject: [PATCH] Iteratively convert PatchesJson6902 to Patches. --- api/types/kustomization.go | 6 ++++++ api/types/patchjson6902.go | 6 ++++++ api/types/patchtarget.go | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/api/types/kustomization.go b/api/types/kustomization.go index 8cc7299b7..464efe878 100644 --- a/api/types/kustomization.go +++ b/api/types/kustomization.go @@ -144,6 +144,12 @@ type Kustomization struct { // moving content of deprecated fields to newer // fields. func (k *Kustomization) FixKustomizationPostUnmarshalling() { + // PatchesJson6902 should be under the Patches field. + for _, patch := range k.PatchesJson6902 { + k.Patches = append(k.Patches, patch.ToPatch()) + } + k.PatchesJson6902 = nil + if k.Kind == "" { k.Kind = KustomizationKind } diff --git a/api/types/patchjson6902.go b/api/types/patchjson6902.go index 1a189aa6d..4c90ce201 100644 --- a/api/types/patchjson6902.go +++ b/api/types/patchjson6902.go @@ -19,3 +19,9 @@ type PatchJson6902 struct { // inline patch string Patch string `json:"patch,omitempty" yaml:"patch,omitempty"` } + +// ToPatch converts a PatchJson6902 to its superset Patch. +func (patch *PatchJson6902) ToPatch() Patch { + selector := patch.Target.ToSelector() + return Patch{Path: patch.Path, Patch: patch.Patch, Target: &selector} +} diff --git a/api/types/patchtarget.go b/api/types/patchtarget.go index ee8c6a691..85f804574 100644 --- a/api/types/patchtarget.go +++ b/api/types/patchtarget.go @@ -13,3 +13,8 @@ type PatchTarget struct { Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"` Name string `json:"name" yaml:"name"` } + +// ToSelector converts a PatchTarget to a Selector. +func (target *PatchTarget) ToSelector() Selector { + return Selector{Name: target.Name, Namespace: target.Namespace, Gvk: target.Gvk} +}