Skip to content

Commit 3969b9b

Browse files
authored
feat: support helm dryrun=server (#6691)
* feat: support helm dryrun=server Signed-off-by: Sam Wang (holyspectral) <sam.wang@suse.com> * fix: CI errors after test-sanity Signed-off-by: Sam Wang (holyspectral) <sam.wang@suse.com> * docs: update testdata/v3/memcached-operator to v4 Signed-off-by: Sam Wang (holyspectral) <sam.wang@suse.com> --------- Signed-off-by: Sam Wang (holyspectral) <sam.wang@suse.com>
1 parent aca3a2c commit 3969b9b

File tree

18 files changed

+53
-19
lines changed

18 files changed

+53
-19
lines changed

.cncf-maintainers

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
approvers:
2+
- acornett21
23
- anik120
34
- everettraven
45
- fabianvf
@@ -10,6 +11,7 @@ approvers:
1011
- theishshah
1112
- varshaprasad96
1213
reviewers:
14+
- acornett21
1315
- anik120
1416
- everettraven
1517
- fabianvf

internal/cmd/helm-operator/run/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ func run(cmd *cobra.Command, f *flags.Flags) {
203203
SuppressOverrideValues: f.SuppressOverrideValues,
204204
MaxConcurrentReconciles: f.MaxConcurrentReconciles,
205205
Selector: w.Selector,
206+
DryRunOption: w.DryRunOption,
206207
})
207208
if err != nil {
208209
log.Error(err, "Failed to add manager factory to controller.")

internal/helm/controller/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type WatchOptions struct {
5252
SuppressOverrideValues bool
5353
MaxConcurrentReconciles int
5454
Selector metav1.LabelSelector
55+
DryRunOption string
5556
}
5657

5758
// Add creates a new helm operator controller and adds it to the manager
@@ -66,6 +67,7 @@ func Add(mgr manager.Manager, options WatchOptions) error {
6667
ReconcilePeriod: options.ReconcilePeriod,
6768
OverrideValues: options.OverrideValues,
6869
SuppressOverrideValues: options.SuppressOverrideValues,
70+
DryRunOption: options.DryRunOption,
6971
}
7072

7173
c, err := controller.New(controllerName, mgr, controller.Options{

internal/helm/controller/reconcile.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type HelmOperatorReconciler struct {
5555
OverrideValues map[string]string
5656
SuppressOverrideValues bool
5757
releaseHook ReleaseHookFunc
58+
DryRunOption string
5859
}
5960

6061
const (
@@ -96,7 +97,7 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile
9697
return reconcile.Result{}, err
9798
}
9899

99-
manager, err := r.ManagerFactory.NewManager(o, r.OverrideValues)
100+
manager, err := r.ManagerFactory.NewManager(o, r.OverrideValues, r.DryRunOption)
100101
if err != nil {
101102
log.Error(err, "Failed to get release manager")
102103
return reconcile.Result{}, err

internal/helm/release/manager.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ type manager struct {
7575
isUpgradeRequired bool
7676
deployedRelease *rpb.Release
7777
chart *cpb.Chart
78+
79+
dryRunOption string
7880
}
7981

8082
type InstallOption func(*action.Install) error
@@ -159,6 +161,7 @@ func (m manager) getCandidateRelease(namespace, name string, chart *cpb.Chart,
159161
upgrade := action.NewUpgrade(m.actionConfig)
160162
upgrade.Namespace = namespace
161163
upgrade.DryRun = true
164+
upgrade.DryRunOption = m.dryRunOption
162165
return upgrade.Run(name, chart, values)
163166
}
164167

internal/helm/release/manager_factory.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
// improves decoupling between reconciliation logic and the Helm backend
3434
// components used to manage releases.
3535
type ManagerFactory interface {
36-
NewManager(r *unstructured.Unstructured, overrideValues map[string]string) (Manager, error)
36+
NewManager(r *unstructured.Unstructured, overrideValues map[string]string, dryRunOption string) (Manager, error)
3737
}
3838

3939
type managerFactory struct {
@@ -47,7 +47,7 @@ func NewManagerFactory(mgr crmanager.Manager, acg client.ActionConfigGetter, cha
4747
return &managerFactory{mgr, acg, chartDir}
4848
}
4949

50-
func (f managerFactory) NewManager(cr *unstructured.Unstructured, overrideValues map[string]string) (Manager, error) {
50+
func (f managerFactory) NewManager(cr *unstructured.Unstructured, overrideValues map[string]string, dryRunOption string) (Manager, error) {
5151
actionConfig, err := f.acg.ActionConfigFor(cr)
5252
if err != nil {
5353
return nil, fmt.Errorf("failed to get helm action config: %w", err)
@@ -86,9 +86,10 @@ func (f managerFactory) NewManager(cr *unstructured.Unstructured, overrideValues
8686
releaseName: releaseName,
8787
namespace: cr.GetNamespace(),
8888

89-
chart: crChart,
90-
values: values,
91-
status: types.StatusFor(cr),
89+
chart: crChart,
90+
values: values,
91+
status: types.StatusFor(cr),
92+
dryRunOption: dryRunOption,
9293
}, nil
9394
}
9495

internal/helm/watches/watches.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Watch struct {
4040
OverrideValues map[string]string `json:"overrideValues,omitempty"`
4141
Selector metav1.LabelSelector `json:"selector"`
4242
ReconcilePeriod metav1.Duration `json:"reconcilePeriod,omitempty"`
43+
DryRunOption string `json:"dryRunOption,omitempty"`
4344
}
4445

4546
// UnmarshalYAML unmarshals an individual watch from the Helm watches.yaml file

internal/helm/watches/watches_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,30 @@ func TestLoadReader(t *testing.T) {
101101
},
102102
expectErr: false,
103103
},
104-
104+
{
105+
name: "valid with dry run option",
106+
data: `---
107+
- group: mygroup
108+
version: v1alpha1
109+
kind: MyKind
110+
chart: ../../../internal/plugins/helm/v1/chartutil/testdata/test-chart
111+
watchDependentResources: false
112+
overrideValues:
113+
key: $MY_VALUE
114+
dryRunOption: server
115+
`,
116+
env: map[string]string{"MY_VALUE": "value"},
117+
expectWatches: []Watch{
118+
{
119+
GroupVersionKind: schema.GroupVersionKind{Group: "mygroup", Version: "v1alpha1", Kind: "MyKind"},
120+
ChartDir: "../../../internal/plugins/helm/v1/chartutil/testdata/test-chart",
121+
WatchDependentResources: &falseVal,
122+
OverrideValues: map[string]string{"key": "value"},
123+
DryRunOption: "server",
124+
},
125+
},
126+
expectErr: false,
127+
},
105128
{
106129
name: "invalid with override template expansion",
107130
data: `---

testdata/go/v4/memcached-operator/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ endif
4848

4949
# Set the Operator SDK version to use. By default, what is installed on the system is used.
5050
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
51-
OPERATOR_SDK_VERSION ?= v1.33.0
51+
OPERATOR_SDK_VERSION ?= v1.34.0
5252

5353
# Image URL to use all building/pushing image targets
5454
IMG ?= controller:latest

testdata/go/v4/monitoring/memcached-operator/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ endif
4848

4949
# Set the Operator SDK version to use. By default, what is installed on the system is used.
5050
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
51-
OPERATOR_SDK_VERSION ?= v1.33.0
51+
OPERATOR_SDK_VERSION ?= v1.34.0
5252

5353
# Image URL to use all building/pushing image targets
5454
IMG ?= controller:latest

0 commit comments

Comments
 (0)