Skip to content

Commit 7bd6436

Browse files
rebenkoyarttor
authored andcommitted
added cert-manager-version flag
1 parent de2e663 commit 7bd6436

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

cmd/helmify/flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func ReadFlags() config.Config {
6464
flag.BoolVar(&result.ImagePullSecrets, "image-pull-secrets", false, "Allows the user to use existing secrets as imagePullSecrets in values.yaml")
6565
flag.BoolVar(&result.GenerateDefaults, "generate-defaults", false, "Allows the user to add empty placeholders for tipical customization options in values.yaml. Currently covers: topology constraints, node selectors, tolerances")
6666
flag.BoolVar(&result.CertManagerAsSubchart, "cert-manager-as-subchart", false, "Allows the user to add cert-manager as a subchart")
67+
flag.StringVar(&result.CertManagerVersion, "cert-manager-version", "v1.12.2", "Allows to define cert-manager version. Only useful with cert-manager-as-subchart.")
6768
flag.BoolVar(&result.FilesRecursively, "r", false, "Scan dirs from -f option recursively")
6869
flag.Var(&files, "f", "File or directory containing k8s manifests")
6970

pkg/app/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (c *appContext) CreateHelm(stop <-chan struct{}) error {
7575
default:
7676
}
7777
}
78-
return c.output.Create(c.config.ChartDir, c.config.ChartName, c.config.Crd, c.config.CertManagerAsSubchart, templates, filenames)
78+
return c.output.Create(c.config.ChartDir, c.config.ChartName, c.config.Crd, c.config.CertManagerAsSubchart, c.config.CertManagerVersion , templates, filenames)
7979
}
8080

8181
func (c *appContext) process(obj *unstructured.Unstructured) (helmify.Template, error) {

pkg/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ type Config struct {
2828
GenerateDefaults bool
2929
// CertManagerAsSubchart enables the generation of a subchart for cert-manager
3030
CertManagerAsSubchart bool
31+
// CertManagerVersion sets cert-manager version in dependency
32+
CertManagerVersion string
3133
// Files - directories or files with k8s manifests
3234
Files []string
3335
// FilesRecursively read Files recursively

pkg/helm/chart.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ type output struct{}
3131
// └── _helpers.tp # Helm default template partials
3232
//
3333
// Overwrites existing values.yaml and templates in templates dir on every run.
34-
func (o output) Create(chartDir, chartName string, crd bool, certManagerAsSubchart bool, templates []helmify.Template, filenames []string) error {
35-
err := initChartDir(chartDir, chartName, crd, certManagerAsSubchart)
34+
func (o output) Create(chartDir, chartName string, crd bool, certManagerAsSubchart bool, certManagerVersion string, templates []helmify.Template, filenames []string) error {
35+
err := initChartDir(chartDir, chartName, crd, certManagerAsSubchart, certManagerVersion)
3636
if err != nil {
3737
return err
3838
}

pkg/helm/init.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,24 @@ dependencies:
129129
- name: cert-manager
130130
repository: https://charts.jetstack.io
131131
condition: certmanager.enabled
132-
alias: certmanager
132+
alias: certmanager
133+
version: %q
133134
`
134135

135136
var chartName = regexp.MustCompile("^[a-zA-Z0-9._-]+$")
136137

137138
const maxChartNameLength = 250
138139

139140
// initChartDir - creates Helm chart structure in chartName directory if not presented.
140-
func initChartDir(chartDir, chartName string, crd bool, certManagerAsSubchart bool) error {
141+
func initChartDir(chartDir, chartName string, crd bool, certManagerAsSubchart bool, certManagerVersion string) error {
141142
if err := validateChartName(chartName); err != nil {
142143
return err
143144
}
144145

145146
cDir := filepath.Join(chartDir, chartName)
146147
_, err := os.Stat(filepath.Join(cDir, "Chart.yaml"))
147148
if os.IsNotExist(err) {
148-
return createCommonFiles(chartDir, chartName, crd, certManagerAsSubchart)
149+
return createCommonFiles(chartDir, chartName, crd, certManagerAsSubchart, certManagerVersion)
149150
}
150151
logrus.Info("Skip creating Chart skeleton: Chart.yaml already exists.")
151152
return err
@@ -161,7 +162,7 @@ func validateChartName(name string) error {
161162
return nil
162163
}
163164

164-
func createCommonFiles(chartDir, chartName string, crd bool, certManagerAsSubchart bool) error {
165+
func createCommonFiles(chartDir, chartName string, crd bool, certManagerAsSubchart bool, certManagerVersion string) error {
165166
cDir := filepath.Join(chartDir, chartName)
166167
err := os.MkdirAll(filepath.Join(cDir, "templates"), 0750)
167168
if err != nil {
@@ -183,16 +184,16 @@ func createCommonFiles(chartDir, chartName string, crd bool, certManagerAsSubcha
183184
logrus.WithField("file", file).Info("created")
184185
}
185186
}
186-
createFile(chartYAML(chartName, certManagerAsSubchart), cDir, "Chart.yaml")
187+
createFile(chartYAML(chartName, certManagerAsSubchart, certManagerVersion), cDir, "Chart.yaml")
187188
createFile([]byte(helmIgnore), cDir, ".helmignore")
188189
createFile(helpersYAML(chartName), cDir, "templates", "_helpers.tpl")
189190
return err
190191
}
191192

192-
func chartYAML(appName string, certManagerAsSubchart bool) []byte {
193+
func chartYAML(appName string, certManagerAsSubchart bool, certManagerVersion string) []byte {
193194
chartFile := defaultChartfile
194195
if certManagerAsSubchart {
195-
chartFile += certManagerDependencies
196+
chartFile += fmt.Sprintf(certManagerDependencies, certManagerVersion)
196197
}
197198
return []byte(fmt.Sprintf(chartFile, appName))
198199
}

pkg/helmify/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Template interface {
2828

2929
// Output - converts Template into helm chart on disk.
3030
type Output interface {
31-
Create(chartName, chartDir string, Crd bool, certManagerAsSubchart bool, templates []Template, filenames []string) error
31+
Create(chartName, chartDir string, Crd bool, certManagerAsSubchart bool, certManagerVersion string, templates []Template, filenames []string) error
3232
}
3333

3434
// AppMetadata handle common information about K8s objects in the chart.

0 commit comments

Comments
 (0)