Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit 929b688

Browse files
feat: dump kubeconfig on entrypoint (#31)
1 parent dcba5ea commit 929b688

File tree

4 files changed

+74
-23
lines changed

4 files changed

+74
-23
lines changed

.goreleaser.yml

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ builds:
1515
goarch:
1616
- amd64
1717
- arm64
18-
- arm
1918
goos:
2019
- linux
2120
- darwin
22-
- windows
2321
flags:
2422
- -trimpath
2523
mod_timestamp: '{{ .CommitTimestamp }}'
@@ -28,13 +26,6 @@ builds:
2826
-X github.com/buttahtoast/subst/subst/cmd.Version={{ .Tag }}
2927
-X github.com/buttahtoast/subst/subst/cmd.GitCommit={{ .Commit }}
3028
-X github.com/buttahtoast/subst/subst/cmd.BuildDate={{ .Date }}
31-
archives:
32-
- format_overrides:
33-
- goos: windows
34-
format: zip
35-
files:
36-
- LICENSE
37-
- README.md
3829
release:
3930
footer: |
4031
**Full Changelog**: https://github.com/buttahtoast/{{ .ProjectName }}/compare/{{ .PreviousTag }}...{{ .Tag }}
@@ -51,7 +42,9 @@ checksum:
5142
snapshot:
5243
name_template: "{{ .Tag }}-next"
5344
dockers:
54-
- image_templates: [ "ghcr.io/buttahtoast/{{ .ProjectName }}:{{ .Tag }}" ]
45+
- image_templates:
46+
- "ghcr.io/buttahtoast/{{ .ProjectName }}:{{ .Tag }}"
47+
- "ghcr.io/buttahtoast/{{ .ProjectName }}:latest"
5548
dockerfile: Dockerfile
5649
goos: linux
5750
goarch: amd64
@@ -93,8 +86,10 @@ dockers:
9386
# - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/buttahtoast/subst/main/README.md"
9487
# - "--label=io.artifacthub.package.logo-url=https://github.com/buttahtoast/subst/raw/main/img/subst.png"
9588
# - "--label=io.artifacthub.package.license=Apache-2.0"
96-
- image_templates: [ "ghcr.io/buttahtoast/{{ .ProjectName }}-cmp:{{ .Tag }}" ]
97-
dockerfile: Dockerfile.argo-cmp
89+
- image_templates:
90+
- "ghcr.io/buttahtoast/{{ .ProjectName }}-cmp:{{ .Tag }}"
91+
- "ghcr.io/buttahtoast/{{ .ProjectName }}-cmp:latest"
92+
dockerfile: argocd-cmp/Dockerfile
9893
goos: linux
9994
goarch: amd64
10095
use: buildx
@@ -116,6 +111,7 @@ dockers:
116111
- "--label=io.artifacthub.package.license=Apache-2.0"
117112
extra_files:
118113
- argocd-cmp/cmp.yaml
114+
- argocd-cmp/entrypoint.sh
119115
#- image_templates: [ "ghcr.io/buttahtoast/{{ .ProjectName }}-cmp:{{ .Tag }}" ]
120116
# dockerfile: Dockerfile.argo-cmp
121117
# goos: linux
@@ -184,13 +180,13 @@ docker_signs:
184180
- 'sign'
185181
- '${artifact}@${digest}'
186182
- --yes
187-
brews:
188-
- tap:
189-
owner: buttahtoast
190-
name: subst
191-
branch: main
192-
license: Apache-2.0
193-
homepage: "github.com/buttahtoast/subst"
194-
description: "subst - Substitution based on Kustomize"
195-
post_install: |
196-
puts '🌈 subst installed 🌈'
183+
#brews:
184+
# - tap:
185+
# owner: buttahtoast
186+
# name: subst
187+
# branch: main
188+
# license: Apache-2.0
189+
# homepage: "github.com/buttahtoast/subst"
190+
# description: "subst - Substitution based on Kustomize"
191+
# post_install: |
192+
# puts '🌈 subst installed 🌈'

argocd-cmp/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
FROM bash:5
3+
ENV KUBECONFIG=/etc/kubernetes/kubeconfig
4+
COPY subst /subst
5+
COPY argocd-cmp/cmp.yaml /home/argocd/cmp-server/config/plugin.yaml
6+
COPY argocd-cmp/entrypoint.sh /entrypoint.sh
7+
RUN adduser -H -D -s /bin/bash -G nobody -u 999 argocd && \
8+
chmod +x /entrypoint.sh
9+
USER argocd:nobody
10+
ENTRYPOINT ["/entrypoint.sh"]
11+

argocd-cmp/cmp.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ spec:
1414
- bash
1515
- -c
1616
- |
17-
/subst render . --secret-name ${ARGOCD_APP_NAME} --secret-namespace argocd --env-regex "^ARGOCD_ENV_.*$" --must-decrypt --kubeconfig /etc/kubernetes/admin.conf
17+
/subst render "." --secret-name "${ARGOCD_APP_NAME}" --secret-namespace "argocd" --env-regex "^ARGOCD_ENV_.*$" --must-decrypt --kubeconfig "/etc/kubernetes/kubeconfig"

argocd-cmp/entrypoint.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
2+
3+
# Create Kubeconfig, if possible (CMP does not have access to the CLuster Kubernetes environment Variables, therefore we need to pass them in)
4+
if [ -f "/etc/kubernetes/kubeconfig" ]; then
5+
echo "🦄 /etc/kubernetes/kubeconfig already present"
6+
else
7+
# Create Kubeconfig, if possible (CMP does not have access to the CLuster Kubernetes environment Variables, therefore we need to pass them in)
8+
TOKEN=""
9+
if [ -f "/var/run/secrets/kubernetes.io/serviceaccount/token" ]; then
10+
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
11+
fi
12+
CA=""
13+
if [ -f "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" ]; then
14+
CA=$(cat /var/run/secrets/kubernetes.io/serviceaccount/ca.crt | base64 -w0)
15+
fi
16+
if [ -z "$TOKEN" ] || [ -z "$CA" ]; then
17+
echo "💥 Unable to create Kubeconfig"
18+
else
19+
cat <<EOF > "/etc/kubernetes/kubeconfig"
20+
apiVersion: v1
21+
clusters:
22+
- cluster:
23+
certificate-authority-data: ${CA}
24+
server: https://kubernetes.default.svc
25+
name: default-cluster
26+
contexts:
27+
- context:
28+
cluster: default-cluster
29+
namespace: default
30+
user: default-auth
31+
name: default-context
32+
current-context: default-context
33+
kind: Config
34+
preferences: {}
35+
users:
36+
- name: default-auth
37+
user:
38+
token: ${TOKEN}
39+
EOF
40+
echo "🦄 Kubeconfig Created"
41+
fi
42+
fi
43+
44+
exec "$@"

0 commit comments

Comments
 (0)