diff --git a/changelog/fragments/ansible-graceful-shutdown-timeout.yaml b/changelog/fragments/ansible-graceful-shutdown-timeout.yaml new file mode 100644 index 00000000000..b2f1679da61 --- /dev/null +++ b/changelog/fragments/ansible-graceful-shutdown-timeout.yaml @@ -0,0 +1,5 @@ +entries: + - description: > + For Ansible-based operators, allow passing a --graceful-shutdown-timeout to configure the duration the manager should wait before stopping. + kind: "addition" + breaking: false diff --git a/internal/ansible/flags/flag.go b/internal/ansible/flags/flag.go index 3fb6cd644e2..53ed8872750 100644 --- a/internal/ansible/flags/flag.go +++ b/internal/ansible/flags/flag.go @@ -35,6 +35,7 @@ type Flags struct { ProbeAddr string LeaderElectionID string LeaderElectionNamespace string + GracefulShutdownTimeout time.Duration AnsibleArgs string } @@ -109,6 +110,12 @@ func (f *Flags) AddTo(flagSet *pflag.FlagSet) { " holding the leader lock (required if running locally with leader"+ " election enabled).", ) + flagSet.DurationVar(&f.GracefulShutdownTimeout, + "graceful-shutdown-timeout", + 30*time.Second, + "The amount of time that will be spent waiting"+ + " for runners to gracefully exit.", + ) flagSet.StringVar(&f.AnsibleArgs, "ansible-args", "", diff --git a/internal/cmd/ansible-operator/run/cmd.go b/internal/cmd/ansible-operator/run/cmd.go index 257361a662a..19724baca6f 100644 --- a/internal/cmd/ansible-operator/run/cmd.go +++ b/internal/cmd/ansible-operator/run/cmd.go @@ -109,6 +109,7 @@ func run(cmd *cobra.Command, f *flags.Flags) { LeaderElectionResourceLock: resourcelock.ConfigMapsResourceLock, LeaderElectionNamespace: f.LeaderElectionNamespace, ClientBuilder: clientbuilder.NewUnstructedCached(), + GracefulShutdownTimeout: &f.GracefulShutdownTimeout, } namespace, found := os.LookupEnv(k8sutil.WatchNamespaceEnvVar)