1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package krusty_test
import (
"testing"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
func TestPatchDeleteOfNotExistingAttributesShouldNotAddExtraElements(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t)
defer th.Reset()
th.WriteF("resource.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: whatever
spec:
template:
spec:
containers:
- env:
- name: EXISTING
value: EXISTING_VALUE
- name: FOR_REMOVAL
value: FOR_REMOVAL_VALUE
name: whatever
image: helloworld
`)
th.WriteF("patch.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: whatever
spec:
template:
spec:
containers:
- name: whatever
env:
- name: FOR_REMOVAL
$patch: delete
- name: NOT_EXISTING_FOR_REMOVAL
$patch: delete
`)
th.WriteK(".", `
resources:
- resource.yaml
patches:
- path: patch.yaml
target:
kind: Deployment
`)
// It's expected that removal of not existing elements should not introduce extra values,
// as a patch can be applied to multiple resources, not all of them can have all the elements being deleted.
expected := `
apiVersion: apps/v1
kind: Deployment
metadata:
name: whatever
spec:
template:
spec:
containers:
- env:
- name: EXISTING
value: EXISTING_VALUE
image: helloworld
name: whatever
`
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, expected)
}
|