Skip to content

Conversation

@arcanez
Copy link

@arcanez arcanez commented Nov 6, 2025

fixes #184 this allows for optional installation of CRDs (using values, not --skip-crds) by wrapping the entire custom resource definition in {{- if .Values.crds.enabled }} .. {{- end }}

  • adds new options
    • -optional-crds, to enable optional CRD installation (default: false)
  • adds the condition value to values.yaml with a default of true

Examples

-optional-crds

➜  cat test_data/k8s-operator-kustomize.output | go run ./cmd/helmify -optional-crds examples/operator
➜  git diff examples/operator/
diff --git a/examples/operator/templates/cephvolume-crd.yaml b/examples/operator/templates/cephvolume-crd.yaml
index 4f17b6b..2b507ff 100644
--- a/examples/operator/templates/cephvolume-crd.yaml
+++ b/examples/operator/templates/cephvolume-crd.yaml
@@ -1,3 +1,4 @@
+{{- if .Values.crds.enabled }}
 apiVersion: apiextensions.k8s.io/v1
 kind: CustomResourceDefinition
 metadata:
@@ -220,3 +221,4 @@ status:
     plural: ""
   conditions: []
   storedVersions: []
+{{- end }}
diff --git a/examples/operator/templates/manifestcephvolume-crd.yaml b/examples/operator/templates/manifestcephvolume-crd.yaml
index 3a5fcb5..61cb9c4 100644
--- a/examples/operator/templates/manifestcephvolume-crd.yaml
+++ b/examples/operator/templates/manifestcephvolume-crd.yaml
@@ -1,3 +1,4 @@
+{{- if .Values.crds.enabled }}
 apiVersion: apiextensions.k8s.io/v1
 kind: CustomResourceDefinition
 metadata:
@@ -90,3 +91,4 @@ status:
     plural: ""
   conditions: []
   storedVersions: []
+{{- end }}
diff --git a/examples/operator/values.yaml b/examples/operator/values.yaml
index 495b164..c73a002 100644
--- a/examples/operator/values.yaml
+++ b/examples/operator/values.yaml
@@ -59,6 +59,8 @@ controllerManager:
     maxSkew: 1
     topologyKey: kubernetes.io/hostname
     whenUnsatisfiable: DoNotSchedule
+crds:
+  enabled: true
 kubernetesClusterDomain: cluster.local
 managerConfig:
   controllerManagerConfigYaml: |-

@arcanez arcanez force-pushed the wrap-crds-in-conditional branch from fe86b3b to 14741e6 Compare November 6, 2025 20:00
@arcanez arcanez force-pushed the wrap-crds-in-conditional branch 2 times, most recently from b595428 to 29de8cd Compare November 17, 2025 00:36
@arcanez arcanez force-pushed the wrap-crds-in-conditional branch from 29de8cd to a84332b Compare November 18, 2025 19:43
@arcanez arcanez requested a review from arttor November 18, 2025 19:46
Copy link
Owner

@arttor arttor left a comment

Choose a reason for hiding this comment

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

Looks good. Just one question: How this option works with existing --crd-dir?

If i remember it correctly, resources in crds directory are not templated, meaning that adding {{ - if ... }} will break it.

Should we validate options and return error if both options enabled?

@arcanez
Copy link
Author

arcanez commented Nov 20, 2025

Looks good. Just one question: How this option works with existing --crd-dir?

If i remember it correctly, resources in crds directory are not templated, meaning that adding {{ - if ... }} will break it.

Should we validate options and return error if both options enabled?

I think this is a valid concern. Any suggestions on how/where, as it doesn't appear this scenario is handled anywhere else.

@arttor
Copy link
Owner

arttor commented Nov 20, 2025

I think ReadFlags() can do validation and return error

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.

allow for wrapping of CRDs in a conditional

2 participants