This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dump kubeconfig on entrypoint (#31)
- Loading branch information
1 parent
dcba5ea
commit 929b688
Showing
4 changed files
with
74 additions
and
23 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
FROM bash:5 | ||
ENV KUBECONFIG=/etc/kubernetes/kubeconfig | ||
COPY subst /subst | ||
COPY argocd-cmp/cmp.yaml /home/argocd/cmp-server/config/plugin.yaml | ||
COPY argocd-cmp/entrypoint.sh /entrypoint.sh | ||
RUN adduser -H -D -s /bin/bash -G nobody -u 999 argocd && \ | ||
chmod +x /entrypoint.sh | ||
USER argocd:nobody | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/sh | ||
|
||
# Create Kubeconfig, if possible (CMP does not have access to the CLuster Kubernetes environment Variables, therefore we need to pass them in) | ||
if [ -f "/etc/kubernetes/kubeconfig" ]; then | ||
echo "🦄 /etc/kubernetes/kubeconfig already present" | ||
else | ||
# Create Kubeconfig, if possible (CMP does not have access to the CLuster Kubernetes environment Variables, therefore we need to pass them in) | ||
TOKEN="" | ||
if [ -f "/var/run/secrets/kubernetes.io/serviceaccount/token" ]; then | ||
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) | ||
fi | ||
CA="" | ||
if [ -f "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" ]; then | ||
CA=$(cat /var/run/secrets/kubernetes.io/serviceaccount/ca.crt | base64 -w0) | ||
fi | ||
if [ -z "$TOKEN" ] || [ -z "$CA" ]; then | ||
echo "💥 Unable to create Kubeconfig" | ||
else | ||
cat <<EOF > "/etc/kubernetes/kubeconfig" | ||
apiVersion: v1 | ||
clusters: | ||
- cluster: | ||
certificate-authority-data: ${CA} | ||
server: https://kubernetes.default.svc | ||
name: default-cluster | ||
contexts: | ||
- context: | ||
cluster: default-cluster | ||
namespace: default | ||
user: default-auth | ||
name: default-context | ||
current-context: default-context | ||
kind: Config | ||
preferences: {} | ||
users: | ||
- name: default-auth | ||
user: | ||
token: ${TOKEN} | ||
EOF | ||
echo "🦄 Kubeconfig Created" | ||
fi | ||
fi | ||
|
||
exec "$@" |