|
| 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. |
0 commit comments