Repository navigation
fix(status): withhold cluster readiness when CNI pods are unhealthy - #93
canonicalayush wants to merge 6 commits into
Conversation
A node reports Ready as soon as kubelet finds a CNI conflist on disk, which occurs before cilium-agent is serving. Consequently, reports on clusters where Cilium is broken or crash-looping. Extend StatusInterface with CheckClusterReady to verify that CNI workload pods (cilium-operator and cilium agent) are Running and Ready when network is enabled. Gate getClusterStatus readiness on this check and log reason when readiness is withheld. Fixes canonical/k8s-snap#1789 Signed-off-by: Ayush Patra <ayush.patra@canonical.com>
Unit Tests
Integration coverage lives in canonical/k8s-snap#2841. |
Refine the CNI readiness check introduced for canonical/k8s-snap#1789: - Call features.StatusChecks.CheckNetwork directly in getClusterStatus when config.Network.GetEnabled() is true, removing the intermediate CheckClusterReady wrapper method and interface method. - Switch log level to log.Error(err, "network pods are not ready") to match the adjacent DNS check log idiom. - Ensure the network check evaluates independently of prior ready flag state. - Add TestGetClusterStatusNetworkGate in pkg/k8sd/api/cluster_test.go testing cluster status response for ready/missing CNI pods and disabled network. - Add ciliumAgentRunningNotReady subtest in pkg/k8sd/features/cilium/status_test.go. Fixes canonical/k8s-snap#1789 Signed-off-by: Ayush Patra <ayush.patra@canonical.com>
Replaces the smoke-test kube-system assertion, which asserted more than the daemon gate guarantees, with a scoped guard plus a dedicated test that breaks the Cilium operator, the Cilium agent, and the agent's readiness probe and asserts `k8s status` withholds readiness while the node is still Ready. Ref: #1789 Depends-On: canonical/k8sd#93 Signed-off-by: Ayush Patra <ayush.patra@canonical.com>
REVERT BEFORE MERGE, once canonical/k8sd#93 lands on k8sd main. Ref: canonical/k8sd#93 Signed-off-by: Ayush Patra <ayush.patra@canonical.com>
Replaces the smoke-test kube-system assertion, which asserted more than the daemon gate guarantees, with a scoped guard plus a dedicated test that breaks the Cilium operator, the Cilium agent, and the agent's readiness probe and asserts `k8s status` withholds readiness while the node is still Ready. Ref: #1789 Depends-On: canonical/k8sd#93 Signed-off-by: Ayush Patra <ayush.patra@canonical.com>
REVERT BEFORE MERGE, once canonical/k8sd#93 lands on k8sd main. Ref: canonical/k8sd#93 Signed-off-by: Ayush Patra <ayush.patra@canonical.com>
louiseschmidtgen
left a comment
There was a problem hiding this comment.
Thanks for the great work on this! You're already showing great understanding of our cilium feature, its wiring and the associated tests thoroughly test the change.
A few comments before we go for the merge:
Extract the readiness logic from getClusterStatus into Endpoints.clusterIsReady and test it directly as an internal test, which drops the testenv and registered handler machinery. Returns (bool, error) so a HasReadyNodes failure still yields an InternalError. Also drops the unused HelmClient from the cilium status test. Ref: canonical/k8s-snap#1789 Signed-off-by: Ayush Patra <ayush.patra@canonical.com>
golangci-lint's godot rule requires declaration comments to end in a period. Signed-off-by: Ayush Patra <ayush.patra@canonical.com>
louiseschmidtgen
left a comment
There was a problem hiding this comment.
This looks good, nice work on cleaning up those tests.
One little nit then I'll review your k8s-snap changes once ready and we can merge this PR :)
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved issues were identified, and all readiness assessments approve the changes.
Review effort: Lite
Findings: None
What changed in this PR
Adds CNI readiness checks so cluster status remains unready until enabled Cilium components are running and ready.
Changes:
- Centralizes node, DNS, and network readiness checks.
- Preserves readiness errors from node checks.
- Adds regression tests for missing and unready Cilium pods.
| File | Description |
|---|---|
pkg/k8sd/features/cilium/status_test.go |
Tests a running but unready Cilium agent. |
pkg/k8sd/api/cluster.go |
Implements combined cluster readiness gates. |
pkg/k8sd/api/cluster_test.go |
Tests enabled and disabled network readiness scenarios. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…usterStatus Be consistent within getClusterStatus by using the log-wrapped ctx everywhere instead of mixing r.Context() calls. This ensures all database operations include the 'endpoint' logging field. Note: r.Context() is preserved inside the Transaction lambda on line 52 where ctx is shadowed by the lambda parameter.
797fbff to
f6bce00
Compare
louiseschmidtgen
left a comment
There was a problem hiding this comment.
The implementation and the test LGTM. Leaving the final approval of this behaviour change to @canonical-berkayoz.
@canonicalayush please add a note in k8s status and in our alternative CNI tutorial on this change. That can be in this PR or in a separate one- I leave that up to you.
…d readiness in case network feature is enabled.
|
Hi @louiseschmidtgen, I have added a small note on k8s status here. Please let me know if this looks good, or if it should be more verbose. I will open a new PR for the alternative CNI tutorial and link it to this PR. |
bschimke95
left a comment
There was a problem hiding this comment.
Thanks @canonicalayush
The code looks good and implements the agreed behavior but please trim your PR descriptions and comments down for this AI slop to something a human can/will read. No human reviewer cares about how many unittests your agent ran. :)
Problem
getClusterStatuswithholdsReady=truewhenever the CNI workload pods, the Cilium agent and the Cilium operator, are missing or not in aRunningplusReady=Truestate.k8s status --wait-readyreportscluster status: readywhile Cilium pods are crash-looping or have not been created yet.Changes
pkg/k8sd/api/cluster.goconfig.Network.GetEnabled(), callfeatures.StatusChecks.CheckNetworkand withhold readiness on error, mirroring the existing DNS gate.Endpoints.clusterIsReady, coveringHasReadyNodesplus the dns and network gates.config.DNS.GetEnabled()so the dns check reads the same way as the network one.pkg/k8sd/api/cluster_test.go, new fileTestClusterIsReadyNetworkGatecovers three cases: network enabled with Cilium ready, network enabled with Cilium missing, and network disabled with Cilium missing. The last one confirms the disabled path short-circuits rather than passing by accident.pkg/k8sd/features/cilium/status_test.gociliumAgentRunningNotReadycase toTestCheckNetwork, where the agent pod is present andRunningbutReady=False.Integration coverage lives in canonical/k8s-snap#2841.
Fixes canonical/k8s-snap#1789
Checklist
k8s-snap-api