Skip to content

Commit 2d22bad

Browse files
authored
create token for k8s 1.24 (#71)
* create token for k8s 1.24 * fix * updated version to 0.6.0 * added logs * testing insecure * removed cacert * reverted `set-cluster` to secure mode * updated to 0.0.516
1 parent 224761d commit 2d22bad

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

add-cluster/add-cluster.sh

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,31 @@
88
# ANNOTATIONS (cm - optional)
99
# CSDP_TOKEN_SECRET
1010

11+
SECRET_NAME=""
12+
13+
function get_service_account_secret_name() {
14+
SECRET_NAME=$(kubectl get ServiceAccount ${SERVICE_ACCOUNT_NAME} -n ${NAMESPACE} -o jsonpath='{.secrets[0].name}')
15+
if [[ -z ${SECRET_NAME} ]]; then
16+
echo "Creating new ServiceAccount token"
17+
# create secret for service account
18+
SECRET_NAME=$(kubectl create -f - <<EOF
19+
apiVersion: v1
20+
kind: Secret
21+
metadata:
22+
generateName: ${SERVICE_ACCOUNT_NAME}-token-
23+
annotations:
24+
kubernetes.io/service-account.name: ${SERVICE_ACCOUNT_NAME}
25+
type: kubernetes.io/service-account-token
26+
EOF
27+
)
28+
SECRET_NAME=$(echo ${SECRET_NAME} | sed s@secret/@@g | sed s/\ created//g)
29+
kubectl patch ServiceAccount ${SERVICE_ACCOUNT_NAME} -n ${NAMESPACE} --patch "{\"secrets\": [{\"name\": \"${SECRET_NAME}\"}]}"
30+
echo "Created ServiceAccount sercret ${SECRET_NAME}"
31+
else
32+
echo "Found ServiceAccount secret ${SECRET_NAME}"
33+
fi
34+
}
35+
1136
echo "ServiceAccount: ${SERVICE_ACCOUNT_NAME}"
1237
echo "Ingress URL: ${INGRESS_URL}"
1338
echo "Context Name: ${CONTEXT_NAME}"
@@ -23,8 +48,7 @@ NAMESPACE=$(cat ${SERVICEACCOUNT}/namespace)
2348
CACERT=${SERVICEACCOUNT}/ca.crt
2449

2550
# get ServiceAccount token
26-
SECRET_NAME=$(kubectl get ServiceAccount ${SERVICE_ACCOUNT_NAME} -n ${NAMESPACE} -o jsonpath='{.secrets[0].name}')
27-
echo "Found ServiceAccount secret ${SECRET_NAME}"
51+
get_service_account_secret_name
2852
BEARER_TOKEN=$(kubectl get secret ${SECRET_NAME} -n ${NAMESPACE} -o jsonpath='{.data.token}' | base64 -d)
2953

3054
# write KUBE_COPNFIG_DATA to local file
@@ -37,6 +61,7 @@ KUBE_CONFIG_B64=$(kubectl config view --minify --flatten --output json --context
3761
ANNOTATIONS_B64=$(cat /etc/config/annotations.yaml | base64 -w 0)
3862
LABELS_B64=$(cat /etc/config/labels.yaml | base64 -w 0)
3963

64+
echo "{ \"name\": \"'${CONTEXT_NAME}'\", \"kubeConfig\": \"'${KUBE_CONFIG_B64}'\", \"annotations\": \"'${ANNOTATIONS_B64}'\", \"labels\": \"'${LABELS_B64}'\" }"
4065
STATUS_CODE=$(curl -X POST ${INGRESS_URL%/}/app-proxy/api/clusters \
4166
-H 'Content-Type: application/json' \
4267
-H 'Authorization: '${CSDP_TOKEN}'' \

add-cluster/helm/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ type: application
66

77
version: 0.2.0
88

9-
appVersion: 0.5.0
9+
appVersion: 0.6.0

add-cluster/kustomize/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace: kube-system
44

55
images:
66
- name: quay.io/codefresh/csdp-add-cluster
7-
newTag: 0.5.0
7+
newTag: 0.6.0
88

99
resources:
1010
- configmap.yaml

csdp/base_components/bootstrap/kustomization.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ configMapGenerator:
1212
- name: codefresh-cm
1313
behavior: create
1414
literals:
15-
- version=0.0.515 # Runtime version
16-
- bootstrapRevision=0.0.515 # Tag to use for bootstrap (change this to the name of your branch if you want to test changes)
15+
- version=0.0.516 # Runtime version
16+
- bootstrapRevision=0.0.516 # Tag to use for bootstrap (change this to the name of your branch if you want to test changes)
1717
- appsetRequeueTime=15
1818

1919
replacements:

0 commit comments

Comments
 (0)