Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use flags pointer #291

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 15 additions & 14 deletions go-chaos/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func NewCmd() *cobra.Command {
Perfect to inject some chaos into your brokers and gateways.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
internal.Verbosity = Verbose
internal.LogVerbose("Flags: %v", flags)
internal.JsonLogging = JsonLogging
if JsonLogging {
internal.JsonLogger = log.With().Logger()
Expand All @@ -99,26 +100,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 @@ -32,13 +32,13 @@
}
},
{
"name": "Should be able to create process instances on partition 1",
"name": "Should be able to create process instances on partition three",
"type": "probe",
"tolerance": 0,
"provider": {
"type": "process",
"path": "zbchaos",
"arguments": ["verify", "instance-creation", "--partitionId", "1"],
"arguments": ["verify", "instance-creation", "--partitionId", "3"],
"timeout": 900
}
}
Expand All @@ -47,11 +47,11 @@
"method": [
{
"type": "action",
"name": "Restart leader of partition 1",
"name": "Restart leader of partition three",
"provider": {
"type": "process",
"path": "zbchaos",
"arguments": ["restart", "broker", "--role", "LEADER", "--partitionId", "1"]
"arguments": ["restart", "broker", "--role", "LEADER", "--partitionId", "3"]
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
}
},
{
"name": "Should be able to create process instances on partition 1",
"name": "Should be able to create process instances on partition two",
"type": "probe",
"tolerance": 0,
"provider": {
"type": "process",
"path": "zbchaos",
"arguments": ["verify", "instance-creation", "--partitionId", "1"],
"arguments": ["verify", "instance-creation", "--partitionId", "2"],
"timeout": 900
}
}
Expand All @@ -47,11 +47,11 @@
"method": [
{
"type": "action",
"name": "Terminate leader of partition 1 non-gracefully",
"name": "Terminate leader of partition two non-gracefully",
"provider": {
"type": "process",
"path": "zbchaos",
"arguments": ["terminate", "broker", "--role", "LEADER", "--partitionId", "1"]
"arguments": ["terminate", "broker", "--role", "LEADER", "--partitionId", "2"]
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
}
},
{
"name": "Should be able to create process instances on partition 1",
"name": "Should be able to create process instances on partition two",
"type": "probe",
"tolerance": 0,
"provider": {
"type": "process",
"path": "zbchaos",
"arguments": ["verify", "instance-creation", "--partitionId", "1"],
"arguments": ["verify", "instance-creation", "--partitionId", "2"],
"timeout": 900
}
}
Expand All @@ -47,11 +47,11 @@
"method": [
{
"type": "action",
"name": "Terminate leader of partition 1 non-gracefully",
"name": "Terminate leader of partition two non-gracefully",
"provider": {
"type": "process",
"path": "zbchaos",
"arguments": ["terminate", "broker", "--role", "LEADER", "--partitionId", "1"]
"arguments": ["terminate", "broker", "--role", "LEADER", "--partitionId", "2"]
}
},
{
Expand All @@ -66,23 +66,23 @@
}
},
{
"name": "Should be able to create process instances on partition 1",
"name": "Should be able to create process instances on partition two",
"type": "probe",
"tolerance": 0,
"provider": {
"type": "process",
"path": "zbchaos",
"arguments": ["verify", "instance-creation", "--partitionId", "1"],
"arguments": ["verify", "instance-creation", "--partitionId", "2"],
"timeout": 900
}
},
{
"type": "action",
"name": "Terminate leader of partition 1 non-gracefully",
"name": "Terminate leader of partition two non-gracefully",
"provider": {
"type": "process",
"path": "zbchaos",
"arguments": ["terminate", "broker", "--role", "LEADER", "--partitionId", "1"]
"arguments": ["terminate", "broker", "--role", "LEADER", "--partitionId", "2"]
}
},
{
Expand All @@ -97,23 +97,23 @@
}
},
{
"name": "Should be able to create process instances on partition 1",
"name": "Should be able to create process instances on partition two",
"type": "probe",
"tolerance": 0,
"provider": {
"type": "process",
"path": "zbchaos",
"arguments": ["verify", "instance-creation", "--partitionId", "1"],
"arguments": ["verify", "instance-creation", "--partitionId", "2"],
"timeout": 900
}
},
{
"type": "action",
"name": "Terminate leader of partition 1 non-gracefully",
"name": "Terminate leader of partition two non-gracefully",
"provider": {
"type": "process",
"path": "zbchaos",
"arguments": ["terminate", "broker", "--role", "LEADER", "--partitionId", "1"]
"arguments": ["terminate", "broker", "--role", "LEADER", "--partitionId", "2"]
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
"provider": {
"type": "process",
"path": "zbchaos",
"arguments": ["stress", "broker", "--cpu"]
"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