Skip to content

Commit fb070ff

Browse files
authored
feat(hack): rewrite check-readiness as a Go command with test suite (#2755)
## What this PR does Replaces the `hack/check-readiness.sh` diagnostic with a Go command at `cmd/check-readiness`, integrated into the build the same way as `cozypkg`: - `make check-readiness` builds `_out/bin/check-readiness`, with `Version` injected via `-ldflags`. - The tool shells out to `kubectl` and reports only **non-ready** cozystack / Flux / Kubernetes resources, parsed from status conditions (not column heuristics). Flags: `--wait`/`--timeout`, `--watch`, `--core`, `--parallel`, `--verbose`, `-n`/`-l` scoping, `--no-color`, `--version`. Adds a black-box golden test suite under `test/check-readiness/`: - A mock `kubectl` serves canned fixtures; the suite diffs stdout/stderr/exit against golden files across 30 scenarios (arg parsing, condition/phase/suspend handling, CRD-not-installed, kubectl arg propagation, wait/timeout, edge cases) plus a PTY test for color output. - `make test-check-readiness` runs it; wired into `make unit-tests`. Supersedes #2740, which added the same feature set to the bash script. ### Release note ```release-note feat(hack): replace check-readiness.sh with a `check-readiness` Go command (build with `make check-readiness`); reports non-ready cozystack/Flux/Kubernetes resources with --wait/--watch/--core/--parallel/--verbose and namespace/label scoping. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Added `check-readiness` command for verifying Kubernetes resource readiness status across namespaces * Supports multiple execution modes: one-shot, wait with timeout, and watch with configurable intervals * Includes namespace filtering, label selectors, parallel resource fetching, and color output control * **Tests** * Added comprehensive test suite validating command behavior across various scenarios <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/cozystack/cozystack/pull/2755?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 8b4d318 + f85ec76 commit fb070ff

54 files changed

Lines changed: 1179 additions & 84 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Makefile‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ manifests:
7171
cozypkg:
7272
go build -ldflags "-X github.com/cozystack/cozystack/cmd/cozypkg/cmd.Version=v$(COZYSTACK_VERSION)" -o _out/bin/cozypkg ./cmd/cozypkg
7373

74+
# Operator diagnostic: reports non-ready cozystack / Flux / Kubernetes resources.
75+
check-readiness:
76+
go build -ldflags "-X main.Version=v$(COZYSTACK_VERSION)" -o _out/bin/check-readiness ./cmd/check-readiness
77+
7478
assets: assets-talos assets-cozypkg openapi-json
7579

7680
openapi-json:
@@ -94,7 +98,7 @@ test:
9498
make -C packages/core/testing apply
9599
make -C packages/core/testing test
96100

97-
unit-tests: helm-unit-tests bats-unit-tests go-unit-tests rd-presets-check
101+
unit-tests: helm-unit-tests bats-unit-tests go-unit-tests rd-presets-check test-check-readiness
98102

99103
helm-unit-tests:
100104
hack/helm-unit-tests.sh
@@ -123,6 +127,13 @@ go-unit-tests:
123127
test-controllers:
124128
go test ./internal/... -count=1
125129

130+
# Black-box golden test for cmd/check-readiness. Builds the binary and runs it
131+
# against a mock kubectl (fixtures under test/check-readiness/testdata),
132+
# diffing stdout/stderr/exit against golden files. Regenerate goldens with:
133+
# go test ./test/check-readiness/ -update
134+
test-check-readiness:
135+
go test ./test/check-readiness/ -count=1
136+
126137
# Discover every hack/*.bats file that is NOT an e2e test and run it
127138
# through cozytest.sh. Drop a new *.bats file in hack/ and it is picked
128139
# up automatically on the next `make unit-tests` run.

0 commit comments

Comments
 (0)