Skip to content

Commit 54df9c5

Browse files
authored
[chore] Update workflow to include CRDs (#1780)
1 parent ecb3d23 commit 54df9c5

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

.github/workflows/update_chart_dependencies.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ jobs:
4343
4444
make update-chart-dep CHART_PATH=${{ matrix.yaml_file_path }} SUBCHART_NAME='${{ matrix.dependency_name }}' DEBUG_MODE=$DEBUG_MODE
4545
46+
- name: Check for Operator CRD Updates
47+
if: ${{ matrix.name == 'operator' }}
48+
run: |
49+
make update-crds DEBUG_MODE=$DEBUG_MODE
50+
4651
- name: Install Skopeo
4752
run: |
4853
sudo apt-get update
@@ -70,6 +75,15 @@ jobs:
7075
make render
7176
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 }}]
7277
78+
- name: Operator CRDs update
79+
env:
80+
COMPONENT: opentelemetry-operator-crds
81+
if: ${{ steps.check_for_update.outputs.CRDS_NEED_UPDATE == 1 }}
82+
run: |
83+
make update-operator-crds DEBUG_MODE=$DEBUG_MODE
84+
make render
85+
make chlog-new FILENAME="update-operator-crds" CHANGE_TYPE=enhancement COMPONENT=$COMPONENT NOTE="Bump subchart $COMPONENT to ${{ steps.check_for_update.outputs.CRDS_LATEST_VER }}" ISSUES=[${{ steps.open_pr.outputs.pull-request-number }}]
86+
7387
- name: Finalize PR with updates
7488
if: ${{ steps.check_for_update.outputs.NEED_UPDATE == 1 }}
7589
uses: peter-evans/create-pull-request@v7

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,7 @@ tidy-all:
217217
echo "Running go mod tidy in $$dir"; \
218218
(cd "$$dir" && rm -f go.sum && go mod tidy); \
219219
done
220+
221+
.PHONY: update-operator-crds
222+
update-operator-crds: ## Update CRDs in the opentelemetry-operator-crds subchart
223+
ci_scripts/update-crds.sh

ci_scripts/update-crds.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
# Purpose: Updates CRDs for the OpenTelemetry Operator in the opentelemetry-operator-crds subchart
3+
# The script compares the current CRDs with those found in the appVersion of the Opentelemetry Operator
4+
# we are using as dependency. If they differ, it updates the CRDs in the opentelemetry-operator-crds subchart.
5+
6+
# Include the base utility functions for setting and debugging variables
7+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8+
source "${SCRIPT_DIR}/base_util.sh"
9+
10+
# Initialize directories and paths
11+
setd "ROOT_DIR" "${SCRIPT_DIR}/../"
12+
setd "COLLECTOR_CHART_DIR" "${ROOT_DIR}/helm-charts/splunk-otel-collector"
13+
setd "CRD_CHART_DIR" "${COLLECTOR_CHART_DIR}/charts/opentelemetry-operator-crds"
14+
setd "CRD_DIR" "${CRD_CHART_DIR}/crds"
15+
setd "CRD_CHART_FILE" "${CRD_CHART_DIR}/Chart.yaml"
16+
setd "OTEL_OPERATOR_REPO" "https://github.com/open-telemetry/opentelemetry-operator.git"
17+
setd "TEMP_DIR" "$(mktemp -d)"
18+
19+
trap "rm -rf $TEMP_DIR" EXIT
20+
21+
# Function: get_operator_app_version
22+
# Description: Retrieves the app version of the OpenTelemetry operator dependency
23+
get_operator_app_version() {
24+
debug "Retrieving OpenTelemetry operator version"
25+
26+
local operator_version
27+
local operator_repo
28+
29+
operator_version=$(yq eval '.dependencies[] | select(.name == "opentelemetry-operator") | .version' "${COLLECTOR_CHART_DIR}/Chart.yaml")
30+
operator_repo=$(yq eval '.dependencies[] | select(.name == "opentelemetry-operator") | .repository' "${COLLECTOR_CHART_DIR}/Chart.yaml")
31+
32+
debug "Pulling OpenTelemetry operator Helm chart version ${operator_version}"
33+
helm pull opentelemetry-operator --version "$operator_version" --repo "$operator_repo" --untar --untardir "$TEMP_DIR/chart"
34+
35+
local app_version
36+
app_version=$(yq eval '.appVersion' "$TEMP_DIR/chart/opentelemetry-operator/Chart.yaml")
37+
38+
echo "$app_version"
39+
}
40+
41+
# Function: bump_patch_version
42+
# Description: Bumps the patch version of the CRDs chart and updates the dependency in the collector chart.
43+
bump_patch_version() {
44+
local current_version
45+
current_version=$(yq eval '.version' "$CRD_CHART_FILE")
46+
debug "Current CRDs chart version: $current_version"
47+
48+
local major minor patch
49+
IFS='.' read -r major minor patch <<< "$current_version"
50+
patch=$((patch + 1))
51+
local new_version="${major}.${minor}.${patch}"
52+
53+
yq eval ".version = \"$new_version\"" -i "$CRD_CHART_FILE"
54+
echo "CRDs chart version bumped to $new_version"
55+
56+
yq eval "(.dependencies[] | select(.name == \"opentelemetry-operator-crds\") | .version) = \"$new_version\"" -i "${COLLECTOR_CHART_DIR}/Chart.yaml"
57+
echo "Updated CRDs chart version in chart dependencies to $new_version"
58+
}
59+
60+
# Function: update_crds
61+
# Description: Updates the OpenTelemetry CRDs if there are changes
62+
update_crds() {
63+
local latest_version
64+
latest_version=$(get_operator_app_version)
65+
setd "LATEST_VERSION" "$latest_version"
66+
echo "OpenTelemetry operator app version: $latest_version"
67+
68+
debug "Cloning OpenTelemetry Operator repository..."
69+
git config --global advice.detachedHead false # Suppress detached HEAD warnings
70+
git clone --quiet --depth 1 --branch "v${latest_version}" ${OTEL_OPERATOR_REPO} ${TEMP_DIR}/opentelemetry-operator || {
71+
echo "Error: Failed to clone OpenTelemetry Operator repository."
72+
exit 1
73+
}
74+
75+
mkdir -p "${CRD_DIR}"
76+
cp ${TEMP_DIR}/opentelemetry-operator/config/crd/bases/*.yaml "${CRD_DIR}/" 2>/dev/null
77+
78+
if git diff --quiet -- "${CRD_DIR}"; then
79+
echo "No CRD updates detected. CRDs are already up to date."
80+
setd "CRDS_NEED_UPDATE" 0
81+
else
82+
echo "CRD updates detected for OpenTelemetry Operator."
83+
setd "CRDS_NEED_UPDATE" 1
84+
bump_patch_version
85+
fi
86+
87+
setd "CRDS_LATEST_VERSION" "$(yq eval '.version' "$CRD_CHART_FILE")"
88+
emit_output "CRDS_NEED_UPDATE"
89+
emit_output "CRDS_LATEST_VERSION"
90+
}
91+
92+
update_crds

0 commit comments

Comments
 (0)