cluster-inventory: Add ClusterProfile discovery for in-cluster mode#4577
cluster-inventory: Add ClusterProfile discovery for in-cluster mode#4577kahirokunn wants to merge 14 commits into
Conversation
7244999 to
aecb41c
Compare
aecb41c to
9a2ca17
Compare
e369623 to
595dfb8
Compare
595dfb8 to
54c6f02
Compare
54c6f02 to
fde608e
Compare
593ca6b to
1cdd0cd
Compare
1cdd0cd to
4b70bff
Compare
|
@illume Could you please review this again when you have a moment? |
|
@illume Hi🥺 |
|
Hey hey. Very cool! Looks like very excellent work. Yes, sorry, I will have a look in the next days. Have to learn what a Cluster Inventory API is too. A quick browse I see it uses CRDs. Can you please add a note to the PR description about why it should be in headlamp rather than in a plugin? It looks like it uses a backend component, and it's an official k8s API? (two good reasons to include it in headlamp rather than in a plugin). |
|
Thank you for taking a look! I have added "Why This Belongs in Headlamp" to the body of the PR. |
|
/retest |
|
I pushed again to re-run GHA. |
illume
left a comment
There was a problem hiding this comment.
Thank you for taking a look! I have added "Why This Belongs in Headlamp" to the body of the PR. I have also addressed the points raised in your review and resolved the conflicts.
Thanks for this!!
I left a few notes about some code organisation.
After reading the Cluster Inventory project a bit more:
- It looks like Cluster Inventory is in an alpha/experimental state so far. Because of this I think we need to make sure it's marked that way to headlamp users. When the project gets into a beta stage we can mark it as beta in headlamp. How does that sound?
- Can you please explain in the PR description how headlamp behaves in clusters where cluster inventory is not installed?
- For the new Golang code imported, I haven't reviewed it yet. I need to understand how this affects the threat model for headlamp. (if you can add a note to the PR description, otherwise I will look into it).
|
@illume Hi, Thank you for your review 🙏 could you please review this again? Thank you 🙏 |
|
I rebased with the latest main. |
Summary
This PR adds support for the Cluster Inventory API to automatically discover and register Kubernetes clusters in Headlamp via
ClusterProfileresources, enabling multi-cluster management without manual kubeconfig configuration.Cluster Inventory support in Headlamp is currently alpha/experimental and is disabled by default. It uses the upstream Cluster Inventory
v1alpha1API from thev0.1.xreleases, so fields and behavior may change until that project reaches beta.Why This Belongs in Headlamp
This is implemented in Headlamp core rather than as a Headlamp UI plugin because Cluster Inventory discovery needs backend integration. Headlamp has to watch
ClusterProfileCRDs, build Kubernetes clients from Cluster Inventory access providers, register discovered clusters in the shared kubeconfig context store, and expose those clusters consistently to the frontend and proxy layer.Cluster Inventory API is also a Kubernetes SIG Multicluster API project under
kubernetes-sigs. It is intended to provide a vendor-neutral, standardized interface for multi-cluster discovery and cluster status. Supporting it in core lets Headlamp interoperate with any implementation of that API instead of tying this behavior to one plugin or one vendor-specific integration.Architecture
graph TB subgraph ManagementCluster["🏢 Management Cluster (Hub)"] HL["Headlamp Server<br/>--enable-cluster-inventory"] CP1["ClusterProfile<br/>name: workload-1<br/>ns: default"] CP2["ClusterProfile<br/>name: workload-2<br/>ns: fleet-a"] subgraph ProviderConfig["🔑 Credential Provider"] PF["provider-config.json"] EXEC["Exec Plugin<br/>(credential-plugin.sh)"] PF --> EXEC end HL -- "ClusterProfile informer/watch" --> CP1 HL -- "ClusterProfile informer/watch" --> CP2 HL -. "Root reconcile loop<br/>watcher lifecycle / no-CRD retry" .-> HL HL -- "Fetch credentials" --> PF end subgraph WorkloadCluster1["⚙️ Workload Cluster 1"] API1["kube-apiserver"] RESOURCES1["Pods, Deployments, ..."] end subgraph WorkloadCluster2["⚙️ Workload Cluster 2"] API2["kube-apiserver"] RESOURCES2["Pods, Deployments, ..."] end CP1 -- "status.accessProviders<br/>server + CA" --> API1 CP2 -- "status.accessProviders<br/>server + CA" --> API2 EXEC -- "ExecCredential<br/>(clientCert + clientKey)" --> API1 EXEC -- "ExecCredential<br/>(clientCert + clientKey)" --> API2 style ManagementCluster fill:#1a237e,stroke:#5c6bc0,color:#fff style WorkloadCluster1 fill:#004d40,stroke:#26a69a,color:#fff style WorkloadCluster2 fill:#004d40,stroke:#26a69a,color:#fff style ProviderConfig fill:#4a148c,stroke:#ce93d8,color:#fffRelated Issue
#4708
Changes
ClusterProfileresources (Cluster Inventory API) in both in-cluster and local/desktop modes--cluster-inventory-label-selector, env var, Helmconfig.clusterInventory.labelSelector) to hide matchingClusterProfileresources.Steps to Test
Prerequisites
kind,kubectl,clusterctl,yqinstalled1. Create a Kind management cluster
2. Install CAPI + k0smotron
3. Create a workload cluster
Wait for the control plane and workers:
4. Install ClusterProfile CRD and create a ClusterProfile
5. Create the credential plugin and provider config
Create
credential-plugin.sh:Create
provider-config.json:6. Start Headlamp and verify
Terminal 1:
Terminal 2:
cluster-inventory-store--kind-headlamp-ci-hub--default--workload-1--64f958ab98d6appears in the cluster list with source Cluster Inventoryheadlamp.dev/ignore=trueand verify it disappears when using the default Helm selector or--cluster-inventory-label-selector='!headlamp.dev/ignore'.7. Clean up
Notes for the Reviewer
sigs.k8s.io/cluster-inventory-apias a new Go dependency.v1alpha1/v0.1.xAPI.--cluster-inventory-provider-fileflag is required when Cluster Inventory is enabled.