Skip to content

Commit 696e7b7

Browse files
committed
chore(hack): add CRD vs registry comparison tool and update greenhouse dependency
- Add hack/compare_crd_vs_registry.go to compare ClusterKubeconfig CRDs against kubectl-registry API; detects corrupt PEM (invalid PEM sentinel) instead of showing (empty) for bad CA bytes - Add hack/compare_kubeconfigs.go for local kubeconfig comparison - Add hack/README.md documenting the kubeconfig provider architecture - Add .claude/commands/compare-crd-registry.md skill command - Update greenhouse dependency from v0.8.0 to github.com/cloudoperators/greenhouse/api v0.19.0 (monorepo split; v0.14.0+ moved API types to separate module) Signed-off-by: onuryilmaz <onur.yilmaz@sap.com>
1 parent 5be3b75 commit 696e7b7

8 files changed

Lines changed: 1158 additions & 122 deletions

File tree

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# compare-crd-registry
2+
3+
Compare `ClusterKubeconfig` CRDs in the Greenhouse cluster against the kubectl-registry API and report what is **missing** and what is **different**.
4+
5+
## Context
6+
7+
There are two independent kubeconfig providers serving the same clusters:
8+
9+
- **kubectl-registry** (current): `kubeconfig-generator` reads Cluster + Secret resources, uploads kubeconfigs to Swift; `kubectl-registry` serves them as a JSON API. The current CLI tool `u8s` consumes this.
10+
- **ClusterKubeconfig CRDs** (future): The ClusterKubeconfig controller (part of Greenhouse) writes `ClusterKubeconfig` resources. `cloudctl sync` consumes these.
11+
12+
The team is migrating from `u8s` to `cloudctl`. During the transition both providers must serve equivalent data. This command is the primary tool for detecting divergence.
13+
14+
**Key architectural differences that explain common diffs:**
15+
16+
- **CA drift (registry stale)**: kubeconfig-generator only watches `Cluster` objects, not Secrets. Gardener CA rotations are only picked up after a 10-hour resync, or when the `caCrt` in the cluster's Helm values file is updated via PR and secrets-injector re-injects the new value.
17+
- **CA drift (CRD stale)**: The ClusterKubeconfig controller watches Secrets directly, so it picks up CA rotations automatically — if the CRD CA is older, check that secrets-injector has rolled out the new value.
18+
- **OIDC client-id/secret drift**: The two generators are configured with different Secret references for OIDC credentials. A credential rotation on one side will not automatically propagate to the other. If the same cluster appears with different client-ids, check which org's Secret each generator is reading.
19+
- **Coverage gap**: The registry currently has ~579 clusters; CRDs cover ~208. Clusters only in the registry were onboarded before the ClusterKubeconfig controller existed and need CRDs created before cloudctl migration.
20+
21+
For full architecture details see `hack/README.md`.
22+
23+
## Usage
24+
25+
```
26+
/compare-crd-registry [--registry <url>] [--show-matches]
27+
```
28+
29+
**Defaults (always both environments):**
30+
- `--context` → `greenhouse-p-eu-de-1,greenhouse-playground`
31+
- `--namespace` → `sci,sci-demo`
32+
- `--registry` → `https://kubectl-registry-replica.eu-nl-1.cloud.sap/api/latest`
33+
- `--show-matches` → omitted (only show differences)
34+
35+
**Known environments:**
36+
- Production: `greenhouse-p-eu-de-1 / sci`
37+
- Playground: `greenhouse-playground / sci-demo` (same registry, same Swift bucket)
38+
39+
## What this command does
40+
41+
1. **Run the comparison tool** — execute `hack/compare_crd_vs_registry.go` with any user-supplied flags and capture the full output.
42+
43+
2. **Parse the output** — extract three categories:
44+
- `[DIFF]` clusters — present in both but with field-level differences (server URL, CA cert, OIDC config).
45+
- `[ONLY IN CRD]` clusters — exist as a CRD in Greenhouse but are **missing** from the registry.
46+
- `Only reg` summary count — clusters present in the registry but **missing** as a CRD in Greenhouse.
47+
- `[MATCH]` clusters — only shown when `--show-matches` is passed.
48+
49+
3. **Present a structured report** with:
50+
- Total counts (registry clusters, CRD clusters, matched, different, only-CRD, only-registry).
51+
- Table of clusters with differences, showing each changed field with registry vs CRD values.
52+
- List of clusters only in the CRD (not in the registry).
53+
- List of clusters only in the registry (not in the CRD).
54+
55+
4. **Classify each diff** using the architecture context above — say which side is likely stale and why, not just that the values differ.
56+
57+
---
58+
59+
## Steps in detail
60+
61+
### 1 — Run the tool
62+
63+
Always pass both environments unless the user explicitly restricts to one:
64+
65+
```bash
66+
go run hack/compare_crd_vs_registry.go \
67+
--context greenhouse-p-eu-de-1,greenhouse-playground \
68+
--namespace sci,sci-demo \
69+
--registry https://kubectl-registry-replica.eu-nl-1.cloud.sap/api/latest \
70+
[--show-matches]
71+
```
72+
73+
If the user passed extra flags to the skill invocation, forward them verbatim. Always run from the repository root so that Go module resolution works.
74+
75+
If the command fails (e.g. cannot reach the cluster or registry), report the error clearly and stop.
76+
77+
### 2 — Get registry-only cluster names (if count > 0)
78+
79+
The base tool suppresses registry-only names in its output. Note in the report that the tool must be re-run with `--show-matches` to see names. Do not silently skip this gap.
80+
81+
### 3 — Present the report
82+
83+
```
84+
## CRD vs Registry Comparison
85+
86+
### Totals
87+
Registry clusters : <N>
88+
CRD clusters : <N>
89+
Matched : <N>
90+
Different : <N>
91+
Only in CRD : <N>
92+
Only in registry : <N>
93+
94+
### Clusters with differences
95+
| Cluster | Field | Registry value | CRD value | Likely cause |
96+
|---------|-------|----------------|-----------|--------------|
97+
| <name> | ca | CN=... exp=... | CN=... exp=... | registry stale — CA rotated, kubeconfig-generator 10h window |
98+
...
99+
100+
### Only in CRD (missing from registry)
101+
- <cluster-name>
102+
103+
### Only in registry (missing from CRD)
104+
- <N> clusters — re-run with --show-matches to see names
105+
106+
### Summary / Action items
107+
- <bullet per actionable finding>
108+
```
109+
110+
### 4 — Actionable guidance per diff type
111+
112+
- **CA mismatch, registry older**: kubeconfig-generator has not yet reconciled after a Gardener CA rotation. Check if `caCrt` in the cluster's Helm values file (e.g. `p-eu-de-1/sci/.../values.yaml`) matches the new CA. If not, open a PR to update it. If values.yaml is already correct, the 10-hour resync will fix it, or annotate the Cluster object with `kubeconfig-generator/force-reconcile: <timestamp>` to trigger immediately (blocked by `restricted-su2` on some clusters).
113+
- **CA mismatch, CRD older**: secrets-injector may not yet have rolled out. Check the cluster's Secret `cloud.sap/injected-refs` annotation for the current CA value.
114+
- **OIDC client-id/secret mismatch**: Identify which Secret each generator reads for this cluster. Registry side: check kubeconfig-generator config for the org. CRD side: check `Organization.spec.authentication.oidc.clientIDReference` or the `greenhouse.sap/oidc-override` annotation on the cluster's Secret.
115+
- **Only in CRD**: Greenhouse manages a cluster that the registry doesn't know about — kubeconfig-generator may not be configured for it, or the Swift upload failed.
116+
- **Only in registry**: This cluster will not appear in `cloudctl sync` output. A `ClusterKubeconfig` resource needs to exist before migration. Coverage gap is expected (~371 clusters as of Nov 2026); track progress toward closing it.

‎go.mod‎

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
module github.com/cloudoperators/cloudctl
22

3-
go 1.25.0
3+
go 1.26.0
44

55
require (
66
github.com/adrg/xdg v0.5.3
77
github.com/charmbracelet/bubbles v1.0.0
88
github.com/charmbracelet/bubbletea v1.3.10
99
github.com/charmbracelet/lipgloss v1.1.0
10-
github.com/cloudoperators/greenhouse v0.8.0
10+
github.com/cloudoperators/greenhouse/api v0.19.0
1111
github.com/dustin/go-humanize v1.0.1
1212
github.com/minio/selfupdate v0.6.0
13-
github.com/onsi/gomega v1.38.3
13+
github.com/onsi/gomega v1.42.1
1414
github.com/spf13/cobra v1.10.2
1515
github.com/spf13/pflag v1.0.10
1616
github.com/spf13/viper v1.21.0
17-
golang.org/x/mod v0.38.0
18-
golang.org/x/term v0.43.0
19-
k8s.io/apimachinery v0.35.0
20-
k8s.io/client-go v0.35.0
17+
golang.org/x/mod v0.40.0
18+
golang.org/x/term v0.45.0
19+
k8s.io/apimachinery v0.36.0
20+
k8s.io/client-go v0.36.0
2121
sigs.k8s.io/controller-runtime v0.22.4
2222
sigs.k8s.io/yaml v1.6.0
2323
)
@@ -49,9 +49,6 @@ require (
4949
github.com/emicklei/go-restful/v3 v3.13.0 // indirect
5050
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
5151
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
52-
github.com/fluxcd/pkg/apis/acl v0.9.0 // indirect
53-
github.com/fluxcd/pkg/apis/meta v1.24.0 // indirect
54-
github.com/fluxcd/source-controller/api v1.7.4 // indirect
5552
github.com/fsnotify/fsnotify v1.9.0 // indirect
5653
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
5754
github.com/go-logr/logr v1.4.3 // indirect
@@ -85,10 +82,7 @@ require (
8582
github.com/muesli/cancelreader v0.2.2 // indirect
8683
github.com/muesli/termenv v0.16.0 // indirect
8784
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
88-
github.com/onsi/ginkgo/v2 v2.27.3 // indirect
8985
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
90-
github.com/prometheus/common v0.67.3 // indirect
91-
github.com/prometheus/procfs v0.19.2 // indirect
9286
github.com/rivo/uniseg v0.4.7 // indirect
9387
github.com/sagikazarmark/locafero v0.12.0 // indirect
9488
github.com/spf13/afero v1.15.0 // indirect
@@ -98,22 +92,21 @@ require (
9892
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
9993
go.yaml.in/yaml/v2 v2.4.3 // indirect
10094
go.yaml.in/yaml/v3 v3.0.4 // indirect
101-
golang.org/x/crypto v0.52.0 // indirect
102-
golang.org/x/net v0.55.0 // indirect
95+
golang.org/x/crypto v0.55.0 // indirect
96+
golang.org/x/net v0.58.0 // indirect
10397
golang.org/x/oauth2 v0.34.0 // indirect
104-
golang.org/x/sys v0.45.0 // indirect
105-
golang.org/x/text v0.37.0 // indirect
98+
golang.org/x/sys v0.47.0 // indirect
99+
golang.org/x/text v0.41.0 // indirect
106100
golang.org/x/time v0.14.0 // indirect
107-
gomodules.xyz/jsonpatch/v2 v2.5.0 // indirect
108-
google.golang.org/protobuf v1.36.11 // indirect
101+
google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af // indirect
109102
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
110103
gopkg.in/inf.v0 v0.9.1 // indirect
111-
k8s.io/api v0.35.0 // indirect
112-
k8s.io/apiextensions-apiserver v0.35.0 // indirect
113-
k8s.io/klog/v2 v2.130.1 // indirect
114-
k8s.io/kube-openapi v0.0.0-20251125145642-4e65d59e963e // indirect
115-
k8s.io/utils v0.0.0-20260106112306-0fe9cd71b2f8 // indirect
104+
k8s.io/api v0.36.0 // indirect
105+
k8s.io/apiextensions-apiserver v0.36.0 // indirect
106+
k8s.io/klog/v2 v2.140.0 // indirect
107+
k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a // indirect
108+
k8s.io/utils v0.0.0-20260319190234-28399d86e0b5 // indirect
116109
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
117110
sigs.k8s.io/randfill v1.0.0 // indirect
118-
sigs.k8s.io/structured-merge-diff/v6 v6.3.1 // indirect
111+
sigs.k8s.io/structured-merge-diff/v6 v6.3.2 // indirect
119112
)

0 commit comments

Comments
 (0)