Skip to content

Commit 9e0e123

Browse files
authored
fix(kubevirt-cdi-operator): pin the vendored CDI release (cozystack#4383)
<!-- Thank you for making a contribution! Here are some tips for you: - Use Conventional Commits for the PR title: `type(scope): description` - Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore - Scopes are not an exhaustive list — pick the most specific scope for the change and extend the list when a genuinely new area appears. Examples: - System components: dashboard, platform, operator, cilium, kube-ovn, linstor, fluxcd, cluster-api - Managed apps: postgres, mariadb, redis, kafka, clickhouse, virtual-machine, kubernetes - Development and maintenance: api, hack, tests, ci, docs, maintenance - Breaking changes: append `!` after type/scope (`feat(api)!: ...`) or add a `BREAKING CHANGE:` footer - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `kind/backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does This pins the CDI release the platform deploys, so it moves only when someone edits a version line. Until now `make update` in `packages/system/kubevirt-cdi-operator` took the release from GitHub's `releases/latest` redirect. Any refresh could move CDI and its image tags, and the diff had no version line to review. The fix follows the shape `packages/system/kubevirt-operator` already uses. - `RELEASE = v1.66.1` names the release. It is the one already vendored, so `templates/` does not change, and `make update` reproduces it byte for byte. - `MANIFEST_SHA256` pins the downloaded asset and matches the digest GitHub publishes for it. On a mismatch the recipe writes nothing. - The download is transformed and patched outside `templates/` and moved in at the end. A refresh that fails halfway leaves the vendored file as it was. - A new `test` target runs a helm-unittest suite over the vendored manifest, then greps it for the operator image at `$(RELEASE)`. The grep is there because helm-unittest cannot see a Makefile variable. Moving the pin without re-running `update` fails here. One thing is left for later. The suite asserts three of the eight image references directly, and the digest keeps the rest in step on `update`, but a hand edit to one of the other image env entries would pass. Closes cozystack#4190 ### Screenshots <!-- REQUIRED for UI changes: attach screenshots or screen recordings demonstrating the visual impact of your changes. PRs with UI changes without screenshots will not be merged. --> ### Downstream repositories <!-- Cozystack is upstream for repositories that are NOT kept in sync with it automatically, and nothing in CI compares the two sides, so a change here can break them silently. Which change forces what, and which file to touch, is the trigger map in docs/agents/contributing.md under "Downstream Repositories". Walk it before you tick anything. IF YOU ARE AN AI AGENT OR AN LLM, THIS IS PART OF THE TASK, NOT A FORM TO FILL IN: 1. Walk the trigger map against the actual diff of this PR, file by file. Do not decide from the PR title or from your memory of what you changed. 2. For every repository you tick, open the follow-up PR there and link it on the same line. A ticked box with no link claims work that does not exist, which is worse than an empty box. Search that repository for an open PR or issue covering it first, and link that instead of filing a duplicate. 3. When the follow-up is out of scope, or needs a decision that is not yours to make, open an issue in that repository instead, link that, and say so in the PR body. Do not push a speculative PR into another repository just to fill a line here. 4. Do not tick "No downstream repository is affected" to make the checklist go away. If you are unsure, leave every box empty and say so in the PR body, so a human decides. --> - [x] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: Nothing on the trigger map applies. The diff touches one package's own Makefile, `.gitignore` and tests, and no shared tooling, values, CRD, namespace or release asset. ### Release note <!-- Write a release note: - Explain what has changed internally and for users. - Start with the same `type(scope):` prefix as in the PR title - Follow the guidelines at https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md. --> ```release-note fix(kubevirt-cdi-operator): pin the vendored CDI release to v1.66.1 and verify the downloaded manifest against a digest, so refreshing the package no longer moves the deployed CDI. The deployed version stays the same. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Updates** * The KubeVirt CDI Operator is now pinned to version 1.66.1, providing a consistent operator version across deployments. * **Reliability** * Operator manifest updates are checked before they’re applied, helping prevent incomplete or mismatched manifests from replacing the current version. * Deployment configuration is validated to ensure it matches the pinned release. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents eec069b + 8dfbaa1 commit 9e0e123

3 files changed

Lines changed: 110 additions & 8 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `update` fetches, transforms and patches here before moving the result into
2+
# templates/. A run that dies between those steps leaves the file behind.
3+
cdi-operator.yaml.download
Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,58 @@
11
export NAME=kubevirt-cdi-operator
22
export NAMESPACE=cozy-kubevirt-cdi
33

4+
# The CDI release whose operator manifest is vendored under templates/. This
5+
# package decides which CDI the platform runs, so moving to another release is
6+
# an edit to this line, MANIFEST_SHA256 and the expectations under tests/,
7+
# rather than a side effect of running `update`.
8+
RELEASE = v1.66.1
9+
10+
# sha256 of the cdi-operator.yaml release asset as published, measured before
11+
# the transforms below run over it. It detects an asset that moved under its
12+
# tag; it is not authenticity verification.
13+
MANIFEST_SHA256 = c7d92bd1b2ee1a3952a5990000437c08d58109f31c0bd48ab6188ec27a13e224
14+
15+
# sha256sum is not everywhere: current macOS carries a native one in /sbin,
16+
# older releases carry only shasum(1). Both print "<digest> <path>", so field
17+
# 1 is the digest whichever gets picked. The rest of `update` needs GNU sed and
18+
# gawk regardless, so this alone does not make the recipe portable.
19+
SHA256SUM := $(shell command -v sha256sum >/dev/null 2>&1 && echo sha256sum || echo 'shasum -a 256')
20+
421
include ../../../hack/package.mk
522

23+
# Phony because hack/package.mk's .PHONY line lists only the targets that file
24+
# defines: with neither name declared, a path named `test` or `update` next to
25+
# this Makefile would make that target up to date and skip the recipe.
26+
.PHONY: test update
27+
test:
28+
helm unittest .
29+
@# helm-unittest reads the vendored file and cannot see RELEASE, so without
30+
@# this a pin moved without re-running `update` leaves every assertion
31+
@# green against the old release.
32+
@if ! grep -q 'image: quay.io/kubevirt/cdi-operator:$(RELEASE)$$' templates/cdi-operator.yaml; then \
33+
echo "ERROR: templates/cdi-operator.yaml carries no cdi-operator image at $(RELEASE). Re-run 'make update'." >&2; \
34+
exit 1; \
35+
fi
36+
637
update:
7-
rm -rf templates
8-
mkdir templates
9-
export VERSION=$$(basename $$(curl -s -w %{redirect_url} https://github.com/kubevirt/containerized-data-importer/releases/latest)) && \
10-
wget https://github.com/kubevirt/containerized-data-importer/releases/download/$$VERSION/cdi-operator.yaml -O templates/cdi-operator.yaml
11-
sed -i 's/namespace: cdi/namespace: cozy-kubevirt-cdi/g' templates/cdi-operator.yaml
12-
awk -i inplace -v RS="---" '!/kind: Namespace/{printf "%s", $$0 RS}' templates/cdi-operator.yaml
13-
patch --no-backup-if-mismatch -p4 < patches/startupProbe.diff
14-
patch --no-backup-if-mismatch -p4 < patches/tolerations.diff
38+
@# The download is verified, transformed and patched outside templates/ and
39+
@# moved in once finished, so a refresh that fails at any step leaves the
40+
@# vendored copy as it was rather than half-replaced.
41+
wget https://github.com/kubevirt/containerized-data-importer/releases/download/$(RELEASE)/cdi-operator.yaml -O cdi-operator.yaml.download || { rm -f cdi-operator.yaml.download; exit 1; }
42+
@actual=$$($(SHA256SUM) cdi-operator.yaml.download | awk '{print $$1}'); \
43+
if [ "$$actual" != "$(MANIFEST_SHA256)" ]; then \
44+
rm -f cdi-operator.yaml.download; \
45+
echo "ERROR: cdi-operator.yaml for $(RELEASE) hashed $$actual," >&2; \
46+
echo " expected $(MANIFEST_SHA256). Nothing was written." >&2; \
47+
echo " Moving to a new release starts from RELEASE, MANIFEST_SHA256 and" >&2; \
48+
echo " the version expectations under tests/. If RELEASE did not" >&2; \
49+
echo " change, the asset moved under a tag that should be immutable:" >&2; \
50+
echo " find out why before pasting the new digest." >&2; \
51+
exit 1; \
52+
fi
53+
sed -i 's/namespace: cdi/namespace: $(NAMESPACE)/g' cdi-operator.yaml.download
54+
awk -i inplace -v RS="---" '!/kind: Namespace/{printf "%s", $$0 RS}' cdi-operator.yaml.download
55+
patch --no-backup-if-mismatch cdi-operator.yaml.download < patches/startupProbe.diff
56+
patch --no-backup-if-mismatch cdi-operator.yaml.download < patches/tolerations.diff
57+
mkdir -p templates
58+
mv cdi-operator.yaml.download templates/cdi-operator.yaml
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
suite: cozy-kubevirt-cdi-operator vendored manifest
2+
release:
3+
name: kubevirt-cdi-operator
4+
namespace: cozy-kubevirt-cdi
5+
tests:
6+
# Addressed by kind rather than by index: the vendored file is one long
7+
# document stream and an upstream reorder would slide any index off the
8+
# Deployment silently. Not by name, which the ServiceAccount and RBAC objects
9+
# share. The selector errors on a second match rather than picking one.
10+
- it: runs the cdi-operator image from the pinned release
11+
template: cdi-operator.yaml
12+
documentSelector:
13+
path: kind
14+
value: Deployment
15+
asserts:
16+
# The Makefile's grep ties this tag back to RELEASE. This one says the
17+
# tag is on the operator Deployment rather than somewhere in the stream.
18+
- equal:
19+
path: spec.template.spec.containers[0].image
20+
value: quay.io/kubevirt/cdi-operator:v1.66.1
21+
# cdi-operator deploys the rest of CDI from its env, so an operator image
22+
# that moved while these did not runs two releases at once.
23+
- contains:
24+
path: spec.template.spec.containers[0].env
25+
content:
26+
name: OPERATOR_VERSION
27+
value: v1.66.1
28+
- contains:
29+
path: spec.template.spec.containers[0].env
30+
content:
31+
name: CONTROLLER_IMAGE
32+
value: quay.io/kubevirt/cdi-controller:v1.66.1
33+
- equal:
34+
path: metadata.namespace
35+
value: cozy-kubevirt-cdi
36+
# Carried by patches/, which `update` re-applies to every download.
37+
- exists:
38+
path: spec.template.spec.containers[0].startupProbe
39+
- contains:
40+
path: spec.template.spec.tolerations
41+
content:
42+
key: CriticalAddonsOnly
43+
operator: Exists
44+
45+
# `any: true` is load-bearing on a negated containsDocument: without it the
46+
# assertion reads "not every document is a Namespace", which is true of any
47+
# multi-document template and would pin nothing.
48+
- it: drops the Namespace object upstream ships
49+
template: cdi-operator.yaml
50+
asserts:
51+
- containsDocument:
52+
apiVersion: v1
53+
kind: Namespace
54+
any: true
55+
not: true

0 commit comments

Comments
 (0)