Skip to content

Commit 56743c7

Browse files
author
Vladimir Kuznichenkov
committed
Update readme for the project
1 parent e09eeaa commit 56743c7

File tree

1 file changed

+88
-49
lines changed

1 file changed

+88
-49
lines changed

README.md

Lines changed: 88 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,108 +5,143 @@ A small Go CLI that tracks Kubernetes resources defined in manifests, showing co
55
Highlights:
66
- Tracks readiness of Deployments, StatefulSets, Jobs, DaemonSets, and arbitrary CRDs.
77
- Prints progress and events; pod logs are only shown when containers fail (ImagePullBackOff, CrashLoopBackOff, OOMKilled, etc.).
8-
- Works with files, directories, or stdin (great for kubectl, helm, or kustomize pipelines).
8+
- Works with files, directories, stdin, and Helm releases (via `kubetracker helm`).
99
- Extensible readiness strategy for CRDs via condition mappings.
10+
- Helm release tracking implemented: `kubetracker helm` reads Helm v3 release Secrets, decodes the rendered manifest, and reuses the same tracker as `track`.
1011

1112
Note: This tool does not apply resources; it tracks resources you’re applying via your deployment tooling (kubectl/helm/Argo/etc.). You can run it concurrently with your apply/upgrade and it will follow the resources defined in your manifests.
1213

1314
## Status
1415

1516
- Tracking implemented: readiness for Deployments, StatefulSets, DaemonSets, Jobs; CRDs via conditions (auto-inferred and custom mappings).
16-
- Progress/events/logs wired; healthy pod logs suppressed by default; pod status enrichment avoids UNKNOWN; built-in CRD rules (cert-manager Certificate Ready=True, Apache APISIX ApisixRoute ResourcesAvailable=True).
17-
- Prints READY on success; supports --exit-on-first-fail and global --timeout; optional --failure-grace-period keeps tracking and retries builtin trackers for transient failures (e.g., ImagePullBackOff).
17+
- Progress/events/logs wired; healthy pod logs suppressed by default; pod status enrichment avoids UNKNOWN; built-in CRD rules (cert-manager `Certificate` `Ready=True`, Apache APISIX `ApisixRoute` `ResourcesAvailable=True`).
18+
- Helm release tracking implemented:
19+
- `kubetracker helm` supports tracking one or more Helm releases directly by reading the cluster Secret for each release and decoding the embedded release manifest.
20+
- Supports release refs as `<namespace>/<name>` or `<name>` with `--namespace` set.
21+
- Picks the latest Helm Secret (type `helm.sh/release.v1`) by numeric `version` label, breaking ties by most recent creation timestamp.
22+
- Emits non-fatal warnings for things like non-integer `version` labels; decode errors surface as invalid input.
23+
- Prints READY on success; supports `--exit-on-first-fail` and global `--timeout`; optional `--failure-grace-period` keeps tracking and retries builtin trackers for transient failures (e.g., ImagePullBackOff).
1824

1925
What’s next:
2026
- More per-CRD defaults and condition heuristics.
2127
- Structured JSON output mode for CI.
22-
- Optional --apply mode and additional QoL improvements.
23-
28+
- Optional `--apply` mode and additional QoL improvements.
2429

2530
## Installation
2631

2732
- Requirements: Go 1.22+
2833

2934
Build locally:
30-
```/dev/null/example.sh#L1-4
31-
# from repo root
32-
cd jenkins-toolbox/files/kubetracker
33-
go build -o ./bin/kubetracker ./cmd/kubetracker
34-
./bin/kubetracker --help
35+
```
36+
go build -o ./bin/kubetracker ./cmd/kubetracker
37+
./bin/kubetracker --help
3538
```
3639

3740
Alternatively, install into GOPATH/bin:
38-
```/dev/null/example.sh#L1-2
39-
cd jenkins-toolbox/files/kubetracker
40-
go install ./cmd/kubetracker
41+
```
42+
go install ./cmd/kubetracker
4143
```
4244

4345
## Usage
4446

4547
Basic tracking from a folder:
46-
```/dev/null/example.sh#L1-2
47-
# Track resources defined in ./manifests
48-
kubetracker track -f ./manifests
48+
```
49+
# Track resources defined in ./manifests
50+
kubetracker track -f ./manifests
4951
```
5052

5153
Track from stdin (kustomize):
52-
```/dev/null/example.sh#L1-2
53-
kustomize build ./overlays/prod | kubetracker track -f -
54+
```
55+
kustomize build ./overlays/prod | kubetracker track -f -
56+
```
57+
58+
Track a Helm release template stream (render locally with `helm template`):
59+
```
60+
helm template myapp ./chart --namespace prod | kubetracker track -f - -n prod
5461
```
5562

56-
Track a Helm release template stream:
57-
```/dev/null/example.sh#L1-2
58-
helm template myapp ./chart --namespace prod | kubetracker track -f - -n prod
63+
Track Helm release(s) directly (reads latest Secret in-cluster):
5964
```
65+
# Single release specified as <ns>/<name>
66+
kubetracker helm prod/myapp
6067
61-
Common flags:
62-
- `-f, --file` Path to a file, directory, or “-” for stdin. Can be repeated.
63-
- `-n, --namespace` Default namespace for namespaceless manifests.
64-
- `--context, --kubeconfig` Standard kube client overrides.
68+
# Multiple releases (different namespaces allowed)
69+
kubetracker helm prod/myapp staging/otherapp
70+
```
71+
72+
You can also omit the namespace per release and use `--namespace`:
73+
```
74+
# Using --namespace for names without <ns>/
75+
kubetracker helm myapp -n prod
76+
kubetracker helm myapp otherapp -n prod
77+
```
78+
79+
Common flags (both `track` and `helm` reuse many options):
80+
- `-n, --namespace` Default namespace for namespaceless manifests or to resolve names when release arg omits namespace.
6581
- `--timeout` Global tracking deadline (e.g. 10m).
6682
- `--failure-grace-period` Grace window to keep tracking and retry builtin trackers after failures (e.g. 2m). 0 disables retry.
6783
- `--include-kind / --exclude-kind` Filter kinds by name (e.g. Deployment, KafkaTopic).
68-
- `--crd-condition` Custom condition mapping for CRDs (see below).
84+
- `--crd-condition` Custom condition mapping for CRDs.
6985
- `--show-events` Show K8s events table along with progress.
7086
- `--only-errors-logs` Only stream pod logs for failing containers (default: true).
7187
- `--exit-on-first-fail` Exit immediately when a resource fails (useful in CI).
88+
- `--kubeconfig / --context` Standard kube client overrides.
89+
- `--verbose` Print additional debug/operational details (including Helm secret selection & decode warnings).
90+
- `--summary` Print a summary of resources being tracked.
7291

7392
Exit codes:
7493
- 0: All tracked resources reached the desired state.
7594
- 1: One or more resources failed.
7695
- 2: Timed out.
77-
- 3: Invalid input (bad YAML, missing kube context, etc.).
96+
- 3: Invalid input (bad YAML, missing kube context, failed to decode Helm release, etc.).
97+
98+
## Helm subcommand details
99+
100+
The `helm` subcommand provides two convenient ways to track Helm-managed resources:
101+
102+
1. Track rendered manifests produced by `helm template` piped to `kubetracker track -f -`.
103+
2. Track releases directly with `kubetracker helm <RELEASE...>` which reads the in-cluster Helm v3 Secret for each release and decodes the `.manifest` embedded in the release payload.
104+
105+
How `kubetracker helm` works:
106+
- Each CLI release arg can be specified as `<namespace>/<name>` or just `<name>` (requires `--namespace`).
107+
- The subcommand lists Secrets in the release namespace labeled `owner=helm` and `name=<release>`.
108+
- It filters Secrets of Type `helm.sh/release.v1` and selects the single best candidate:
109+
- Prefers the highest numeric `version` label.
110+
- If multiple Secrets share the same numeric `version`, picks the most recently created one.
111+
- If a Secret has a non-integer `version` label, kubetracker may emit a non-fatal warning and treat that version as `-1` for selection purposes (verbose mode will show the warning).
112+
- The Secret's `data["release"]` payload is decoded:
113+
- Base64 decode
114+
- If gzipped, gunzip the payload
115+
- Unmarshal JSON and extract the `manifest` field
116+
- The extracted manifest (multi-document YAML) is fed to the same manifest loader used by `track`, then tracked normally.
117+
118+
Caveats and limitations:
119+
- Only Helm v3 release Secrets of Type `helm.sh/release.v1` are supported.
120+
- If your Helm installation uses a different storage backend (e.g., secrets encrypted by external tooling, or a different secret type), `kubetracker helm` may not be able to decode the manifest.
121+
- RBAC: listing Secrets in the release namespace requires permissions; lacking access will produce an error.
122+
- If the release Secret is missing, empty, or cannot be decoded, `kubetracker helm` will surface an invalid input error.
78123

79124
## What is tracked
80125

81-
- Native workload kinds: Deployment, StatefulSet, DaemonSet, Job (readiness).
126+
- Native workload kinds: `Deployment`, `StatefulSet`, `DaemonSet`, `Job` (readiness).
82127
- Pods under the hood for status and logs (but logs are shown only for failing states).
83-
- Arbitrary CRDs: readiness determined by conditions (configurable), or presence-only fallback.
128+
- Arbitrary CRDs: readiness determined by `status.conditions` (configurable), or presence-only fallback.
84129

85130
### CRDs readiness strategy
86131

87-
By default, kubetracker tries to infer readiness via status.conditions:
88-
- If a resource exposes `status.conditions` with a recognizable Ready”, “Available”, “Healthy, or similar positive condition, kubetracker waits for that condition to be True.
132+
By default, kubetracker tries to infer readiness via `status.conditions`:
133+
- If a resource exposes `status.conditions` with a recognizable `Ready`, `Available`, `Healthy`, or similar positive condition, kubetracker waits for that condition to be `True`.
89134
- If such conditions are absent, kubetracker falls back to presence (created) which is often sufficient for controller-managed resources but may be too permissive.
90135

91136
You can customize CRD readiness via `--crd-condition`:
92-
```/dev/null/example.sh#L1-5
93-
# Format: group/version,Kind=ConditionType=ExpectedValue
94-
# Multiple mappings allowed.
95-
kubetracker track -f ./manifests \
96-
--crd-condition "external-secrets.io/v1beta1,ExternalSecret=Ready=True" \
97-
--crd-condition "kafka.strimzi.io/v1beta2,KafkaTopic=Ready=True"
98-
```
99-
100-
Examples:
101-
- ExternalSecret (external-secrets.io): `Ready=True`
102-
- KafkaTopic (Strimzi): `Ready=True`
103-
- Certificate (cert-manager.io): `Ready=True` (built-in default)
104-
- ApisixRoute (apisix.apache.org): `ResourcesAvailable=True` (built-in default)
137+
# Format: group/version,Kind=ConditionType=ExpectedValue
138+
# Multiple mappings allowed.
139+
kubetracker track -f ./manifests \
140+
--crd-condition "external-secrets.io/v1beta1,ExternalSecret=Ready=True" \
141+
--crd-condition "kafka.strimzi.io/v1beta2,KafkaTopic=Ready=True"
105142

106143
Built-in mappings are applied unless overridden by `--crd-condition`.
107144

108-
If your CRD uses a different condition type or value, point kubetracker to it with another mapping.
109-
110145
## How it works (high level)
111146

112147
- Parse input manifests into `unstructured.Unstructured` objects.
@@ -122,7 +157,7 @@ If your CRD uses a different condition type or value, point kubetracker to it wi
122157
- Any resource fails; or
123158
- Timeout occurs.
124159

125-
The log filtering rule:
160+
Log filtering:
126161
- For each container in a pod:
127162
- If waiting reason is problematic (ImagePullBackOff, ErrImagePull, CrashLoopBackOff, CreateContainerConfigError, etc.) OR
128163
- If terminated with non-zero exit code OR
@@ -145,6 +180,8 @@ Golang standard layout with clear separation of concerns:
145180
- Dynamic tracker task building for readiness/presence.
146181
- CRD condition mapping, resource classification, timeouts.
147182
- Pod log selector/filtering logic.
183+
- `internal/helm/`
184+
- Helpers to locate and decode Helm v3 release Secrets and extract the rendered manifest used by `kubetracker helm`.
148185
- `pkg/printer/`
149186
- Progress/events/log tables (inspired by nelm’s printer).
150187
- Adjusted to suppress healthy pod logs; render only failure logs.
@@ -159,17 +196,19 @@ This separation keeps the CLI thin and the tracking logic testable and reusable.
159196
- CRD readiness via common conditions + custom mapping flag; built-in defaults for common CRDs.
160197
- Progress/events; logs only for failures; pod status enrichment; READY banner on success.
161198
- Failure grace period for transient errors on builtin trackers; exit-on-first-fail support.
199+
- Helm release tracking (`kubetracker helm`) to read and decode Helm v3 Secrets and track rendered manifests.
162200
- v0.1: Better CRD support
163201
- More per-kind defaults (ExternalSecret, KafkaTopic, PrometheusRule, etc.) and improved heuristics.
164202
- v0.2: Quality-of-life
165203
- Structured JSON output mode for CI consumption.
166-
- --apply flag (optional) to apply manifests inline before tracking.
204+
- `--apply` flag (optional) to apply manifests inline before tracking.
167205
- Namespace discovery from manifests when not provided.
168206

169207
## Best practices and notes
170208

171209
- Run kubetracker alongside your deploy step (kubectl/helm). If you must serialize, consider `--apply` in a future version.
172-
- Keep CRD readiness explicit via `--crd-condition` whenever your controller doesn’t expose a standard “Ready=True”.
210+
- For Helm releases, prefer `kubetracker helm <ns>/<name>` when you want in-cluster rendered manifests to be tracked, or pipe `helm template` to `kubetracker track` if you render locally.
211+
- Keep CRD readiness explicit via `--crd-condition` whenever your controller doesn’t expose a standard `Ready=True`.
173212
- If your CI needs machine readable output, prefer the future JSON mode. For now, you can grep by headers and statuses.
174213

175214
## License

0 commit comments

Comments
 (0)