mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Delete penultimate use of Patches field.
This commit is contained in:
@@ -89,7 +89,7 @@ func (o *addPatchOptions) RunAddPatch(fSys fs.FileSystem) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range patches {
|
for _, p := range patches {
|
||||||
if patch.Exist(m.PatchesStrategicMerge, p) || kustfile.StringInSlice(p, m.Patches) {
|
if patch.Exist(m.PatchesStrategicMerge, p) {
|
||||||
log.Printf("patch %s already in kustomization file", p)
|
log.Printf("patch %s already in kustomization file", p)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,16 +110,17 @@ func (mf *kustomizationFile) Read() (*types.Kustomization, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var kustomization types.Kustomization
|
var k types.Kustomization
|
||||||
err = yaml.Unmarshal(data, &kustomization)
|
err = yaml.Unmarshal(data, &k)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
k.DealWithDeprecatedFields()
|
||||||
err = mf.parseCommentedFields(data)
|
err = mf.parseCommentedFields(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &kustomization, err
|
return &k, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mf *kustomizationFile) Write(kustomization *types.Kustomization) error {
|
func (mf *kustomizationFile) Write(kustomization *types.Kustomization) error {
|
||||||
|
|||||||
@@ -50,6 +50,48 @@ func TestWriteAndRead(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated fields should not survive being read.
|
||||||
|
func TestDeprecationOfPatches(t *testing.T) {
|
||||||
|
hasDeprecatedFields := []byte(`
|
||||||
|
namePrefix: acme
|
||||||
|
patches:
|
||||||
|
- alice
|
||||||
|
patchesStrategicMerge:
|
||||||
|
- bob
|
||||||
|
`)
|
||||||
|
fSys := fs.MakeFakeFS()
|
||||||
|
fSys.WriteTestKustomizationWith(hasDeprecatedFields)
|
||||||
|
mf, err := NewKustomizationFile(fSys)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unexpected Error: %v", err)
|
||||||
|
}
|
||||||
|
k, err := mf.Read()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Couldn't read kustomization file: %v\n", err)
|
||||||
|
}
|
||||||
|
if k.NamePrefix != "acme" {
|
||||||
|
t.Fatalf("Unexpected name prefix")
|
||||||
|
}
|
||||||
|
if len(k.Patches) > 0 {
|
||||||
|
t.Fatalf("Expected nothing in Patches.")
|
||||||
|
}
|
||||||
|
if len(k.PatchesStrategicMerge) != 2 {
|
||||||
|
t.Fatalf(
|
||||||
|
"Expected len(k.PatchesStrategicMerge) == 2, got %d",
|
||||||
|
len(k.PatchesStrategicMerge))
|
||||||
|
}
|
||||||
|
m := make(map[string]bool)
|
||||||
|
for _, v := range k.PatchesStrategicMerge {
|
||||||
|
m[string(v)] = true
|
||||||
|
}
|
||||||
|
if _, f := m["alice"]; !f {
|
||||||
|
t.Fatalf("Expected alice in PatchesStrategicMerge")
|
||||||
|
}
|
||||||
|
if _, f := m["bob"]; !f {
|
||||||
|
t.Fatalf("Expected bob in PatchesStrategicMerge")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestNewNotExist(t *testing.T) {
|
func TestNewNotExist(t *testing.T) {
|
||||||
fakeFS := fs.MakeFakeFS()
|
fakeFS := fs.MakeFakeFS()
|
||||||
_, err := NewKustomizationFile(fakeFS)
|
_, err := NewKustomizationFile(fakeFS)
|
||||||
|
|||||||
@@ -124,13 +124,16 @@ type Kustomization struct {
|
|||||||
// DealWithDeprecatedFields should be called immediately after
|
// DealWithDeprecatedFields should be called immediately after
|
||||||
// loading from storage.
|
// loading from storage.
|
||||||
func (k *Kustomization) DealWithDeprecatedFields() {
|
func (k *Kustomization) DealWithDeprecatedFields() {
|
||||||
// The Patches field, meant to hold StrategicMerge patches,
|
if len(k.Patches) > 0 {
|
||||||
// is deprecated. Append anything found there to the
|
// The Patches field, meant to hold strategic merge
|
||||||
// PatchesStrategicMerge field.
|
// patches, is deprecated. Append anything found
|
||||||
// This happened when the PatchesJson6902 field was introduced.
|
// there to the PatchesStrategicMerge field.
|
||||||
|
// This happened when the PatchesJson6902 field
|
||||||
|
// was introduced.
|
||||||
k.PatchesStrategicMerge = patch.Append(
|
k.PatchesStrategicMerge = patch.Append(
|
||||||
k.PatchesStrategicMerge, k.Patches...)
|
k.PatchesStrategicMerge, k.Patches...)
|
||||||
k.Patches = []string{}
|
k.Patches = []string{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigMapArgs contains the metadata of how to generate a configmap.
|
// ConfigMapArgs contains the metadata of how to generate a configmap.
|
||||||
|
|||||||
Reference in New Issue
Block a user