-
Notifications
You must be signed in to change notification settings - Fork 4
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
Allow overriding k8s namespace #193
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1aaaa5e
feat: start worker for zbchaos jobs
lenaschoenburg c3950a5
fix: set default timeout of 15 minutes
lenaschoenburg 6e042bd
deps: upgrade zeebe client to 8.1
lenaschoenburg bf245ce
fix: add license header
lenaschoenburg ef96192
deps: bump go versionto 1.19
lenaschoenburg 8373fcb
build: add docker image for zbchaos
lenaschoenburg 5b8e0b5
ci: build zbchaos docker image
lenaschoenburg 91de1e9
feat: allow overriding kubernetes namespace
lenaschoenburg 0106a02
refactor: set namespace and kubeconfig from cli
lenaschoenburg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Release zbchaos Docker Image | ||
on: | ||
pull_request: {} | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
publish-image: | ||
runs-on: ubuntu-latest | ||
env: | ||
VERSION: ${{ github.event.release.name || github.sha }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup BuildKit | ||
uses: docker/setup-buildx-action@v2 | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: gcr.io | ||
username: _json_key | ||
password: ${{ secrets.DOCKER_GCR }} | ||
- name: Publish Docker Image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: go-chaos | ||
push: true | ||
tags: gcr.io/zeebe-io/zbchaos:${{ env.VERSION }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.* | ||
!cmd/ | ||
!internal | ||
!main.go | ||
!go.mod | ||
!go.sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# syntax=docker/dockerfile:1.4 | ||
FROM golang:alpine as builder | ||
|
||
WORKDIR /app | ||
|
||
COPY --link go.mod go.sum . | ||
RUN go mod download | ||
|
||
COPY --link cmd/ ./cmd | ||
COPY --link internal ./internal | ||
COPY --link main.go ./ | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o zbchaos main.go | ||
|
||
FROM scratch | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /app/zbchaos /usr/local/bin/ | ||
|
||
ENTRYPOINT ["zbchaos"] | ||
CMD ["worker"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// 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 ( | ||
"context" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/camunda/zeebe/clients/go/v8/pkg/entities" | ||
"github.com/camunda/zeebe/clients/go/v8/pkg/worker" | ||
"github.com/camunda/zeebe/clients/go/v8/pkg/zbc" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const jobType = "zbchaos" | ||
|
||
func init() { | ||
rootCmd.AddCommand(workerCommand) | ||
} | ||
|
||
var workerCommand = &cobra.Command{ | ||
Use: "worker", | ||
Short: "Starts a worker for zbchaos jobs", | ||
Long: "Starts a worker for zbchaos jobs that executes zbchaos commands", | ||
Run: start_worker, | ||
} | ||
|
||
type ChaosProvider struct { | ||
path string | ||
args []string | ||
timeout int64 | ||
} | ||
|
||
type ZbChaosVariables struct { | ||
clusterId string | ||
provider ChaosProvider | ||
} | ||
|
||
func start_worker(cmd *cobra.Command, args []string) { | ||
credsProvider, err := zbc.NewOAuthCredentialsProvider(&zbc.OAuthProviderConfig{ | ||
ClientID: os.Getenv("TESTBENCH_CLIENT_ID"), | ||
ClientSecret: os.Getenv("TESTBENCH_CLIENT_SECRET"), | ||
Audience: strings.TrimSuffix(os.Getenv("TESTBENCH_ADDRESS"), ":443"), | ||
AuthorizationServerURL: os.Getenv("TESTBENCH_AUTHORIZATION_SERVER_URL"), | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
client, err := zbc.NewClient(&zbc.ClientConfig{ | ||
GatewayAddress: os.Getenv("TESTBENCH_ADDRESS"), | ||
CredentialsProvider: credsProvider, | ||
}) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
jobWorker := client.NewJobWorker().JobType(jobType).Handler(handleZbChaosJob).Open() | ||
jobWorker.AwaitClose() | ||
} | ||
|
||
func handleZbChaosJob(client worker.JobClient, job entities.Job) { | ||
ctx := context.Background() | ||
|
||
jobVariables := ZbChaosVariables{ | ||
provider: ChaosProvider{ | ||
timeout: 15 * 60, // 15 minute default timeout | ||
}, | ||
} | ||
err := job.GetVariablesAs(&jobVariables) | ||
if err != nil { | ||
// Can't parse variables, no sense in retrying | ||
_, _ = client.NewFailJobCommand().JobKey(job.Key).Retries(0).Send(ctx) | ||
return | ||
} | ||
|
||
timeout := time.Duration(jobVariables.provider.timeout) * time.Second | ||
commandCtx, cancelCommand := context.WithTimeout(ctx, timeout) | ||
defer cancelCommand() | ||
|
||
err = runZbChaosCommand(jobVariables.provider.args, commandCtx) | ||
if err != nil { | ||
_, _ = client.NewFailJobCommand().JobKey(job.Key).Retries(job.Retries - 1).Send(ctx) | ||
return | ||
} | ||
|
||
_, _ = client.NewCompleteJobCommand().JobKey(job.Key).Send(ctx) | ||
} | ||
|
||
func runZbChaosCommand(args []string, ctx context.Context) error { | ||
rootCmd.SetArgs(args) | ||
_, err := rootCmd.ExecuteContextC(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we need also some defaults ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default for the config path is set here: https://github.com/zeebe-io/zeebe-chaos/pull/193/files#diff-464316c02acb79ad2acc14ad37881cf54b046e8f496271a18a68502f674944b0R79-R88