diff --git a/internal/controller/applicationdefinition_controller.go b/internal/controller/applicationdefinition_controller.go index 6ce252490..6570d12b0 100644 --- a/internal/controller/applicationdefinition_controller.go +++ b/internal/controller/applicationdefinition_controller.go @@ -6,10 +6,12 @@ import ( "encoding/hex" "encoding/json" "slices" + "strings" "sync" "time" cozyv1alpha1 "github.com/cozystack/cozystack/api/v1alpha1" + "github.com/cozystack/cozystack/pkg/config" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -67,6 +69,33 @@ func (r *ApplicationDefinitionReconciler) SetupWithManager(mgr ctrl.Manager) err type appDefHashView struct { Name string `json:"name"` Spec cozyv1alpha1.ApplicationDefinitionSpec `json:"spec"` + // Annotations holds the release.cozystack.io/* subset of the definition's + // metadata annotations. They belong in the hash because cozystack-api reads + // them once, at start-up (CozyServerOptions.Complete in pkg/cmd/server/start.go), + // and this rollout is the only thing that delivers a change in one: a + // definition whose whole change is an annotation would otherwise leave the + // running api serving the previous behaviour until its pod restarted for an + // unrelated reason. Only that prefix is hashed, because kubectl and Helm + // rewrite annotations of their own on every apply and hashing those would + // roll the api Deployment on every reconcile. + Annotations map[string]string `json:"annotations,omitempty"` +} + +// releaseAnnotations returns the release.cozystack.io/* annotations of a +// definition, or nil when it carries none, so a definition without them hashes +// exactly as it did before this field existed. +func releaseAnnotations(annotations map[string]string) map[string]string { + var selected map[string]string + for k, v := range annotations { + if !strings.HasPrefix(k, config.ReleaseAnnotationPrefix) { + continue + } + if selected == nil { + selected = make(map[string]string) + } + selected[k] = v + } + return selected } func (r *ApplicationDefinitionReconciler) computeConfigHash(ctx context.Context) (string, error) { @@ -80,8 +109,9 @@ func (r *ApplicationDefinitionReconciler) computeConfigHash(ctx context.Context) views := make([]appDefHashView, 0, len(list.Items)) for i := range list.Items { views = append(views, appDefHashView{ - Name: list.Items[i].Name, - Spec: list.Items[i].Spec, + Name: list.Items[i].Name, + Spec: list.Items[i].Spec, + Annotations: releaseAnnotations(list.Items[i].Annotations), }) } b, err := json.Marshal(views) diff --git a/internal/controller/applicationdefinition_controller_test.go b/internal/controller/applicationdefinition_controller_test.go index f3ac64375..e7a661cfd 100644 --- a/internal/controller/applicationdefinition_controller_test.go +++ b/internal/controller/applicationdefinition_controller_test.go @@ -6,6 +6,7 @@ import ( "time" cozyv1alpha1 "github.com/cozystack/cozystack/api/v1alpha1" + "github.com/cozystack/cozystack/pkg/config" appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -229,3 +230,65 @@ func TestApplicationDefinition_HashUnchangedSkipsPatch(t *testing.T) { t.Fatalf("expected lastHandled advanced after no-op reconcile") } } + +// hashWithAnnotations computes the config hash for a single ApplicationDefinition +// carrying the given metadata annotations. +func hashWithAnnotations(t *testing.T, annotations map[string]string) string { + t.Helper() + + scheme := newAppDefScheme(t) + appDef := &cozyv1alpha1.ApplicationDefinition{ + ObjectMeta: metav1.ObjectMeta{Name: "vm-instance", Annotations: annotations}, + } + r := &ApplicationDefinitionReconciler{ + Client: fake.NewClientBuilder().WithScheme(scheme).WithObjects(appDef).Build(), + Scheme: scheme, + } + + hash, err := r.computeConfigHash(context.TODO()) + if err != nil { + t.Fatalf("computeConfigHash: %v", err) + } + return hash +} + +// TestApplicationDefinition_HashCoversReleaseAnnotations pins that a change +// confined to a release.cozystack.io/* annotation moves the hash. cozystack-api +// reads those annotations once, at start-up (pkg/cmd/server/start.go), so the +// config-hash rollout is the only thing that makes such a change take effect. +// A hash built from spec alone leaves the annotation inert on an existing +// cluster until the api pod happens to restart for an unrelated reason, which +// is indistinguishable from the change never having been delivered. +func TestApplicationDefinition_HashCoversReleaseAnnotations(t *testing.T) { + bare := hashWithAnnotations(t, nil) + annotated := hashWithAnnotations(t, map[string]string{ + config.HelmInstallDisableWaitAnnotation: "true", + }) + + if bare == annotated { + t.Fatalf("hash ignores %s: %q for both", config.HelmInstallDisableWaitAnnotation, bare) + } + + flipped := hashWithAnnotations(t, map[string]string{ + config.HelmInstallDisableWaitAnnotation: "false", + }) + if flipped == annotated { + t.Fatalf("hash ignores the annotation's value: %q for both true and false", annotated) + } +} + +// TestApplicationDefinition_HashIgnoresUnrelatedAnnotations pins the other half: +// only the release.cozystack.io/ prefix counts. kubectl and Flux rewrite their +// own annotations on every apply, and hashing those would roll out cozystack-api +// on every reconcile of every ApplicationDefinition. +func TestApplicationDefinition_HashIgnoresUnrelatedAnnotations(t *testing.T) { + bare := hashWithAnnotations(t, nil) + noisy := hashWithAnnotations(t, map[string]string{ + "kubectl.kubernetes.io/last-applied-configuration": `{"metadata":{"name":"vm-instance"}}`, + "meta.helm.sh/release-name": "vm-instance-rd", + }) + + if bare != noisy { + t.Fatalf("unrelated annotations moved the hash: %q vs %q", bare, noisy) + } +} diff --git a/internal/controller/applicationdefinition_helmreconciler.go b/internal/controller/applicationdefinition_helmreconciler.go index 5f4f63bd6..2a07fe04c 100644 --- a/internal/controller/applicationdefinition_helmreconciler.go +++ b/internal/controller/applicationdefinition_helmreconciler.go @@ -5,6 +5,7 @@ import ( "fmt" cozyv1alpha1 "github.com/cozystack/cozystack/api/v1alpha1" + "github.com/cozystack/cozystack/pkg/config" helmv2 "github.com/fluxcd/helm-controller/api/v2" "k8s.io/apimachinery/pkg/runtime" @@ -163,6 +164,44 @@ func (r *ApplicationDefinitionHelmReconciler) updateHelmReleaseChart(ctx context updated = true } + // Check and update the readiness wait. cozystack-api reads + // release.cozystack.io/helm-install-disable-wait off the definition when it + // builds a release, and only there, so a release created before the + // annotation appeared keeps waiting on readiness until its Application is + // written through the apps API again. Where the wait is what broke, that is + // every existing instance of the kind at once, each looping upgrade and + // timeout until an operator rewrites it by hand. The definition is the + // source of truth in both directions, since the API rebuilds the whole spec + // on every write and emits DisableWait=false once the annotation is gone. + disableWait, err := config.ParseHelmInstallDisableWaitAnnotation( + appDef.Annotations[config.HelmInstallDisableWaitAnnotation], + ) + if err != nil { + // cozystack-api refuses to start on this same value, so the cluster + // already has a loud signal; leave the field as it is rather than guess. + logger.Error(err, "Skipping HelmRelease wait update: invalid annotation", + "appDef", appDef.Name, "annotation", config.HelmInstallDisableWaitAnnotation) + } else { + // An absent install/upgrade block already behaves as DisableWait=false, + // so it is only materialised when the definition asks to disable the wait. + if disableWait && hrCopy.Spec.Install == nil { + hrCopy.Spec.Install = &helmv2.Install{} + } + if hrCopy.Spec.Install != nil && hrCopy.Spec.Install.DisableWait != disableWait { + logger.V(4).Info("Updating HelmRelease install wait", "name", hr.Name, "namespace", hr.Namespace, "disableWait", disableWait) + hrCopy.Spec.Install.DisableWait = disableWait + updated = true + } + if disableWait && hrCopy.Spec.Upgrade == nil { + hrCopy.Spec.Upgrade = &helmv2.Upgrade{} + } + if hrCopy.Spec.Upgrade != nil && hrCopy.Spec.Upgrade.DisableWait != disableWait { + logger.V(4).Info("Updating HelmRelease upgrade wait", "name", hr.Name, "namespace", hr.Namespace, "disableWait", disableWait) + hrCopy.Spec.Upgrade.DisableWait = disableWait + updated = true + } + } + // Check and update labels from ApplicationDefinition if len(appDef.Spec.Release.Labels) > 0 { if hrCopy.Labels == nil { diff --git a/internal/controller/applicationdefinition_helmreconciler_test.go b/internal/controller/applicationdefinition_helmreconciler_test.go index e7215067a..f8d055184 100644 --- a/internal/controller/applicationdefinition_helmreconciler_test.go +++ b/internal/controller/applicationdefinition_helmreconciler_test.go @@ -5,6 +5,7 @@ import ( "testing" cozyv1alpha1 "github.com/cozystack/cozystack/api/v1alpha1" + "github.com/cozystack/cozystack/pkg/config" helmv2 "github.com/fluxcd/helm-controller/api/v2" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -352,3 +353,231 @@ func TestValuesFromEqual(t *testing.T) { }) } } + +// vmInstanceRelease builds a VMInstance HelmRelease carrying the application +// labels this reconciler selects on, with the given wait configuration. +func vmInstanceRelease(install, upgrade *bool) *helmv2.HelmRelease { + hr := &helmv2.HelmRelease{ + ObjectMeta: metav1.ObjectMeta{ + Name: "vm-instance-web", + Namespace: "tenant-foo", + Labels: map[string]string{ + "apps.cozystack.io/application.kind": "VMInstance", + "apps.cozystack.io/application.group": "apps.cozystack.io", + }, + }, + Spec: helmv2.HelmReleaseSpec{ + ChartRef: &helmv2.CrossNamespaceSourceReference{ + Kind: "ExternalArtifact", + Name: "vm-instance-app", + Namespace: "cozy-system", + }, + }, + } + if install != nil { + hr.Spec.Install = &helmv2.Install{DisableWait: *install} + } + if upgrade != nil { + hr.Spec.Upgrade = &helmv2.Upgrade{DisableWait: *upgrade} + } + return hr +} + +// vmInstanceAppDef builds the VMInstance ApplicationDefinition, optionally +// carrying the disable-wait annotation. +func vmInstanceAppDef(annotations map[string]string) *cozyv1alpha1.ApplicationDefinition { + return &cozyv1alpha1.ApplicationDefinition{ + ObjectMeta: metav1.ObjectMeta{Name: "vm-instance", Annotations: annotations}, + Spec: cozyv1alpha1.ApplicationDefinitionSpec{ + Application: cozyv1alpha1.ApplicationDefinitionApplication{Kind: "VMInstance"}, + Release: cozyv1alpha1.ApplicationDefinitionRelease{ + ChartRef: &helmv2.CrossNamespaceSourceReference{ + Kind: "ExternalArtifact", + Name: "vm-instance-app", + Namespace: "cozy-system", + }, + }, + }, + } +} + +func reconcileVMInstance(t *testing.T, appDef *cozyv1alpha1.ApplicationDefinition, hr *helmv2.HelmRelease) *helmv2.HelmRelease { + t.Helper() + + scheme := newAppDefHelmScheme(t) + fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(appDef, hr).Build() + r := &ApplicationDefinitionHelmReconciler{Client: fakeClient, Scheme: scheme} + + if _, err := r.Reconcile(context.TODO(), reconcile.Request{ + NamespacedName: types.NamespacedName{Name: appDef.Name}, + }); err != nil { + t.Fatalf("unexpected error: %v", err) + } + + got := &helmv2.HelmRelease{} + if err := fakeClient.Get(context.TODO(), types.NamespacedName{Name: hr.Name, Namespace: hr.Namespace}, got); err != nil { + t.Fatalf("get HR: %v", err) + } + return got +} + +// TestAppDefHelm_DisableWaitApplied pins the drift this reconciler exists to +// close, for the one field a running release cannot pick up on its own: a +// HelmRelease created before the definition carried +// release.cozystack.io/helm-install-disable-wait keeps waiting on readiness +// until its Application is written through the apps API again. On a cluster +// where the wait is what broke (a KubeVirt VirtualMachine the kstatus poller +// reads as permanently InProgress), that is every existing VM, each one +// looping upgrade and timeout, and re-writing them by hand is the operator's +// only way out. Bring the field to what the definition asks for instead. +func TestAppDefHelm_DisableWaitApplied(t *testing.T) { + no := false + got := reconcileVMInstance(t, + vmInstanceAppDef(map[string]string{config.HelmInstallDisableWaitAnnotation: "true"}), + vmInstanceRelease(&no, &no)) + + if got.Spec.Install == nil || !got.Spec.Install.DisableWait { + t.Fatalf("expected Install.DisableWait=true, got %+v", got.Spec.Install) + } + if got.Spec.Upgrade == nil || !got.Spec.Upgrade.DisableWait { + t.Fatalf("expected Upgrade.DisableWait=true, got %+v", got.Spec.Upgrade) + } +} + +// TestAppDefHelm_DisableWaitAppliedToAbsentBlocks pins the same on a release +// that carries no install/upgrade block at all: the field still has to land. +func TestAppDefHelm_DisableWaitAppliedToAbsentBlocks(t *testing.T) { + got := reconcileVMInstance(t, + vmInstanceAppDef(map[string]string{config.HelmInstallDisableWaitAnnotation: "true"}), + vmInstanceRelease(nil, nil)) + + if got.Spec.Install == nil || !got.Spec.Install.DisableWait { + t.Fatalf("expected Install.DisableWait=true, got %+v", got.Spec.Install) + } + if got.Spec.Upgrade == nil || !got.Spec.Upgrade.DisableWait { + t.Fatalf("expected Upgrade.DisableWait=true, got %+v", got.Spec.Upgrade) + } +} + +// TestAppDefHelm_DisableWaitRemoved pins the other direction, because the +// definition is the source of truth in both: cozystack-api rebuilds the whole +// spec on every write and emits DisableWait=false once the annotation is gone, +// so a release left at true would drift back the moment anyone touched it. +func TestAppDefHelm_DisableWaitRemoved(t *testing.T) { + yes := true + got := reconcileVMInstance(t, vmInstanceAppDef(nil), vmInstanceRelease(&yes, &yes)) + + if got.Spec.Install == nil || got.Spec.Install.DisableWait { + t.Fatalf("expected Install.DisableWait=false, got %+v", got.Spec.Install) + } + if got.Spec.Upgrade == nil || got.Spec.Upgrade.DisableWait { + t.Fatalf("expected Upgrade.DisableWait=false, got %+v", got.Spec.Upgrade) + } +} + +// TestAppDefHelm_DisableWaitLeavesAbsentBlocksAlone pins that the false case +// does not materialise empty install/upgrade blocks on a release that has +// none: writing them would change nothing about the release's behaviour and +// would make every such reconcile an update. +func TestAppDefHelm_DisableWaitLeavesAbsentBlocksAlone(t *testing.T) { + got := reconcileVMInstance(t, vmInstanceAppDef(nil), vmInstanceRelease(nil, nil)) + + if got.Spec.Install != nil { + t.Fatalf("expected Install left absent, got %+v", got.Spec.Install) + } + if got.Spec.Upgrade != nil { + t.Fatalf("expected Upgrade left absent, got %+v", got.Spec.Upgrade) + } +} + +// TestAppDefHelm_DisableWaitInSyncSkipsUpdate pins idempotence: a release that +// already matches must not be written, or every reconcile of every definition +// bumps the resourceVersion of every release it owns and wakes helm-controller. +func TestAppDefHelm_DisableWaitInSyncSkipsUpdate(t *testing.T) { + yes := true + hr := vmInstanceRelease(&yes, &yes) + hr.Spec.ValuesFrom = expectedValuesFrom() + + scheme := newAppDefHelmScheme(t) + appDef := vmInstanceAppDef(map[string]string{config.HelmInstallDisableWaitAnnotation: "true"}) + fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(appDef, hr).Build() + + before := &helmv2.HelmRelease{} + if err := fakeClient.Get(context.TODO(), types.NamespacedName{Name: hr.Name, Namespace: hr.Namespace}, before); err != nil { + t.Fatalf("get HR: %v", err) + } + + r := &ApplicationDefinitionHelmReconciler{Client: fakeClient, Scheme: scheme} + if _, err := r.Reconcile(context.TODO(), reconcile.Request{ + NamespacedName: types.NamespacedName{Name: appDef.Name}, + }); err != nil { + t.Fatalf("unexpected error: %v", err) + } + + after := &helmv2.HelmRelease{} + if err := fakeClient.Get(context.TODO(), types.NamespacedName{Name: hr.Name, Namespace: hr.Namespace}, after); err != nil { + t.Fatalf("get HR after reconcile: %v", err) + } + if after.ResourceVersion != before.ResourceVersion { + t.Fatalf("release rewritten with nothing to change: %q -> %q", before.ResourceVersion, after.ResourceVersion) + } +} + +// TestAppDefHelm_DisableWaitInvalidAnnotationLeavesReleaseAlone pins the +// invalid-annotation branch. The parser returns false alongside its error, so +// applying that value would switch the wait back on for every release of the +// kind; the release must keep what it has instead. +func TestAppDefHelm_DisableWaitInvalidAnnotationLeavesReleaseAlone(t *testing.T) { + yes := true + got := reconcileVMInstance(t, + vmInstanceAppDef(map[string]string{config.HelmInstallDisableWaitAnnotation: "yes"}), + vmInstanceRelease(&yes, &yes)) + + if got.Spec.Install == nil || !got.Spec.Install.DisableWait { + t.Fatalf("expected Install.DisableWait=true kept, got %+v", got.Spec.Install) + } + if got.Spec.Upgrade == nil || !got.Spec.Upgrade.DisableWait { + t.Fatalf("expected Upgrade.DisableWait=true kept, got %+v", got.Spec.Upgrade) + } +} + +// TestAppDefHelm_DisableWaitScopedToKind pins the kind label in the selector: +// a release of another kind in the same group must not pick up the wait +// setting of the VMInstance definition. +func TestAppDefHelm_DisableWaitScopedToKind(t *testing.T) { + no := false + vm := vmInstanceRelease(&no, &no) + other := vmInstanceRelease(&no, &no) + other.Name = "harbor-registry" + other.Labels["apps.cozystack.io/application.kind"] = "Harbor" + + scheme := newAppDefHelmScheme(t) + appDef := vmInstanceAppDef(map[string]string{config.HelmInstallDisableWaitAnnotation: "true"}) + fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(appDef, vm, other).Build() + + r := &ApplicationDefinitionHelmReconciler{Client: fakeClient, Scheme: scheme} + if _, err := r.Reconcile(context.TODO(), reconcile.Request{ + NamespacedName: types.NamespacedName{Name: appDef.Name}, + }); err != nil { + t.Fatalf("unexpected error: %v", err) + } + + gotVM := &helmv2.HelmRelease{} + if err := fakeClient.Get(context.TODO(), types.NamespacedName{Name: vm.Name, Namespace: vm.Namespace}, gotVM); err != nil { + t.Fatalf("get VMInstance HR: %v", err) + } + if gotVM.Spec.Install == nil || !gotVM.Spec.Install.DisableWait { + t.Fatalf("expected VMInstance Install.DisableWait=true, got %+v", gotVM.Spec.Install) + } + + gotOther := &helmv2.HelmRelease{} + if err := fakeClient.Get(context.TODO(), types.NamespacedName{Name: other.Name, Namespace: other.Namespace}, gotOther); err != nil { + t.Fatalf("get Harbor HR: %v", err) + } + if gotOther.Spec.Install == nil || gotOther.Spec.Install.DisableWait { + t.Fatalf("expected Harbor Install.DisableWait=false, got %+v", gotOther.Spec.Install) + } + if gotOther.Spec.Upgrade == nil || gotOther.Spec.Upgrade.DisableWait { + t.Fatalf("expected Harbor Upgrade.DisableWait=false, got %+v", gotOther.Spec.Upgrade) + } +} diff --git a/packages/system/vm-instance-rd/Makefile b/packages/system/vm-instance-rd/Makefile index 621d74bd3..b7d7d6221 100644 --- a/packages/system/vm-instance-rd/Makefile +++ b/packages/system/vm-instance-rd/Makefile @@ -2,3 +2,7 @@ export NAME=vm-instance-rd export NAMESPACE=cozy-system include ../../../hack/package.mk + +.PHONY: test +test: + helm unittest . diff --git a/packages/system/vm-instance-rd/cozyrds/vm-instance.yaml b/packages/system/vm-instance-rd/cozyrds/vm-instance.yaml index cad2cf052..2d7d45b24 100644 --- a/packages/system/vm-instance-rd/cozyrds/vm-instance.yaml +++ b/packages/system/vm-instance-rd/cozyrds/vm-instance.yaml @@ -2,6 +2,10 @@ apiVersion: cozystack.io/v1alpha1 kind: ApplicationDefinition metadata: name: vm-instance + annotations: + # KubeVirt leaves a VirtualMachine's status.observedGeneration behind its + # generation, so kstatus never reports the VM Current and the wait never ends. + release.cozystack.io/helm-install-disable-wait: "true" spec: application: kind: VMInstance diff --git a/packages/system/vm-instance-rd/tests/readiness_gate_test.yaml b/packages/system/vm-instance-rd/tests/readiness_gate_test.yaml new file mode 100644 index 000000000..ce5f39206 --- /dev/null +++ b/packages/system/vm-instance-rd/tests/readiness_gate_test.yaml @@ -0,0 +1,33 @@ +suite: vm-instance ApplicationDefinition readiness gate +templates: + - templates/cozyrd.yaml + +# A VMInstance is served as a Flux HelmRelease that renders a KubeVirt +# VirtualMachine. From cozystack v1.5.0 (helm-controller v1.4.3 to v1.5.0) the +# generated release is health-assessed by the kstatus poller, whose generation +# check (checkGeneration in fluxcd/cli-utils pkg/kstatus/status/generic.go) +# returns InProgress for any object whose status.observedGeneration trails +# metadata.generation. vm-instance sets no healthCheckExprs, so that check is +# what decides. KubeVirt legitimately runs a VirtualMachine with +# observedGeneration behind generation (a template change pending a restart, a +# stopped VM, or kubevirt/kubevirt#18700), so a healthy VM is read as +# permanently InProgress and the release never converges. Disabling the wait +# restores the pre-1.5.0 behaviour: the release settles once the manifests are +# applied and VM health is observed on the VirtualMachine itself, not on the +# HelmRelease. +tests: + - it: renders the vm-instance ApplicationDefinition + asserts: + - containsDocument: + apiVersion: cozystack.io/v1alpha1 + kind: ApplicationDefinition + name: vm-instance + + - it: disables the helm-controller readiness wait for the VMInstance release + documentSelector: + path: metadata.name + value: vm-instance + asserts: + - equal: + path: metadata.annotations["release.cozystack.io/helm-install-disable-wait"] + value: "true" diff --git a/pkg/config/config.go b/pkg/config/config.go index cd87bdf02..d330970d1 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -26,6 +26,13 @@ import ( "github.com/fluxcd/pkg/apis/kustomize" ) +// ReleaseAnnotationPrefix is the prefix shared by every ApplicationDefinition +// metadata annotation that changes how cozystack-api builds the generated +// HelmRelease (the three constants below). cozystack-api reads them once, at +// start-up, so cozystack-controller has to roll the api Deployment when one of +// them changes; it selects them by this prefix when hashing the definitions. +const ReleaseAnnotationPrefix = "release.cozystack.io/" + // HelmInstallTimeoutAnnotation is the ApplicationDefinition metadata // annotation key that overrides the Flux HelmRelease Install.Timeout and // Upgrade.Timeout for a given Application kind. diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index f97bd5f42..46d268200 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -272,3 +272,22 @@ func TestParseHelmInstallDisableWaitAnnotation(t *testing.T) { }) } } + +// TestReleaseAnnotationsShareThePrefix pins that every annotation cozystack-api +// reads off an ApplicationDefinition lives under ReleaseAnnotationPrefix. +// cozystack-operator selects them by that prefix when it hashes the definitions +// to decide whether to roll the api Deployment, so an annotation introduced +// outside the prefix would be read at start-up but never trigger the restart +// that delivers it. +func TestReleaseAnnotationsShareThePrefix(t *testing.T) { + for _, annotation := range []string{ + HelmInstallTimeoutAnnotation, + HelmUpgradeTimeoutAnnotation, + HelmInstallDisableWaitAnnotation, + } { + if !strings.HasPrefix(annotation, ReleaseAnnotationPrefix) { + t.Errorf("annotation %q is outside %q, so a change to it never rolls cozystack-api", + annotation, ReleaseAnnotationPrefix) + } + } +}