Created
April 19, 2022 09:53
-
-
Save ormergi/6712a76327bfb1c0c4bc873accc628da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -ex | |
CRI=${CRI:-podman} | |
kind="./kind" | |
! [ -f $kind ] && \ | |
wget -nv "https://github.com/kubernetes-sigs/kind/releases/download/v0.11.1/kind-linux-amd64" -O $kind && \ | |
chmod +x $kind | |
CLUSTER_NAME=test | |
! [ $($kind get clusters 2> /dev/null | grep "$CLUSTER_NAME") ] && \ | |
$kind create cluster --name "${CLUSTER_NAME}" | |
kubeconfig="./kubeconfig" | |
$kind get kubeconfig --name "${CLUSTER_NAME}" > "kubeconfig" | |
export KUBECONFIG=$kubeconfig | |
kubectl get nodes -A | |
kubectl get pods -A | |
echo "" | |
BINARY_NAME="framework" | |
go build -o $BINARY_NAME ./kiagnose/cmd/ | |
TAG="devel" | |
FRAMEWORK_IMAGE="${BINARY_NAME}:${TAG}" | |
$CRI build -t ${FRAMEWORK_IMAGE} -f- . <<EOF | |
FROM alpine:3.15.0 | |
RUN apk add --no-cache libc6-compat | |
COPY $BINARY_NAME /usr/local/bin | |
ENTRYPOINT $BINARY_NAME | |
EOF | |
$kind load docker-image --name ${CLUSTER_NAME} ${FRAMEWORK_IMAGE} | |
FRAMEWORK_NAMESPACE="framework" | |
kubectl create ns "${FRAMEWORK_NAMESPACE}" || true | |
CHECKUP_IMAGE="hello-world" | |
CHECKUP_CONFIGMAP="echo-checkup" | |
cat <<EOF | kubectl apply -f - | |
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: ${CHECKUP_CONFIGMAP} | |
namespace: ${FRAMEWORK_NAMESPACE} | |
data: | |
spec.image: ${CHECKUP_IMAGE} | |
spec.timeout: 1m | |
spec.param.message: "Hi!" | |
EOF | |
ADMIN_CLUSTER_ROLE_BINDING=${FRAMEWORK_NAMESPACE}-sa-admin | |
kubectl create clusterrolebinding "${ADMIN_CLUSTER_ROLE_BINDING}" --clusterrole=cluster-admin --serviceaccount="${FRAMEWORK_NAMESPACE}:default" || true | |
cat <<EOF | kubectl apply -f - | |
apiVersion: batch/v1 | |
kind: Job | |
metadata: | |
name: checkup-launcher | |
namespace: ${FRAMEWORK_NAMESPACE} | |
spec: | |
backoffLimit: 0 | |
template: | |
spec: | |
restartPolicy: Never | |
containers: | |
- name: checkup-launcher | |
image: ${FRAMEWORK_IMAGE} | |
env: | |
- name: CONFIGMAP_NAMESPACE | |
value: ${FRAMEWORK_NAMESPACE} | |
- name: CONFIGMAP_NAME | |
value: ${CHECKUP_CONFIGMAP} | |
EOF | |
pod=$(kubectl get pod -n $FRAMEWORK_NAMESPACE -l job-name=checkup-launcher --no-headers | awk '{print $1}') | |
kubectl wait pod -n $FRAMEWORK_NAMESPACE $pod --timeout 1m --for condition=ready | |
kubectl logs -n $FRAMEWORK_NAMESPACE $pod -f | |
kubectl delete ns $FRAMEWORK_NAMESPACE | |
kubectl delete clusterrolebinding $ADMIN_CLUSTER_ROLE_BINDING |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment