Skip to content

Instantly share code, notes, and snippets.

@saviour123
Forked from alanmatiasdev/job.sh
Created January 22, 2025 13:17

Revisions

  1. @alanmatiasdev alanmatiasdev created this gist Nov 3, 2023.
    23 changes: 23 additions & 0 deletions job.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/bin/sh
    namespaces="${NAMESPACES}"

    if [ -z "$NAMESPACES" ]; then
    namespaces="default"
    fi

    if [ -z "$SECRET_NAME" ]; then
    SECRET_NAME=regcred
    fi

    TOKEN=`aws ecr get-login-password --region ${AWS_REGION}`

    for namespace in $namespaces; do
    echo "Updating ecr token to namespace: $namespace"
    kubectl delete secret -n $namespace --ignore-not-found $SECRET_NAME
    kubectl create secret -n $namespace docker-registry $SECRET_NAME \
    --docker-server=$ECR_REPOSITORY \
    --docker-username=AWS \
    --docker-password=$TOKEN \
    --namespace=$namespace
    kubectl patch serviceaccount default -p '{"imagePullSecrets":[{"name":"'$SECRET_NAME'"}]}' -n $namespace
    done