mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 02:20:53 +00:00
Updates in image transformer (#911)
- Decouple `mutateImage` from `updateContainers` to be reused as `mutateFunc` - Ignore default image transform error for CRD which may contain non-array type `containers` field Related to #890, #904, fixes #890
This commit is contained in:
committed by
Jingfang Liu
parent
21a0cba43e
commit
2490e605c3
@@ -320,3 +320,64 @@ spec:
|
||||
action: makehoney
|
||||
`)
|
||||
}
|
||||
|
||||
func TestCrdWithContainers(t *testing.T) {
|
||||
th := NewKustTestHarness(t, "/app/crd/containers")
|
||||
th.writeK("/app/crd/containers", `
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- crd.yaml
|
||||
|
||||
images:
|
||||
- name: test/test
|
||||
newName: registry.gitlab.com/test
|
||||
newTag: latest
|
||||
`)
|
||||
th.writeF("/app/crd/containers/crd.yaml", `
|
||||
apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
name: crontabs.stable.example.com
|
||||
spec:
|
||||
group: stable.example.com
|
||||
scope: Namespaced
|
||||
names:
|
||||
plural: crontabs
|
||||
singular: crontab
|
||||
kind: CronTab
|
||||
shortNames:
|
||||
- ct
|
||||
validation:
|
||||
openAPIV3Schema:
|
||||
properties:
|
||||
spec:
|
||||
containers:
|
||||
description: Containers allows injecting additional containers
|
||||
`)
|
||||
m, err := th.makeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
th.assertActualEqualsExpected(m, `
|
||||
apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
name: crontabs.stable.example.com
|
||||
spec:
|
||||
group: stable.example.com
|
||||
names:
|
||||
kind: CronTab
|
||||
plural: crontabs
|
||||
shortNames:
|
||||
- ct
|
||||
singular: crontab
|
||||
scope: Namespaced
|
||||
validation:
|
||||
openAPIV3Schema:
|
||||
properties:
|
||||
spec:
|
||||
containers:
|
||||
description: Containers allows injecting additional containers
|
||||
`)
|
||||
}
|
||||
|
||||
@@ -233,11 +233,11 @@ spec3:
|
||||
th.writeF("/app/base/config/custom.yaml", `
|
||||
images:
|
||||
- kind: Custom
|
||||
path: spec/template/spec/myContainers
|
||||
path: spec/template/spec/myContainers/image
|
||||
- kind: Custom
|
||||
path: spec2/template/spec/myContainers
|
||||
path: spec2/template/spec/myContainers/image
|
||||
- kind: Custom
|
||||
path: spec3/template/spec/myInitContainers
|
||||
path: spec3/template/spec/myInitContainers/image
|
||||
`)
|
||||
}
|
||||
func TestTransfomersImageCustomConfig(t *testing.T) {
|
||||
@@ -283,3 +283,56 @@ spec3:
|
||||
name: my-cool-app
|
||||
`)
|
||||
}
|
||||
|
||||
func makeTransfomersImageKnativeBase(th *KustTestHarness) {
|
||||
th.writeK("/app/base", `
|
||||
resources:
|
||||
- knative.yaml
|
||||
configurations:
|
||||
- config/knative.yaml
|
||||
images:
|
||||
- name: solsa-echo
|
||||
newTag: foo
|
||||
`)
|
||||
th.writeF("/app/base/knative.yaml", `
|
||||
apiVersion: serving.knative.dev/v1alpha1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: echo
|
||||
spec:
|
||||
runLatest:
|
||||
configuration:
|
||||
revisionTemplate:
|
||||
spec:
|
||||
container:
|
||||
image: solsa-echo
|
||||
`)
|
||||
th.writeF("/app/base/config/knative.yaml", `
|
||||
images:
|
||||
- path: spec/runLatest/configuration/revisionTemplate/spec/container/image
|
||||
apiVersion: serving.knative.dev/v1alpha1
|
||||
kind: Service
|
||||
`)
|
||||
}
|
||||
|
||||
func TestTransfomersImageKnativeConfig(t *testing.T) {
|
||||
th := NewKustTestHarness(t, "/app/base")
|
||||
makeTransfomersImageKnativeBase(th)
|
||||
m, err := th.makeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
th.assertActualEqualsExpected(m, `
|
||||
apiVersion: serving.knative.dev/v1alpha1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: echo
|
||||
spec:
|
||||
runLatest:
|
||||
configuration:
|
||||
revisionTemplate:
|
||||
spec:
|
||||
container:
|
||||
image: solsa-echo:foo
|
||||
`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user