Skip to content

Commit 5f8dfdd

Browse files
committed
feat: support helm dryrun=server
Signed-off-by: Sam Wang (holyspectral) [email protected]
1 parent 1fd7f4d commit 5f8dfdd

File tree

6 files changed

+15
-6
lines changed

6 files changed

+15
-6
lines changed

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

0 commit comments

Comments
 (0)