Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flag to change certmanager.installCRDs value in Helm chart #148

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cmd/helmify/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/helm/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/helmify/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading