Skip to content

Commit

Permalink
Merge pull request #162 from zeebe-io/zell-hackdays-fault-injection-tool
Browse files Browse the repository at this point in the history
Fault injection cli: zbchaos
  • Loading branch information
ChrisKujawa authored Aug 12, 2022
2 parents ab8fd71 + b8dbe34 commit 72c9c7d
Show file tree
Hide file tree
Showing 36 changed files with 1,765 additions and 405 deletions.
13 changes: 0 additions & 13 deletions chaos-workers/chaos-experiments/scripts/apply_sys_time.sh

This file was deleted.

36 changes: 0 additions & 36 deletions chaos-workers/chaos-experiments/scripts/connect-leader-follower.sh

This file was deleted.

14 changes: 0 additions & 14 deletions chaos-workers/chaos-experiments/scripts/connect-nodes.sh

This file was deleted.

30 changes: 0 additions & 30 deletions chaos-workers/chaos-experiments/scripts/disconnect-elastic.sh

This file was deleted.

This file was deleted.

106 changes: 0 additions & 106 deletions chaos-workers/chaos-experiments/scripts/network-partition.sh

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions go-chaos/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
zbchaos
dist/
4 changes: 2 additions & 2 deletions go-chaos/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ directory=.

# test: runs the tests without updating the golden files (runs checks against golden files)
.PHONY: test
test:
test: build
go test $(directory)/...
# go build
.PHONY: build
build:
build: fmt
go build -o zbchaos main.go

# golden: runs the tests with updating the golden files
Expand Down
20 changes: 20 additions & 0 deletions go-chaos/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash -xeu

OS=( linux windows darwin )
BINARY=( zbchaos zbchaos.exe zbchaos.darwin )
SRC_DIR=$(dirname "${BASH_SOURCE[0]}")
DIST_DIR="$SRC_DIR/dist"

VERSION=${RELEASE_VERSION:-development}
COMMIT=${RELEASE_HASH:-$(git rev-parse HEAD)}

mkdir -p ${DIST_DIR}
rm -rf ${DIST_DIR}/*

for i in "${!OS[@]}"; do
if [ $# -eq 0 ] || [ ${OS[$i]} = $1 ]; then
CGO_ENABLED=0 GOOS="${OS[$i]}" GOARCH=amd64 go build -a -tags netgo -ldflags "-w -X github.com/zeebe-io/zeebe-chaos/go-chaos/cmd.Version=${VERSION} -X github.com/zeebe-io/zeebe-chaos/go-chaos/cmd.Commit=${COMMIT}" -o "${DIST_DIR}/${BINARY[$i]}" "${SRC_DIR}/main.go" # &
fi
done

# wait
71 changes: 71 additions & 0 deletions go-chaos/cmd/connect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2022 Camunda Services GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"fmt"

"github.com/spf13/cobra"
"github.com/zeebe-io/zeebe-chaos/go-chaos/internal"
)

func init() {
rootCmd.AddCommand(connect)
connect.AddCommand(connectBrokers)
}

var connect = &cobra.Command{
Use: "connect",
Short: "Connect Zeebe nodes",
Long: `Connect all Zeebe nodes again, after they have been disconnected uses sub-commands to connect brokers, gateways, etc.`,
}

var connectBrokers = &cobra.Command{
Use: "brokers",
Short: "Connect Zeebe Brokers",
Long: `Connect all Zeebe Brokers again, after they have been disconnected.`,
Run: func(cmd *cobra.Command, args []string) {
internal.Verbosity = Verbose
k8Client, err := internal.CreateK8Client()
if err != nil {
panic(err)
}

// No patch is need, since we expect that disconnect was executed before.
// If not all fine and the pods are already connected.

// We run connect on all nodes, since roles can have been changed in between so it is easier to run the commands on all nodes.

podNames, err := k8Client.GetBrokerPodNames()
if err != nil {
panic(err.Error())
}

if len(podNames) <= 0 {
panic(fmt.Sprintf("Expected to find brokers in current namespace %s, but found nothing\n", k8Client.GetCurrentNamespace()))
}

for _, pod := range podNames {
err = internal.MakeIpReachableForPod(k8Client, pod)
if err != nil {
if Verbose {
fmt.Printf("Error on connection Broker: %s. Error: %s\n", pod, err.Error())
}
} else {
fmt.Printf("Connected %s again, removed unreachable routes.\n", pod)
}
}
},
}
Loading

0 comments on commit 72c9c7d

Please sign in to comment.