Repository navigation
feat(sync): preserve not-ready clusters in local kubeconfig - #87
Conversation
Previously, clusters whose Ready condition was False were silently removed from the local kubeconfig on the next sync. This meant a transient controller failure (e.g. missing secret key during a Greenhouse upgrade) would cut off access to the cluster, making it impossible to reach and investigate the issue. This change keeps not-ready entries intact in the local kubeconfig: - notReady clusters that already exist locally are preserved via stub entries injected into the server-side config before the stale-cleanup pass in mergeKubeconfig. The stubs prevent deletion without touching the local entry's content. - A new --include-not-ready flag opts into fully merging not-ready cluster spec data, useful when the controller is temporarily degraded but the CRD spec is known-good (e.g. during a Greenhouse rollout). Signed-off-by: onuryilmaz <onur.yilmaz@sap.com>
There was a problem hiding this comment.
🟡 Changes recommended
The sync logic can abort on prefixed references, create dangling references, and delete managed entries when resource and context names differ.
6 open issues
Match stubs by spec context names, not resource names · New Strip managed prefixes from stub context references · New Read include-not-ready from Viper · New Allow include-not-ready when no resources are ready · New Exclude merged resources from skipped result reporting · New Skip unmanaged contexts when copying stubs · New
What changed in this PR
This PR aims to preserve local Kubernetes access during transient Greenhouse readiness failures by keeping existing kubeconfig entries for not-ready clusters.
Changes:
- Adds local-entry stubs intended to prevent stale cleanup from deleting not-ready clusters.
- Introduces
--include-not-readyto opt into merging their spec data. - Adds tests for stub creation, unknown-cluster handling, and not-ready spec conversion.
| File | Description |
|---|---|
cmd/sync.go |
Adds preservation logic, the opt-in flag, and updated command help. |
cmd/sync_test.go |
Adds tests for preservation stubs and not-ready spec merging. |
Review effort: Balanced
Six issues identified in PR review: - Match stubs by spec context names (not CKC resource name) so clusters whose context name differs from the resource name (e.g. e2e "demo"/ "ctx1") are correctly protected from stale cleanup. - Strip managed prefix from stub context references to prevent double-prefixed names (cloudctl:cloudctl:...) when mergeIdenticalUsers is disabled or when the merger re-applies the prefix. - Read includeNotReady from Viper so CLOUDCTL_INCLUDE_NOT_READY env var and config-file values are honoured, consistent with all other flags. - Allow --include-not-ready to bypass the len(ready)==0 early return; previously the flag had no effect when every cluster was not-ready, which is the primary motivation for the flag. - Pass the actual merge/skip sets to result builders so clusters merged via --include-not-ready are reported as synced, not skipped. - Skip unmanaged contexts in injectNotReadyStubs to avoid accidentally converting a manually-created entry into a managed one. Signed-off-by: onuryilmaz <onur.yilmaz@sap.com>
Signed-off-by: onuryilmaz <onur.yilmaz@sap.com>
There was a problem hiding this comment.
🟡 Changes recommended
Not-ready resource handling can delete existing kubeconfig entries or alter preserved contexts’ effective identities, while the regression test does not exercise the production decision.
3 open issues
6 resolved since last review
Review effort: Balanced
- Bulgu 1: notReady entries with empty spec are kept on the preservation path even with --include-not-ready; previously they would be merged with no incoming data, causing their existing local entries to be deleted. Introduces hasSpecData() helper and filters the merged/skipped split. - Bulgu 2: stub authinfo entries are no longer added to serverConfig to avoid mergeKubeconfig's deduplication pass assigning a new hash-derived managed name and redirecting the preserved context to a different identity. injectNotReadyStubs now returns a preSeed map (server-side name → local managed name) that is pre-populated into authInfoMap before merge. The no-merge mode cleanup path also honours the pre-seed map so it does not delete protected managed authinfos. - Bulgu 3: TestIncludeNotReady_BypassesEarlyReturnWhenAllNotReady now calls the production shouldSkipMerge() helper (extracted from runSync) instead of evaluating a copied expression, so it would catch a revert. Signed-off-by: onuryilmaz <onur.yilmaz@sap.com>
There was a problem hiding this comment.
🟡 Changes recommended
With --merge-identical-users=false, context resolution ignores pre-seeded user mappings and can rewrite a reused unmanaged user reference to a nonexistent user, breaking cluster access.
1 open issue
3 resolved since last review
Review effort: Balanced
When --merge-identical-users=false, context merging and stale-context validation were ignoring preSeedAuthInfoMap and falling back to managedNameFunc, which would rewrite a stub context's authinfo reference to cloudctl:<name> even though that entry does not exist in localConfig, breaking cluster access. Both the context-merge path (lines 775-776) and the stale-context validation path (lines 872-873) now check preSeedAuthInfoMap first and use the pre-seeded local managed name when present. Signed-off-by: onuryilmaz <onur.yilmaz@sap.com>


Summary
Ready=Falsecondition (e.g. during a Greenhouse controller upgrade or a missing secret key) previously caused cloudctl to remove the local entry, making the cluster unreachable.--include-not-readyflag fully merges not-ready cluster spec data, for cases where the CRD spec is known-good but the controller is temporarily degraded.Motivation
During the Greenhouse
v0.18.0 → v0.19.0rollout (PR cloudoperators/greenhouse#2245), all 208ClusterKubeconfigresources in thescinamespace reportReady=Falsewith reasonKubeconfigMissing. Theirspec.kubeconfigis fully populated. Runningcloudctl syncin this window would delete all 208 entries from users' local kubeconfigs, cutting off cluster access at the worst possible time.Behaviour change
Ready=False, exists in local kubeconfigReady=False, not yet in local kubeconfig--include-not-readyflagReady=FalseTest plan
TestInjectNotReadyStubs_PreservesLocalEntries— stub injection keeps existing local entriesTestInjectNotReadyStubs_SkipsUnknownClusters— no stubs for clusters not yet in local configTestIncludeNotReady_MergesSpecData—--include-not-readymerges spec data from not-ready CRDscmdtests pass