Skip to content

Add spec.kubeconfig.metadata to allow setting annotations/labels on generated kubeconfig secrets #13628

@jonathanrainer

Description

@jonathanrainer

What would you like to be added (User Story)?

As a user I would like to be able to set custom annotations and labels on the secrets that are created that hold the KubeConfig data. I could then use these custom annotations to allow Cluster API to integrate better with tools like reflector (https://github.com/emberstack/kubernetes-reflector) which require you to annotate source secrets.

Detailed Description

CAPI creates a kubeconfig Secret for each managed cluster but provides no way to set
custom annotations or labels on that secret. Tools that gate on annotations (e.g.
Reflector, which requires reflector.v1.k8s.emberstack.com/reflection-allowed: "true")
cannot be used without some kind of workaround, like a CronJob that continuously re-patches the annotation
after CAPI reconciliation removes it.

This issue proposes adding spec.kubeconfig.metadata.{annotations,labels} to ClusterSpec
so that CAPI sets and maintains these values on the generated kubeconfig secret.

Use case

Reflector (https://github.com/emberstack/kubernetes-reflector) mirrors Kubernetes secrets
across namespaces. It requires the source secret to carry
reflector.v1.k8s.emberstack.com/reflection-allowed: "true". Any tool with similar
annotation-based admission gating has the same problem.

Prior art

This was previously proposed in #9651 and closed for lack of a concrete use case.

Proposed API

apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
spec:
  kubeconfig:
    metadata:
      annotations:
        reflector.v1.k8s.emberstack.com/reflection-allowed: "true"

Anything else you would like to add?

Already have a PR in mind and will submit that shortly!

Label(s) to be applied

/kind feature
/area cluster

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/clusterIssues or PRs related to clusterskind/featureCategorizes issue or PR as related to a new feature.needs-priorityIndicates an issue lacks a `priority/foo` label and requires one.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions