Add OpenCost pod restart stability check (#91)#113
Open
Aadarsh-Sankar wants to merge 1 commit into
Open
Conversation
Assert OpenCost container restart count is zero at end of integration suite; skip when kubectl/cluster unavailable; dump pod describe and previous-container logs on failure. Signed-off-by: Aadarsh Sankar <aadarshsankar53@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new reliability integration-test suite that asserts every OpenCost container reports a restartCount of 0 at the end of the run, helping catch pods that crashed/restarted during the suite. It introduces a Bats wrapper, a Go test that shells out to kubectl, and two new env helpers (GetOpenCostNamespace, GetOpenCostLabelSelector) so the namespace and label selector are configurable. The PR also adds explanatory comments above several existing env getters.
Changes:
- New
reliabilitytest that queries OpenCost pods viakubectl ... -o json, fails on any non-zerorestartCount, and dumpsdescribe/previous-container logs on failure; skips when kubectl/cluster is unavailable. - New
OPENCOST_NAMESPACE/OPENCOST_LABEL_SELECTORenv getters with defaults. - Added doc comments to existing
env.gogetters.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
test/integration/reliability/no_pod_restarts_test.go |
New Go test verifying zero OpenCost container restarts, with kubectl gating and failure diagnostics. |
test/integration/reliability/test.bats |
Bats wrapper that runs the new Go test, consistent with other suites. |
pkg/env/env.go |
Adds configurable namespace/label-selector getters and doc comments to existing getters. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return strings.TrimRight(url, "/") | ||
| } | ||
|
|
||
| // checks if OPENCOST_URL is set, if not, use the default URL |
| func requireKubectl(t *testing.T) { | ||
| t.Helper() | ||
|
|
||
| if _, err := exec.LookPath("kubectl"); err != nil { //chwcks PATH to see if kubectl is installed |
Comment on lines
+62
to
+67
| out, err := exec.Command( | ||
| "kubectl", "get", "pods", | ||
| "-n", env.GetOpenCostNamespace(), | ||
| "-l", env.GetOpenCostLabelSelector(), | ||
| "-o", "json", | ||
| ).CombinedOutput() |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Assert OpenCost container restart count is zero at end of integration suite; skip when kubectl/cluster unavailable; dump pod describe and previous-container logs on failure.