mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Alpha commands e2e tests
This commit is contained in:
14
Makefile
14
Makefile
@@ -18,7 +18,7 @@ verify-kustomize: \
|
|||||||
test-examples-kustomize-against-latest
|
test-examples-kustomize-against-latest
|
||||||
|
|
||||||
.PHONY: verify-kustomize-e2e
|
.PHONY: verify-kustomize-e2e
|
||||||
verify-kustomize-e2e: test-examples-e2e-kustomize-against-HEAD
|
verify-kustomize-e2e: test-examples-e2e-kustomize
|
||||||
|
|
||||||
# Other builds in this repo might want a different linter version.
|
# Other builds in this repo might want a different linter version.
|
||||||
# Without one Makefile to rule them all, the different makes
|
# Without one Makefile to rule them all, the different makes
|
||||||
@@ -202,8 +202,16 @@ test-examples-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip
|
|||||||
./hack/testExamplesAgainstKustomize.sh HEAD
|
./hack/testExamplesAgainstKustomize.sh HEAD
|
||||||
|
|
||||||
.PHONY:
|
.PHONY:
|
||||||
test-examples-e2e-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip $(MYGOBIN)/resource
|
test-examples-e2e-kustomize: $(MYGOBIN)/mdrip
|
||||||
./hack/testExamplesE2EAgainstKustomize.sh HEAD
|
( \
|
||||||
|
set -e; \
|
||||||
|
/bin/rm -f $(MYGOBIN)/kustomize; \
|
||||||
|
echo "Installing kustomize from ."; \
|
||||||
|
cd kustomize; go install .; cd ..; \
|
||||||
|
echo "Installing resource from ."; \
|
||||||
|
cd cmd/resource; go install .; cd ../..; \
|
||||||
|
./hack/testExamplesE2EAgainstKustomize.sh .; \
|
||||||
|
)
|
||||||
|
|
||||||
.PHONY:
|
.PHONY:
|
||||||
test-examples-kustomize-against-latest: $(MYGOBIN)/mdrip
|
test-examples-kustomize-against-latest: $(MYGOBIN)/mdrip
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ require (
|
|||||||
k8s.io/component-base v0.17.0 // indirect
|
k8s.io/component-base v0.17.0 // indirect
|
||||||
k8s.io/kubectl v0.0.0-20191219154910-1528d4eea6dd
|
k8s.io/kubectl v0.0.0-20191219154910-1528d4eea6dd
|
||||||
sigs.k8s.io/controller-runtime v0.4.0
|
sigs.k8s.io/controller-runtime v0.4.0
|
||||||
sigs.k8s.io/kustomize/kstatus v0.0.0-20200109211150-9555095de939
|
sigs.k8s.io/kustomize/kstatus v0.0.1
|
||||||
sigs.k8s.io/kustomize/kyaml v0.0.2
|
sigs.k8s.io/kustomize/kyaml v0.0.2
|
||||||
)
|
)
|
||||||
|
|
||||||
replace (
|
replace (
|
||||||
sigs.k8s.io/kustomize/kstatus v0.0.0-20200109211150-9555095de939 => ../../kstatus
|
sigs.k8s.io/kustomize/kstatus v0.0.1 => ../../kstatus
|
||||||
sigs.k8s.io/kustomize/kyaml v0.0.0 => ../../kyaml
|
sigs.k8s.io/kustomize/kyaml v0.0.0 => ../../kyaml
|
||||||
)
|
)
|
||||||
|
|||||||
113
examples/alphaTestExamples/helloworld/README.md
Normal file
113
examples/alphaTestExamples/helloworld/README.md
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
[base]: ../../docs/glossary.md#base
|
||||||
|
[config]: https://github.com/kinflate/example-hello
|
||||||
|
[gitops]: ../../docs/glossary.md#gitops
|
||||||
|
[hello]: https://github.com/monopole/hello
|
||||||
|
[kustomization]: ../../docs/glossary.md#kustomization
|
||||||
|
[original]: https://github.com/kinflate/example-hello
|
||||||
|
[overlay]: ../../docs/glossary.md#overlay
|
||||||
|
[overlays]: ../../docs/glossary.md#overlay
|
||||||
|
[patch]: ../../docs/glossary.md#patch
|
||||||
|
[variant]: ../../docs/glossary.md#variant
|
||||||
|
[variants]: ../../docs/glossary.md#variant
|
||||||
|
|
||||||
|
# Demo: hello world
|
||||||
|
|
||||||
|
Steps:
|
||||||
|
|
||||||
|
1. Clone an existing configuration as a [base].
|
||||||
|
1. Customize it.
|
||||||
|
|
||||||
|
First define a place to work:
|
||||||
|
|
||||||
|
<!-- @makeWorkplace @testE2EAgainstLatestRelease-->
|
||||||
|
```
|
||||||
|
DEMO_HOME=$(mktemp -d)
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, use
|
||||||
|
|
||||||
|
> ```
|
||||||
|
> DEMO_HOME=~/hello
|
||||||
|
> ```
|
||||||
|
|
||||||
|
## Establish the base
|
||||||
|
|
||||||
|
Let's run the [hello] service.
|
||||||
|
|
||||||
|
To keep this document shorter, the base resources are
|
||||||
|
off in a supplemental data directory rather than
|
||||||
|
declared here as HERE documents. Download them:
|
||||||
|
|
||||||
|
<!-- @downloadBase @testE2EAgainstLatestRelease-->
|
||||||
|
```
|
||||||
|
BASE=$DEMO_HOME/base
|
||||||
|
mkdir -p $BASE
|
||||||
|
|
||||||
|
curl -s -o "$BASE/#1.yaml" "https://raw.githubusercontent.com\
|
||||||
|
/kubernetes-sigs/kustomize\
|
||||||
|
/master/examples/alphaTestExamples/helloWorld\
|
||||||
|
/{configMap,deployment,grouping,kustomization,service}.yaml"
|
||||||
|
```
|
||||||
|
|
||||||
|
### The Base Kustomization
|
||||||
|
|
||||||
|
The `base` directory has a [kustomization] file:
|
||||||
|
|
||||||
|
<!-- @showKustomization @testE2EAgainstLatestRelease -->
|
||||||
|
```
|
||||||
|
more $BASE/kustomization.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
### Customize the base
|
||||||
|
|
||||||
|
A first customization step could be to change the _app
|
||||||
|
label_ applied to all resources:
|
||||||
|
|
||||||
|
<!-- @addLabel @testE2EAgainstLatestRelease -->
|
||||||
|
```
|
||||||
|
sed -i.bak 's/app: hello/app: my-hello/' \
|
||||||
|
$BASE/kustomization.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
To do end to end tests using kustomize, go through the following section. You should have GOPATH set up and "kind" installed(https://github.com/kubernetes-sigs/kind).
|
||||||
|
|
||||||
|
<!-- @setGoBin @testE2EAgainstLatestRelease -->
|
||||||
|
```
|
||||||
|
MYGOBIN=$GOPATH/bin
|
||||||
|
```
|
||||||
|
|
||||||
|
Delete any existing kind cluster and create a new one. By default the name of the cluster is "kind"
|
||||||
|
<!-- @deleteAndCreateKindCluster @testE2EAgainstLatestRelease -->
|
||||||
|
```
|
||||||
|
kind delete cluster;
|
||||||
|
kind create cluster;
|
||||||
|
```
|
||||||
|
|
||||||
|
Use the kustomize binary in MYGOBIN to apply a deployment, fetch the status and verify the status.
|
||||||
|
<!-- @e2eTestUsingKustomize @testE2EAgainstLatestRelease -->
|
||||||
|
```
|
||||||
|
export KUSTOMIZE_ENABLE_ALPHA_COMMANDS=true
|
||||||
|
|
||||||
|
$MYGOBIN/kustomize resources apply $BASE --status;
|
||||||
|
|
||||||
|
status=$(mktemp);
|
||||||
|
$MYGOBIN/resource status fetch $BASE > $status
|
||||||
|
|
||||||
|
test 1 == \
|
||||||
|
$(grep "the-deployment" $status | grep "Deployment is available. Replicas: 3" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
test 1 == \
|
||||||
|
$(grep "the-map" $status | grep "Resource is always ready" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
|
||||||
|
test 1 == \
|
||||||
|
$(grep "the-service" $status | grep "Service is ready" | wc -l); \
|
||||||
|
echo $?
|
||||||
|
```
|
||||||
|
|
||||||
|
Clean-up the cluster
|
||||||
|
<!-- @createKindCluster @testE2EAgainstLatestRelease -->
|
||||||
|
```
|
||||||
|
kind delete cluster;
|
||||||
|
```
|
||||||
7
examples/alphaTestExamples/helloworld/configMap.yaml
Normal file
7
examples/alphaTestExamples/helloworld/configMap.yaml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: the-map
|
||||||
|
data:
|
||||||
|
altGreeting: "Good Morning!"
|
||||||
|
enableRisky: "false"
|
||||||
30
examples/alphaTestExamples/helloworld/deployment.yaml
Normal file
30
examples/alphaTestExamples/helloworld/deployment.yaml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: the-deployment
|
||||||
|
spec:
|
||||||
|
replicas: 3
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
deployment: hello
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: the-container
|
||||||
|
image: monopole/hello:1
|
||||||
|
command: ["/hello",
|
||||||
|
"--port=8080",
|
||||||
|
"--enableRiskyFeature=$(ENABLE_RISKY)"]
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
|
env:
|
||||||
|
- name: ALT_GREETING
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: the-map
|
||||||
|
key: altGreeting
|
||||||
|
- name: ENABLE_RISKY
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: the-map
|
||||||
|
key: enableRisky
|
||||||
6
examples/alphaTestExamples/helloworld/grouping.yaml
Normal file
6
examples/alphaTestExamples/helloworld/grouping.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: inventory-map
|
||||||
|
labels:
|
||||||
|
"kustomize.config.k8s.io/inventory-id": "hello-world-app"
|
||||||
10
examples/alphaTestExamples/helloworld/kustomization.yaml
Normal file
10
examples/alphaTestExamples/helloworld/kustomization.yaml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Example configuration for the webserver
|
||||||
|
# at https://github.com/monopole/hello
|
||||||
|
commonLabels:
|
||||||
|
app: hello
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- deployment.yaml
|
||||||
|
- service.yaml
|
||||||
|
- configMap.yaml
|
||||||
|
- grouping.yaml
|
||||||
12
examples/alphaTestExamples/helloworld/service.yaml
Normal file
12
examples/alphaTestExamples/helloworld/service.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
kind: Service
|
||||||
|
apiVersion: v1
|
||||||
|
metadata:
|
||||||
|
name: the-service
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
deployment: hello
|
||||||
|
type: LoadBalancer
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 8666
|
||||||
|
targetPort: 8080
|
||||||
@@ -22,7 +22,7 @@ Steps:
|
|||||||
|
|
||||||
First define a place to work:
|
First define a place to work:
|
||||||
|
|
||||||
<!-- @makeWorkplace @testAgainstLatestRelease @testE2EAgainstLatestRelease-->
|
<!-- @makeWorkplace @testAgainstLatestRelease -->
|
||||||
```
|
```
|
||||||
DEMO_HOME=$(mktemp -d)
|
DEMO_HOME=$(mktemp -d)
|
||||||
```
|
```
|
||||||
@@ -44,7 +44,7 @@ To keep this document shorter, the base resources are
|
|||||||
off in a supplemental data directory rather than
|
off in a supplemental data directory rather than
|
||||||
declared here as HERE documents. Download them:
|
declared here as HERE documents. Download them:
|
||||||
|
|
||||||
<!-- @downloadBase @testAgainstLatestRelease @testE2EAgainstLatestRelease-->
|
<!-- @downloadBase @testAgainstLatestRelease -->
|
||||||
```
|
```
|
||||||
BASE=$DEMO_HOME/base
|
BASE=$DEMO_HOME/base
|
||||||
mkdir -p $BASE
|
mkdir -p $BASE
|
||||||
@@ -309,31 +309,3 @@ To deploy, pipe the above commands to kubectl apply:
|
|||||||
> kustomize build $OVERLAYS/production |\
|
> kustomize build $OVERLAYS/production |\
|
||||||
> kubectl apply -f -
|
> kubectl apply -f -
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
[Alpha] To do end to end tests using kustomize, use the following commands on any folder. You should have GOPATH set up and "kind" installed(https://github.com/kubernetes-sigs/kind).
|
|
||||||
|
|
||||||
<!-- @e2eTest @testE2EAgainstLatestRelease -->
|
|
||||||
```
|
|
||||||
MYGOBIN=$GOPATH/bin
|
|
||||||
kind delete cluster;
|
|
||||||
kind create cluster;
|
|
||||||
$MYGOBIN/kustomize build $BASE | kubectl apply -f -;
|
|
||||||
status=$(mktemp);
|
|
||||||
$MYGOBIN/resource status events $BASE #Waits for all transient events to finish
|
|
||||||
$MYGOBIN/resource status fetch $BASE > $status
|
|
||||||
|
|
||||||
test 1 == \
|
|
||||||
$(grep "apps/v1/Deployment" $status | grep "Deployment is available. Replicas: 3" | wc -l); \
|
|
||||||
echo $?
|
|
||||||
|
|
||||||
test 1 == \
|
|
||||||
$(grep "v1/ConfigMap" $status | grep "Resource is always ready" | wc -l); \
|
|
||||||
echo $?
|
|
||||||
|
|
||||||
test 1 == \
|
|
||||||
$(grep "v1/Service" $status | grep "Service is ready" | wc -l); \
|
|
||||||
echo $?
|
|
||||||
|
|
||||||
$MYGOBIN/kustomize build $BASE | kubectl delete -f -;
|
|
||||||
kind delete cluster;
|
|
||||||
```
|
|
||||||
@@ -8,6 +8,6 @@ set -o errexit
|
|||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
mdrip --blockTimeOut 60m0s --mode test \
|
mdrip --blockTimeOut 60m0s --mode test \
|
||||||
--label testE2EAgainstLatestRelease examples
|
--label testE2EAgainstLatestRelease examples/alphaTestExamples
|
||||||
|
|
||||||
echo "Example e2e tests passed against ${version}."
|
echo "Example e2e tests passed against ."
|
||||||
|
|||||||
@@ -18,3 +18,8 @@ exclude (
|
|||||||
github.com/russross/blackfriday v2.0.0+incompatible
|
github.com/russross/blackfriday v2.0.0+incompatible
|
||||||
sigs.k8s.io/kustomize/api v0.2.0
|
sigs.k8s.io/kustomize/api v0.2.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace (
|
||||||
|
sigs.k8s.io/kustomize/cmd/kubectl v0.0.3 => ../cmd/kubectl
|
||||||
|
sigs.k8s.io/kustomize/kstatus v0.0.1 => ../kstatus
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user