mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-10 08:20:59 +00:00
Define some constants in a test for later reuse.
This commit is contained in:
@@ -10,6 +10,44 @@ import (
|
||||
kusttest_test "sigs.k8s.io/kustomize/v3/pkg/kusttest"
|
||||
)
|
||||
|
||||
const patchAddProbe = `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-deployment
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: my-deployment
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /healthz
|
||||
port: 8080
|
||||
`
|
||||
|
||||
const patchDnsPolicy = `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-deployment
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
dnsPolicy: ClusterFirst
|
||||
`
|
||||
|
||||
const patchRestartPolicy = `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-deployment
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
restartPolicy: Always
|
||||
`
|
||||
|
||||
// Here's a composite kustomization, that combines multiple overlays
|
||||
// (replicas, dns and metadata) which patch the same base resource.
|
||||
//
|
||||
@@ -47,77 +85,30 @@ func writeProbeOverlay(th *kusttest_test.KustTestHarness) {
|
||||
th.WriteK("/app/probe", `
|
||||
resources:
|
||||
- ../base
|
||||
|
||||
patchesStrategicMerge:
|
||||
- dep-patch.yaml
|
||||
`)
|
||||
|
||||
th.WriteF("/app/probe/dep-patch.yaml", `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-deployment
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: my-deployment
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /healthz
|
||||
port: 8080
|
||||
`)
|
||||
th.WriteF("/app/probe/dep-patch.yaml", patchAddProbe)
|
||||
}
|
||||
|
||||
func writeDNSOverlay(th *kusttest_test.KustTestHarness) {
|
||||
th.WriteK("/app/dns", `
|
||||
resources:
|
||||
- ../base
|
||||
|
||||
patchesStrategicMerge:
|
||||
- dep-patch.yaml
|
||||
`)
|
||||
|
||||
th.WriteF("/app/dns/dep-patch.yaml", `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-deployment
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
dnsPolicy: ClusterFirst
|
||||
`)
|
||||
th.WriteF("/app/dns/dep-patch.yaml", patchDnsPolicy)
|
||||
}
|
||||
|
||||
func writeRestartOverlay(th *kusttest_test.KustTestHarness) {
|
||||
th.WriteK("/app/restart", `
|
||||
resources:
|
||||
- ../base
|
||||
|
||||
patchesStrategicMerge:
|
||||
- dep-patch.yaml
|
||||
`)
|
||||
|
||||
th.WriteF("/app/restart/dep-patch.yaml", `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-deployment
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
restartPolicy: Always
|
||||
`)
|
||||
}
|
||||
|
||||
func writeComposite(th *kusttest_test.KustTestHarness) {
|
||||
th.WriteK("/app/composite", `
|
||||
resources:
|
||||
- ../probe
|
||||
- ../dns
|
||||
- ../restart
|
||||
`)
|
||||
th.WriteF("/app/restart/dep-patch.yaml", patchRestartPolicy)
|
||||
}
|
||||
|
||||
func TestCompositeDiamond(t *testing.T) {
|
||||
@@ -126,7 +117,13 @@ func TestCompositeDiamond(t *testing.T) {
|
||||
writeProbeOverlay(th)
|
||||
writeDNSOverlay(th)
|
||||
writeRestartOverlay(th)
|
||||
writeComposite(th)
|
||||
|
||||
th.WriteK("/app/composite", `
|
||||
resources:
|
||||
- ../probe
|
||||
- ../dns
|
||||
- ../restart
|
||||
`)
|
||||
|
||||
_, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user