From 2ae7a6d36813fbe67ba979d1dbe70c471ee14f2b Mon Sep 17 00:00:00 2001 From: Joe Sirianni Date: Wed, 24 Jan 2024 16:50:01 -0500 Subject: [PATCH 01/13] wip: auto rollout --- action.yml | 4 ++++ entrypoint.sh | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 513ee8d..dcffaf9 100644 --- a/action.yml +++ b/action.yml @@ -25,6 +25,9 @@ inputs: description: 'Path to the directory which will contain the rendered OTEL format of the configuration resources' token: description: 'The GitHub token used to authenticate to GitHub when writing OTEL configs back to the repo' + enable_auto_rollout: + description: 'When enabled, the action will trigger a rollout for all configurations that have been updated' + default: false runs: using: 'docker' @@ -42,3 +45,4 @@ runs: - ${{ inputs.enable_otel_config_write_back }} - ${{ inputs.configuration_output_dir }} - ${{ inputs.token }} + - ${{ inputs.enable_auto_rollout }} diff --git a/entrypoint.sh b/entrypoint.sh index 7399f51..66af9b7 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -13,6 +13,7 @@ configuration_path=${7} enable_otel_config_write_back=${8} configuration_output_dir=${9} token=${10} +enable_auto_rollout=${11} # This branch name will be compared to target_branch to determine if the action # should apply or write back configurations. @@ -157,7 +158,13 @@ main() { bindplane apply "$destination_path" echo "Applying configuration path: $configuration_path" - bindplane apply "$configuration_path" + bindplane apply "$configuration_path" > configuration.out + + # When auto rollout is enabled + if [ "$enable_auto_rollout" = true ]; then + echo "Auto rollout enabled." + cat configuration.out + fi # When write back is enabled, write the raw otel configs # back to the repository. From dbeb8d831db8b4a62de5b430147422b57fe437d5 Mon Sep 17 00:00:00 2001 From: Joe Sirianni Date: Wed, 24 Jan 2024 16:51:18 -0500 Subject: [PATCH 02/13] test against this branch --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7fa3927..11daf21 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,7 @@ on: branches: - main - dev + - auto-rollout permissions: # Allow action to write raw configs back to the repository. @@ -99,7 +100,7 @@ jobs: destination_path: test/resources/destinations/resource.yaml configuration_path: test/resources/configurations/resource.yaml configuration_output_dir: test/otel/${{ matrix.bindplane_versions }} - target_branch: dev + target_branch: auto-rollout # TODO this should be main # Token should have contents: write permissions token: ${{ secrets.GITHUB_TOKEN }} enable_otel_config_write_back: true From 9af35ca41891cef9f2721835959c0886b150ebd7 Mon Sep 17 00:00:00 2001 From: Joe Sirianni Date: Wed, 24 Jan 2024 16:57:49 -0500 Subject: [PATCH 03/13] add auto rollout to workflow --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11daf21..7e67f9f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -104,6 +104,7 @@ jobs: # Token should have contents: write permissions token: ${{ secrets.GITHUB_TOKEN }} enable_otel_config_write_back: true + enable_auto_rollout: true - name: Get Resources if: always() From 737a3b9bac9a8a9e54093325eff31585d5f22a46 Mon Sep 17 00:00:00 2001 From: Joe Sirianni Date: Wed, 24 Jan 2024 17:01:24 -0500 Subject: [PATCH 04/13] print config apply output --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 66af9b7..112334d 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -159,11 +159,11 @@ main() { echo "Applying configuration path: $configuration_path" bindplane apply "$configuration_path" > configuration.out + cat configuration.out # When auto rollout is enabled if [ "$enable_auto_rollout" = true ]; then echo "Auto rollout enabled." - cat configuration.out fi # When write back is enabled, write the raw otel configs From b8865488e1d896e83b190c0a0e5bbe94606da5ed Mon Sep 17 00:00:00 2001 From: Joe Sirianni Date: Wed, 24 Jan 2024 17:08:18 -0500 Subject: [PATCH 05/13] check rollout status --- entrypoint.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 112334d..55536bc 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -164,6 +164,10 @@ main() { # When auto rollout is enabled if [ "$enable_auto_rollout" = true ]; then echo "Auto rollout enabled." + for config in $(cat configuration.out | awk '{print $2}'); do + bindplane rollout status "$config" + #| grep Pending + done fi # When write back is enabled, write the raw otel configs From 79d62553765d21605444362186ef1b29f8503e90 Mon Sep 17 00:00:00 2001 From: Joe Sirianni Date: Wed, 24 Jan 2024 17:13:18 -0500 Subject: [PATCH 06/13] check for pending rollout --- entrypoint.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 55536bc..6a44ef5 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -165,8 +165,11 @@ main() { if [ "$enable_auto_rollout" = true ]; then echo "Auto rollout enabled." for config in $(cat configuration.out | awk '{print $2}'); do - bindplane rollout status "$config" - #| grep Pending + status=$(bindplane rollout status "${config}" -o json | jq .status) + if [ "$status" = 0 ]; then + echo "Configuration ${config} has a pending rollout, triggering rollout." + bindplane rollout start "$config" + fi done fi From 33b4edcf4cd5a56ca49dd9deca38350e9ea47f71 Mon Sep 17 00:00:00 2001 From: Joe Sirianni Date: Wed, 24 Jan 2024 17:15:44 -0500 Subject: [PATCH 07/13] shellcheck: Fix loop logic --- entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 6a44ef5..4c00524 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -164,7 +164,8 @@ main() { # When auto rollout is enabled if [ "$enable_auto_rollout" = true ]; then echo "Auto rollout enabled." - for config in $(cat configuration.out | awk '{print $2}'); do + awk '{print $2}' < configuration.out | while IFS= read -r config + do status=$(bindplane rollout status "${config}" -o json | jq .status) if [ "$status" = 0 ]; then echo "Configuration ${config} has a pending rollout, triggering rollout." From 06c1490e2c7d45fefbc78549f00697f38d507d46 Mon Sep 17 00:00:00 2001 From: Joe Sirianni Date: Wed, 24 Jan 2024 17:16:21 -0500 Subject: [PATCH 08/13] install jq --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b0c2834..085168b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # Container image that runs your code FROM alpine:3.10 -RUN apk add --no-cache bash curl git +RUN apk add --no-cache bash curl git jq COPY --chmod=0755 entrypoint.sh /entrypoint.sh From 2475874b488cad7fd96c3ff819f4e8f2302d1d24 Mon Sep 17 00:00:00 2001 From: Joe Sirianni Date: Wed, 24 Jan 2024 17:19:38 -0500 Subject: [PATCH 09/13] add enable_auto_rollout to readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ca59726..8eb3e7f 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ server. It also supports exporting the OpenTelemetry configurations back to the | enable_otel_config_write_back | `false` | Whether or not the action should write the raw OpenTelemetry configurations back to the repository. | | configuration_output_dir | | When write back is enabled, this is the path that will be written to. | | token | | The Github token that will be used to write to the repo. Usually secrets.GITHUB_TOKEN is sufficient. Requires the `contents.write` permission. | +| enable_auto_rollout | `false` | When enabled, the action will trigger a rollout for any configuration that has been updated. | ## Usage @@ -80,6 +81,7 @@ jobs: enable_otel_config_write_back: true configuration_output_dir: otel/ token: ${{ secrets.GITHUB_TOKEN }} + enable_auto_rollout: true ``` After the action is executed, you can expect to see OTEL configurations From 1fcf3288f69b761f0211bb2d4a6034e849f9bc8c Mon Sep 17 00:00:00 2001 From: Joe Sirianni Date: Wed, 24 Jan 2024 17:20:17 -0500 Subject: [PATCH 10/13] revert this change, use external repo for testing this pr --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e67f9f..a8a12a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -100,7 +100,7 @@ jobs: destination_path: test/resources/destinations/resource.yaml configuration_path: test/resources/configurations/resource.yaml configuration_output_dir: test/otel/${{ matrix.bindplane_versions }} - target_branch: auto-rollout # TODO this should be main + target_branch: dev # Token should have contents: write permissions token: ${{ secrets.GITHUB_TOKEN }} enable_otel_config_write_back: true From 7cc8fc99e3ff3f2e7501db78e01e6c2851e988c9 Mon Sep 17 00:00:00 2001 From: Joe Sirianni Date: Wed, 24 Jan 2024 17:23:47 -0500 Subject: [PATCH 11/13] check for stable configs as well --- entrypoint.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 4c00524..9b15551 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -167,9 +167,13 @@ main() { awk '{print $2}' < configuration.out | while IFS= read -r config do status=$(bindplane rollout status "${config}" -o json | jq .status) + # TODO(jsirianni): Use switch case and check for all status codes, before + # merging this PR. Just need to look up the mapping. if [ "$status" = 0 ]; then echo "Configuration ${config} has a pending rollout, triggering rollout." bindplane rollout start "$config" + elif [ "$status" = 4 ]; then + echo "Configuration ${config} is stable, skipping rollout." fi done fi From 8d7a6dc4f5f1334977c8af3ef06df5dc664b4acd Mon Sep 17 00:00:00 2001 From: Joe Sirianni Date: Wed, 24 Jan 2024 17:24:06 -0500 Subject: [PATCH 12/13] remove branch from ci, we will test using an external repo --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8a12a5..f0db9eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,6 @@ on: branches: - main - dev - - auto-rollout permissions: # Allow action to write raw configs back to the repository. From 8c8471f351550aa0f19a7e13955556f5380eb826 Mon Sep 17 00:00:00 2001 From: jsirianni Date: Fri, 26 Jan 2024 12:22:36 -0500 Subject: [PATCH 13/13] use case --- entrypoint.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 9b15551..6bb66e7 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -167,14 +167,18 @@ main() { awk '{print $2}' < configuration.out | while IFS= read -r config do status=$(bindplane rollout status "${config}" -o json | jq .status) - # TODO(jsirianni): Use switch case and check for all status codes, before - # merging this PR. Just need to look up the mapping. - if [ "$status" = 0 ]; then - echo "Configuration ${config} has a pending rollout, triggering rollout." - bindplane rollout start "$config" - elif [ "$status" = 4 ]; then - echo "Configuration ${config} is stable, skipping rollout." - fi + case "$status" in + 0) + echo "Configuration ${config} has a pending rollout, triggering rollout." + bindplane rollout start "$config" + ;; + 4) + echo "Configuration ${config} is stable, skipping rollout." + ;; + *) + echo "Configuration ${config} has an unknown status, skipping rollout." + ;; + esac done fi