diff --git a/docs/images/sorted.png b/docs/images/sorted.png new file mode 100644 index 000000000..64d7fccee Binary files /dev/null and b/docs/images/sorted.png differ diff --git a/docs/v_2.1.0.md b/docs/v_2.1.0.md index 51a60b945..7174db868 100644 --- a/docs/v_2.1.0.md +++ 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 `) }