Skip to content

Commit

Permalink
Add kubectl and helm to kind image (#6)
Browse files Browse the repository at this point in the history
* set local bin path

* install kubectl

* install helm, default kind version

* default helm version
  • Loading branch information
tenyo authored Feb 12, 2024
1 parent 4960b7b commit 3b0349f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This plugin allows for creation and configuration of a KinD cluster within a Bui
* k8s_version: The major and minor release of K8S that you would like to target (i.e. v1.29, v1.28, etc.). Default (`v1.29`)
* custom_image: The repository location of a KinD node image that you would like to use rather than the standard published versions from the KinD project (ex: quay.io/myorg/mynodeimage:v1.0.0). This will take priority over `k8s_version`.
* kind_version: The version of the KinD binary you would like to use. Defaults to `v0.21.0`.
* helm_version: The version of the Helm binary you would like to install. Defaults to `v3.14.0`.
* config_path: A path within your codebase that contains a KinD configuration file.
* debug_plugin: Whether to add verbosity to the logging of the plugin itself. This sets the `-x` flag within the plugin to show what commands are being run.

Expand All @@ -17,7 +18,7 @@ steps:
- label: ":k8s: Get Pods"
command: "kubectl get pods"
plugins:
- ssh://[email protected]/equinixmetal-buildkite/kind-cluster-buildkite-plugin#v0.0.1:
- ssh://[email protected]/equinixmetal-buildkite/kind-cluster-buildkite-plugin#v0.2.0:
k8s_version: "1.29"
config_path: ./config/my-config.yml
```
Expand Down
5 changes: 5 additions & 0 deletions hooks/environment
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ fi

echo "--- :k8s: Setting Cluster Name"
export CLUSTER_NAME=buildkite-${BUILDKITE_STEP_ID:-000}

echo "--- :bash: Setting local bin path"
export LOCAL_BIN=~/.local/bin
mkdir -p $LOCAL_BIN
export PATH=$PATH:$LOCAL_BIN
4 changes: 2 additions & 2 deletions hooks/post-command
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ else
set -eu
fi

echo "--- :k8s: Uploading Logs"
./kind export logs --name ${CLUSTER_NAME} ${CLUSTER_NAME}-kind-logs
echo "--- :package: Uploading Logs"
kind export logs --name ${CLUSTER_NAME} ${CLUSTER_NAME}-kind-logs
tar czvf "${CLUSTER_NAME}-logs.tar.gz" ${CLUSTER_NAME}-kind-logs
buildkite-agent artifact upload ${CLUSTER_NAME}-logs.tar.gz
26 changes: 22 additions & 4 deletions hooks/pre-command
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,31 @@ else
set -eu
fi

export KIND_VERSION=${BUILDKITE_PLUGIN_KIND_CLUSTER_KIND_VERSION:-v0.21.0}
export HELM_VERSION=${BUILDKITE_PLUGIN_KIND_CLUSTER_HELM_VERSION:-v3.14.0}

echo "--- :k8s: Installing KinD"
curl -Lo ./kind "https://kind.sigs.k8s.io/dl/v0.21.0/kind-linux-amd64"
chmod +x ./kind
curl -Lo ${LOCAL_BIN}/kind "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-linux-amd64"
chmod +x ${LOCAL_BIN}/kind
kind version

echo "--- :k8s: Installing kubectl"
curl -Lo ${LOCAL_BIN}/kubectl https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && \
chmod +x ${LOCAL_BIN}/kubectl
kubectl version --client

echo "--- :helm: Installing Helm"
curl -L --fail --remote-name-all "https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz"
tar xzf helm-${HELM_VERSION}-linux-amd64.tar.gz linux-amd64/helm && \
mv linux-amd64/helm ${LOCAL_BIN}/ && \
rmdir linux-amd64 && \
rm helm-${HELM_VERSION}-linux-amd64.tar.gz
helm version

echo "--- :k8s: Creating Cluster - ${CLUSTER_NAME}"
./kind create cluster --name ${CLUSTER_NAME} --image ${IMAGE} ${KIND_CONFIG:-} --wait 2m
kind create cluster --name ${CLUSTER_NAME} --image ${IMAGE} ${KIND_CONFIG:-} --wait 2m

echo "--- :k8s: Setting Kubeconfig"
./kind export kubeconfig --name ${CLUSTER_NAME} --kubeconfig ./kubeconfig-${CLUSTER_NAME}
kind export kubeconfig --name ${CLUSTER_NAME} --kubeconfig ./kubeconfig-${CLUSTER_NAME}
export KUBECONFIG=$(pwd)/kubeconfig-${CLUSTER_NAME}

2 changes: 1 addition & 1 deletion hooks/pre-exit
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ else
set -eu
fi

./kind delete cluster --name ${CLUSTER_NAME}
kind delete cluster --name ${CLUSTER_NAME}
2 changes: 2 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ configuration:
type: string
kind_version:
type: string
helm_version:
type: string
config_path:
type: string
debug_plugin:
Expand Down

0 comments on commit 3b0349f

Please sign in to comment.