Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Auto rollout #4

Merged
merged 13 commits into from
Jan 29, 2024
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,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()
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -42,3 +45,4 @@ runs:
- ${{ inputs.enable_otel_config_write_back }}
- ${{ inputs.configuration_output_dir }}
- ${{ inputs.token }}
- ${{ inputs.enable_auto_rollout }}
25 changes: 24 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -157,7 +158,29 @@ main() {
bindplane apply "$destination_path"

echo "Applying configuration path: $configuration_path"
bindplane apply "$configuration_path"
bindplane apply "$configuration_path" > configuration.out
cat configuration.out
Comment on lines +161 to +162
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capture the output in configuration.out to be used later. Cat it out so it is still visable in the action output.


# When auto rollout is enabled
if [ "$enable_auto_rollout" = true ]; then
echo "Auto rollout enabled."
awk '{print $2}' < configuration.out | while IFS= read -r config
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loops through each line in the file. The file looks like this:

Configuration k8s-cluster:1 created
Configuration k8s-gateway:1 created
Configuration k8s-node:1 created

Awk is used to grab the second column, which would be the config name with the version suffix. This allows us to do a bindplane rollout status $config for each configuration that was applied. This is better than checking all configs that might exist in bindplane, we only want to check on configs managed by the action.

do
status=$(bindplane rollout status "${config}" -o json | jq .status)
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

# When write back is enabled, write the raw otel configs
# back to the repository.
Expand Down
Loading