Skip to content

Commit

Permalink
Fix/karpenter setup with sed (#2536)
Browse files Browse the repository at this point in the history
* Fixing the sed command in the create karpenter resources job

* Fixing some silliness

* Please let me blame that on Friday brain

* Let's do it

* What was I doing before?

* Using a more robust method for grabbing workflow and usernames
  • Loading branch information
AidanHilt authored May 1, 2024
1 parent ec4053e commit 7f56512
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
20 changes: 17 additions & 3 deletions kube/services/argo-events/workflows/sensor-created.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,22 @@ spec:
args:
- "-c"
- |
#!/bin/bash
if [ -z "$PROVISIONER_TEMPLATE" ]; then
PROVISIONER_TEMPLATE="provisioner.yaml"
fi
if [ -z "$AWSNODETEMPLATE_TEMPLATE" ]; then
AWSNODETEMPLATE_TEMPLATE="nodetemplate.yaml"
fi
if ! kubectl get awsnodetemplate workflow-$WORKFLOW_NAME >/dev/null 2>&1; then
sed -e "s/WORKFLOW_NAME/$workflow_name/" -e "s/GEN3_USERNAME/$workflow_user/" -e "s/ENVIRONMENT/$ENVIRONMENT/" | kubectl apply -f -
sed -e "s/WORKFLOW_NAME/$WORKFLOW_NAME/" -e "s/GEN3_USERNAME/$GEN3_USERNAME/" -e "s/ENVIRONMENT/$ENVIRONMENT/" "$AWSNODETEMPLATE_TEMPLATE" | kubectl apply -f -
fi
if ! kubectl get provisioner workflow-$WORKFLOW_NAME >/dev/null 2>&1; then
sed -e "s/WORKFLOW_NAME/$workflow_name/" -e "s/GEN3_USERNAME/$workflow_user/" -e "s/ENVIRONMENT/$ENVIRONMENT/" | kubectl apply -f -
sed -e "s/WORKFLOW_NAME/$WORKFLOW_NAME/" -e "s/GEN3_USERNAME/$GEN3_USERNAME/" -e "s/ENVIRONMENT/$ENVIRONMENT/" "$PROVISIONER_TEMPLATE" | kubectl apply -f -
fi
env:
- name: WORKFLOW_NAME
Expand All @@ -76,9 +86,13 @@ spec:
configMapKeyRef:
name: environment
key: environment
- name: PROVISIONER_TEMPLATE
value: /manifests/provisioner.yaml
- name: AWSNODETEMPLATE_TEMPLATE
value: /manifests/nodetemplate.yaml
volumeMounts:
- name: karpenter-templates-volume
mountPath: /home/manifests
mountPath: /manifests
volumes:
- name: karpenter-templates-volume
configMap:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,32 @@ spec:
ENVIRONMENT=$(kubectl -n default get configmap global -o jsonpath="{.data.environment}")
RAW_WORKFLOWS=$(kubectl get workflows -n argo -o yaml)
WORKFLOWS=$(echo "${RAW_WORKFLOWS}" | yq -r '.items[] | [.metadata.name, .metadata.labels.gen3username] | join(" ")')
WORKFLOWS=$(kubectl get workflows -n argo -o=jsonpath='{range .items[*]}{.metadata.name}{" "}{.metadata.labels.gen3username}{"\n"}')
WORKFLOW_ARRAY=()
while IFS= read -r line; do
WORKFLOW_ARRAY+=("$line")
done <<< "$WORKFLOWS"
echo $WORKFLOWS
for workflow in "${WORKFLOW_ARRAY[@]}"
do
workflow_name=$(echo "$workflow" | awk '{print $1}')
workflow_user=$(echo "$workflow" | awk '{print $2}')
if ! kubectl get awsnodetemplate workflow-$workflow_name >/dev/null 2>&1; then
echo "No awsnodetemplate found for ${workflow_name}, creating one"
sed -e "s/WORKFLOW_NAME/$workflow_name/" -e "s/GEN3_USERNAME/$workflow_user/" -e "s/ENVIRONMENT/$ENVIRONMENT/" "$AWSNODETEMPLATE_TEMPLATE" | kubectl apply -f -
fi
if [ ! -z "$workflow_name" ]; then
if ! kubectl get awsnodetemplate workflow-$workflow_name >/dev/null 2>&1; then
echo "No awsnodetemplate found for ${workflow_name}, creating one"
sed -e "s/WORKFLOW_NAME/$workflow_name/" -e "s/GEN3_USERNAME/$workflow_user/" -e "s/ENVIRONMENT/$ENVIRONMENT/" "$AWSNODETEMPLATE_TEMPLATE" | kubectl apply -f -
fi
if ! kubectl get provisioner workflow-$workflow_name >/dev/null 2>&1; then
echo "No provisioner found for ${workflow_name}, creating one"
sed -e "s/WORKFLOW_NAME/$workflow_name/" -e "s/GEN3_USERNAME/$workflow_user/" -e "s/ENVIRONMENT/$ENVIRONMENT/" "$PROVISIONER_TEMPLATE" | kubectl apply -f -
if ! kubectl get provisioner workflow-$workflow_name >/dev/null 2>&1; then
echo "No provisioner found for ${workflow_name}, creating one"
sed -e "s/WORKFLOW_NAME/$workflow_name/" -e "s/GEN3_USERNAME/$workflow_user/" -e "s/ENVIRONMENT/$ENVIRONMENT/" "$PROVISIONER_TEMPLATE" | kubectl apply -f -
fi
fi
done
restartPolicy: OnFailure

0 comments on commit 7f56512

Please sign in to comment.