Skip to content

Instantly share code, notes, and snippets.

@colinjfw
Last active December 23, 2021 18:28
Show Gist options
  • Save colinjfw/58ec321708b761b79c0fd9c33eec8716 to your computer and use it in GitHub Desktop.
Save colinjfw/58ec321708b761b79c0fd9c33eec8716 to your computer and use it in GitHub Desktop.

Revisions

  1. colinjfw revised this gist Aug 29, 2019. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions kustomize-deploy.sh
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,8 @@
    # revision=ab331a
    # images='[{ "name": "nginx", "newTag": "latest" }]'
    # variables='{"host": "pr123.example.com"}'
    set -e
    echo "deploying $release into namespace $namespace using overlay overlays/$target"

    mkdir -p build
    cd build
    @@ -40,8 +42,6 @@ apiVersion: v1
    kind: Namespace
    metadata:
    name: $namespace
    labels:
    deliverybot.io/release: $release
    EOF

    echo $variables > variables.yaml
    @@ -50,4 +50,4 @@ yq --yaml-output -s add ../overlays/$target/variables.yaml variables.yaml > merg
    kustomize build | mustache merged.yaml - > build.yaml

    kubectl apply -f namespace.yaml
    kubectl apply -f build.yaml --prune --selector deliverybot.io/release=$release
    kubectl apply -f build.yaml --prune --selector deliverybot.io/release=$release --prune-whitelist=core/v1/Namespace
  2. colinjfw revised this gist Aug 29, 2019. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions kustomize-remove.sh
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,23 @@
    # Kustomize based deletion workflow. Requires jq, kubectl.
    #
    # Expected variables:
    # - namespace Namespace for the release.
    # -
    # - release A unique name to give to this collection of manifests.
    # - delete Resource delete whitelist.
    #
    # Example inputs:
    # namespace=pr123
    # release=app-pr123
    # delete='["deployment", "service", "ingress", "namespace"]'
    set -e

    echo "removing $release with resources $delete"

    resources=$(echo $delete | jq -r 'join(",")')
    kubectl --namespace $namespace delete $resources --selector deliverybot.io/release=$release

    remove_namespace=$(echo $delete | jq 'contains(["namespace"])')
    if [ "$remove_namespace" = "true" ]; then
    kubectl delete ns/$namespace || exit 0
    fi
  3. colinjfw revised this gist Aug 29, 2019. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  4. colinjfw revised this gist Aug 29, 2019. No changes.
  5. colinjfw revised this gist Aug 29, 2019. 2 changed files with 12 additions and 0 deletions.
    File renamed without changes.
    12 changes: 12 additions & 0 deletions remove.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    # Kustomize based deletion workflow. Requires jq, kubectl.
    #
    # Expected variables:
    # - release A unique name to give to this collection of manifests.
    # - delete Resource delete whitelist.
    #
    # Example inputs:
    # release=app-pr123
    # delete='["deployment", "service", "ingress", "namespace"]'

    resources=$(echo $delete | jq -r 'join(",")')
    kubectl --namespace $namespace delete $resources --selector deliverybot.io/release=$release
  6. colinjfw revised this gist Aug 29, 2019. No changes.
  7. colinjfw created this gist Aug 29, 2019.
    53 changes: 53 additions & 0 deletions kustomize-deploy.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    # Kustomize based apply workflow. Requires jq, yq, kubectl, kustomize, mustache.
    #
    # Expected variables
    # - namespace Namespace for all resources.
    # - release A unique name to give to this collection of manifests.
    # - revision Release revision.
    # - images Image replacements.
    # - variables Variable replacements.
    #
    # Example inputs:
    # namespace=pr123
    # release=app-pr123
    # target=review
    # revision=ab331a
    # images='[{ "name": "nginx", "newTag": "latest" }]'
    # variables='{"host": "pr123.example.com"}'

    mkdir -p build
    cd build

    cat > kustomization.yaml <<EOF
    namespace: $namespace
    namePrefix: $release-
    commonLabels:
    deliverybot.io/release: $release
    commonAnnotations:
    deliverybot.io/target: $target
    deliverybot.io/revision: $revision
    images: $images
    resources:
    - ../overlays/$target
    EOF

    cat > namespace.yaml <<EOF
    apiVersion: v1
    kind: Namespace
    metadata:
    name: $namespace
    labels:
    deliverybot.io/release: $release
    EOF

    echo $variables > variables.yaml
    yq --yaml-output -s add ../overlays/$target/variables.yaml variables.yaml > merged.yaml

    kustomize build | mustache merged.yaml - > build.yaml

    kubectl apply -f namespace.yaml
    kubectl apply -f build.yaml --prune --selector deliverybot.io/release=$release