Skip to content

Commit

Permalink
chart dependency workflow update (#1083)
Browse files Browse the repository at this point in the history
* Add CHANGELOG.md support to the update chart dependencies github workflow

* Fix indentation issue in Chart.yaml

* Refactor past certmanager and operator CHANGELOG.md entries to match new format

* fix comment

* fix more comments

* Remove extra exit checks in github workflows
  • Loading branch information
jvoravong authored Dec 15, 2023
1 parent e170b80 commit a30a33a
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 72 deletions.
97 changes: 45 additions & 52 deletions .github/workflows/update_chart_dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,71 +19,64 @@ on:
required: false
default: 'false'

env:
CHART_YAML: helm-charts/splunk-otel-collector/Chart.yaml

jobs:
maybe_update:
check_and_update:
runs-on: ubuntu-latest
strategy:
fail-fast: false # Continue all jobs even if one fails
matrix:
# Currently this worfklow will update the listed dependencies in the Chart.yaml
repo: ['cert-manager', 'opentelemetry-operator'] # Add other repos here
# Chart dependencies to check for version updates
include:
- name: 'certmanager'
component: 'operator'
yaml_file_path: 'helm-charts/splunk-otel-collector/Chart.yaml'
dependency_name: 'cert-manager'
- name: 'operator'
component: 'operator'
yaml_file_path: 'helm-charts/splunk-otel-collector/Chart.yaml'
dependency_name: 'opentelemetry-operator'
env:
DEBUG_MODE: ${{ github.event.inputs.DEBUG_MODE }}
steps:
- uses: actions/checkout@v4
- name: Update Chart
id: update_chart
run: |
echo "Update dependencies for Helm chart"
# Set debug argument if DEBUG_MODE is true
DEBUG_ARG=""
if [ "${{ github.event.inputs.DEBUG_MODE }}" == "true" ]; then
DEBUG_ARG="--debug"
fi
# Ensure chart dependencies are up-to-date
make dep-update
# Fetch the latest version using helm search repo
LATEST_VER=$(helm search repo ${{ matrix.repo }} --versions | awk 'NR==2{print $2}')
echo "LATEST_VER=$LATEST_VER" >> $GITHUB_OUTPUT
# Retrieve the current version from chart.yaml
DEP_PATH=$(yq eval ".dependencies[] | select(.name == \"${{ matrix.repo }}\") | .version" $CHART_YAML)
echo "Current version of ${{ matrix.repo }} is $DEP_PATH, latest is $LATEST_VER"

if [ "$LATEST_VER" == "$DEP_PATH" ]; then
echo We are already up to date. Nothing else to do.
else
echo 'Looks like we need to update...'
echo Updating to new version in chart.yaml
echo "NEED_UPDATE=1" >> $GITHUB_OUTPUT
- name: Check for Version Updates
id: check_for_update
run: |
echo "Checking chart dependency version for ${{ matrix.name }}"
# Update the version in chart.yaml using yq and jq
DEP_LINE=$(yq eval ".dependencies | keys | map(tonumber) | map(select(. != null)) | map(select(. < 10000)) | map(. + 1)" $CHART_YAML | jq ".[] | select(.[\"name\"] == \"${{ matrix.repo }}\")")
sed -i "${DEP_LINE}s/$DEP_PATH/$LATEST_VER/" $CHART_YAML
make update-chart-dep CHART_PATH=${{ matrix.yaml_file_path }} SUBCHART_NAME='${{ matrix.dependency_name }}' DEBUG_MODE=$DEBUG_MODE
if [ ${{ matrix.repo }} == "opentelemetry-operator" ]; then
echo "Update Splunk Operator Instrumentation Images if Needed"
./ci_scripts/update-images-operator-otel.sh ${{ matrix.language }} $DEBUG_ARG || exit 1
fi
- name: Open PR for Version Update
id: open_pr
if: ${{ steps.check_for_update.outputs.NEED_UPDATE == 1 }}
uses: peter-evans/create-pull-request@v5
with:
commit-message: Update ${{ matrix.name }} chart dependency version
title: Bump ${{ matrix.name }} from ${{ steps.check_for_update.outputs.CURRENT_VER }} to ${{ steps.check_for_update.outputs.LATEST_VER }} in ${{ matrix.yaml_file_path }}
body: Use the latest version of ${{ matrix.name }}
branch: "update-${{ matrix.name }}" # Same branch name for all PRs
base: main
delete-branch: true
modify-outputs: false

echo Updating rendered examples
make render
- name: Apply Version Update and Generate Changelog
if: ${{ steps.check_for_update.outputs.NEED_UPDATE == 1 }}
run: |
# Apply the version update, update the rendered examples with the version update, and create a changelog entry
# We run `make update-chart-dep` again here because the open_pr peter-evans/create-pull-request step before clears out the update changes locally
make update-chart-dep CHART_PATH=${{ matrix.yaml_file_path }} SUBCHART_NAME='${{ matrix.dependency_name }}' DEBUG_MODE=$DEBUG_MODE
make render
make chlog-new FILENAME="update-${{ matrix.name }}" CHANGE_TYPE=enhancement COMPONENT=${{ matrix.component }} NOTE="Bump ${{ matrix.name }} to ${{ steps.check_for_update.outputs.LATEST_VER }} in ${{ matrix.yaml_file_path }}" ISSUES=[${{ steps.open_pr.outputs.pull-request-number }}]
echo "Current git diff:"
git --no-pager diff
fi
- name: PR the new version
if: ${{ steps.update_chart.outputs.NEED_UPDATE == 1 }}
- name: Finalize PR with updates
if: ${{ steps.check_for_update.outputs.NEED_UPDATE == 1 }}
uses: peter-evans/create-pull-request@v5
with:
commit-message: Update ${{ matrix.repo }} chart version
title: Update ${{ matrix.repo }} chart version to ${{ steps.update_chart.outputs.LATEST_VER }}
body: Use the new version of the ${{ matrix.repo }} chart
branch: "update-${{ matrix.repo }}-${{ steps.update_chart.outputs.LATEST_VER }}"
commit-message: Update ${{ matrix.name }} chart dependency version
title: Bump ${{ matrix.name }} from ${{ steps.check_for_update.outputs.CURRENT_VER }} to ${{ steps.check_for_update.outputs.LATEST_VER }} in ${{ matrix.yaml_file_path }}
body: Use the latest version of ${{ matrix.name }}
branch: "update-${{ matrix.name }}" # Same branch name for all PRs
base: main
delete-branch: true
modify-outputs: false
8 changes: 4 additions & 4 deletions .github/workflows/update_docker_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: |
echo "Checking docker image version for ${{ matrix.name }}"
make update-docker-image FILE_PATH=${{ matrix.yaml_file_path }} QUERY_STRING='${{ matrix.yaml_value_path }}' DEBUG_MODE=$DEBUG_MODE || exit 1
make update-docker-image FILE_PATH=${{ matrix.yaml_file_path }} QUERY_STRING='${{ matrix.yaml_value_path }}' DEBUG_MODE=$DEBUG_MODE
- name: Open PR for Version Update
id: open_pr
Expand All @@ -68,9 +68,9 @@ jobs:
run: |
# Apply the version update, update the rendered examples with the version update, and create a changelog entry
# We run `make update-docker-image` again here because the open_pr peter-evans/create-pull-request step before clears out the update changes locally
make update-docker-image FILE_PATH=${{ matrix.yaml_file_path }} QUERY_STRING='${{ matrix.yaml_value_path }}' DEBUG_MODE=$DEBUG_MODE || exit 1
make render || exit 1
make chlog-new FILENAME="update-${{ matrix.name }}" CHANGE_TYPE=enhancement COMPONENT=${{ matrix.component }} NOTE="Bump ${{ matrix.name }} to ${{ steps.check_for_update.outputs.LATEST_TAG }} in ${{ matrix.yaml_file_path }}" ISSUES=[${{ steps.open_pr.outputs.pull-request-number }}] || exit 1
make update-docker-image FILE_PATH=${{ matrix.yaml_file_path }} QUERY_STRING='${{ matrix.yaml_value_path }}' DEBUG_MODE=$DEBUG_MODE
make render
make chlog-new FILENAME="update-${{ matrix.name }}" CHANGE_TYPE=enhancement COMPONENT=${{ matrix.component }} NOTE="Bump ${{ matrix.name }} to ${{ steps.check_for_update.outputs.LATEST_TAG }} in ${{ matrix.yaml_file_path }}" ISSUES=[${{ steps.open_pr.outputs.pull-request-number }}]
- name: Finalize PR with updates
if: ${{ steps.check_for_update.outputs.NEED_UPDATE == 1 }}
Expand Down
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ This Splunk OpenTelemetry Collector for Kubernetes release adopts the [Splunk Op
- `agent`: Remove the use of the `max_connections` configuration key, use `max_idle_conns_per_host` instead. ([#1034](https://github.com/signalfx/splunk-otel-collector-chart/pull/1034))
- `operator`: Bump java to v1.29.1 in helm-charts/splunk-otel-collector/values.yaml ([#1042](https://github.com/signalfx/splunk-otel-collector-chart/pull/1042))
- `operator`: Bump nodejs to v2.5.1 in helm-charts/splunk-otel-collector/values.yaml ([#1040](https://github.com/signalfx/splunk-otel-collector-chart/pull/1040))
- `operator`: Update opentelemetry-operator to version 0.42.3 ([#1025](https://github.com/signalfx/splunk-otel-collector-chart/pull/1025))
- `operator`: Bump operator to 0.42.3 in helm-charts/splunk-otel-collector/Chart.yaml ([#1025](https://github.com/signalfx/splunk-otel-collector-chart/pull/1025))

## [0.87.0] - 2023-11-15

Expand All @@ -59,8 +59,8 @@ This Splunk OpenTelemetry Collector for Kubernetes release adopts the [Splunk Op

- `agent, fluentd`: Allow users to override `enable_stat_watcher` and `refresh_interval` for tail plugin from values.yaml ([#982](https://github.com/signalfx/splunk-otel-collector-chart/pull/982))
- `agent`: Add combineWith field to multiline configuration ([#756](https://github.com/signalfx/splunk-otel-collector-chart/pull/756))
- `operator`: cert-manager upgraded to v1.13.2 ([#1007](https://github.com/signalfx/splunk-otel-collector-chart/pull/1007))
- `operator`: opentelemetry-operator upgraded to v0.41.0 ([#985](https://github.com/signalfx/splunk-otel-collector-chart/pull/985))
- `operator`: Bump certmanager to v1.13.2 in helm-charts/splunk-otel-collector/Chart.yaml ([#1007](https://github.com/signalfx/splunk-otel-collector-chart/pull/1007))
- `operator`: Bump operator to 0.41.0 in helm-charts/splunk-otel-collector/Chart.yaml ([#985](https://github.com/signalfx/splunk-otel-collector-chart/pull/985))

### 🧰 Bug fixes 🧰

Expand All @@ -84,8 +84,8 @@ This Splunk OpenTelemetry Collector for Kubernetes release adopts the [Splunk Op
- `agent`: Drop time attribute used during parsing the time from log record, so it is not reported as an extra field. ([#912](https://github.com/signalfx/splunk-otel-collector-chart/pull/912))
- `agent`: Change the default logs collection engine (`logsEngine`) to the native OpenTelemetry logs collection (`otel`) ([#934](https://github.com/signalfx/splunk-otel-collector-chart/pull/934))
If you want to keep using Fluentd sidecar for the logs collection, set `logsEngine' to 'fluentd` in your values.yaml
- `operator`: cert-manager upgraded to v1.13.1 ([#941](https://github.com/signalfx/splunk-otel-collector-chart/pull/941))
- `operator`: opentelemetry-operator upgraded to v0.39.1 ([#940](https://github.com/signalfx/splunk-otel-collector-chart/pull/940))
- `operator`: Bump certmanager to v1.13.1 in helm-charts/splunk-otel-collector/Chart.yaml ([#941](https://github.com/signalfx/splunk-otel-collector-chart/pull/941))
- `operator`: Bump operator to 0.39.1 in helm-charts/splunk-otel-collector/Chart.yaml ([#940](https://github.com/signalfx/splunk-otel-collector-chart/pull/940))
- `chart`: Add support for OpenTelemetry CHANGELOG.md generator tool, see [chloggen](https://github.com/open-telemetry/opentelemetry-operator/tree/main/.chloggen) ([#923](https://github.com/signalfx/splunk-otel-collector-chart/pull/923))

### 🧰 Bug fixes 🧰
Expand Down
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ install-tools: ## Install tools (macOS/Linux)
# Tasks related to building the Helm chart

.PHONY: dep-update
dep-update: ## Update Helm chart dependencies to latest, build the Helm chart with latest dependencies
dep-update: ## Fetch Helm chart dependency repositories, build the Helm chart with the dependencies specified in the Chart.yaml
@{ \
if ! (helm repo list | grep -q open-telemetry) ; then \
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts || exit 1; \
Expand Down Expand Up @@ -145,3 +145,14 @@ update-docker-image: ## Updates the Docker image tag in a YAML file to the lates
exit 1; \
fi
ci_scripts/update-docker-image.sh "$(FILE_PATH)" "$(QUERY_STRING)" $(DEBUG)

# Example Usage:
# make update-chart-dep CHART_PATH=./helm-charts/splunk-otel-collector/Chart.yaml SUBCHART_NAME='opentelemetry-operator'
.PHONY: update-chart-dep
update-chart-dep: dep-update ## Updates the dependency version in the Chart.yaml file to the latest version
@if [ -z "$(CHART_PATH)" ] || [ -z "$(SUBCHART_NAME)" ]; then \
echo "Error: CHART_PATH and SUBCHART_NAME are mandatory."; \
echo "Usage: make update-docker-image FILE_PATH=path/to/file.yaml QUERY_STRING='yq.query' [DEBUG=--debug]"; \
exit 1; \
fi
ci_scripts/update-chart-dependency.sh $(CHART_PATH) $(SUBCHART_NAME) $(DEBUG_MODE)
79 changes: 79 additions & 0 deletions ci_scripts/update-chart-dependency.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash
# Purpose: Updates Helm chart dependencies and related image tags.
# Notes:
# - Automates the process of updating Helm chart dependencies in Chart.yaml and related image tags in values.yaml.
# - Specifically designed to update the opentelemetry-operator as a subchart and related instrumentation configurations in values.yaml.
# - Relies on Helm and yq tools for processing Helm charts and YAML files.
#
# Parameters:
# $1: The file path to the Chart.yaml file of the Helm chart (mandatory).
# $2: The name of the dependency (subchart) to check for updates (mandatory).
# --debug: (Optional) Activates debug mode for verbose output, aiding in troubleshooting.
#
# Usage Examples:
# ./update-chart-dependency.sh ./path/to/Chart.yaml opentelemetry-operator
# ./update-chart-dependency.sh ./path/to/Chart.yaml opentelemetry-operator --debug

# Include the base utility functions for setting and debugging variables
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$SCRIPT_DIR/base_util.sh"

# ---- Validate Input Arguments ----
if [ "$#" -lt 2 ]; then
echo "Error: Incorrect number of arguments provided."
echo "Usage: $0 <path-to-chart-file> <yq-query-string> [--debug]"
exit 1
fi

# ---- Initialize Variables ----
# Set the YAML file path and the yq query string
setd "CHART_PATH" "$1"
setd "SUBCHART_NAME" "$2"

# Function: update_operator_images
# Description: Updates OpenTelemetry operator images
update_operator_images() {
# TODO: Migrate the logic from update-images-operator-otel.sh to here
echo "Updating OpenTelemetry operator images for $SUBCHART_NAME..."
$SCRIPT_DIR/update-images-operator-otel.sh
}

# Function: maybe_update_chart_dependency_version
# Description: Updates the chart dependency version if a newer version is available.
maybe_update_chart_dependency_version() {
echo "Checking for updates to $SUBCHART_NAME in $CHART_PATH..."

# Fetch the latest version using Helm
LATEST_VER=$(helm search repo $SUBCHART_NAME --versions | awk 'NR==2{print $2}')
echo "Latest version of $SUBCHART_NAME is $LATEST_VER"

# Retrieve the current version from Chart.yaml
CURRENT_VER=$(yq eval ".dependencies[] | select(.name == \"$SUBCHART_NAME\") | .version" $CHART_PATH)
echo "Current version of $SUBCHART_NAME in Chart.yaml is $CURRENT_VER"

if [ "$LATEST_VER" != "$CURRENT_VER" ]; then
echo "Updating to new version $LATEST_VER in Chart.yaml"

# Emit the NEED_UPDATE variable to either GitHub output or stdout
NEED_UPDATE=1
emit_output "NEED_UPDATE"
emit_output "CURRENT_VER"
emit_output "LATEST_VER"

# Update the version in Chart.yaml
yq eval -i "(.dependencies[] | select(.name == \"$SUBCHART_NAME\")).version = \"$LATEST_VER\"" $CHART_PATH

if [ "$SUBCHART_NAME" == "opentelemetry-operator" ]; then
update_operator_images
fi

echo "Current git diff:"
git --no-pager diff
else
echo "We are already up to date. Nothing else to do."
fi
}

# ---- Update Version Information ----
# Call the maybe_update_chart_dependency_version function to update the version if necessary
maybe_update_chart_dependency_version
20 changes: 10 additions & 10 deletions helm-charts/splunk-otel-collector/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ description: Splunk OpenTelemetry Collector for Kubernetes
icon: https://github.com/signalfx/splunk-otel-collector-chart/tree/main/splunk.png
type: application
keywords:
- splunk
- opentelemetry
- observability
- logs
- traces
- metrics
- apm
- splunk
- opentelemetry
- observability
- logs
- traces
- metrics
- apm
maintainers:
- name: dmitryax
- name: jvoravong
- name: emaderer
- name: dmitryax
- name: jvoravong
- name: emaderer
dependencies:
# Subchart Notes:
# - Avoid uppercase letters in names/aliases, they cause install failure due to subchart resource naming
Expand Down

0 comments on commit a30a33a

Please sign in to comment.