@@ -37,26 +37,43 @@ func (o *Options) UnmarshalYAML(unmarshal func(interface{}) error) error {
3737
3838// WaitOption controls the wait behavior for cluster operations.
3939type WaitOption struct {
40- Enabled bool `yaml:"enabled" default:"true"`
40+ Enabled * bool `yaml:"enabled" default:"true"`
4141}
4242
4343// DrainOption controls the drain behavior for cluster operations.
4444type DrainOption struct {
45- Enabled bool `yaml:"enabled" default:"true"`
45+ Enabled * bool `yaml:"enabled" default:"true"`
4646 GracePeriod time.Duration `yaml:"gracePeriod" default:"120s"`
4747 Timeout time.Duration `yaml:"timeout" default:"300s"`
48- Force bool `yaml:"force" default:"true"`
49- IgnoreDaemonSets bool `yaml:"ignoreDaemonSets" default:"true"`
50- DeleteEmptyDirData bool `yaml:"deleteEmptyDirData" default:"true"`
48+ Force * bool `yaml:"force" default:"true"`
49+ IgnoreDaemonSets * bool `yaml:"ignoreDaemonSets" default:"true"`
50+ DeleteEmptyDirData * bool `yaml:"deleteEmptyDirData" default:"true"`
5151 PodSelector string `yaml:"podSelector" default:""`
5252 SkipWaitForDeleteTimeout time.Duration `yaml:"skipWaitForDeleteTimeout" default:"0s"`
5353}
5454
55+ // EnabledValue returns the effective enabled flag, defaulting to true when unset.
56+ func (w WaitOption ) EnabledValue () bool {
57+ return boolPtrValue (w .Enabled , true )
58+ }
59+
60+ // EnabledValue returns the effective enabled flag, defaulting to true when unset.
61+ func (d DrainOption ) EnabledValue () bool {
62+ return boolPtrValue (d .Enabled , true )
63+ }
64+
65+ func boolPtrValue (value * bool , def bool ) bool {
66+ if value == nil {
67+ return def
68+ }
69+ return * value
70+ }
71+
5572// ToKubectlArgs converts the DrainOption to kubectl arguments.
5673func (d * DrainOption ) ToKubectlArgs () string {
5774 args := []string {}
5875
59- if d .Force {
76+ if boolPtrValue ( d .Force , true ) {
6077 args = append (args , "--force" )
6178 }
6279
@@ -76,11 +93,11 @@ func (d *DrainOption) ToKubectlArgs() string {
7693 args = append (args , fmt .Sprintf ("--skip-wait-for-delete-timeout=%s" , d .SkipWaitForDeleteTimeout ))
7794 }
7895
79- if d .DeleteEmptyDirData {
96+ if boolPtrValue ( d .DeleteEmptyDirData , true ) {
8097 args = append (args , "--delete-emptydir-data" )
8198 }
8299
83- if d .IgnoreDaemonSets {
100+ if boolPtrValue ( d .IgnoreDaemonSets , true ) {
84101 args = append (args , "--ignore-daemonsets" )
85102 }
86103
0 commit comments