Skip to content

Fix isManagedByHelm to check the existing CRD, not the desired one - #27

Merged
gianlucam76 merged 1 commit into
projectsveltos:mainfrom
magic-peach:fix/helm-managed-crd-check
Sep 18, 2026
Merged

gianlucam76 merged 1 commit into
projectsveltos:mainfrom
magic-peach:fix/helm-managed-crd-check

Conversation

@magic-peach

Copy link
Copy Markdown
Contributor

processCustomResourceDefinition fetches the live CustomResourceDefinition from the cluster into customResourceDefinition, then calls isManagedByHelm(u), where u is the freshly parsed desired CRD manifest from the embedded YAML in pkg/crds/crds.go.

That embedded manifest never carries the app.kubernetes.io/managed-by label (confirmed zero occurrences of that label across pkg/crds/crds.go), so isManagedByHelm always returned false regardless of whether the live CRD in the cluster was actually Helm managed. As a result the Job force updated every CRD on every run, including ones that should have been left alone.

Fixed by passing the fetched customResourceDefinition instead of u, and changed isManagedByHelm's signature to take a *apiextensionsv1.CustomResourceDefinition so the compiler enforces this going forward.

Added cmd/main_test.go with three tests using the controller-runtime fake client:

  • Helm managed CRD is left untouched
  • Non Helm managed CRD is updated with the desired changes
  • Missing CRD is created

Reverting the fix locally and rerunning the new test confirms it fails against the original code and passes against the fix.

@gianlucam76
gianlucam76 self-requested a review September 16, 2026 13:39
@gianlucam76

gianlucam76 commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Thank you @magic-peach this is a good catch. Fix is correct. Can you please

  1. use gingko for the unit test so to be consistent with every other Sveltos repo.
  2. fix the lint issue

Thank you again. Nice catch.

@gianlucam76 gianlucam76 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch. Can you please:

  1. use gingko for the unit test so to be consistent with every other Sveltos repo.
  2. fix the lint issue

processCustomResourceDefinition fetches the live CustomResourceDefinition
from the cluster into customResourceDefinition, then calls
isManagedByHelm(u), where u is the freshly parsed desired CRD manifest
from the embedded YAML. That manifest never carries the
app.kubernetes.io/managed-by label (confirmed there are zero occurrences
of that label across pkg/crds/crds.go), so isManagedByHelm always
returned false and the Job force-updated every CRD on every run,
including ones actually managed by Helm.

Fixed by passing the fetched customResourceDefinition instead of u, and
changed isManagedByHelm's signature to take a
*apiextensionsv1.CustomResourceDefinition so the compiler enforces this
going forward. Added cmd/main_test.go covering the Helm managed skip
path, the normal update path, and the create-when-missing path using the
controller-runtime fake client. Reverting the fix locally and rerunning
the new test confirms it fails against the original bug.

Signed-off-by: Akanksha Trehun <akankshatrehun@gmail.com>
@magic-peach
magic-peach force-pushed the fix/helm-managed-crd-check branch from 39d9411 to 17276d8 Compare September 18, 2026 10:30

@gianlucam76 gianlucam76 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gianlucam76
gianlucam76 merged commit 1b59ca4 into projectsveltos:main Sep 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants