| 1 |
// Copyright 2019 The Kubernetes Authors. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package krusty_test |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" |
| 10 |
) |
| 11 |
|
| 12 |
// This test checks that if a resource is annotated as "local-config", this resource won't be ignored until |
| 13 |
// all transformations have completed. This makes sure the local resource can be used as a transformation input. |
| 14 |
// See https://github.com/kubernetes-sigs/kustomize/issues/4124 for details. |
| 15 |
func TestSKipLocalConfigAfterTransform(t *testing.T) { |
| 16 |
th := kusttest_test.MakeHarness(t) |
| 17 |
th.WriteK(".", `resources: |
| 18 |
- pod.yaml |
| 19 |
- deployment.yaml |
| 20 |
transformers: |
| 21 |
- replacement.yaml |
| 22 |
`) |
| 23 |
th.WriteF("pod.yaml", `apiVersion: v1 |
| 24 |
kind: Pod |
| 25 |
metadata: |
| 26 |
name: buildup |
| 27 |
annotations: |
| 28 |
config.kubernetes.io/local-config: "true" |
| 29 |
spec: |
| 30 |
containers: |
| 31 |
- name: app |
| 32 |
image: nginx |
| 33 |
`) |
| 34 |
th.WriteF("deployment.yaml", `apiVersion: apps/v1 |
| 35 |
kind: Deployment |
| 36 |
metadata: |
| 37 |
name: buildup |
| 38 |
`) |
| 39 |
th.WriteF("replacement.yaml", ` |
| 40 |
apiVersion: builtin |
| 41 |
kind: ReplacementTransformer |
| 42 |
metadata: |
| 43 |
name: buildup |
| 44 |
replacements: |
| 45 |
- source: |
| 46 |
kind: Pod |
| 47 |
fieldPath: spec |
| 48 |
targets: |
| 49 |
- select: |
| 50 |
kind: Deployment |
| 51 |
fieldPaths: |
| 52 |
- spec.template.spec |
| 53 |
options: |
| 54 |
create: true |
| 55 |
`) |
| 56 |
m := th.Run(".", th.MakeDefaultOptions()) |
| 57 |
th.AssertActualEqualsExpected(m, `apiVersion: apps/v1 |
| 58 |
kind: Deployment |
| 59 |
metadata: |
| 60 |
name: buildup |
| 61 |
spec: |
| 62 |
template: |
| 63 |
spec: |
| 64 |
containers: |
| 65 |
- image: nginx |
| 66 |
name: app |
| 67 |
`) |
| 68 |
} |