Skip to content

Add OpenCost pod restart stability check (#91)#113

Open
Aadarsh-Sankar wants to merge 1 commit into
opencost:mainfrom
Aadarsh-Sankar:issue-91-no-pod-restarts
Open

Add OpenCost pod restart stability check (#91)#113
Aadarsh-Sankar wants to merge 1 commit into
opencost:mainfrom
Aadarsh-Sankar:issue-91-no-pod-restarts

Conversation

@Aadarsh-Sankar

Copy link
Copy Markdown

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.

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>
Copilot AI review requested due to automatic review settings June 23, 2026 20:15
@Aadarsh-Sankar
Aadarsh-Sankar requested a review from a team as a code owner June 23, 2026 20:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 reliability test that queries OpenCost pods via kubectl ... -o json, fails on any non-zero restartCount, and dumps describe/previous-container logs on failure; skips when kubectl/cluster is unavailable.
  • New OPENCOST_NAMESPACE / OPENCOST_LABEL_SELECTOR env getters with defaults.
  • Added doc comments to existing env.go getters.

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.

Comment thread pkg/env/env.go
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants