re-enabled TestFnContainerTransformer with e2econtainerconfig container

This commit is contained in:
yutaroyamanaka
2023-03-27 21:33:57 +09:00
parent bf6e6ad33b
commit 436a047617

View File

@@ -714,103 +714,49 @@ spec:
} }
func TestFnContainerTransformer(t *testing.T) { func TestFnContainerTransformer(t *testing.T) {
t.Skip("wait for #3881")
skipIfNoDocker(t) skipIfNoDocker(t)
// Function plugins should not need the env setup done by MakeEnhancedHarness
th := kusttest_test.MakeHarness(t) th := kusttest_test.MakeHarness(t)
o := th.MakeOptionsPluginsEnabled()
th.WriteK(".", ` fSys := filesys.MakeFsOnDisk()
b := MakeKustomizer(&o)
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
resources: resources:
- data.yaml - deployment.yaml
transformers: transformers:
- transf1.yaml - e2econtainerconfig.yaml
- transf2.yaml `)))
`) assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "deployment.yaml"), []byte(`
th.WriteF("data.yaml", `
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: nginx name: foo
labels: `)))
app: nginx
annotations: assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "e2econtainerconfig.yaml"), []byte(`
tshirt-size: small # this injects the resource reservations apiVersion: example.com/v1alpha1
spec: kind: Input
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
`)
// This transformer should add resource reservations based on annotation in data.yaml
// See https://github.com/kubernetes-sigs/kustomize/tree/master/functions/examples/injection-tshirt-sizes
th.WriteF("transf1.yaml", `
apiVersion: examples.config.kubernetes.io/v1beta1
kind: Validator
metadata: metadata:
name: valid name: foo
annotations:
config.kubernetes.io/function: |-
container:
image: gcr.io/kustomize-functions/example-tshirt:v0.2.0
`)
// This transformer will check resources without and won't do any changes
// See https://github.com/kubernetes-sigs/kustomize/tree/master/functions/examples/validator-kubeval
th.WriteF("transf2.yaml", `
apiVersion: examples.config.kubernetes.io/v1beta1
kind: Kubeval
metadata:
name: validate
annotations: annotations:
config.kubernetes.io/function: | config.kubernetes.io/function: |
container: container:
image: gcr.io/kustomize-functions/example-validator-kubeval:v0.1.0 image: "gcr.io/kustomize-functions/e2econtainerconfig"
spec: `)))
strict: true m, err := b.Run(fSys, tmpDir.String())
ignoreMissingSchemas: true assert.NoError(t, err)
actual, err := m.AsYaml()
# TODO: Update this to use network/volumes features. assert.NoError(t, err)
# Relevant issues: assert.Equal(t, `apiVersion: apps/v1
# - https://github.com/kubernetes-sigs/kustomize/issues/1901
# - https://github.com/kubernetes-sigs/kustomize/issues/1902
kubernetesVersion: "1.16.0"
schemaLocation: "file:///schemas"
`)
m := th.Run(".", th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
annotations: annotations:
tshirt-size: small a-bool-value: "false"
labels: a-int-value: "0"
app: nginx a-string-value: ""
name: nginx name: foo
spec: `, string(actual))
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
name: nginx
resources:
requests:
cpu: 200m
memory: 50M
`)
} }
func TestFnContainerTransformerWithConfig(t *testing.T) { func TestFnContainerTransformerWithConfig(t *testing.T) {