Skip to content

Commit

Permalink
Merge pull request #26 from jenting/migrate-to-kind
Browse files Browse the repository at this point in the history
Migrate from k3d to kind cluster
  • Loading branch information
joe-elliott authored Apr 15, 2020
2 parents ed44ba4 + 077d54d commit e862aff
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 84 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ The number of seconds until a certificate stored in a kubernetes secret expires.
### Other Docs

- [Testing](https://github.com/joe-elliott/cert-exporter/blob/master/docs/testing.md)
- An overview of the testing scripts and how to run them.
- An overview of the testing scripts and how to run them. It requires [kind](https://github.com/kubernetes-sigs/kind) CLI.
- [Deployment](https://github.com/joe-elliott/cert-exporter/blob/master/docs/deploy.md)
- Information on how to deploy cert-exporter as well as examples for a kops cluster.
- [Daemonset for Prometheus-operator](https://github.com/joe-elliott/cert-exporter/blob/master/docs/daemonset-prom-operator.md)
Expand Down
68 changes: 27 additions & 41 deletions test/cert-manager-v1alpha1/test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# requires a k8s cluster running with cert-manager running in it
# assumes the location of kubeconfig at ~/.kube/config
# requires k3d
# assumes the location of kubeconfig at $HOME/.kube/config
# requires kind https://github.com/kubernetes-sigs/kind
#

validateMetrics() {
Expand Down Expand Up @@ -30,70 +30,56 @@ validateMetrics() {
fi
}

export KUBECONFIG=""
K3D_NAME=cert-exporter
CONFIG_PATH="k3d get-kubeconfig --name=$K3D_NAME"
KIND_CLUSTER_NAME=cert-exporter
CONFIG_PATH=cert-exporter.kubeconfig

k3d create --name=$K3D_NAME
echo -n "Ensuring k3d is running..."
while true; do
k3d list 2>&1 | grep ".*$K3D_NAME.*running" >/dev/null && echo "done" && break \
|| (echo -n . && sleep 1)
done
echo -n "Create cluster"
kind create cluster --name=$KIND_CLUSTER_NAME --kubeconfig=$CONFIG_PATH

echo -n "Getting kubeconfig..."
while true; do
eval $CONFIG_PATH 2>&1 | grep "$K3D_NAME/kubeconfig.yaml" >/dev/null && echo done && break \
|| (echo -n . && sleep 1)
done
echo Config is available at $(eval $CONFIG_PATH)
kubectl --kubeconfig=$CONFIG_PATH create namespace cert-manager
kubectl --kubeconfig=$CONFIG_PATH label namespace cert-manager certmanager.k8s.io/disable-validation=true
kubectl --kubeconfig=$CONFIG_PATH apply -f https://github.com/jetstack/cert-manager/releases/download/v0.10.1/cert-manager.yaml

kubectl --kubeconfig $(eval $CONFIG_PATH) create namespace cert-manager
kubectl --kubeconfig $(eval $CONFIG_PATH) label namespace cert-manager certmanager.k8s.io/disable-validation=true
kubectl --kubeconfig $(eval $CONFIG_PATH) apply -f https://github.com/jetstack/cert-manager/releases/download/v0.10.1/cert-manager.yaml
kubectl --kubeconfig=$CONFIG_PATH wait --for=condition=available deploy --all -n cert-manager --timeout=3m

sleep 180
GO111MODULE=on go mod vendor
go build ../../main.go

kubectl --kubeconfig $(eval $CONFIG_PATH) create -f ./certs.yaml
kubectl --kubeconfig=$CONFIG_PATH apply -f ./certs.yaml

go build ../../main.go
chmod +x ./main
kubectl --kubeconfig=$CONFIG_PATH wait --for=condition=ready certificate/selfsigned-cert -n cert-manager-test

echo "** Testing Label Selector"
# run exporter
./main --kubeconfig $(eval $CONFIG_PATH) \
--secrets-label-selector 'certmanager.k8s.io/certificate-name' \
--secrets-include-glob='*.crt' \
--alsologtostderr &
./main --kubeconfig=$CONFIG_PATH \
--secrets-label-selector='certmanager.k8s.io/certificate-name' \
--secrets-include-glob='*.crt' \
--alsologtostderr &
pid=$!
sleep 5
sleep 10

validateMetrics 'cert_exporter_secret_expires_in_seconds{cn="example.com",issuer="example.com",key_name="ca.crt",secret_name="selfsigned-cert-tls",secret_namespace="cert-manager-test"}' 100

# kill exporter
echo "** Killing $pid"
kill $pid

sleep 5

echo "** Testing Label Selector And Namespace"
# run exporter
./main --kubeconfig $(eval $CONFIG_PATH) \
--secrets-label-selector 'certmanager.k8s.io/certificate-name' \
--secrets-namespace 'cert-manager-test' \
--secrets-include-glob='*.crt' \
--alsologtostderr &
./main --kubeconfig=$CONFIG_PATH \
--secrets-label-selector='certmanager.k8s.io/certificate-name' \
--secrets-namespace='cert-manager-test' \
--secrets-include-glob='*.crt' \
--alsologtostderr &
pid=$!
sleep 5
sleep 10

validateMetrics 'cert_exporter_secret_expires_in_seconds{cn="example.com",issuer="example.com",key_name="ca.crt",secret_name="selfsigned-cert-tls",secret_namespace="cert-manager-test"}' 100

# kill exporter
echo "** Killing $pid"
kill $pid

read -p "press enter"

rm ./main
kubectl --kubeconfig $(eval $CONFIG_PATH) delete -f ./certs.yaml
k3d delete --name=$K3D_NAME
kind delete cluster --name=$KIND_CLUSTER_NAME --kubeconfig=$CONFIG_PATH
rm $CONFIG_PATH
70 changes: 29 additions & 41 deletions test/cert-manager-v1alpha2/test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# requires a k8s cluster running with cert-manager running in it
# assumes the location of kubeconfig at ~/.kube/config
# requires k3d
# assumes the location of kubeconfig at $HOME/.kube/config
# requires kind https://github.com/kubernetes-sigs/kind
#

validateMetrics() {
Expand Down Expand Up @@ -35,42 +35,30 @@ validateMetrics() {
fi
}

export KUBECONFIG=""
K3D_NAME=cert-exporter
CONFIG_PATH="k3d get-kubeconfig --name=$K3D_NAME"
KIND_CLUSTER_NAME=cert-exporter
CONFIG_PATH=cert-exporter.kubeconfig

k3d create --name=$K3D_NAME
echo -n "Ensuring k3d is running..."
while true; do
k3d list 2>&1 | grep ".*$K3D_NAME.*running" >/dev/null && echo "done" && break \
|| (echo -n . && sleep 1)
done
echo -n "Create cluster"
kind create cluster --name=$KIND_CLUSTER_NAME --kubeconfig=$CONFIG_PATH

echo -n "Getting kubeconfig..."
while true; do
eval $CONFIG_PATH 2>&1 | grep "$K3D_NAME/kubeconfig.yaml" >/dev/null && echo done && break \
|| (echo -n . && sleep 1)
done
echo Config is available at $(eval $CONFIG_PATH)
kubectl --kubeconfig=$CONFIG_PATH create namespace cert-manager
kubectl --kubeconfig=$CONFIG_PATH label namespace cert-manager certmanager.k8s.io/disable-validation=true
kubectl --kubeconfig=$CONFIG_PATH apply -f https://github.com/jetstack/cert-manager/releases/download/v0.14.0/cert-manager.yaml

kubectl --kubeconfig $(eval $CONFIG_PATH) create namespace cert-manager
kubectl --kubeconfig $(eval $CONFIG_PATH) label namespace cert-manager certmanager.k8s.io/disable-validation=true
kubectl --kubeconfig $(eval $CONFIG_PATH) apply -f https://github.com/jetstack/cert-manager/releases/download/v0.14.0/cert-manager.yaml
kubectl --kubeconfig=$CONFIG_PATH wait --for=condition=available deploy --all -n cert-manager --timeout=3m

sleep 180

kubectl --kubeconfig $(eval $CONFIG_PATH) create -f ./certs.yaml
kubectl --kubeconfig=$CONFIG_PATH apply -f ./certs.yaml

GO111MODULE=on go mod vendor
go build ../../main.go
chmod +x ./main

echo "** Testing Label Selector"
# run exporter
./main --kubeconfig $(eval $CONFIG_PATH) \
--secrets-annotation-selector='cert-manager.io/certificate-name' \
--secrets-annotation-selector='test' \
--secrets-include-glob='*.crt' \
--alsologtostderr &
./main --kubeconfig=$CONFIG_PATH \
--secrets-annotation-selector='cert-manager.io/certificate-name' \
--secrets-annotation-selector='test' \
--secrets-include-glob='*.crt' \
--alsologtostderr &
pid=$!
sleep 10

Expand All @@ -83,11 +71,11 @@ kill $pid

echo "** Testing Label Selector And Namespace"
# run exporter
./main --kubeconfig $(eval $CONFIG_PATH) \
--secrets-annotation-selector='cert-manager.io/certificate-name' \
--secrets-namespace 'cert-manager-test' \
--secrets-include-glob='*.crt' \
--alsologtostderr &
./main --kubeconfig=$CONFIG_PATH \
--secrets-annotation-selector='cert-manager.io/certificate-name' \
--secrets-namespace='cert-manager-test' \
--secrets-include-glob='*.crt' \
--alsologtostderr &
pid=$!
sleep 10

Expand All @@ -99,11 +87,11 @@ kill $pid

echo "** Testing Label Selector And Exclude Glob"
# run exporter
./main --kubeconfig $(eval $CONFIG_PATH) \
--secrets-annotation-selector='cert-manager.io/certificate-name' \
--secrets-namespace 'cert-manager-test' \
--secrets-exclude-glob='*.key' \
--alsologtostderr &
./main --kubeconfig=$CONFIG_PATH \
--secrets-annotation-selector='cert-manager.io/certificate-name' \
--secrets-namespace='cert-manager-test' \
--secrets-exclude-glob='*.key' \
--alsologtostderr &
pid=$!
sleep 10

Expand All @@ -114,5 +102,5 @@ echo "** Killing $pid"
kill $pid

rm ./main
kubectl --kubeconfig $(eval $CONFIG_PATH) delete -f ./certs.yaml
k3d delete --name=$K3D_NAME
kind delete cluster --name=$KIND_CLUSTER_NAME --kubeconfig=$CONFIG_PATH
rm $CONFIG_PATH
2 changes: 1 addition & 1 deletion test/files/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ validateMetrics() {
./testCleanup.sh

# build
GO111MODULE=on go mod vendor
go build ../../main.go
chmod +x main

days=${1:-100}
export NODE_NAME="master0"
Expand Down

0 comments on commit e862aff

Please sign in to comment.