diff --git a/README.md b/README.md index 4cd9fc7..592b299 100644 --- a/README.md +++ b/README.md @@ -109,8 +109,9 @@ Usage: | -image-pull-secrets | Allows the user to use existing secrets as imagePullSecrets | `helmify -image-pull-secrets` | | -original-name | Use the object's original name instead of adding the chart's release name as the common prefix. | `helmify -original-name` | | -cert-manager-as-subchart | Allows the user to install cert-manager as a subchart | `helmify -cert-manager-as-subchart` | -| -cert-manager-version | Allows the user to specify cert-manager subchart version. Only useful with cert-manager-as-subchart. (default "v1.12.2") | `helmify -cert-manager-as-subchart` | -| -preserve-ns | Allows users to use the object's original namespace instead of adding all the resources to a common namespace. (default "false") | `helmify -preserve-ns` | +| -cert-manager-version | Allows the user to specify cert-manager subchart version. Only useful with cert-manager-as-subchart. (default "v1.12.2") | `helmify -cert-manager-version=v1.12.2` | +| -cert-manager-install-crd | Allows the user to install cert-manager CRD as part of the cert-manager subchart.(default "true") | `helmify -cert-manager-install-crd` | +| -preserve-ns | Allows users to use the object's original namespace instead of adding all the resources to a common namespace. (default "false") | `helmify -preserve-ns` | ## Status Supported k8s resources: - Deployment, DaemonSet, StatefulSet diff --git a/cmd/helmify/flags.go b/cmd/helmify/flags.go index 7fca65d..39d94d0 100644 --- a/cmd/helmify/flags.go +++ b/cmd/helmify/flags.go @@ -54,7 +54,7 @@ func (i *arrayFlags) Set(value string) error { func ReadFlags() config.Config { files := arrayFlags{} result := config.Config{} - var h, help, version, crd , preservens bool + var h, help, version, crd, preservens bool flag.BoolVar(&h, "h", false, "Print help. Example: helmify -h") flag.BoolVar(&help, "help", false, "Print help. Example: helmify -help") flag.BoolVar(&version, "version", false, "Print helmify version. Example: helmify -version") @@ -65,6 +65,7 @@ func ReadFlags() config.Config { flag.BoolVar(&result.GenerateDefaults, "generate-defaults", false, "Allows the user to add empty placeholders for typical customization options in values.yaml. Currently covers: topology constraints, node selectors, tolerances") flag.BoolVar(&result.CertManagerAsSubchart, "cert-manager-as-subchart", false, "Allows the user to add cert-manager as a subchart") flag.StringVar(&result.CertManagerVersion, "cert-manager-version", "v1.12.2", "Allows the user to specify cert-manager subchart version. Only useful with cert-manager-as-subchart.") + flag.BoolVar(&result.CertManagerInstallCRD, "cert-manager-install-crd", true, "Allows the user to install cert-manager CRD. Only useful with cert-manager-as-subchart.") flag.BoolVar(&result.FilesRecursively, "r", false, "Scan dirs from -f option recursively") flag.BoolVar(&result.OriginalName, "original-name", false, "Use the object's original name instead of adding the chart's release name as the common prefix.") flag.Var(&files, "f", "File or directory containing k8s manifests") diff --git a/pkg/app/context.go b/pkg/app/context.go index 2c4e52e..613f839 100644 --- a/pkg/app/context.go +++ b/pkg/app/context.go @@ -75,7 +75,7 @@ func (c *appContext) CreateHelm(stop <-chan struct{}) error { default: } } - return c.output.Create(c.config.ChartDir, c.config.ChartName, c.config.Crd, c.config.CertManagerAsSubchart, c.config.CertManagerVersion , templates, filenames) + return c.output.Create(c.config.ChartDir, c.config.ChartName, c.config.Crd, c.config.CertManagerAsSubchart, c.config.CertManagerVersion, c.config.CertManagerInstallCRD, templates, filenames) } func (c *appContext) process(obj *unstructured.Unstructured) (helmify.Template, error) { diff --git a/pkg/config/config.go b/pkg/config/config.go index 506ff9d..cb314da 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -30,6 +30,8 @@ type Config struct { CertManagerAsSubchart bool // CertManagerVersion sets cert-manager version in dependency CertManagerVersion string + // CertManagerVersion enables installation of cert-manager CRD + CertManagerInstallCRD bool // Files - directories or files with k8s manifests Files []string // FilesRecursively read Files recursively diff --git a/pkg/helm/chart.go b/pkg/helm/chart.go index 0748fcd..8d80eb9 100644 --- a/pkg/helm/chart.go +++ b/pkg/helm/chart.go @@ -31,7 +31,7 @@ type output struct{} // └── _helpers.tp # Helm default template partials // // Overwrites existing values.yaml and templates in templates dir on every run. -func (o output) Create(chartDir, chartName string, crd bool, certManagerAsSubchart bool, certManagerVersion string, templates []helmify.Template, filenames []string) error { +func (o output) Create(chartDir, chartName string, crd bool, certManagerAsSubchart bool, certManagerVersion string, certManagerInstallCRD bool, templates []helmify.Template, filenames []string) error { err := initChartDir(chartDir, chartName, crd, certManagerAsSubchart, certManagerVersion) if err != nil { return err @@ -56,7 +56,7 @@ func (o output) Create(chartDir, chartName string, crd bool, certManagerAsSubcha return err } } - err = overwriteValuesFile(cDir, values, certManagerAsSubchart) + err = overwriteValuesFile(cDir, values, certManagerAsSubchart, certManagerInstallCRD) if err != nil { return err } @@ -101,9 +101,9 @@ func overwriteTemplateFile(filename, chartDir string, crd bool, templates []helm return nil } -func overwriteValuesFile(chartDir string, values helmify.Values, certManagerAsSubchart bool) error { +func overwriteValuesFile(chartDir string, values helmify.Values, certManagerAsSubchart bool, certManagerInstallCRD bool) error { if certManagerAsSubchart { - _, err := values.Add(true, "certmanager", "installCRDs") + _, err := values.Add(certManagerInstallCRD, "certmanager", "installCRDs") if err != nil { return fmt.Errorf("%w: unable to add cert-manager.installCRDs", err) } diff --git a/pkg/helmify/model.go b/pkg/helmify/model.go index 4494885..c7f7d40 100644 --- a/pkg/helmify/model.go +++ b/pkg/helmify/model.go @@ -28,7 +28,7 @@ type Template interface { // Output - converts Template into helm chart on disk. type Output interface { - Create(chartName, chartDir string, Crd bool, certManagerAsSubchart bool, certManagerVersion string, templates []Template, filenames []string) error + Create(chartName, chartDir string, Crd bool, certManagerAsSubchart bool, certManagerVersion string, certManagerInstallCRD bool, templates []Template, filenames []string) error } // AppMetadata handle common information about K8s objects in the chart.