-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add inline patch support for Strategic Merge Patch and JSON patch
- Loading branch information
1 parent
a9848f2
commit 35481ec
Showing
6 changed files
with
273 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
// Copyright 2019 The Kubernetes Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package target_test | ||
|
||
import ( | ||
"sigs.k8s.io/kustomize/v3/pkg/kusttest" | ||
"testing" | ||
) | ||
|
||
func makeResourcesForPatchTest(th *kusttest_test.KustTestHarness) { | ||
th.WriteF("/app/base/deployment.yaml", ` | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx | ||
labels: | ||
app: nginx | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx | ||
volumeMounts: | ||
- name: nginx-persistent-storage | ||
mountPath: /tmp/ps | ||
volumes: | ||
- name: nginx-persistent-storage | ||
emptyDir: {} | ||
- configMap: | ||
name: configmap-in-base | ||
name: configmap-in-base | ||
`) | ||
} | ||
|
||
func TestStrategicMergePatchInline(t *testing.T) { | ||
th := kusttest_test.NewKustTestHarness(t, "/app/base") | ||
makeResourcesForPatchTest(th) | ||
th.WriteK("/app/base", ` | ||
resources: | ||
- deployment.yaml | ||
patchesStrategicMerge: | ||
- |- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: image1 | ||
`) | ||
m, err := th.MakeKustTarget().MakeCustomizedResMap() | ||
if err != nil { | ||
t.Fatalf("Err: %v", err) | ||
} | ||
th.AssertActualEqualsExpected(m, ` | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: nginx | ||
name: nginx | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- image: image1 | ||
name: nginx | ||
volumeMounts: | ||
- mountPath: /tmp/ps | ||
name: nginx-persistent-storage | ||
volumes: | ||
- emptyDir: {} | ||
name: nginx-persistent-storage | ||
- configMap: | ||
name: configmap-in-base | ||
name: configmap-in-base | ||
`) | ||
} | ||
|
||
func TestJSONPatchInline(t *testing.T) { | ||
th := kusttest_test.NewKustTestHarness(t, "/app/base") | ||
makeResourcesForPatchTest(th) | ||
th.WriteK("/app/base", ` | ||
resources: | ||
- deployment.yaml | ||
patchesJson6902: | ||
- target: | ||
group: apps | ||
version: v1 | ||
kind: Deployment | ||
name: nginx | ||
patch: |- | ||
- op: replace | ||
path: /spec/template/spec/containers/0/image | ||
value: image1 | ||
`) | ||
m, err := th.MakeKustTarget().MakeCustomizedResMap() | ||
if err != nil { | ||
t.Fatalf("Err: %v", err) | ||
} | ||
th.AssertActualEqualsExpected(m, ` | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: nginx | ||
name: nginx | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- image: image1 | ||
name: nginx | ||
volumeMounts: | ||
- mountPath: /tmp/ps | ||
name: nginx-persistent-storage | ||
volumes: | ||
- emptyDir: {} | ||
name: nginx-persistent-storage | ||
- configMap: | ||
name: configmap-in-base | ||
name: configmap-in-base | ||
`) | ||
} | ||
|
||
func TestExtendedPatchInlineJSON(t *testing.T) { | ||
th := kusttest_test.NewKustTestHarness(t, "/app/base") | ||
makeResourcesForPatchTest(th) | ||
th.WriteK("/app/base", ` | ||
resources: | ||
- deployment.yaml | ||
patches: | ||
- target: | ||
kind: Deployment | ||
name: nginx | ||
patch: |- | ||
- op: replace | ||
path: /spec/template/spec/containers/0/image | ||
value: image1 | ||
`) | ||
m, err := th.MakeKustTarget().MakeCustomizedResMap() | ||
if err != nil { | ||
t.Fatalf("Err: %v", err) | ||
} | ||
th.AssertActualEqualsExpected(m, ` | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: nginx | ||
name: nginx | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- image: image1 | ||
name: nginx | ||
volumeMounts: | ||
- mountPath: /tmp/ps | ||
name: nginx-persistent-storage | ||
volumes: | ||
- emptyDir: {} | ||
name: nginx-persistent-storage | ||
- configMap: | ||
name: configmap-in-base | ||
name: configmap-in-base | ||
`) | ||
} | ||
|
||
func TestExtendedPatchInlineYAML(t *testing.T) { | ||
th := kusttest_test.NewKustTestHarness(t, "/app/base") | ||
makeResourcesForPatchTest(th) | ||
th.WriteK("/app/base", ` | ||
resources: | ||
- deployment.yaml | ||
patches: | ||
- target: | ||
kind: Deployment | ||
name: nginx | ||
patch: |- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: image1 | ||
`) | ||
m, err := th.MakeKustTarget().MakeCustomizedResMap() | ||
if err != nil { | ||
t.Fatalf("Err: %v", err) | ||
} | ||
th.AssertActualEqualsExpected(m, ` | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: nginx | ||
name: nginx | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- image: image1 | ||
name: nginx | ||
volumeMounts: | ||
- mountPath: /tmp/ps | ||
name: nginx-persistent-storage | ||
volumes: | ||
- emptyDir: {} | ||
name: nginx-persistent-storage | ||
- configMap: | ||
name: configmap-in-base | ||
name: configmap-in-base | ||
`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters