zarf
zarf copied to clipboard
Refactor actions to move to common library
Describe what should be investigated or refactored
The actions functionality of zarf should be refactored and moved to https://github.com/defenseunicorns/pkg so it can by other projects.
Tying this to this: https://github.com/defenseunicorns/zarf/issues/2203 since they are related
We should ensure we add unit tests during this migration: https://github.com/defenseunicorns/zarf/issues/1750
requesting an easier pattern to set ZARF_VAR
s
Currently now there's no way to set multiple ZARF_VAR
s that have different values in a single action.
Something like how github actions implemented scales nicely
For example:
components:
- name: fetch-staged-aws-ssm-vars
required: false
description: "Fetch staged json object from AWS SSM Parameter Store and extract values for zarf variables"
actions:
onDeploy:
before:
# get the cluster name
- cmd: kubectl config current-context | awk -F'[:/]' '{print $NF}'
setVariables:
- name: CLUSTER_NAME
- cmd: aws eks describe-cluster --name ${ZARF_VAR_CLUSTER_NAME} --query 'cluster.endpoint' --output text | cut -d . -f3
setVariables:
- name: CLUSTER_AWS_REGION
- cmd: aws ssm get-parameter --name "/${ZARF_VAR_CLUSTER_NAME}/${ZARF_VAR_CLUSTER_AUTOSCALER_HELM_INPUT_VALUES_PATH}" --with-decryption
setVariables:
- name: CLUSTER_AUTOSCALER_HELM_INPUT_VALUES
- cmd: jq -r '.Parameter.Value | fromjson | .iam_role_arn' <<< "$ZARF_VAR_CLUSTER_AUTOSCALER_HELM_INPUT_VALUES"
setVariables:
- name: IAM_ROLE_ARN
- cmd: jq -r '.Parameter.Value | fromjson | .service_account' <<< "$ZARF_VAR_CLUSTER_AUTOSCALER_HELM_INPUT_VALUES"
setVariables:
- name: SERVICE_ACCOUNT
could become
- name: fetch-staged-aws-ssm-vars
required: false
description: "Fetch staged json object from AWS SSM Parameter Store and extract values for zarf variables"
actions:
onDeploy:
before:
- cmd: |
echo "CLUSTER_NAME=$(kubectl config current-context | awk -F'[:/]' '{print $NF}')" >> ZARF_ENV
echo "CLUSTER_AWS_REGION=$(aws eks describe-cluster --name ${ZARF_VAR_CLUSTER_NAME} --query 'cluster.endpoint' --output text | cut -d . -f3)" >> ZARF_ENV
echo "CLUSTER_AUTOSCALER_HELM_INPUT_VALUES=$(aws ssm get-parameter --name "/${ZARF_VAR_CLUSTER_NAME}/${ZARF_VAR_CLUSTER_AUTOSCALER_HELM_INPUT_VALUES_PATH}" --with-decryption)" >> ZARF_ENV
echo "IAM_ROLE_ARN=$(jq -r '.Parameter.Value | fromjson | .iam_role_arn' <<< "$ZARF_VAR_CLUSTER_AUTOSCALER_HELM_INPUT_VALUES")" >> ZARF_ENV
echo "SERVICE_ACCOUNT=$(jq -r '.Parameter.Value | fromjson | .service_account' <<< "$ZARF_VAR_CLUSTER_AUTOSCALER_HELM_INPUT_VALUES")" >> ZARF_ENV