Skip to content

Commit 3db00d1

Browse files
gprosslinerarttor
authored andcommitted
refactored flag into config.Config struct
1 parent 3859ee9 commit 3db00d1

File tree

6 files changed

+9
-26
lines changed

6 files changed

+9
-26
lines changed

cmd/helmify/flags.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"path/filepath"
88

99
"github.com/arttor/helmify/pkg/config"
10-
"github.com/arttor/helmify/pkg/processor/imagePullSecrets"
1110
)
1211

1312
const helpText = `Helmify parses kubernetes resources from std.in and converts it to a Helm chart.
@@ -37,7 +36,7 @@ func ReadFlags() config.Config {
3736
flag.BoolVar(&result.Verbose, "v", false, "Enable verbose output (print WARN & INFO). Example: helmify -v")
3837
flag.BoolVar(&result.VeryVerbose, "vv", false, "Enable very verbose output. Same as verbose but with DEBUG. Example: helmify -vv")
3938
flag.BoolVar(&crd, "crd-dir", false, "Enable crd install into 'crds' directory.\nWarning: CRDs placed in 'crds' directory will not be templated by Helm.\nSee https://helm.sh/docs/chart_best_practices/custom_resource_definitions/#some-caveats-and-explanations\nExample: helmify -crd-dir")
40-
flag.BoolVar(&imagePullSecrets.Enabled, "image-pull-secrets", false, "Allows the user to use existing secrets as imagePullSecrets in values.yaml")
39+
flag.BoolVar(&result.ImagePullSecrets, "image-pull-secrets", false, "Allows the user to use existing secrets as imagePullSecrets in values.yaml")
4140

4241
flag.Parse()
4342
if h || help {

pkg/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ type Config struct {
2121
VeryVerbose bool
2222
// crd-dir set true to enable crd folder.
2323
Crd bool
24+
// ImagePullSecrets flag
25+
ImagePullSecrets bool
2426
}
2527

2628
func (c *Config) Validate() error {

pkg/processor/daemonset/daemonset.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ func (d daemonset) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstru
149149
return true, nil, err
150150
}
151151

152-
imagePullSecrets.ProcessSpecMap(specMap, &values)
152+
if appMeta.Config().ImagePullSecrets {
153+
imagePullSecrets.ProcessSpecMap(specMap, &values)
154+
}
153155

154156
spec, err := yamlformat.Marshal(specMap, 6)
155157
if err != nil {

pkg/processor/deployment/deployment.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ func (d deployment) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstr
156156
return true, nil, err
157157
}
158158

159-
imagePullSecrets.ProcessSpecMap(specMap, &values)
159+
if appMeta.Config().ImagePullSecrets {
160+
imagePullSecrets.ProcessSpecMap(specMap, &values)
161+
}
160162

161163
spec, err := yamlformat.Marshal(specMap, 6)
162164
if err != nil {

pkg/processor/imagePullSecrets/imagePullSecrets.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@ import "github.com/arttor/helmify/pkg/helmify"
44

55
const helmExpression = "{{ .Values.imagePullSecrets | default list | toJson }}"
66

7-
// Enabled is set by flags to enable the feature
8-
var Enabled bool
9-
107
// ProcessSpecMap adds 'imagePullSecrets' to the podSpec in specMap, if it doesn't
118
// already has one defined.
129
func ProcessSpecMap(specMap map[string]interface{}, values *helmify.Values) {
1310

14-
if !Enabled {
15-
return
16-
}
17-
1811
if _, defined := specMap["imagePullSecrets"]; !defined {
1912
specMap["imagePullSecrets"] = helmExpression
2013
(*values)["imagePullSecrets"] = []string{}

pkg/processor/imagePullSecrets/imagePullSecrets_test.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
)
99

1010
func Test_imagePullSecrets_RespectExistingSpec(t *testing.T) {
11-
Enabled = true
1211
spec := make(map[string]interface{})
1312

1413
type ipsReference struct {
@@ -28,7 +27,6 @@ func Test_imagePullSecrets_RespectExistingSpec(t *testing.T) {
2827
}
2928

3029
func Test_imagePullSecrets_ProvideDefault(t *testing.T) {
31-
Enabled = true
3230
spec := make(map[string]interface{})
3331

3432
values := &helmify.Values{}
@@ -40,16 +38,3 @@ func Test_imagePullSecrets_ProvideDefault(t *testing.T) {
4038
assert.Equal(t, ips, helmExpression)
4139
assert.Equal(t, 1, len(*values))
4240
}
43-
44-
func Test_imagePullSecrets_DoNothingIfNotEnabled(t *testing.T) {
45-
Enabled = false
46-
spec := make(map[string]interface{})
47-
48-
values := &helmify.Values{}
49-
ProcessSpecMap(spec, values)
50-
51-
_, found := spec["imagePullSecrets"]
52-
assert.False(t, found)
53-
54-
assert.Equal(t, 0, len(*values))
55-
}

0 commit comments

Comments
 (0)