diff --git a/go-chaos/cmd/restart.go b/go-chaos/cmd/restart.go index 3c3708322..08638ff6b 100644 --- a/go-chaos/cmd/restart.go +++ b/go-chaos/cmd/restart.go @@ -50,8 +50,13 @@ func AddRestartCmd(rootCmd *cobra.Command, flags *Flags) { Run: func(cmd *cobra.Command, args []string) { k8Client, err := createK8ClientWithFlags(flags) ensureNoError(err) - gatewayPod := restartGateway(k8Client, nil) - internal.LogInfo("Restarted %s", gatewayPod) + + if flags.all { + restartGateways(k8Client, "restart", nil) + } else { + gatewayPod := restartGateway(k8Client, nil) + internal.LogInfo("Restarted %s", gatewayPod) + } }, } @@ -76,6 +81,8 @@ func AddRestartCmd(rootCmd *cobra.Command, flags *Flags) { restartBrokerCmd.MarkFlagsMutuallyExclusive("role", "all") restartCmd.AddCommand(restartGatewayCmd) + restartGatewayCmd.Flags().BoolVar(&flags.all, "all", false, "Specify whether all gateways should be restarted") + restartCmd.AddCommand(restartWorkerCmd) restartWorkerCmd.Flags().BoolVar(&flags.all, "all", false, "Specify whether all workers should be restarted") } diff --git a/go-chaos/cmd/terminate.go b/go-chaos/cmd/terminate.go index 937086b36..aeaa660dc 100644 --- a/go-chaos/cmd/terminate.go +++ b/go-chaos/cmd/terminate.go @@ -55,8 +55,13 @@ func AddTerminateCommand(rootCmd *cobra.Command, flags *Flags) { k8Client, err := createK8ClientWithFlags(flags) ensureNoError(err) gracePeriodSec := int64(0) - gatewayPod := restartGateway(k8Client, &gracePeriodSec) - internal.LogInfo("Terminated %s", gatewayPod) + + if flags.all { + restartGateways(k8Client, "terminate", &gracePeriodSec) + } else { + gatewayPod := restartGateway(k8Client, &gracePeriodSec) + internal.LogInfo("Restarted %s", gatewayPod) + } }, } @@ -83,6 +88,7 @@ func AddTerminateCommand(rootCmd *cobra.Command, flags *Flags) { terminateBrokerCmd.MarkFlagsMutuallyExclusive("role", "all") terminateCmd.AddCommand(terminateGatewayCmd) + terminateGatewayCmd.Flags().BoolVar(&flags.all, "all", false, "Specify whether all gateways should be terminated") terminateCmd.AddCommand(terminateWorkerCmd) terminateWorkerCmd.Flags().BoolVar(&flags.all, "all", false, "Specify whether all workers should be terminated") @@ -142,6 +148,23 @@ func restartGateway(k8Client internal.K8Client, gracePeriod *int64) string { return gatewayPod } +// Restarts all gateways in the current namespace. +// GracePeriod (in second) can be nil, which would mean using K8 default. +func restartGateways(k8Client internal.K8Client, actionName string, gracePeriod *int64) { + gatewayPodNames, err := k8Client.GetGatewayPodNames() + ensureNoError(err) + + if len(gatewayPodNames) <= 0 { + panic(errors.New(fmt.Sprintf("Expected to find a Zeebe gateways in namespace %s, but none found", k8Client.GetCurrentNamespace()))) + } + + for _, gatewayPodName := range gatewayPodNames { + err = k8Client.RestartPodWithGracePeriod(gatewayPodName, gracePeriod) + ensureNoError(err) + internal.LogInfo("%s %s", actionName, gatewayPodName) + } +} + // Restart a worker pod. The pod is the first from a list of existing pods, if all is not specified. // GracePeriod (in second) can be nil, which would mean using K8 default. // The actionName specifies whether it was restarted or terminated to log the right thing.