Skip to content

Commit a84332b

Browse files
committed
PR feedback updates
1 parent 6beac23 commit a84332b

File tree

5 files changed

+22
-30
lines changed

5 files changed

+22
-30
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Usage:
113113
| -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` |
114114
| -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` |
115115
| -add-webhook-option | Adds an option to enable/disable webhook installation | `helmify -add-webhook-option`|
116+
| -optional-crds | Enable optional CRD installation through values. | `helmify -optional-crds` |
116117
## Status
117118
Supported k8s resources:
118119
- Deployment, DaemonSet, StatefulSet

cmd/helmify/flags.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ func ReadFlags() config.Config {
7171
flag.Var(&files, "f", "File or directory containing k8s manifests.")
7272
flag.BoolVar(&preservens, "preserve-ns", false, "Use the object's original namespace instead of adding all the resources to a common namespace.")
7373
flag.BoolVar(&result.AddWebhookOption, "add-webhook-option", false, "Allows the user to add webhook option in values.yaml.")
74-
flag.BoolVar(&result.WrapCRDs, "wrap-crds", false, "Allows the user to wrap CRDs in a conditional.")
75-
flag.StringVar(&result.WrapCRDsCondition, "wrap-crds-condition", "crds.enabled", "Allows the user to wrap CRDs in helm chart by specifying a condition name.")
74+
flag.BoolVar(&result.OptionalCRDs, "optional-crds", false, "Enable optional CRD installation through values.")
7675

7776
flag.Parse()
7877
if h || help {

pkg/config/config.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ type Config struct {
4343
PreserveNs bool
4444
// AddWebhookOption enables the generation of a webhook option in values.yaml
4545
AddWebhookOption bool
46-
// WrapCRDs wraps Custom Resource Definitions in a conditional
47-
WrapCRDs bool
48-
// WrapCRDsCondition is the condition used to wrap the Custom Resource Definitions
49-
WrapCRDsCondition string
46+
// OptionalCRDs - Enable optional CRD installation through values.
47+
OptionalCRDs bool
5048
}
5149

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

pkg/processor/crd/crd.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ status:
3535
conditions: []
3636
storedVersions: []`
3737

38+
const optionalCRDsConditional = "crds.enabled"
39+
3840
var crdGVC = schema.GroupVersionKind{
3941
Group: "apiextensions.k8s.io",
4042
Version: "v1",
@@ -132,12 +134,10 @@ func (c crd) Process(appMeta helmify.AppMetadata, obj *unstructured.Unstructured
132134

133135
values := helmify.Values{}
134136

135-
if appMeta.Config().WrapCRDs {
136-
137-
cond := appMeta.Config().WrapCRDsCondition
138-
res = fmt.Sprintf("{{- if .Values.%s }}\n%s\n{{- end }}", cond, res)
139-
_, _ = values.Add(true, strings.Split(appMeta.Config().WrapCRDsCondition, ".")...)
140-
logrus.WithField("crd", name).WithField("condition", cond).Info("wrapping CRDs in conditional")
137+
if appMeta.Config().OptionalCRDs {
138+
res = fmt.Sprintf("{{- if .Values.%s }}\n%s\n{{- end }}", optionalCRDsConditional, res)
139+
_, _ = values.Add(true, strings.Split(optionalCRDsConditional, ".")...)
140+
logrus.WithField("crd", name).WithField("condition", optionalCRDsConditional).Debug("enabling optional CRD installation")
141141
}
142142

143143
return true, &result{

pkg/processor/crd/crd_test.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,21 @@ func Test_crd_Process(t *testing.T) {
5151
t.Run("wrapped with condition", func(t *testing.T) {
5252
obj := internal.GenerateObj(strCRD)
5353

54-
conditions := []string{"crds.create", "crds.enabled", "installCRDs"}
55-
56-
for _, cond := range conditions {
57-
t.Run(cond, func(t *testing.T) {
58-
meta := metadata.New(config.Config{WrapCRDs: true, WrapCRDsCondition: cond})
59-
processed, tmpl, err := testInstance.Process(meta, obj)
60-
assert.NoError(t, err)
61-
assert.True(t, processed)
62-
assert.NotNil(t, tmpl)
54+
meta := metadata.New(config.Config{OptionalCRDs: true})
55+
processed, tmpl, err := testInstance.Process(meta, obj)
56+
assert.NoError(t, err)
57+
assert.True(t, processed)
58+
assert.NotNil(t, tmpl)
6359

64-
data := string(tmpl.(*result).data)
60+
data := string(tmpl.(*result).data)
6561

66-
assert.Contains(t, data, "{{- if .Values."+cond+" }}", "template should start with conditional")
67-
assert.Contains(t, data, "{{- end }}", "template should end with conditional")
62+
assert.Contains(t, data, "{{- if .Values."+optionalCRDsConditional+" }}", "template should start with conditional")
63+
assert.Contains(t, data, "{{- end }}", "template should end with conditional")
6864

69-
values := tmpl.(*result).values
70-
val, ok := getValue(values, cond)
71-
assert.True(t, ok, "expected key crds."+cond+" in values")
72-
assert.Equal(t, true, val)
73-
})
74-
}
65+
values := tmpl.(*result).values
66+
val, ok := getValue(values, optionalCRDsConditional)
67+
assert.True(t, ok, "expected key crds."+optionalCRDsConditional+" in values")
68+
assert.Equal(t, true, val)
7569
})
7670
}
7771

0 commit comments

Comments
 (0)