forked from banzaicloud/koperator
-
Notifications
You must be signed in to change notification settings - Fork 18
fix: propagate Kafka broker exit code to pod phase #260
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
Open
DarkIsDude
wants to merge
4
commits into
adobe:master
Choose a base branch
from
DarkIsDude:fix/propagate-kafka-broker-exit-code
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+112
−4
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5e8f9ab
🐛 propagate Kafka broker exit code to pod phase
DarkIsDude f1ac2b6
🐛 suppress signal-based exit codes during controlled shutdowns
DarkIsDude 393a148
🐛 suppress signal-based exit codes during controlled shutdowns
DarkIsDude e1e8c29
🧪 add graceful shutdown test for wait-for-envoy-sidecar.sh
DarkIsDude 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 hidden or 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 hidden or 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,99 @@ | ||
| // Copyright © 2020 Cisco Systems, Inc. and/or its affiliates | ||
| // | ||
| // 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 kafka | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| // TestWaitForEnvoySidecarExitCodes verifies that the wait-for-envoy-sidecar.sh script | ||
| // correctly translates exit code 143 (SIGTERM controlled shutdown) to 0, and propagates | ||
| // all other exit codes unchanged. | ||
| func TestWaitForEnvoySidecarExitCodes(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| kafkaExit int | ||
| expectedExit int | ||
| }{ | ||
| { | ||
| name: "graceful shutdown (SIGTERM → exit 0)", | ||
| kafkaExit: 143, | ||
| expectedExit: 0, | ||
| }, | ||
| { | ||
| name: "OOM kill (SIGKILL) propagated", | ||
| kafkaExit: 137, | ||
| expectedExit: 137, | ||
| }, | ||
| { | ||
| name: "generic crash propagated", | ||
| kafkaExit: 1, | ||
| expectedExit: 1, | ||
| }, | ||
| { | ||
| name: "normal exit propagated", | ||
| kafkaExit: 0, | ||
| expectedExit: 0, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| tmp := t.TempDir() | ||
|
|
||
| // Create mock kafka-server-start.sh that exits with the desired code. | ||
| binDir := filepath.Join(tmp, "bin") | ||
| if err := os.MkdirAll(binDir, 0o755); err != nil { | ||
| t.Fatalf("create bin dir: %v", err) | ||
| } | ||
| stub := filepath.Join(binDir, "kafka-server-start.sh") | ||
| stubContent := fmt.Sprintf("#!/bin/bash\nexit %d\n", tc.kafkaExit) | ||
| if err := os.WriteFile(stub, []byte(stubContent), 0o755); err != nil { | ||
| t.Fatalf("write stub: %v", err) | ||
| } | ||
|
|
||
| waitDir := filepath.Join(tmp, "wait") | ||
| if err := os.MkdirAll(waitDir, 0o755); err != nil { | ||
| t.Fatalf("create wait dir: %v", err) | ||
| } | ||
|
|
||
| cmd := exec.Command("bash", "-c", envoySidecarScript) | ||
| cmd.Env = []string{ | ||
| "KAFKA_HOME=" + tmp, | ||
| "WAIT_DIR=" + waitDir, | ||
| // Leave ENVOY_SIDECAR_STATUS and CLUSTER_ID unset to skip those blocks. | ||
| } | ||
|
|
||
| err := cmd.Run() | ||
|
|
||
| got := 0 | ||
| if err != nil { | ||
| if exitErr, ok := err.(*exec.ExitError); ok { | ||
| got = exitErr.ExitCode() | ||
| } else { | ||
| t.Fatalf("unexpected error running script: %v", err) | ||
| } | ||
| } | ||
|
|
||
| if got != tc.expectedExit { | ||
| t.Errorf("kafka exit %d: want script exit %d, got %d", tc.kafkaExit, tc.expectedExit, got) | ||
| } | ||
| }) | ||
| } | ||
| } |
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.
hmm - not sure about this.
e.g 137 can be an actual OOM/SIGKILL of the Java process, the wrapper exiting 0
makes the broker pod look Succeeded
Why no simply passing the exact value of $KAFKA_EXIT code?
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.
Tests was failing. I'm trying this one (not sure it was a flaky or not 😬). I can of course revert
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.
@amuraru tests are now green. It's a right concern so I changed my approach 🙏. Do you prefer to change tests instead ?
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.
Can we add a test for a graceful shutdown and see whether the handling of sigterm signal is actually correctly handled by the operator?