Skip to content

Commit

Permalink
Cover input order == output order with tests.
Browse files Browse the repository at this point in the history
Modify all test coverage to compare actual build
output against a non-sorted version of expected
output.

Expected output is specified in the same order as
the inputs are specified in the kustomization
file, using a depth-first ordering when overlays
are involved.

Fixes kubernetes-sigs#756
Related kubernetes-sigs#821
  • Loading branch information
monopole committed Jun 17, 2019
1 parent ed21e77 commit 37f1af4
Show file tree
Hide file tree
Showing 20 changed files with 555 additions and 549 deletions.
41 changes: 32 additions & 9 deletions docs/v_2.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,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]
Expand All @@ -38,6 +36,26 @@ as one or more [Go modules] for use in other
programs (kubectl, kubebuilder, etc.) and in
kustomize plugins (see below).

## Resource ordering

Kustomize now retains the depth-first order of
resources as read.

The `build` command now accepts a `--reorder`
flag with values `legacy` and `none`,
with a default value of `legacy`.

`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.


## Inventory generation for pruning

Expand Down Expand Up @@ -147,13 +165,18 @@ path or URL to a kustomization directory in the
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. Just move the arguments of the
`bases` field to the `resources` field,
arranging entries in the desired order. It's OK
to mix the ordering of bases and plain
resources.

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]
Expand Down
14 changes: 0 additions & 14 deletions pkg/kusttest/kusttestharness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.")
}
Expand All @@ -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)
Expand Down
143 changes: 70 additions & 73 deletions pkg/target/baseandoverlaymedium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
`)
}

Expand All @@ -139,7 +139,7 @@ commonLabels:
repo: test-infra
commonAnnotations:
note: This is a test annotation
bases:
resources:
- ../base
patchesStrategicMerge:
- deployment/deployment.yaml
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
`)
}
Loading

0 comments on commit 37f1af4

Please sign in to comment.