Skip to content

Commit

Permalink
Merge branch 'main' into zell-not-always-broker-one
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisKujawa authored Dec 21, 2022
2 parents 33221ee + 1aa1b5a commit db2e494
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 33 deletions.
10 changes: 5 additions & 5 deletions go-chaos/cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/zeebe-io/zeebe-chaos/go-chaos/internal"
)

func AddBackupCommand(rootCmd *cobra.Command, flags Flags) {
func AddBackupCommand(rootCmd *cobra.Command, flags *Flags) {

var backupCommand = &cobra.Command{
Use: "backup",
Expand Down Expand Up @@ -182,7 +182,7 @@ func createBackupSecret(k8Client internal.K8Client, namespace string) (*core.Sec
)
}

func takeBackup(flags Flags) error {
func takeBackup(flags *Flags) error {
k8Client, err := createK8ClientWithFlags(flags)
if err != nil {
panic(err)
Expand Down Expand Up @@ -211,7 +211,7 @@ func takeBackup(flags Flags) error {
return err
}

func waitForBackup(flags Flags) error {
func waitForBackup(flags *Flags) error {
k8Client, err := createK8ClientWithFlags(flags)
if err != nil {
panic(err)
Expand Down Expand Up @@ -240,7 +240,7 @@ func waitForBackup(flags Flags) error {

}

func restoreFromBackup(flags Flags) error {
func restoreFromBackup(flags *Flags) error {
k8Client, err := createK8ClientWithFlags(flags)
if err != nil {
panic(err)
Expand Down Expand Up @@ -314,7 +314,7 @@ func restoreFromBackup(flags Flags) error {
return nil
}

func restoreEnvFromSfs(flags Flags, sfs *apps.StatefulSet) []core.EnvVar {
func restoreEnvFromSfs(flags *Flags, sfs *apps.StatefulSet) []core.EnvVar {
zeebeEnv := sfs.Spec.Template.Spec.Containers[0].Env
restoreEnv := make([]core.EnvVar, 0)
for _, env := range zeebeEnv {
Expand Down
2 changes: 1 addition & 1 deletion go-chaos/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/zeebe-io/zeebe-chaos/go-chaos/backend"
)

func AddConnectCmd(rootCmd *cobra.Command, flags Flags) {
func AddConnectCmd(rootCmd *cobra.Command, flags *Flags) {
var connect = &cobra.Command{
Use: "connect",
Short: "Connect Zeebe nodes",
Expand Down
2 changes: 1 addition & 1 deletion go-chaos/cmd/dataloss_sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/zeebe-io/zeebe-chaos/go-chaos/internal"
)

func AddDatalossSimulationCmd(rootCmd *cobra.Command, flags Flags) {
func AddDatalossSimulationCmd(rootCmd *cobra.Command, flags *Flags) {

var datalossCmd = &cobra.Command{
Use: "dataloss",
Expand Down
2 changes: 1 addition & 1 deletion go-chaos/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/zeebe-io/zeebe-chaos/go-chaos/internal"
)

func AddDeployCmd(rootCmd *cobra.Command, flags Flags) {
func AddDeployCmd(rootCmd *cobra.Command, flags *Flags) {

var deployCmd = &cobra.Command{
Use: "deploy",
Expand Down
2 changes: 1 addition & 1 deletion go-chaos/cmd/disconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func ensureNoError(err error) {
}
}

func AddDisconnectCommand(rootCmd *cobra.Command, flags Flags) {
func AddDisconnectCommand(rootCmd *cobra.Command, flags *Flags) {

var disconnect = &cobra.Command{
Use: "disconnect",
Expand Down
2 changes: 1 addition & 1 deletion go-chaos/cmd/exporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/zeebe-io/zeebe-chaos/go-chaos/internal"
)

func AddExportingCmds(rootCmd *cobra.Command, flags Flags) {
func AddExportingCmds(rootCmd *cobra.Command, flags *Flags) {
var exportingCommand = &cobra.Command{
Use: "exporting",
Short: "Controls Zeebe Exporting",
Expand Down
2 changes: 1 addition & 1 deletion go-chaos/cmd/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/zeebe-io/zeebe-chaos/go-chaos/internal"
)

func AddPublishCmd(rootCmd *cobra.Command, flags Flags) {
func AddPublishCmd(rootCmd *cobra.Command, flags *Flags) {

var publishCmd = &cobra.Command{
Use: "publish",
Expand Down
2 changes: 1 addition & 1 deletion go-chaos/cmd/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/zeebe-io/zeebe-chaos/go-chaos/internal"
)

func AddRestartCmd(rootCmd *cobra.Command, flags Flags) {
func AddRestartCmd(rootCmd *cobra.Command, flags *Flags) {

var restartCmd = &cobra.Command{
Use: "restart",
Expand Down
30 changes: 16 additions & 14 deletions go-chaos/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ func NewCmd() *cobra.Command {
Long: `A chaos experimenting toolkit for Zeebe.
Perfect to inject some chaos into your brokers and gateways.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
internal.LogInfo("%v", flags)
internal.Verbosity = Verbose
internal.LogVerbose("Flags: %v", flags)
internal.JsonLogging = JsonLogging
if JsonLogging {
internal.JsonLogger = log.With().Logger()
Expand All @@ -99,26 +101,26 @@ func NewCmd() *cobra.Command {
rootCmd.PersistentFlags().StringVar(&flags.kubeConfigPath, "kubeconfig", "", "path the the kube config that will be used")
rootCmd.PersistentFlags().StringVarP(&flags.namespace, "namespace", "n", "", "connect to the given namespace")

AddBackupCommand(rootCmd, flags)
AddBrokersCommand(rootCmd, flags)
AddConnectCmd(rootCmd, flags)
AddDatalossSimulationCmd(rootCmd, flags)
AddDeployCmd(rootCmd, flags)
AddDisconnectCommand(rootCmd, flags)
AddExportingCmds(rootCmd, flags)
AddPublishCmd(rootCmd, flags)
AddRestartCmd(rootCmd, flags)
AddStressCmd(rootCmd, flags)
AddTerminateCommand(rootCmd, flags)
AddTopologyCmd(rootCmd, flags)
AddVerifyCommands(rootCmd, flags)
AddBackupCommand(rootCmd, &flags)
AddBrokersCommand(rootCmd, &flags)
AddConnectCmd(rootCmd, &flags)
AddDatalossSimulationCmd(rootCmd, &flags)
AddDeployCmd(rootCmd, &flags)
AddDisconnectCommand(rootCmd, &flags)
AddExportingCmds(rootCmd, &flags)
AddPublishCmd(rootCmd, &flags)
AddRestartCmd(rootCmd, &flags)
AddStressCmd(rootCmd, &flags)
AddTerminateCommand(rootCmd, &flags)
AddTopologyCmd(rootCmd, &flags)
AddVerifyCommands(rootCmd, &flags)
AddVersionCmd(rootCmd)
AddWorkerCmd(rootCmd)

return rootCmd
}

func createK8ClientWithFlags(flags Flags) (internal.K8Client, error) {
func createK8ClientWithFlags(flags *Flags) (internal.K8Client, error) {
return internal.CreateK8Client(flags.kubeConfigPath, flags.namespace)
}

Expand Down
2 changes: 1 addition & 1 deletion go-chaos/cmd/stress.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
v1 "k8s.io/api/core/v1"
)

func AddStressCmd(rootCmd *cobra.Command, flags Flags) {
func AddStressCmd(rootCmd *cobra.Command, flags *Flags) {
stress := &cobra.Command{
Use: "stress",
Short: "Put stress on a Zeebe node",
Expand Down
2 changes: 1 addition & 1 deletion go-chaos/cmd/terminate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/zeebe-io/zeebe-chaos/go-chaos/internal"
)

func AddTerminateCommand(rootCmd *cobra.Command, flags Flags) {
func AddTerminateCommand(rootCmd *cobra.Command, flags *Flags) {

var terminateCmd = &cobra.Command{
Use: "terminate",
Expand Down
2 changes: 1 addition & 1 deletion go-chaos/cmd/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/zeebe-io/zeebe-chaos/go-chaos/internal"
)

func AddTopologyCmd(rootCmd *cobra.Command, flags Flags) {
func AddTopologyCmd(rootCmd *cobra.Command, flags *Flags) {

var topologyCmd = &cobra.Command{
Use: "topology",
Expand Down
2 changes: 1 addition & 1 deletion go-chaos/cmd/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/zeebe-io/zeebe-chaos/go-chaos/internal"
)

func AddVerifyCommands(rootCmd *cobra.Command, flags Flags) {
func AddVerifyCommands(rootCmd *cobra.Command, flags *Flags) {

var verifyCmd = &cobra.Command{
Use: "verify",
Expand Down
2 changes: 1 addition & 1 deletion go-chaos/cmd/zeebePods.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/zeebe-io/zeebe-chaos/go-chaos/internal"
)

func AddBrokersCommand(rootCmd *cobra.Command, flags Flags) {
func AddBrokersCommand(rootCmd *cobra.Command, flags *Flags) {
var getZeebeBrokersCmd = &cobra.Command{
Use: "brokers",
Short: "Print the name of the Zeebe broker pods",
Expand Down
4 changes: 3 additions & 1 deletion go-chaos/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ func Test_ShouldBeAbleToRunExperiments(t *testing.T) {
go cmd.OpenWorkers(zeebeClient)
go func() {
internal.LogInfo("Create ChaosToolkit instance")
response, err := commandStep3.WithResult().Send(ctx)
deadline, cancelFunc := context.WithDeadline(ctx, time.UnixMilli(time.Now().UnixMilli()+int64(60*time.Minute)))
defer cancelFunc()
response, err := commandStep3.WithResult().Send(deadline)
require.NoError(t, err)
internal.LogInfo("Instance %d [definition %d ] completed", response.ProcessInstanceKey, response.ProcessDefinitionKey)
close(done)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
"type": "process",
"path": "zbchaos",
"arguments": ["stress", "broker", "--cpu", "--role=LEADER", "--partitionId=3"]
},
"pauses": {
"after": 30
}
}
],
Expand Down
5 changes: 4 additions & 1 deletion go-chaos/internal/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/portforward"
"k8s.io/client-go/tools/remotecommand"
Expand Down Expand Up @@ -281,11 +282,13 @@ func (c K8Client) createPortForwarder(localPort int, remotePort int, portForward

// createPortForwardUrl constructs the Url to which is used to create the port forwarding
func (c K8Client) createPortForwardUrl(names []string) *url.URL {
gatewayName := names[rand.Intn(len(names))]
LogVerbose("Port forward to %s", gatewayName)
restClient := c.Clientset.CoreV1().RESTClient()
portForwardCreateURL := restClient.Post().
Resource("pods").
Namespace(c.GetCurrentNamespace()).
Name(names[0]).
Name(gatewayName).
SubResource("portforward").
URL()
return portForwardCreateURL
Expand Down

0 comments on commit db2e494

Please sign in to comment.