mirror of https://github.com/fluxcd/cli-utils.git
E2E tests framework for kapply
This commit is contained in:
parent
712551fbfd
commit
ba26ffbce3
|
@ -0,0 +1,38 @@
|
|||
# Copyright 2019 The Kubernetes Authors.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Makefile for kapply CLI.
|
||||
|
||||
MYGOBIN := $(shell go env GOPATH)/bin
|
||||
SHELL := /bin/bash
|
||||
export PATH := $(MYGOBIN):$(PATH)
|
||||
|
||||
.PHONY: verify-kapply-e2e
|
||||
verify-kapply-e2e: test-examples-e2e-kapply
|
||||
|
||||
$(MYGOBIN)/mdrip:
|
||||
go install github.com/monopole/mdrip
|
||||
|
||||
.PHONY:
|
||||
test-examples-e2e-kapply: $(MYGOBIN)/mdrip $(MYGOBIN)/kind
|
||||
( \
|
||||
set -e; \
|
||||
/bin/rm -f $(MYGOBIN)/kapply; \
|
||||
echo "Installing kapply from ."; \
|
||||
cd cmd/kapply/; go install .; cd ../..; \
|
||||
./hack/testExamplesE2EAgainstKapply.sh .; \
|
||||
)
|
||||
|
||||
$(MYGOBIN)/kind:
|
||||
( \
|
||||
set -e; \
|
||||
d=$(shell mktemp -d); cd $$d; \
|
||||
wget -O ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-$(shell uname)-amd64; \
|
||||
chmod +x ./kind; \
|
||||
mv ./kind $(MYGOBIN); \
|
||||
rm -rf $$d; \
|
||||
)
|
||||
|
||||
.PHONY: nuke
|
||||
nuke: clean
|
||||
sudo rm -rf $(shell go env GOPATH)/pkg/mod/sigs.k8s.io
|
|
@ -0,0 +1,128 @@
|
|||
[hello]: https://github.com/monopole/hello
|
||||
[kind]: https://github.com/kubernetes-sigs/kind
|
||||
|
||||
# Demo: hello app
|
||||
|
||||
This demo helps you to deploy an example hello app end-to-end using kustomize.
|
||||
|
||||
Steps:
|
||||
1. Create the resources files.
|
||||
3. Spin-up kubernetes cluster on local using [kind].
|
||||
4. Deploy the app using kapply and verify the status.
|
||||
|
||||
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.
|
||||
|
||||
<!-- @createBase @testE2EAgainstLatestRelease-->
|
||||
```
|
||||
BASE=$DEMO_HOME/base
|
||||
mkdir -p $BASE
|
||||
OUTPUT=$DEMO_HOME/output
|
||||
mkdir -p $OUTPUT
|
||||
```
|
||||
|
||||
Now lets add a simple config map resource to the `base`
|
||||
|
||||
<!-- @createConfigMapYaml @testE2EAgainstLatestRelease-->
|
||||
```
|
||||
cat <<EOF >$BASE/configMap.yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: the-map
|
||||
data:
|
||||
altGreeting: "Good Morning!"
|
||||
enableRisky: "false"
|
||||
EOF
|
||||
```
|
||||
|
||||
Create `service.yaml` pointing to the deployment created above
|
||||
|
||||
<!-- @createServiceYaml @testE2EAgainstLatestRelease-->
|
||||
```
|
||||
cat <<EOF >$BASE/service.yaml
|
||||
kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: the-service
|
||||
spec:
|
||||
selector:
|
||||
deployment: hello
|
||||
type: LoadBalancer
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 8666
|
||||
targetPort: 8080
|
||||
EOF
|
||||
```
|
||||
|
||||
Create a `grouping.yaml` resource. By this, you are defining the grouping of the current directory, `base`. Kustomize uses the unique label in this file to track any future state changes made to this directory. Make sure the label key is `kustomize.config.k8s.io/inventory-id` and give any unique label value and DO NOT change it in future.
|
||||
|
||||
<!-- @createGroupingYaml @testE2EAgainstLatestRelease-->
|
||||
```
|
||||
cat <<EOF >$BASE/grouping.yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: inventory-map
|
||||
labels:
|
||||
cli-utils.sigs.k8s.io/inventory-id: hello-app
|
||||
EOF
|
||||
```
|
||||
|
||||
## Run end-to-end tests
|
||||
|
||||
The following requires installation of [kind].
|
||||
|
||||
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 kapply binary in MYGOBIN to apply a deployment and verify it is successful.
|
||||
<!-- @runHelloApp @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kapply apply -f $BASE;
|
||||
|
||||
```
|
||||
|
||||
Now let's replace the configMap with configMap2 apply the config, fetch and verify the status. This should delete the-map from deployment and add the-map2.
|
||||
<!-- @replaceConfigMapInHello @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
cat <<EOF >$BASE/configMap2.yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: the-map2
|
||||
data:
|
||||
altGreeting: "Good Evening!"
|
||||
enableRisky: "false"
|
||||
EOF
|
||||
|
||||
rm $BASE/configMap.yaml
|
||||
|
||||
kapply apply -f $BASE;
|
||||
|
||||
```
|
||||
|
||||
Clean-up the cluster
|
||||
<!-- @deleteKindCluster @testE2EAgainstLatestRelease -->
|
||||
```
|
||||
kind delete cluster
|
||||
```
|
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Copyright 2019 The Kubernetes Authors.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
set -o nounset
|
||||
set -o errexit
|
||||
set -o pipefail
|
||||
|
||||
mdrip --blockTimeOut 60m0s --mode test \
|
||||
--label testE2EAgainstLatestRelease examples/alphaTestExamples
|
||||
|
||||
echo "Example e2e tests passed against ."
|
Loading…
Reference in New Issue