From 0b555e1b2c7cf1e30799e78be44cad72bde89315 Mon Sep 17 00:00:00 2001 From: Jeffrey Regan Date: Mon, 17 Jun 2019 14:41:43 -0700 Subject: [PATCH] Modify tests to present expected data in unsorted order. Modify all `build` tests to use the raw, non-sorted output of build. This makes every test provide coverage for how kustomize re-orders (or doesn't reorder) resources during processing. Going forward, the ordering of resources in _expected_ output should match the depth-first ordering specified in the `resources:` field used in the test's kustomization file. The only exception to this rule would be tests that actually confirmed some other output ordering, e.g. the test of the `LegacyOrderTransformer` plugin. Fixes #756 Related #821 --- docs/images/sorted.png | Bin 0 -> 10601 bytes docs/v_2.1.0.md | 114 ++++++--- pkg/kusttest/kusttestharness.go | 14 -- pkg/target/baseandoverlaymedium_test.go | 143 ++++++----- pkg/target/baseandoverlaysmall_test.go | 125 +++++----- pkg/target/chartinflatorplugin_test.go | 36 +-- pkg/target/configmaps_test.go | 6 +- pkg/target/crd_test.go | 3 +- pkg/target/customconfig_test.go | 37 ++- pkg/target/generatormergeandreplace_test.go | 222 +++++++++--------- pkg/target/generatoroptions_test.go | 20 +- pkg/target/kusttarget_test.go | 14 +- pkg/target/multiplepatch_test.go | 88 +++---- pkg/target/pruneconfigmap_test.go | 64 ++--- pkg/target/resourceconflict_test.go | 19 +- pkg/target/variableref_test.go | 196 ++++++++-------- .../InventoryTransformer_test.go | 4 +- .../NamespaceTransformer_test.go | 30 +-- .../PrefixSuffixTransformer_test.go | 16 +- .../ReplicaCountTransformer_test.go | 8 +- .../v1/chartinflator/ChartInflator_test.go | 36 +-- 21 files changed, 613 insertions(+), 582 deletions(-) create mode 100644 docs/images/sorted.png diff --git a/docs/images/sorted.png b/docs/images/sorted.png new file mode 100644 index 0000000000000000000000000000000000000000..64d7fcceebaf65627e69322cbb4d44ec5217a1ce GIT binary patch literal 10601 zcmZ`AuT4X>Y;z;1E;B~kF0HB~D10jUF`JlND*eNUE{wr>ALy4uuANmssArk?n z{UMYJ+5Dw6k)i+9&XXNs{r4Cd+Cs>mN(D!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++ b/docs/v_2.1.0.md @@ -6,6 +6,7 @@ [imgModules]: images/goModules.png [imgPlugins]: images/plugins.png [imgPruning]: images/pruning.png +[imgSorted]: images/sorted.png [imgWheels]: images/abandonedTrainingWheels.png [kustomization]: glossary.md#kustomization [_kustomization_]: glossary.md#kustomization @@ -25,8 +26,6 @@ _Summary_: Go modules, inventory, plugins, eased loading restrictions, and about ~80 issues closed since [v2.0.3] (over 300 commits). - - ## Go modules ![gopher with boxes][imgModules] @@ -38,23 +37,27 @@ as one or more [Go modules] for use in other programs (kubectl, kubebuilder, etc.) and in kustomize plugins (see below). +## Resource ordering -## Inventory generation for pruning +![sort order retained][imgSorted] -![pruning dead branches][imgPruning] +Kustomize now retains the depth-first order of +resources as read. -Users can add an `inventory` stanza to their -kustomization file, to add a special _inventory -object_ to the `build` result. +The `build` command now accepts a `--reorder` +flag with values `legacy` and `none`, +with a default value of `legacy`. -This object applies to the cluster along with -everything else in the build result and can be -used by other clients to intelligently _prune_ -orphaned cluster resources. - -For more information see the -[kustomize inventory object documentation]. +`legacy` means apply an ordering based on +GVK, that currently emits `Namespace` objects +first, and `ValidatingWebhookConfiguration` +objects last. +`none` means do not reorder the resources before +output. This means kustomize respects the input +order of the data, giving the user a means to +control output order. Generated resources always +come last. ## Generator and transformer plugins @@ -82,7 +85,7 @@ requests for kustomize revolve around changing the behavior of the builtin generators and transformers. -[v2.1.0] adds a _alpha_ plugin framework, that +[v2.1.0] adds an _alpha_ plugin framework, that encourages users to write their own generators or transformers, _declaring them as kubernetes objects just like everything else_, and apply them @@ -93,7 +96,7 @@ confirm that the plugin framework can offer plugin authors the same capabilities as builtin operations, all the builtin generators and tranformers have been converted to plugin form -(with a few exceptions awaiting Go module +(with one exceptions awaiting Go module refinements). This means that adding, say, a `secretGenerator` or `commonAnnotations` directive to your kustomization will (in [v2.1.0]) trigger @@ -126,34 +129,79 @@ patch file. To share _resources_, use a relative path or URL to a kustomization directory in the `resources` directive. +## Inventory generation for pruning + +![pruning dead branches][imgPruning] + +_Alpha_ + +Users can add an `inventory` stanza to their +kustomization file, to add a special _inventory +object_ to the `build` result. + +This object applies to the cluster along with +everything else in the build result and can be +used by other clients to intelligently _prune_ +orphaned cluster resources. + +For more information see the +[kustomize inventory object documentation]. + ## Field changes / deprecations * Generalized `resources` field. - The `resources` field has been generalized, and - can now accept what formerly could only - be specified in the `bases` field. + The `resources` field has been generalized; it + now accepts what formerly could only be + specified in the `bases` field. This change was made so that the `resources`, `generators` and `transformers` fields all accept the same argument format. - Each field's argument is a _string list_, where - each entry is either a _resource_ (a relative - path to a YAML file) or a [_kustomization_] (a - relative path or URL pointing to a directory - with a kustomization file). A kustomization - directory used in this context is called a - [_base_]. + > Each field's argument is a _string list_, + > where each entry is either a _resource_ (a + > relative path to a YAML file) or a + > [_kustomization_] (a relative path or URL + > pointing to a directory with a kustomization + > file). A kustomization directory used in this + > context is called a [_base_]. - The `bases` field still works, but is no longer - necessary, and will likely be deprecated in the - next release. The _base_ as a concept is as - important as ever, it's just that two new fields - (`generators` and `tranformers`) and one existing - field (`resources`) now accept arguments - that were once accepted only by `bases`. + The `bases` field still works, but is + deprecated. Deal with this by simply moving the + arguments of the `bases` field to the + `resources` field in the desired order, e.g. + + > ``` + > resources: + > - someResouceFile.yaml + > - someOtherResourceFile.yaml + > bases: + > - ../../someBaseDir + > ``` + + could become + + > ``` + > resources: + > - someResouceFile.yaml + > - ../../someBaseDir + > - someOtherResourceFile.yaml + > ``` + + The depth-first traversal order of items in the + `resources:` field is respected by + kustomize, allowing one to, say, process + `someBaseDir` between the two resource files. + See this discussion of + [the `build --reorder` flag](#resource-ordering). + + The _base_ as a concept is as important as ever, + it's just that two new fields (`generators` and + `tranformers`) and one existing field + (`resources`) now accept arguments that were + once accepted only by `bases`. The fact that the `generators` and `transformers` field accept [bases] diff --git a/pkg/kusttest/kusttestharness.go b/pkg/kusttest/kusttestharness.go index a52b9553b..0b46d94b2 100644 --- a/pkg/kusttest/kusttestharness.go +++ b/pkg/kusttest/kusttestharness.go @@ -20,7 +20,6 @@ import ( "sigs.k8s.io/kustomize/pkg/target" "sigs.k8s.io/kustomize/pkg/transformers/config/defaultconfig" "sigs.k8s.io/kustomize/pkg/types" - "sigs.k8s.io/kustomize/plugin/builtin" ) // KustTestHarness helps test kustomization generation and transformation. @@ -190,16 +189,6 @@ func hint(a, b string) string { func (th *KustTestHarness) AssertActualEqualsExpected( m resmap.ResMap, expected string) { - th.assertActualEqualsExpected(m, expected, true) -} - -func (th *KustTestHarness) AssertActualEqualsExpectedNoSort( - m resmap.ResMap, expected string) { - th.assertActualEqualsExpected(m, expected, false) -} - -func (th *KustTestHarness) assertActualEqualsExpected( - m resmap.ResMap, expected string, doLegacySort bool) { if m == nil { th.t.Fatalf("Map should not be nil.") } @@ -208,9 +197,6 @@ func (th *KustTestHarness) assertActualEqualsExpected( if len(expected) > 0 && expected[0] == 10 { expected = expected[1:] } - if doLegacySort { - builtin.NewLegacyOrderTransformerPlugin().Transform(m) - } actual, err := m.AsYaml() if err != nil { th.t.Fatalf("Unexpected err: %v", err) diff --git a/pkg/target/baseandoverlaymedium_test.go b/pkg/target/baseandoverlaymedium_test.go index 67d5d9543..d8de8fc61 100644 --- a/pkg/target/baseandoverlaymedium_test.go +++ b/pkg/target/baseandoverlaymedium_test.go @@ -79,22 +79,6 @@ func TestMediumBase(t *testing.T) { t.Fatalf("Err: %v", err) } th.AssertActualEqualsExpected(m, ` -apiVersion: v1 -kind: Service -metadata: - annotations: - baseAnno: This is a base annotation - labels: - app: mungebot - foo: bar - name: baseprefix-mungebot-service -spec: - ports: - - port: 7002 - selector: - app: mungebot - foo: bar ---- apiVersion: extensions/v1beta1 kind: Deployment metadata: @@ -125,6 +109,22 @@ spec: name: nginx ports: - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + baseAnno: This is a base annotation + labels: + app: mungebot + foo: bar + name: baseprefix-mungebot-service +spec: + ports: + - port: 7002 + selector: + app: mungebot + foo: bar `) } @@ -139,7 +139,7 @@ commonLabels: repo: test-infra commonAnnotations: note: This is a test annotation -bases: +resources: - ../base patchesStrategicMerge: - deployment/deployment.yaml @@ -210,63 +210,7 @@ spec: if err != nil { t.Fatalf("Err: %v", err) } - // TODO(#669): The name of the patched Deployment is - // test-infra-baseprefix-mungebot, retaining the base - // prefix (example of correct behavior). th.AssertActualEqualsExpected(m, ` -apiVersion: v1 -data: - nonsense: "Lorem ipsum dolor sit amet, consectetur\nadipiscing elit, sed do eiusmod - tempor\nincididunt ut labore et dolore magna aliqua. \n" -kind: ConfigMap -metadata: - annotations: - note: This is a test annotation - labels: - app: mungebot - org: kubernetes - repo: test-infra - name: test-infra-app-config-f462h769f9 ---- -apiVersion: v1 -data: - DB_PASSWORD: somepw - DB_USERNAME: admin - ENERGY: electronvolt - FRUIT: banana - LEGUME: chickpea - LENGTH: kilometer -kind: ConfigMap -metadata: - annotations: - note: This is a test annotation - labels: - app: mungebot - org: kubernetes - repo: test-infra - name: test-infra-app-env-ffmd9b969m ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - baseAnno: This is a base annotation - note: This is a test annotation - labels: - app: mungebot - foo: bar - org: kubernetes - repo: test-infra - name: test-infra-baseprefix-mungebot-service -spec: - ports: - - port: 7002 - selector: - app: mungebot - foo: bar - org: kubernetes - repo: test-infra ---- apiVersion: extensions/v1beta1 kind: Deployment metadata: @@ -325,5 +269,58 @@ spec: - configMap: name: test-infra-app-env-ffmd9b969m name: app-env +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + baseAnno: This is a base annotation + note: This is a test annotation + labels: + app: mungebot + foo: bar + org: kubernetes + repo: test-infra + name: test-infra-baseprefix-mungebot-service +spec: + ports: + - port: 7002 + selector: + app: mungebot + foo: bar + org: kubernetes + repo: test-infra +--- +apiVersion: v1 +data: + DB_PASSWORD: somepw + DB_USERNAME: admin + ENERGY: electronvolt + FRUIT: banana + LEGUME: chickpea + LENGTH: kilometer +kind: ConfigMap +metadata: + annotations: + note: This is a test annotation + labels: + app: mungebot + org: kubernetes + repo: test-infra + name: test-infra-app-env-ffmd9b969m +--- +apiVersion: v1 +data: + nonsense: "Lorem ipsum dolor sit amet, consectetur\nadipiscing elit, sed do eiusmod + tempor\nincididunt ut labore et dolore magna aliqua. \n" +kind: ConfigMap +metadata: + annotations: + note: This is a test annotation + labels: + app: mungebot + org: kubernetes + repo: test-infra + name: test-infra-app-config-f462h769f9 `) } diff --git a/pkg/target/baseandoverlaysmall_test.go b/pkg/target/baseandoverlaysmall_test.go index 38fc5b1ba..a8f1d0a55 100644 --- a/pkg/target/baseandoverlaysmall_test.go +++ b/pkg/target/baseandoverlaysmall_test.go @@ -83,7 +83,7 @@ metadata: if err != nil { t.Fatalf("Err: %v", err) } - th.AssertActualEqualsExpectedNoSort(m, ` + th.AssertActualEqualsExpected(m, ` apiVersion: v1 kind: Namespace metadata: @@ -197,19 +197,6 @@ func TestSmallBase(t *testing.T) { t.Fatalf("Err: %v", err) } th.AssertActualEqualsExpected(m, ` -apiVersion: v1 -kind: Service -metadata: - labels: - app: myApp - name: a-myService -spec: - ports: - - port: 7002 - selector: - app: myApp - backend: bungie ---- apiVersion: apps/v1 kind: Deployment metadata: @@ -229,6 +216,19 @@ spec: containers: - image: whatever name: whatever +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: myApp + name: a-myService +spec: + ports: + - port: 7002 + selector: + app: myApp + backend: bungie `) } @@ -239,7 +239,7 @@ func TestSmallOverlay(t *testing.T) { namePrefix: b- commonLabels: env: prod -bases: +resources: - ../base patchesStrategicMerge: - deployment/deployment.yaml @@ -268,25 +268,7 @@ spec: if err != nil { t.Fatalf("Err: %v", err) } - // TODO(#669): The name of the patched Deployment is - // b-a-myDeployment, retaining the base prefix - // (example of correct behavior). th.AssertActualEqualsExpected(m, ` -apiVersion: v1 -kind: Service -metadata: - labels: - app: myApp - env: prod - name: b-a-myService -spec: - ports: - - port: 7002 - selector: - app: myApp - backend: bungie - env: prod ---- apiVersion: apps/v1 kind: Deployment metadata: @@ -310,6 +292,21 @@ spec: containers: - image: whatever:1.8.0 name: whatever +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: myApp + env: prod + name: b-a-myService +spec: + ports: + - port: 7002 + selector: + app: myApp + backend: bungie + env: prod `) } @@ -321,7 +318,7 @@ func TestSharedPatchDisAllowed(t *testing.T) { th.WriteK("/app/overlay", ` commonLabels: env: prod -bases: +resources: - ../base patchesStrategicMerge: - ../shared/deployment-patch.yaml @@ -353,7 +350,7 @@ func TestSharedPatchAllowed(t *testing.T) { th.WriteK("/app/overlay", ` commonLabels: env: prod -bases: +resources: - ../base patchesStrategicMerge: - ../shared/deployment-patch.yaml @@ -371,21 +368,6 @@ spec: t.Fatalf("Err: %v", err) } th.AssertActualEqualsExpected(m, ` -apiVersion: v1 -kind: Service -metadata: - labels: - app: myApp - env: prod - name: a-myService -spec: - ports: - - port: 7002 - selector: - app: myApp - backend: bungie - env: prod ---- apiVersion: apps/v1 kind: Deployment metadata: @@ -409,6 +391,21 @@ spec: containers: - image: whatever name: whatever +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: myApp + env: prod + name: a-myService +spec: + ports: + - port: 7002 + selector: + app: myApp + backend: bungie + env: prod `) } @@ -416,7 +413,7 @@ func TestSmallOverlayJSONPatch(t *testing.T) { th := kusttest_test.NewKustTestHarness(t, "/app/overlay") writeSmallBase(th) th.WriteK("/app/overlay", ` -bases: +resources: - ../base patchesJson6902: - target: @@ -436,19 +433,6 @@ patchesJson6902: t.Fatalf("Err: %v", err) } th.AssertActualEqualsExpected(m, ` -apiVersion: v1 -kind: Service -metadata: - labels: - app: myApp - name: a-myService -spec: - ports: - - port: 7002 - selector: - app: myApp - backend: beagle ---- apiVersion: apps/v1 kind: Deployment metadata: @@ -468,5 +452,18 @@ spec: containers: - image: whatever name: whatever +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: myApp + name: a-myService +spec: + ports: + - port: 7002 + selector: + app: myApp + backend: beagle `) } diff --git a/pkg/target/chartinflatorplugin_test.go b/pkg/target/chartinflatorplugin_test.go index f744976c4..f2264a931 100644 --- a/pkg/target/chartinflatorplugin_test.go +++ b/pkg/target/chartinflatorplugin_test.go @@ -68,6 +68,24 @@ metadata: type: Opaque --- apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + volume.alpha.kubernetes.io/storage-class: default + labels: + app: release-name-minecraft + chart: minecraft-1.0.3 + heritage: Tiller + release: release-name + name: LOOOOOOOONG-release-name-minecraft-datadir +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi +--- +apiVersion: v1 kind: Service metadata: labels: @@ -85,23 +103,5 @@ spec: selector: app: release-name-minecraft type: LoadBalancer ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - annotations: - volume.alpha.kubernetes.io/storage-class: default - labels: - app: release-name-minecraft - chart: minecraft-1.0.3 - heritage: Tiller - release: release-name - name: LOOOOOOOONG-release-name-minecraft-datadir -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi `) } diff --git a/pkg/target/configmaps_test.go b/pkg/target/configmaps_test.go index edc275e2b..854d295d9 100644 --- a/pkg/target/configmaps_test.go +++ b/pkg/target/configmaps_test.go @@ -190,7 +190,7 @@ configMapGenerator: - from=base `) th.WriteK("/app/overlay/o1", ` -bases: +resources: - ../../base1 configMapGenerator: - name: com1 @@ -199,7 +199,7 @@ configMapGenerator: - from=overlay `) th.WriteK("/app/overlay/o2", ` -bases: +resources: - ../../base2 configMapGenerator: - name: com2 @@ -208,7 +208,7 @@ configMapGenerator: - from=overlay `) th.WriteK("/app/overlay", ` -bases: +resources: - o1 - o2 configMapGenerator: diff --git a/pkg/target/crd_test.go b/pkg/target/crd_test.go index 09f5a297a..2c638a75e 100644 --- a/pkg/target/crd_test.go +++ b/pkg/target/crd_test.go @@ -278,7 +278,7 @@ func TestCrdWithOverlay(t *testing.T) { apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization namePrefix: prod- -bases: +resources: - ../base patchesStrategicMerge: - bee.yaml @@ -330,7 +330,6 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - crd.yaml - images: - name: test/test newName: registry.gitlab.com/test diff --git a/pkg/target/customconfig_test.go b/pkg/target/customconfig_test.go index 79c84d660..2fa2ade44 100644 --- a/pkg/target/customconfig_test.go +++ b/pkg/target/customconfig_test.go @@ -41,27 +41,27 @@ vars: fieldref: fieldpath: spec.diet resources: +- animalPark.yaml - giraffes.yaml - gorilla.yaml -- animalPark.yaml configurations: - config/defaults.yaml - config/custom.yaml `) th.WriteF("/app/base/giraffes.yaml", ` kind: Giraffe -metadata: - name: may -spec: - diet: acacia - location: SE ---- -kind: Giraffe metadata: name: april spec: diet: mimosa location: NE +--- +kind: Giraffe +metadata: + name: may +spec: + diet: acacia + location: SE `) th.WriteF("/app/base/gorilla.yaml", ` kind: Gorilla @@ -248,9 +248,8 @@ commonLabels: patchesStrategicMerge: - animalPark.yaml resources: -- ursus.yaml -bases: - ../base +- ursus.yaml `) th.WriteF("/app/overlay/ursus.yaml", ` kind: Gorilla @@ -312,15 +311,6 @@ spec: location: SE --- kind: Gorilla -metadata: - labels: - movie: planetOfTheApes - name: o-ursus -spec: - diet: heston - location: Arizona ---- -kind: Gorilla metadata: labels: app: myApp @@ -329,5 +319,14 @@ metadata: spec: diet: bambooshoots location: SW +--- +kind: Gorilla +metadata: + labels: + movie: planetOfTheApes + name: o-ursus +spec: + diet: heston + location: Arizona `) } diff --git a/pkg/target/generatormergeandreplace_test.go b/pkg/target/generatormergeandreplace_test.go index f22038019..30a12b201 100644 --- a/pkg/target/generatormergeandreplace_test.go +++ b/pkg/target/generatormergeandreplace_test.go @@ -36,9 +36,9 @@ commonLabels: commonAnnotations: note: This is a test annotation resources: + - service.yaml - deployment.yaml - networkpolicy.yaml - - service.yaml `) th.WriteF("/app/base/service.yaml", ` apiVersion: v1 @@ -237,52 +237,6 @@ func TestBaseWithGeneratorsAlone(t *testing.T) { t.Fatalf("Err: %v", err) } th.AssertActualEqualsExpected(m, ` -apiVersion: v1 -data: - foo: bar -kind: ConfigMap -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - org: example.com - team: foo - name: team-foo-configmap-in-base-bbdmdh7m8t ---- -apiVersion: v1 -data: - password: c29tZXB3 - username: YWRtaW4= -kind: Secret -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - org: example.com - team: foo - name: team-foo-secret-in-base-tkm7hhtf8d -type: Opaque ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - org: example.com - team: foo - name: team-foo-nginx -spec: - ports: - - port: 80 - selector: - app: mynginx - org: example.com - team: foo ---- apiVersion: apps/v1beta2 kind: Deployment metadata: @@ -320,6 +274,52 @@ spec: - configMap: name: team-foo-configmap-in-base-bbdmdh7m8t name: configmap-in-base +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + org: example.com + team: foo + name: team-foo-nginx +spec: + ports: + - port: 80 + selector: + app: mynginx + org: example.com + team: foo +--- +apiVersion: v1 +data: + foo: bar +kind: ConfigMap +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + org: example.com + team: foo + name: team-foo-configmap-in-base-bbdmdh7m8t +--- +apiVersion: v1 +data: + password: c29tZXB3 + username: YWRtaW4= +kind: Secret +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + org: example.com + team: foo + name: team-foo-secret-in-base-tkm7hhtf8d +type: Opaque `) } @@ -351,9 +351,9 @@ commonLabels: env: staging team: override-foo patchesStrategicMerge: - - deployment.yaml -bases: - - ../app +- deployment.yaml +resources: +- ../app configMapGenerator: - name: configmap-in-overlay literals: @@ -373,67 +373,6 @@ secretGenerator: t.Fatalf("Err: %v", err) } th.AssertActualEqualsExpected(m, ` -apiVersion: v1 -data: - hello: world -kind: ConfigMap -metadata: - labels: - env: staging - team: override-foo - name: staging-configmap-in-overlay-k7cbc75tg8 ---- -apiVersion: v1 -data: - foo: override-bar -kind: ConfigMap -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - env: staging - org: example.com - team: override-foo - name: staging-team-foo-configmap-in-base-gh9d7t85gb ---- -apiVersion: v1 -data: - password: c29tZXB3 - proxy: aGFwcm94eQ== - username: YWRtaW4= -kind: Secret -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - env: staging - org: example.com - team: override-foo - name: staging-team-foo-secret-in-base-c8db7gk2m2 -type: Opaque ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - env: staging - org: example.com - team: override-foo - name: staging-team-foo-nginx -spec: - ports: - - port: 80 - selector: - app: mynginx - env: staging - org: example.com - team: override-foo ---- apiVersion: apps/v1beta2 kind: Deployment metadata: @@ -478,6 +417,67 @@ spec: - configMap: name: staging-team-foo-configmap-in-base-gh9d7t85gb name: configmap-in-base +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + env: staging + org: example.com + team: override-foo + name: staging-team-foo-nginx +spec: + ports: + - port: 80 + selector: + app: mynginx + env: staging + org: example.com + team: override-foo +--- +apiVersion: v1 +data: + foo: override-bar +kind: ConfigMap +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + env: staging + org: example.com + team: override-foo + name: staging-team-foo-configmap-in-base-gh9d7t85gb +--- +apiVersion: v1 +data: + password: c29tZXB3 + proxy: aGFwcm94eQ== + username: YWRtaW4= +kind: Secret +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + env: staging + org: example.com + team: override-foo + name: staging-team-foo-secret-in-base-c8db7gk2m2 +type: Opaque +--- +apiVersion: v1 +data: + hello: world +kind: ConfigMap +metadata: + labels: + env: staging + team: override-foo + name: staging-configmap-in-overlay-k7cbc75tg8 `) } diff --git a/pkg/target/generatoroptions_test.go b/pkg/target/generatoroptions_test.go index b4a8ce578..b4b5325a2 100644 --- a/pkg/target/generatoroptions_test.go +++ b/pkg/target/generatoroptions_test.go @@ -78,7 +78,7 @@ configMapGenerator: th.WriteK("/app/overlay", ` apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization -bases: +resources: - ../base generatorOptions: disableNameSuffixHash: false @@ -95,15 +95,6 @@ configMapGenerator: } th.AssertActualEqualsExpected(m, ` apiVersion: v1 -data: - fruit: apple -kind: ConfigMap -metadata: - labels: - fruit: apple - name: shouldHaveHash-2k9hc848ff ---- -apiVersion: v1 data: foo: bar kind: ConfigMap @@ -111,5 +102,14 @@ metadata: labels: foo: bar name: shouldNotHaveHash +--- +apiVersion: v1 +data: + fruit: apple +kind: ConfigMap +metadata: + labels: + fruit: apple + name: shouldHaveHash-2k9hc848ff `) } diff --git a/pkg/target/kusttarget_test.go b/pkg/target/kusttarget_test.go index 657d68665..cc1643c9a 100644 --- a/pkg/target/kusttarget_test.go +++ b/pkg/target/kusttarget_test.go @@ -256,15 +256,15 @@ func TestIssue596AllowDirectoriesThatAreSubstringsOfEachOther(t *testing.T) { th := kusttest_test.NewKustTestHarness(t, "/app/overlays/aws-sandbox2.us-east-1") th.WriteK("/app/base", "") th.WriteK("/app/overlays/aws", ` -bases: +resources: - ../../base `) th.WriteK("/app/overlays/aws-nonprod", ` -bases: +resources: - ../aws `) th.WriteK("/app/overlays/aws-sandbox2.us-east-1", ` -bases: +resources: - ../aws-nonprod `) m, err := th.MakeKustTarget().MakeCustomizedResMap() @@ -363,7 +363,7 @@ vars: objref: kind: Service name: apple -bases: +resources: - ../../base `) th.WriteK("/app/overlays/o2", ` @@ -372,7 +372,7 @@ vars: objref: kind: Leafy name: kale -bases: +resources: - ../o1 `) ra, err := th.MakeKustTarget().AccumulateTarget() @@ -416,7 +416,7 @@ vars: objref: kind: Service name: academy -bases: +resources: - ../../base `) th.WriteK("/app/overlays/o2", ` @@ -425,7 +425,7 @@ vars: objref: kind: Leafy name: kale -bases: +resources: - ../o1 `) _, err := th.MakeKustTarget().AccumulateTarget() diff --git a/pkg/target/multiplepatch_test.go b/pkg/target/multiplepatch_test.go index 73c2a7c47..c14b0173d 100644 --- a/pkg/target/multiplepatch_test.go +++ b/pkg/target/multiplepatch_test.go @@ -90,7 +90,7 @@ commonLabels: patchesStrategicMerge: - deployment-patch1.yaml - deployment-patch2.yaml -bases: +resources: - ../../base configMapGenerator: - name: configmap-in-overlay @@ -148,49 +148,6 @@ spec: t.Fatalf("Err: %v", err) } th.AssertActualEqualsExpected(m, ` -apiVersion: v1 -data: - hello: world -kind: ConfigMap -metadata: - labels: - env: staging - name: staging-configmap-in-overlay-k7cbc75tg8 ---- -apiVersion: v1 -data: - foo: bar -kind: ConfigMap -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - env: staging - org: example.com - team: foo - name: staging-team-foo-configmap-in-base-g7k6gt2889 ---- -apiVersion: v1 -kind: Service -metadata: - annotations: - note: This is a test annotation - labels: - app: mynginx - env: staging - org: example.com - team: foo - name: staging-team-foo-nginx -spec: - ports: - - port: 80 - selector: - app: mynginx - env: staging - org: example.com - team: foo ---- apiVersion: apps/v1beta2 kind: Deployment metadata: @@ -242,6 +199,49 @@ spec: - configMap: name: staging-team-foo-configmap-in-base-g7k6gt2889 name: configmap-in-base +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + env: staging + org: example.com + team: foo + name: staging-team-foo-nginx +spec: + ports: + - port: 80 + selector: + app: mynginx + env: staging + org: example.com + team: foo +--- +apiVersion: v1 +data: + foo: bar +kind: ConfigMap +metadata: + annotations: + note: This is a test annotation + labels: + app: mynginx + env: staging + org: example.com + team: foo + name: staging-team-foo-configmap-in-base-g7k6gt2889 +--- +apiVersion: v1 +data: + hello: world +kind: ConfigMap +metadata: + labels: + env: staging + name: staging-configmap-in-overlay-k7cbc75tg8 `) } diff --git a/pkg/target/pruneconfigmap_test.go b/pkg/target/pruneconfigmap_test.go index bd31b13d0..f44ebf051 100644 --- a/pkg/target/pruneconfigmap_test.go +++ b/pkg/target/pruneconfigmap_test.go @@ -107,38 +107,6 @@ data: } //nolint th.AssertActualEqualsExpected(m, ` -apiVersion: v1 -kind: ConfigMap -metadata: - annotations: - kustomize.config.k8s.io/Inventory: '{"current":{"apps_v1beta2_Deployment|default|my-mysql":null,"~G_v1_Secret|default|my-pass":[{"group":"apps","version":"v1beta2","kind":"Deployment","name":"my-mysql","namespace":"default"}],"~G_v1_Service|default|my-mmmysql":null}}' - kustomize.config.k8s.io/InventoryHash: kd67f7ht8t - name: haha - namespace: default ---- -apiVersion: v1 -data: - password: YWRtaW4= - username: jingfang -kind: Secret -metadata: - name: my-pass - namespace: default -type: Opaque ---- -apiVersion: v1 -kind: Service -metadata: - labels: - app: mysql - name: my-mmmysql - namespace: default -spec: - ports: - - port: 3306 - selector: - app: mysql ---- apiVersion: apps/v1beta2 kind: Deployment metadata: @@ -175,5 +143,37 @@ spec: volumes: - emptyDir: {} name: mysql-persistent-storage +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app: mysql + name: my-mmmysql + namespace: default +spec: + ports: + - port: 3306 + selector: + app: mysql +--- +apiVersion: v1 +data: + password: YWRtaW4= + username: jingfang +kind: Secret +metadata: + name: my-pass + namespace: default +type: Opaque +--- +apiVersion: v1 +kind: ConfigMap +metadata: + annotations: + kustomize.config.k8s.io/Inventory: '{"current":{"apps_v1beta2_Deployment|default|my-mysql":null,"~G_v1_Secret|default|my-pass":[{"group":"apps","version":"v1beta2","kind":"Deployment","name":"my-mysql","namespace":"default"}],"~G_v1_Service|default|my-mmmysql":null}}' + kustomize.config.k8s.io/InventoryHash: kd67f7ht8t + name: haha + namespace: default `) } diff --git a/pkg/target/resourceconflict_test.go b/pkg/target/resourceconflict_test.go index 127975204..87efd2ccd 100644 --- a/pkg/target/resourceconflict_test.go +++ b/pkg/target/resourceconflict_test.go @@ -42,13 +42,13 @@ subjects: func writeMidOverlays(th *kusttest_test.KustTestHarness) { // Mid-level overlays th.WriteK("/app/overlays/a", ` -bases: +resources: - ../../base namePrefix: a- nameSuffix: -suffixA `) th.WriteK("/app/overlays/b", ` -bases: +resources: - ../../base namePrefix: b- nameSuffix: -suffixB @@ -58,7 +58,7 @@ nameSuffix: -suffixB func writeTopOverlay(th *kusttest_test.KustTestHarness) { // Top overlay, combining the mid-level overlays th.WriteK("/app/combined", ` -bases: +resources: - ../overlays/a - ../overlays/b `) @@ -162,11 +162,6 @@ kind: ServiceAccount metadata: name: a-pfx-serviceaccount-sfx-suffixA --- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: b-pfx-serviceaccount-sfx-suffixB ---- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: RoleBinding metadata: @@ -179,6 +174,11 @@ subjects: - kind: ServiceAccount name: a-pfx-serviceaccount-sfx-suffixA --- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: b-pfx-serviceaccount-sfx-suffixB +--- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: RoleBinding metadata: @@ -200,12 +200,11 @@ func TestMultibasesWithConflict(t *testing.T) { writeTopOverlay(th) th.WriteK("/app/overlays/a", ` -bases: -- ../../base namePrefix: a- nameSuffix: -suffixA resources: - serviceaccount.yaml +- ../../base `) // Expect an error because this resource in the overlay // matches a resource in the base. diff --git a/pkg/target/variableref_test.go b/pkg/target/variableref_test.go index 8b6e3e102..18ec8b43c 100644 --- a/pkg/target/variableref_test.go +++ b/pkg/target/variableref_test.go @@ -27,8 +27,11 @@ func TestVariableRef(t *testing.T) { th.WriteK("/app/base", ` namePrefix: base- resources: - - cockroachdb-statefulset-secure.yaml - - cronjob.yaml +- role-stuff.yaml +- services.yaml +- statefulset.yaml +- cronjob.yaml +- pdb.yaml configMapGenerator: - name: test-config-map literals: @@ -87,7 +90,54 @@ spec: - name: CDB_PUBLIC_SVC value: "$(CDB_PUBLIC_SVC)" `) - th.WriteF("/app/base/cockroachdb-statefulset-secure.yaml", ` + th.WriteF("/app/base/services.yaml", ` +apiVersion: v1 +kind: Service +metadata: + name: cockroachdb + labels: + app: cockroachdb + annotations: + service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" + # Enable automatic monitoring of all instances when Prometheus is running in the cluster. + prometheus.io/scrape: "true" + prometheus.io/path: "_status/vars" + prometheus.io/port: "8080" +spec: + ports: + - port: 26257 + targetPort: 26257 + name: grpc + - port: 8080 + targetPort: 8080 + name: http + clusterIP: None + selector: + app: cockroachdb +--- +apiVersion: v1 +kind: Service +metadata: + # This service is meant to be used by clients of the database. It exposes a ClusterIP that will + # automatically load balance connections to the different database pods. + name: cockroachdb-public + labels: + app: cockroachdb +spec: + ports: + # The main port, served by gRPC, serves Postgres-flavor SQL, internode + # traffic and the cli. + - port: 26257 + targetPort: 26257 + name: grpc + # The secondary port serves the UI as well as health and debug endpoints. + - port: 8080 + targetPort: 8080 + name: http + selector: + app: cockroachdb +`) + th.WriteF("/app/base/role-stuff.yaml", ` apiVersion: v1 kind: ServiceAccount metadata: @@ -155,53 +205,8 @@ subjects: - kind: ServiceAccount name: cockroachdb namespace: default ---- -apiVersion: v1 -kind: Service -metadata: - # This service is meant to be used by clients of the database. It exposes a ClusterIP that will - # automatically load balance connections to the different database pods. - name: cockroachdb-public - labels: - app: cockroachdb -spec: - ports: - # The main port, served by gRPC, serves Postgres-flavor SQL, internode - # traffic and the cli. - - port: 26257 - targetPort: 26257 - name: grpc - # The secondary port serves the UI as well as health and debug endpoints. - - port: 8080 - targetPort: 8080 - name: http - selector: - app: cockroachdb ---- -apiVersion: v1 -kind: Service -metadata: - name: cockroachdb - labels: - app: cockroachdb - annotations: - service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" - # Enable automatic monitoring of all instances when Prometheus is running in the cluster. - prometheus.io/scrape: "true" - prometheus.io/path: "_status/vars" - prometheus.io/port: "8080" -spec: - ports: - - port: 26257 - targetPort: 26257 - name: grpc - - port: 8080 - targetPort: 8080 - name: http - clusterIP: None - selector: - app: cockroachdb ---- +`) + th.WriteF("/app/base/pdb.yaml", ` apiVersion: policy/v1beta1 kind: PodDisruptionBudget metadata: @@ -213,7 +218,8 @@ spec: matchLabels: app: cockroachdb maxUnavailable: 1 ---- +`) + th.WriteF("/app/base/statefulset.yaml", ` apiVersion: apps/v1beta1 kind: StatefulSet metadata: @@ -324,7 +330,7 @@ spec: `) th.WriteK("/app/overlay/staging", ` namePrefix: dev- -bases: +resources: - ../../base `) m, err := th.MakeKustTarget().MakeCustomizedResMap() @@ -401,14 +407,6 @@ subjects: namespace: default --- apiVersion: v1 -data: - baz: qux - foo: bar -kind: ConfigMap -metadata: - name: dev-base-test-config-map-b2g2dmd64b ---- -apiVersion: v1 kind: Service metadata: annotations: @@ -575,6 +573,14 @@ spec: selector: matchLabels: app: cockroachdb +--- +apiVersion: v1 +data: + baz: qux + foo: bar +kind: ConfigMap +metadata: + name: dev-base-test-config-map-b2g2dmd64b `) } @@ -582,9 +588,9 @@ func TestVariableRefIngress(t *testing.T) { th := kusttest_test.NewKustTestHarness(t, "/app/overlay") th.WriteK("/app/base", ` resources: +- service.yaml - deployment.yaml - ingress.yaml -- service.yaml vars: - name: DEPLOYMENT_NAME @@ -655,7 +661,7 @@ spec: `) th.WriteK("/app/overlay", ` nameprefix: kustomized- -bases: +resources: - ../base `) m, err := th.MakeKustTarget().MakeCustomizedResMap() @@ -768,11 +774,6 @@ vars: t.Fatalf("Err: %v", err) } th.AssertActualEqualsExpected(m, ` -apiVersion: v1 -kind: Namespace -metadata: - name: my-namespace ---- apiVersion: apps/v1 kind: Deployment metadata: @@ -792,6 +793,11 @@ spec: volumes: - emptyDir: {} name: my-volume +--- +apiVersion: v1 +kind: Namespace +metadata: + name: my-namespace `) } @@ -834,11 +840,6 @@ vars: t.Fatalf("Err: %v", err) } th.AssertActualEqualsExpected(m, ` -apiVersion: v1 -kind: Namespace -metadata: - name: my-namespace ---- apiVersion: apps/v1 kind: Deployment metadata: @@ -851,6 +852,11 @@ spec: containers: - image: busybox name: app +--- +apiVersion: v1 +kind: Namespace +metadata: + name: my-namespace `) } @@ -858,7 +864,7 @@ func TestVaribaleRefDifferentPrefix(t *testing.T) { th := kusttest_test.NewKustTestHarness(t, "/app/base") th.WriteK("/app/base", ` namePrefix: base- -bases: +resources: - dev - test `) @@ -948,28 +954,6 @@ spec: } th.AssertActualEqualsExpected(m, ` -apiVersion: v1 -kind: Service -metadata: - name: base-dev-elasticsearch -spec: - clusterIP: None - ports: - - name: transport - port: 9300 - protocol: TCP ---- -apiVersion: v1 -kind: Service -metadata: - name: base-test-elasticsearch -spec: - clusterIP: None - ports: - - name: transport - port: 9300 - protocol: TCP ---- apiVersion: apps/v1 kind: StatefulSet metadata: @@ -983,6 +967,17 @@ spec: value: base-dev-elasticsearch.monitoring.svc.cluster.local name: elasticsearch --- +apiVersion: v1 +kind: Service +metadata: + name: base-dev-elasticsearch +spec: + clusterIP: None + ports: + - name: transport + port: 9300 + protocol: TCP +--- apiVersion: apps/v1 kind: StatefulSet metadata: @@ -995,5 +990,16 @@ spec: - name: DISCOVERY_SERVICE value: base-test-elasticsearch.monitoring.svc.cluster.local name: elasticsearch +--- +apiVersion: v1 +kind: Service +metadata: + name: base-test-elasticsearch +spec: + clusterIP: None + ports: + - name: transport + port: 9300 + protocol: TCP `) } diff --git a/plugin/builtin/inventorytransformer/InventoryTransformer_test.go b/plugin/builtin/inventorytransformer/InventoryTransformer_test.go index d6f0d08ac..6510bc342 100644 --- a/plugin/builtin/inventorytransformer/InventoryTransformer_test.go +++ b/plugin/builtin/inventorytransformer/InventoryTransformer_test.go @@ -99,7 +99,7 @@ name: pruneCM namespace: default `, content) - th.AssertActualEqualsExpected(rm, inv+"---"+content) + th.AssertActualEqualsExpected(rm, content+"---"+inv) } func TestInventoryTransformerDefaultPolicy(t *testing.T) { @@ -120,5 +120,5 @@ name: pruneCM namespace: default `, content) - th.AssertActualEqualsExpected(rm, inv+"---"+content) + th.AssertActualEqualsExpected(rm, content+"---"+inv) } diff --git a/plugin/builtin/namespacetransformer/NamespaceTransformer_test.go b/plugin/builtin/namespacetransformer/NamespaceTransformer_test.go index f8669336d..612c8dfd8 100644 --- a/plugin/builtin/namespacetransformer/NamespaceTransformer_test.go +++ b/plugin/builtin/namespacetransformer/NamespaceTransformer_test.go @@ -80,15 +80,22 @@ metadata: th.AssertActualEqualsExpected(rm, ` apiVersion: v1 +kind: ConfigMap +metadata: + name: cm1 + namespace: test +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: cm2 + namespace: test +--- +apiVersion: v1 kind: Namespace metadata: name: ns1 --- -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - name: crd ---- apiVersion: v1 kind: ServiceAccount metadata: @@ -116,17 +123,10 @@ subjects: name: another namespace: random --- -apiVersion: v1 -kind: ConfigMap +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition metadata: - name: cm1 - namespace: test ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: cm2 - namespace: test + name: crd `) } diff --git a/plugin/builtin/prefixsuffixtransformer/PrefixSuffixTransformer_test.go b/plugin/builtin/prefixsuffixtransformer/PrefixSuffixTransformer_test.go index 0ed935ece..d7406c5b2 100644 --- a/plugin/builtin/prefixsuffixtransformer/PrefixSuffixTransformer_test.go +++ b/plugin/builtin/prefixsuffixtransformer/PrefixSuffixTransformer_test.go @@ -48,6 +48,14 @@ metadata: `) th.AssertActualEqualsExpected(rm, ` +apiVersion: v1 +kind: Service +metadata: + name: baked-apple-pie +spec: + ports: + - port: 7002 +--- apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: @@ -57,13 +65,5 @@ apiVersion: v1 kind: ConfigMap metadata: name: baked-cm-pie ---- -apiVersion: v1 -kind: Service -metadata: - name: baked-apple-pie -spec: - ports: - - port: 7002 `) } diff --git a/plugin/builtin/replicacounttransformer/ReplicaCountTransformer_test.go b/plugin/builtin/replicacounttransformer/ReplicaCountTransformer_test.go index dfd7c9838..451b56e58 100644 --- a/plugin/builtin/replicacounttransformer/ReplicaCountTransformer_test.go +++ b/plugin/builtin/replicacounttransformer/ReplicaCountTransformer_test.go @@ -109,16 +109,16 @@ spec: apiVersion: apps/v1 kind: Deployment metadata: - name: myapp + name: otherapp spec: - replicas: 23 + replicas: 5 --- apiVersion: apps/v1 kind: Deployment metadata: - name: otherapp + name: myapp spec: - replicas: 5 + replicas: 23 --- apiVersion: apps/v1 kind: StatefulSet diff --git a/plugin/someteam.example.com/v1/chartinflator/ChartInflator_test.go b/plugin/someteam.example.com/v1/chartinflator/ChartInflator_test.go index 15325e2f8..f2dff3588 100644 --- a/plugin/someteam.example.com/v1/chartinflator/ChartInflator_test.go +++ b/plugin/someteam.example.com/v1/chartinflator/ChartInflator_test.go @@ -49,6 +49,24 @@ metadata: type: Opaque --- apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + annotations: + volume.alpha.kubernetes.io/storage-class: default + labels: + app: release-name-minecraft + chart: minecraft-1.0.3 + heritage: Tiller + release: release-name + name: release-name-minecraft-datadir +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi +--- +apiVersion: v1 kind: Service metadata: labels: @@ -66,23 +84,5 @@ spec: selector: app: release-name-minecraft type: LoadBalancer ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - annotations: - volume.alpha.kubernetes.io/storage-class: default - labels: - app: release-name-minecraft - chart: minecraft-1.0.3 - heritage: Tiller - release: release-name - name: release-name-minecraft-datadir -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 1Gi `) }