Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
Move out of kubernetes-manifests into an image
Browse files Browse the repository at this point in the history
Removes dependency to install jq and curl at runtime
  • Loading branch information
george-angel committed Apr 12, 2024
0 parents commit 1314227
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:3.19

RUN apk add --no-cache curl jq

COPY kube-control-plane-labeller /

ENTRYPOINT ["/kube-control-plane-labeller"]
22 changes: 22 additions & 0 deletions kube-control-plane-labeller
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

set -e;

KUBE_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token);

labelsPresent="false"
while [[ "${labelsPresent}" == "false" ]]; do
echo "Attempting to label node"
body=$(curl -sS --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt \
-H "Authorization: Bearer $KUBE_TOKEN" \
-H "Accept: application/json" \
-H "Content-Type: application/strategic-merge-patch+json" \
-X PATCH \
-d '{"metadata": {"labels":{"node-role.kubernetes.io/master": "", "node-role.kubernetes.io/control-plane": ""}}}' \
https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}/api/v1/nodes/${NODE_NAME}/status;)
echo ${body}
labelsPresent=$(echo ${body} | jq -r '.metadata.labels | has("node-role.kubernetes.io/master") and has("node-role.kubernetes.io/control-plane")')
sleep 5;
done;
echo "Node labelled, sleeping..."
sleep infinity

0 comments on commit 1314227

Please sign in to comment.