Skip to content

Commit 7f77237

Browse files
committed
feat: add dry-run flag for sync and apply
Signed-off-by: yxxhero <[email protected]>
1 parent 0256c83 commit 7f77237

File tree

9 files changed

+33
-0
lines changed

9 files changed

+33
-0
lines changed

cmd/apply.go

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func NewApplyCmd(globalCfg *config.GlobalImpl) *cobra.Command {
6868
f.StringVar(&applyOptions.PostRenderer, "post-renderer", "", `pass --post-renderer to "helm template" or "helm upgrade --install"`)
6969
f.StringArrayVar(&applyOptions.PostRendererArgs, "post-renderer-args", nil, `pass --post-renderer-args to "helm template" or "helm upgrade --install"`)
7070
f.StringVar(&applyOptions.Cascade, "cascade", "", "pass cascade to helm exec, default: background")
71+
f.StringVar(&applyOptions.DryRyn, "dry-run", "", "pass dry-run to helm exec")
7172

7273
return cmd
7374
}

cmd/sync.go

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func NewSyncCmd(globalCfg *config.GlobalImpl) *cobra.Command {
4747
f.StringVar(&syncOptions.PostRenderer, "post-renderer", "", `pass --post-renderer to "helm template" or "helm upgrade --install"`)
4848
f.StringArrayVar(&syncOptions.PostRendererArgs, "post-renderer-args", nil, `pass --post-renderer-args to "helm template" or "helm upgrade --install"`)
4949
f.StringVar(&syncOptions.Cascade, "cascade", "", "pass cascade to helm exec, default: background")
50+
f.StringVar(&syncOptions.DryRyn, "dry-run", "", "pass dry-run to helm exec")
5051

5152
return cmd
5253
}

pkg/app/app.go

+2
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,7 @@ Do you really want to apply?
14821482
ResetValues: c.ResetValues(),
14831483
PostRenderer: c.PostRenderer(),
14841484
PostRendererArgs: c.PostRendererArgs(),
1485+
DryRun: c.DryRun(),
14851486
}
14861487
return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), syncOpts)
14871488
}))
@@ -1874,6 +1875,7 @@ Do you really want to sync?
18741875
ResetValues: c.ResetValues(),
18751876
PostRenderer: c.PostRenderer(),
18761877
PostRendererArgs: c.PostRendererArgs(),
1878+
DryRun: c.DryRun(),
18771879
}
18781880
return subst.SyncReleases(&affectedReleases, helm, c.Values(), c.Concurrency(), opts)
18791881
}))

pkg/app/app_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,7 @@ func (c configImpl) KubeVersion() string {
21922192
type applyConfig struct {
21932193
args string
21942194
cascade string
2195+
dryRun string
21952196
values []string
21962197

21972198
// TODO: Remove this function once Helmfile v0.x
@@ -2396,6 +2397,10 @@ func (a applyConfig) KubeVersion() string {
23962397
return a.kubeVersion
23972398
}
23982399

2400+
func (a applyConfig) DryRun() string {
2401+
return a.dryRun
2402+
}
2403+
23992404
type depsConfig struct {
24002405
skipRepos bool
24012406
includeTransitiveNeeds bool

pkg/app/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type ApplyConfigProvider interface {
5050
PostRenderer() string
5151
PostRendererArgs() []string
5252
Cascade() string
53+
DryRun() string
5354

5455
Values() []string
5556
Set() []string
@@ -96,6 +97,7 @@ type SyncConfigProvider interface {
9697
PostRenderer() string
9798
PostRendererArgs() []string
9899
Cascade() string
100+
DryRun() string
99101

100102
Values() []string
101103
Set() []string

pkg/config/apply.go

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ type ApplyOptions struct {
6262
PostRendererArgs []string
6363
// Cascade '--cascade' to helmv3 delete, available values: background, foreground, or orphan, default: background
6464
Cascade string
65+
// DryRun is for helm dry-run flag
66+
DryRyn string
6567
}
6668

6769
// NewApply creates a new Apply
@@ -233,3 +235,8 @@ func (a *ApplyImpl) PostRendererArgs() []string {
233235
func (a *ApplyImpl) Cascade() string {
234236
return a.ApplyOptions.Cascade
235237
}
238+
239+
// DryRun returns dry-run flag
240+
func (a *ApplyImpl) DryRun() string {
241+
return a.ApplyOptions.DryRyn
242+
}

pkg/config/sync.go

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ type SyncOptions struct {
3232
PostRendererArgs []string
3333
// Cascade '--cascade' to helmv3 delete, available values: background, foreground, or orphan, default: background
3434
Cascade string
35+
// DryRun is for helm dry-run flag
36+
DryRyn string
3537
}
3638

3739
// NewSyncOptions creates a new Apply
@@ -132,3 +134,8 @@ func (t *SyncImpl) PostRendererArgs() []string {
132134
func (t *SyncImpl) Cascade() string {
133135
return t.SyncOptions.Cascade
134136
}
137+
138+
// DryRun returns dry-run flag
139+
func (t *SyncImpl) DryRun() string {
140+
return t.SyncOptions.DryRyn
141+
}

pkg/state/helmx.go

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ func (st *HelmState) appendWaitFlags(flags []string, release *ReleaseSpec, ops *
8787
}
8888
return flags
8989
}
90+
func (st *HelmState) appendDryRunFlags(flags []string, opt *SyncOpts) []string {
91+
if opt != nil && opt.DryRun != "" {
92+
flags = append(flags, "--dry-run", opt.DryRun)
93+
}
94+
return flags
95+
}
9096

9197
// append post-renderer flags to helm flags
9298
func (st *HelmState) appendCascadeFlags(flags []string, helm helmexec.Interface, release *ReleaseSpec, cascade string) []string {

pkg/state/state.go

+2
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ type SyncOpts struct {
725725
ResetValues bool
726726
PostRenderer string
727727
PostRendererArgs []string
728+
DryRun string
728729
}
729730

730731
type SyncOpt interface{ Apply(*SyncOpts) }
@@ -2580,6 +2581,7 @@ func (st *HelmState) flagsForUpgrade(helm helmexec.Interface, release *ReleaseSp
25802581
postRendererArgs = opt.PostRendererArgs
25812582
}
25822583
flags = st.appendPostRenderArgsFlags(flags, release, postRendererArgs)
2584+
flags = st.appendDryRunFlags(flags, opt)
25832585

25842586
common, clean, err := st.namespaceAndValuesFlags(helm, release, workerIndex)
25852587
if err != nil {

0 commit comments

Comments
 (0)