zarf icon indicating copy to clipboard operation
zarf copied to clipboard

Refactor actions to move to common library

Open AustinAbro321 opened this issue 1 year ago • 3 comments

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.

AustinAbro321 avatar Jan 24 '24 18:01 AustinAbro321

Tying this to this: https://github.com/defenseunicorns/zarf/issues/2203 since they are related

Racer159 avatar Jan 25 '24 01:01 Racer159

We should ensure we add unit tests during this migration: https://github.com/defenseunicorns/zarf/issues/1750

Racer159 avatar Jan 25 '24 01:01 Racer159

requesting an easier pattern to set ZARF_VARs

Currently now there's no way to set multiple ZARF_VARs 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

zack-is-cool avatar Jan 30 '24 17:01 zack-is-cool