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

[chore] Operator Docker image updater workflow improvements #1219

Merged
merged 2 commits into from Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/update_chart_dependencies.yaml
Expand Up @@ -47,6 +47,11 @@ jobs:

make update-chart-dep CHART_PATH=${{ matrix.yaml_file_path }} SUBCHART_NAME='${{ matrix.dependency_name }}' DEBUG_MODE=$DEBUG_MODE

- name: Install Skopeo
run: |
sudo apt-get update
sudo apt-get install -y skopeo

- name: Open PR for Version Update
id: open_pr
if: ${{ steps.check_for_update.outputs.NEED_UPDATE == 1 }}
Expand Down
2 changes: 1 addition & 1 deletion ci_scripts/install-tools.sh
Expand Up @@ -98,7 +98,7 @@ install_helm_plugin() {
}

# install brew-based tools
for tool in kubectl helm chart-testing pre-commit go; do
for tool in chart-testing go helm kubectl pre-commit skopeo; do
install "$tool" brew
done

Expand Down
45 changes: 36 additions & 9 deletions ci_scripts/update-images-operator-otel.sh
Expand Up @@ -14,9 +14,11 @@ source "$SCRIPT_DIR/base_util.sh"

# ---- Initialize Temporary Files ----
# Create a temporary file to hold a subsection of the values.yaml file
setd "TEMP_VALUES_FILE" "$SCRIPT_DIR/temp_values_subsection.yaml"
# Create a temporary file to store version information
setd "TEMP_VERSIONS" "$SCRIPT_DIR/versions.txt"
setd "TEMP_VALUES_FILE" "$SCRIPT_DIR/temp_values_subsection.out"
# Create a temporary file to store operator main.go code containing docker image repository information
setd "TEMP_MAIN_FILE" "$SCRIPT_DIR/temp_main.out"
# Create a temporary file to store docker image version information
setd "TEMP_VERSIONS" "$SCRIPT_DIR/temp_versions.out"

# ---- Operator Subchart Version Extraction ----
# Extract the version of the opentelemetry-operator subchart from the main Chart.yaml
Expand All @@ -32,6 +34,14 @@ debug "Fetching: $SUBCHART_URL"
APP_VERSION=$(curl -s "$SUBCHART_URL" | grep 'appVersion:' | awk '{print $2}')
debug "Operator App Version: $APP_VERSION"

# ---- Fetch Docker Repository Information ----
# Fetch the code containing information about what instrumentation language uses what docker repository.
MAIN_URL="https://raw.githubusercontent.com/open-telemetry/opentelemetry-operator/v$APP_VERSION/main.go"
debug "Fetching: $MAIN_URL"
curl -s "$MAIN_URL" > "$TEMP_MAIN_FILE"
debug "Extracted main.go of the operator:"
debug "$TEMP_MAIN_FILE"

# ---- Fetch Version Mapping ----
# Fetch the version mappings from versions.txt for the fetched appVersion.
# This gives us a mapping of image keys to their corresponding version tags.
Expand All @@ -51,9 +61,19 @@ while IFS='=' read -r IMAGE_KEY VERSION; do
if [[ "$IMAGE_KEY" =~ ^autoinstrumentation-.* ]]; then
# Upstream Operator Values
setd "INST_LIB_NAME" "${IMAGE_KEY#autoinstrumentation-}"
setd "REPOSITORY_UPSTREAM" "ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-${INST_LIB_NAME}"
setd "TAG_UPSTREAM" "${VERSION}"

# Find the proper docker repository for the instrumentation library by scraping the main.go file of the operator
INST_LIB_REPO=$(grep "auto-instrumentation-${INST_LIB_NAME}-image" "$TEMP_MAIN_FILE" | grep -o 'ghcr.io/[a-zA-Z0-9_-]*/[a-zA-Z0-9_-]*/autoinstrumentation-[a-zA-Z0-9_-]*' | sort | uniq )
if [ -n "$INST_LIB_REPO" ]; then
# Set the REPOSITORY_UPSTREAM variable
setd "REPOSITORY_UPSTREAM" "$INST_LIB_REPO"
debug "Set REPOSITORY_UPSTREAM to ${INST_LIB_REPO}"
else
echo "Failed to find repository for ${INST_LIB_NAME}"
exit 1
fi

setd "REPOSITORY_LOCAL_PATH" "${INST_LIB_NAME}.repository"
setd "REPOSITORY_LOCAL" "$(yq eval ".${REPOSITORY_LOCAL_PATH}" "${TEMP_VALUES_FILE}")"

Expand All @@ -63,9 +83,17 @@ while IFS='=' read -r IMAGE_KEY VERSION; do
setd "TAG_LOCAL_PATH" "${INST_LIB_NAME}.tag"
setd "TAG_LOCAL" "$(yq eval ".${TAG_LOCAL_PATH}" "${TEMP_VALUES_FILE}")"
if [[ -z "${TAG_LOCAL}" || "${TAG_LOCAL}" == "null" || "${TAG_LOCAL}" != "$TAG_UPSTREAM" ]]; then
debug "Upserting value for ${REPOSITORY_LOCAL}:${TAG_LOCAL}"
yq eval -i ".${TAG_LOCAL_PATH} = \"${TAG_UPSTREAM}\"" "${TEMP_VALUES_FILE}"
setd "NEED_UPDATE" 1
IMAGE="${REPOSITORY_UPSTREAM}:${TAG_UPSTREAM}"
# Skopeo validates the existence of the Docker images no matter the current host architecture used
if skopeo inspect --retry-times 3 --raw "docker://$IMAGE" &>/dev/null; then
echo "Image $IMAGE exists."
echo "Upserting value for ${REPOSITORY_LOCAL}:${TAG_UPSTREAM}"
yq eval -i ".${TAG_LOCAL_PATH} = \"${TAG_UPSTREAM}\"" "${TEMP_VALUES_FILE}"
setd "NEED_UPDATE" 1
else
echo "Failed to find Docker image $IMAGE. Check image repository and tag."
exit 1
fi
else
debug "Retaining existing value for ${REPOSITORY_LOCAL}:${TAG_LOCAL}"
fi
Expand All @@ -91,8 +119,7 @@ awk '
# Replace the original values.yaml with the updated version
mv "${VALUES_FILE_PATH}.updated" "$VALUES_FILE_PATH"
# Cleanup temporary files
rm "$TEMP_VALUES_FILE"
rm "$TEMP_VERSIONS"
rm "$TEMP_MAIN_FILE" "$TEMP_VERSIONS" "$TEMP_VALUES_FILE"

echo "Image update process completed successfully!"
exit 0
Expand Up @@ -62,10 +62,10 @@ spec:
- name: OTEL_RESOURCE_ATTRIBUTES
value: splunk.zc.method=splunk-otel-java:v1.31.0
nginx:
image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-nginx:1.0.4
image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-apache-httpd:1.0.4
env:
- name: OTEL_RESOURCE_ATTRIBUTES
value: splunk.zc.method=autoinstrumentation-nginx:1.0.4
value: splunk.zc.method=autoinstrumentation-apache-httpd:1.0.4
nodejs:
image: ghcr.io/signalfx/splunk-otel-js/splunk-otel-js:v2.7.1
env:
Expand Down
2 changes: 1 addition & 1 deletion helm-charts/splunk-otel-collector/values.yaml
Expand Up @@ -1216,7 +1216,7 @@ operator:
repository: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-python
tag: 0.43b0
nginx:
repository: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-nginx
repository: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-apache-httpd
tag: 1.0.4
# Auto-instrumentation Libraries (End)
admissionWebhooks:
Expand Down