Skip to content

Commit

Permalink
Test examples against HEAD as well as against latest release.
Browse files Browse the repository at this point in the history
  • Loading branch information
monopole committed Aug 20, 2019
1 parent 2b6a406 commit 423a8a6
Show file tree
Hide file tree
Showing 26 changed files with 244 additions and 223 deletions.
2 changes: 1 addition & 1 deletion docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ chmod u+x kustomize

Requires [Go] v1.12 or higher:

<!-- @installkustomize @test -->
<!-- @installkustomize @testAgainstLatestRelease -->
```
go install sigs.k8s.io/kustomize/v3/cmd/kustomize
```
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ chmod u+x kustomize

使用 [Go] v1.10.1 或更高版本安装(如果可以访问 [golang.org]):

<!-- @installkustomize @test -->
<!-- @installkustomize @testAgainstLatestRelease -->
```
go install sigs.k8s.io/kustomize/v3/cmd/kustomize
```
14 changes: 5 additions & 9 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ English | [简体中文](zh/README.md)

# Examples

These examples assume that `kustomize` is on your `$PATH`.
To run these examples, your `$PATH` must contain `kustomize`.
See the [installation instructions](../docs/INSTALL.md).

They are covered by [pre-commit](../travis/pre-commit.sh)
tests, and should work with HEAD

<!-- @installkustomize @test -->
```
go get sigs.k8s.io/kustomize/v3/cmd/kustomize
```
These examples are [tested](../travis/pre-commit.sh)
to work with the latest _released_ version of kustomize.

Basic Usage

Expand Down Expand Up @@ -71,4 +67,4 @@ Multi Variant Examples
* [breakfast](breakfast.md) - Customize breakfast for
Alice and Bob.

* [multibases](multibases/README.md) - Composing three variants (dev, staging, production) with a common base.
* [multibases](multibases/README.md) - Composing three variants (dev, staging, production) with a common base.
18 changes: 9 additions & 9 deletions examples/breakfast.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

Define a place to work:

<!-- @makeWorkplace @test -->
<!-- @makeWorkplace @testAgainstLatestRelease -->
```
DEMO_HOME=$(mktemp -d)
```

Make a place to put the base breakfast configuration:

<!-- @baseDir @test -->
<!-- @baseDir @testAgainstLatestRelease -->
```
mkdir -p $DEMO_HOME/breakfast/base
```

Make a `kustomization` to define what goes into
breakfast. This breakfast has coffee and pancakes:

<!-- @baseKustomization @test -->
<!-- @baseKustomization @testAgainstLatestRelease -->
```
cat <<EOF >$DEMO_HOME/breakfast/base/kustomization.yaml
resources:
Expand All @@ -34,7 +34,7 @@ Here's a _coffee_ type. Give it a `kind` and `metdata/name` field
to conform to [kubernetes API object style]; no other
file or definition is needed:

<!-- @coffee @test -->
<!-- @coffee @testAgainstLatestRelease -->
```
cat <<EOF >$DEMO_HOME/breakfast/base/coffee.yaml
kind: Coffee
Expand All @@ -50,7 +50,7 @@ The `name` field merely distinguishes this instance of
coffee from others (if there were any).

Likewise, define _pancakes_:
<!-- @pancakes @test -->
<!-- @pancakes @testAgainstLatestRelease -->
```
cat <<EOF >$DEMO_HOME/breakfast/base/pancakes.yaml
kind: Pancakes
Expand All @@ -64,7 +64,7 @@ EOF
Make a custom [variant] of breakfast for Alice, who
likes her coffee hot:

<!-- @aliceOverlay @test -->
<!-- @aliceOverlay @testAgainstLatestRelease -->
```
mkdir -p $DEMO_HOME/breakfast/overlays/alice
Expand All @@ -87,7 +87,7 @@ EOF

And likewise a [variant] for Bob, who wants _five_ pancakes, with strawberries:

<!-- @bobOverlay @test -->
<!-- @bobOverlay @testAgainstLatestRelease -->
```
mkdir -p $DEMO_HOME/breakfast/overlays/bob
Expand All @@ -111,14 +111,14 @@ EOF

One can now generate the configs for Alice’s breakfast:

<!-- @generateAlice @test -->
<!-- @generateAlice @testAgainstLatestRelease -->
```
kustomize build $DEMO_HOME/breakfast/overlays/alice
```

Likewise for Bob:

<!-- @generateBob @test -->
<!-- @generateBob @testAgainstLatestRelease -->
```
kustomize build $DEMO_HOME/breakfast/overlays/bob
```
16 changes: 8 additions & 8 deletions examples/combineConfigs.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ defined in the [helloworld] demo.

It will all live in this work directory:

<!-- @makeWorkplace @test -->
<!-- @makeWorkplace @testAgainstLatestRelease -->
```
DEMO_HOME=$(mktemp -d)
```
Expand All @@ -139,7 +139,7 @@ DEMO_HOME=$(mktemp -d)

Make a place to put the base configuration:

<!-- @baseDir @test -->
<!-- @baseDir @testAgainstLatestRelease -->
```
mkdir -p $DEMO_HOME/base
```
Expand All @@ -150,7 +150,7 @@ environments. Here we're only defining a java
properties file, and a `kustomization` file that
references it.

<!-- @baseKustomization @test -->
<!-- @baseKustomization @testAgainstLatestRelease -->
```
cat <<EOF >$DEMO_HOME/base/common.properties
color=blue
Expand All @@ -171,14 +171,14 @@ EOF
Make an abbreviation for the parent of the overlay
directories:

<!-- @overlays @test -->
<!-- @overlays @testAgainstLatestRelease -->
```
OVERLAYS=$DEMO_HOME/overlays
```

Create the files that define the _development_ overlay:

<!-- @developmentFiles @test -->
<!-- @developmentFiles @testAgainstLatestRelease -->
```
mkdir -p $OVERLAYS/development
Expand Down Expand Up @@ -206,7 +206,7 @@ EOF

One can now generate the configMaps for development:

<!-- @runDev @test -->
<!-- @runDev @testAgainstLatestRelease -->
```
kustomize build $OVERLAYS/development
```
Expand Down Expand Up @@ -260,7 +260,7 @@ deletes unused configMaps.
Next, create the files for the _production_ overlay:


<!-- @productionFiles @test -->
<!-- @productionFiles @testAgainstLatestRelease -->
```
mkdir -p $OVERLAYS/production
Expand All @@ -287,7 +287,7 @@ EOF

One can now generate the configMaps for production:

<!-- @runProd @test -->
<!-- @runProd @testAgainstLatestRelease -->
```
kustomize build $OVERLAYS/production
```
Expand Down
20 changes: 10 additions & 10 deletions examples/configGeneration.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ In this demo, the same [hello_world](helloWorld/README.md) is used while the Con
### Establish base and staging

Establish the base with a configMapGenerator
<!-- @establishBase @test -->
<!-- @establishBase @testAgainstLatestRelease -->
```
DEMO_HOME=$(mktemp -d)
Expand All @@ -53,7 +53,7 @@ EOF
```

Establish the staging with a patch applied to the ConfigMap
<!-- @establishStaging @test -->
<!-- @establishStaging @testAgainstLatestRelease -->
```
OVERLAYS=$DEMO_HOME/overlays
mkdir -p $OVERLAYS/staging
Expand Down Expand Up @@ -91,7 +91,7 @@ configured with data from a configMap.
The deployment refers to this map by name:


<!-- @showDeployment @test -->
<!-- @showDeployment @testAgainstLatestRelease -->
```
grep -C 2 configMapKeyRef $BASE/deployment.yaml
```
Expand All @@ -117,7 +117,7 @@ collected](https://github.com/kubernetes-sigs/kustomize/issues/242).

The _staging_ [variant] here has a configMap [patch]:

<!-- @showMapPatch @test -->
<!-- @showMapPatch @testAgainstLatestRelease -->
```
cat $OVERLAYS/staging/map.yaml
```
Expand All @@ -128,7 +128,7 @@ resource spec.

The ConfigMap it modifies is declared from a configMapGenerator.

<!-- @showMapBase @test -->
<!-- @showMapBase @testAgainstLatestRelease -->
```
grep -C 4 configMapGenerator $BASE/kustomization.yaml
```
Expand All @@ -141,7 +141,7 @@ _not_ what gets used in the cluster. By design,
kustomize modifies names of ConfigMaps declared from ConfigMapGenerator. To see the names
ultimately used in the cluster, just run kustomize:

<!-- @grepStagingName @test -->
<!-- @grepStagingName @testAgainstLatestRelease -->
```
kustomize build $OVERLAYS/staging |\
grep -B 8 -A 1 staging-the-map
Expand All @@ -159,15 +159,15 @@ The suffix to the configMap name is generated from a
hash of the maps content - in this case the name suffix
is _k25m8k5k5m_:

<!-- @grepStagingHash @test -->
<!-- @grepStagingHash @testAgainstLatestRelease -->
```
kustomize build $OVERLAYS/staging | grep k25m8k5k5m
```

Now modify the map patch, to change the greeting
the server will use:

<!-- @changeMap @test -->
<!-- @changeMap @testAgainstLatestRelease -->
```
sed -i.bak 's/pineapple/kiwi/' $OVERLAYS/staging/map.yaml
```
Expand All @@ -181,7 +181,7 @@ kustomize build $OVERLAYS/staging |\

Run kustomize again to see the new configMap names:

<!-- @grepStagingName @test -->
<!-- @grepStagingName @testAgainstLatestRelease -->
```
kustomize build $OVERLAYS/staging |\
grep -B 8 -A 1 staging-the-map
Expand All @@ -192,7 +192,7 @@ in three new names ending in _cd7kdh48fd_ - one in the
configMap name itself, and two in the deployment that
uses the map:

<!-- @countHashes @test -->
<!-- @countHashes @testAgainstLatestRelease -->
```
test 3 == \
$(kustomize build $OVERLAYS/staging | grep cd7kdh48fd | wc -l); \
Expand Down
6 changes: 3 additions & 3 deletions examples/generatorOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DEMO_HOME=$(mktemp -d)

Create a kustomization and add a ConfigMap generator to it.

<!-- @createCMGenerator @test -->
<!-- @createCMGenerator @testAgainstLatestRelease -->
```
cat > $DEMO_HOME/kustomization.yaml << EOF
configMapGenerator:
Expand All @@ -25,7 +25,7 @@ EOF
```

Add following generatorOptions
<!-- @addGeneratorOptions @test -->
<!-- @addGeneratorOptions @testAgainstLatestRelease -->
```
cat >> $DEMO_HOME/kustomization.yaml << EOF
generatorOptions:
Expand All @@ -39,7 +39,7 @@ EOF
Run `kustomize build` and make sure that the generated ConfigMap

- doesn't have name suffix
<!-- @verify @test -->
<!-- @verify @testAgainstLatestRelease -->
```
test 1 == \
$(kustomize build $DEMO_HOME | grep "name: my-configmap$" | wc -l); \
Expand Down

0 comments on commit 423a8a6

Please sign in to comment.