-
Notifications
You must be signed in to change notification settings - Fork 10
Add drain-delay flag to wait before eviction #13
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ type Options struct { | |
DeleteLocalData bool | ||
Selector string | ||
PodSelector string | ||
DrainDelay time.Duration `mapstructure:"drain-delay"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, I don't understand the significance of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope I got it right. err := viper.Unmarshal(target, func(config *mapstructure.DecoderConfig) {
config.ErrorUnused = false
config.ZeroFields = false
}) I tested it without a mapstructure tag and it couldn't parse flags properly: the value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, I believe, that some other flags, like for example I added simple debug output at the end of serve/Parse() function to check it: // Parse parses all flags and settings to options
func (o *ServeOptions) Parse(cmd *cobra.Command) error {
settings.Bind(cmd.Flags()) // needs to be run inside the command and before any viper usage for flags to be visible
if debug {
log.Debug().Msgf("All keys: %+v", viper.AllKeys())
log.Debug().Msgf("All settings: %+v", viper.AllSettings())
cmd.Flags().VisitAll(func(flag *pflag.Flag) {
log.Debug().Msgf("'%s' -> flag: '%+v' | setting: '%+v'", flag.Name, flag.Value, viper.Get(flag.Name))
})
log.Debug().Msgf("Settings: %+v", *o)
}
if err := settings.Parse(o.Kubernetes); err != nil {
return err
}
if err := settings.Parse(o.Drainer); err != nil {
return err
}
if err := settings.Parse(o.AWS); err != nil {
return err
}
log.Debug().Msgf("Parsed settings: %+v", *o) # <--- this one
return nil
} and I see next behaviour when starting kubedrainer with
{"level":"debug","time":1613463410,"message":"Settings: {Kubernetes:{ConfigFlags:{CacheDir:/Users/rtim/.kube/http-cache KubeConfig: ClusterName: AuthInfoName: Context: Namespace:<nil> APIServer: Insecure:false CertFile: KeyFile: CAFile: BearerToken: Impersonate:<nil> ImpersonateGroup:<nil> Username:<nil> Password:<nil> Timeout:0 clientConfig:<nil> lock:{state:0 sema:0} usePersistentConfig:true}} Drainer:{Node: Force:false GracePeriodSeconds:-1 IgnoreAllDaemonSets:true Timeout:1m0s DeleteLocalData:true Selector: PodSelector: DrainDelay:0s} AWS:0xc00003a6e0}"}
{"level":"debug","time":1613463410,"message":"Parsed settings: {Kubernetes:{ConfigFlags:{CacheDir:/Users/rtim/.kube/http-cache KubeConfig: ClusterName: AuthInfoName: Context: Namespace:<nil> APIServer: Insecure:false CertFile: KeyFile: CAFile: BearerToken: Impersonate:<nil> ImpersonateGroup:<nil> Username:<nil> Password:<nil> Timeout:0 clientConfig:<nil> lock:{state:0 sema:0} usePersistentConfig:true}} Drainer:{Node: Force:false GracePeriodSeconds:-1 IgnoreAllDaemonSets:true Timeout:1m0s DeleteLocalData:true Selector: PodSelector: DrainDelay:0s} AWS:0xc00003a6e0}"} you can see that PodSelector(at the end of JSONs) doesn't change
{"level":"debug","time":1613463080,"message":"Settings: {Kubernetes:{ConfigFlags:{CacheDir:/Users/rtim/.kube/http-cache KubeConfig: ClusterName: AuthInfoName: Context: Namespace:<nil> APIServer: Insecure:false CertFile: KeyFile: CAFile: BearerToken: Impersonate:<nil> ImpersonateGroup:<nil> Username:<nil> Password:<nil> Timeout:0 clientConfig:<nil> lock:{state:0 sema:0} usePersistentConfig:true}} Drainer:{Node: Force:false GracePeriodSeconds:-1 IgnoreAllDaemonSets:true Timeout:1m0s DeleteLocalData:true Selector: PodSelector: DrainDelay:0s} AWS:0xc00029e5f0}"}
{"level":"debug","time":1613463080,"message":"Parsed settings: {Kubernetes:{ConfigFlags:{CacheDir:/Users/rtim/.kube/http-cache KubeConfig: ClusterName: AuthInfoName: Context: Namespace:<nil> APIServer: Insecure:false CertFile: KeyFile: CAFile: BearerToken: Impersonate:<nil> ImpersonateGroup:<nil> Username:<nil> Password:<nil> Timeout:0 clientConfig:<nil> lock:{state:0 sema:0} usePersistentConfig:true}} Drainer:{Node: Force:false GracePeriodSeconds:-1 IgnoreAllDaemonSets:true Timeout:1m0s DeleteLocalData:true Selector: PodSelector:checking DrainDelay:0s} AWS:0xc00029e5f0}"} You can verify it yourself and if you want I can work on this issue as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're absolutely right, thank you for looking at other fields as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to me to continue in this PR then or should we merge this one and open a new PR to fix other fields? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll merge this one, and if you would be son kind we'll gladly accept the fix for the other fields (was about to start working on it) :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, I can fix other fields |
||
} | ||
|
||
func (o *Options) String() string { | ||
|
@@ -72,6 +73,7 @@ func New(client kubernetes.Interface, options *Options) Drainer { | |
ErrOut: errOut, | ||
Out: out, | ||
}, | ||
drainDelay: options.DrainDelay, | ||
drainer: &drain.Helper{ | ||
Client: client, | ||
ErrOut: errOut, | ||
|
@@ -142,6 +144,9 @@ func (o *drainCmdOptions) Drain(nodeName string) error { | |
_ = printObj(n, o.Out) | ||
} | ||
|
||
log.Info().Msgf("Sleep for %v before starting to evict", o.drainDelay.String()) | ||
time.Sleep(o.drainDelay) | ||
|
||
return o.deleteOrEvictPodsSimple(nodeName) | ||
} | ||
|
||
|
@@ -151,6 +156,8 @@ type drainCmdOptions struct { | |
PrintFlags *genericclioptions.PrintFlags | ||
ToPrinter func(string) (printers.ResourcePrinterFunc, error) | ||
|
||
drainDelay time.Duration | ||
|
||
drainer *drain.Helper | ||
nodes *node.Node | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the fact it's zero for backward compatibility