|
|
|
@ -4,6 +4,8 @@ metadata: |
|
|
|
name: flightctl-update-digest |
|
|
|
spec: |
|
|
|
params: |
|
|
|
- name: image-name |
|
|
|
type: string |
|
|
|
- name: new-image-digest |
|
|
|
type: string |
|
|
|
- description: The label selector to identify the fleet(s) to update. |
|
|
|
@ -22,6 +24,10 @@ spec: |
|
|
|
value: "false" |
|
|
|
- name: FLEET_LABEL_SELECTOR |
|
|
|
value: "$(params.fleet-label-selector)" |
|
|
|
- name: IMAGE_NAME |
|
|
|
value: "$(params.image-name)" |
|
|
|
- name: NEW_IMAGE_DIGEST |
|
|
|
value: "$(params.new-image-digest)" |
|
|
|
script: | |
|
|
|
#!/bin/bash |
|
|
|
set -Eeuo pipefail |
|
|
|
@ -39,9 +45,6 @@ spec: |
|
|
|
|
|
|
|
# Print versions of the program we use |
|
|
|
echo "=== Environment ===" |
|
|
|
echo "---> flightctl" |
|
|
|
flightctl version |
|
|
|
echo |
|
|
|
echo "---> bash" |
|
|
|
bash --version |
|
|
|
echo |
|
|
|
@ -55,28 +58,21 @@ spec: |
|
|
|
id |
|
|
|
echo |
|
|
|
echo "---> flightctl" |
|
|
|
flightctl version |
|
|
|
flightctl --config-dir $(workspaces.flightctl-config.path) version |
|
|
|
echo |
|
|
|
echo "---> config file" |
|
|
|
ls -lZ $(workspaces.flightctl-config.path) |
|
|
|
echo |
|
|
|
|
|
|
|
# List fleets matching the label selector and update their image to the new digest |
|
|
|
flightctl --config-dir $(workspaces.flightctl-config.path) get fleets --limit 0 -l "${FLEET_LABEL_SELECTOR}" -o name | while read -r fleet; do |
|
|
|
echo "Updating fleet $fleet to image digest $(params.new-image-digest)" |
|
|
|
echo "Updating fleet $fleet to image ${IMAGE_NAME}@${NEW_IMAGE_DIGEST}" |
|
|
|
|
|
|
|
# Get the current fleet definition |
|
|
|
flightctl --config-dir $(workspaces.flightctl-config.path) get fleet/$fleet -o yaml > /tmp/fleet.yaml |
|
|
|
|
|
|
|
# Extract the current image from the fleet definition |
|
|
|
CURRENT_IMAGE="$(yq eval '.spec.template.spec.os.image' /tmp/fleet.yaml)" |
|
|
|
|
|
|
|
# Splits the CURRENT_IMAGE on the "@" or ":" character and takes the first part (the image name without tag or digest) |
|
|
|
# Using only bash built-in features to avoid dependencies on other tools |
|
|
|
IMAGE_NAME="${CURRENT_IMAGE%%[@:]*}" |
|
|
|
|
|
|
|
# Construct the new image with the new digest |
|
|
|
NEW_IMAGE="${IMAGE_NAME}@$(params.new-image-digest)" |
|
|
|
|
|
|
|
# Update the fleet definition with the new image |
|
|
|
yq eval -i ".spec.template.spec.os.image = \"$NEW_IMAGE\"" /tmp/fleet.yaml |
|
|
|
yq eval -i ".spec.template.spec.os.image = \"${IMAGE_NAME}@${NEW_IMAGE_DIGEST}\"" /tmp/fleet.yaml |
|
|
|
|
|
|
|
# Apply the updated fleet definition |
|
|
|
flightctl --config-dir $(workspaces.flightctl-config.path) apply -f /tmp/fleet.yaml |
|
|
|
|