Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Set ClusterctlMoveHierarchyLabel on HelmChartProxy in CRD definition #110

Merged
merged 1 commit into from
Oct 16, 2023

Conversation

Jont828
Copy link
Contributor

@Jont828 Jont828 commented Aug 17, 2023

What this PR does / why we need it: Have the HelmChartProxy controller set the ClusterctlMoveHierarchyLabel on HelmChartProxies so that it will be discovered by clusterctl move.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #103

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 17, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Jont828

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 17, 2023
if helmChartProxy.Labels == nil {
helmChartProxy.Labels = make(map[string]string)
}
helmChartProxy.Labels[clusterctl.ClusterctlMoveHierarchyLabel] = "true"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative approach would be to have the user set the label in the YAML like here in CAPZ. That would allow users to opt-out, but the downside would be that users would have to remember to do that every time.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we decide this approach is better we could also change the CAPZ AzureClusterIdentity approach

@Jont828
Copy link
Contributor Author

Jont828 commented Sep 6, 2023

@CecileRobertMichon @jackfrancis TL;DR HelmChartProxies need the clusterctl.ClusterctlMoveHierarchyLabel label attached in order for clusterctl move to work properly. Do you think it's appropriate to have the controller always add it, or instead leave it up to the user to opt-in?

@CecileRobertMichon
Copy link

@fabriziopandini do you have thoughts on this?

IMO if it can always be set so the user doesn't have to worry about it that's better, but what happens if the user is using the same HelmChartProxy across several clusters and moves 1 or some of the clusters?

note: if the goal is to set the label to every HelmChartProxy, the book indicates this can be done on the CRD itself so it applies to all HelmChartProxies instead of labelling each object.

Note. clusterctl.cluster.x-k8s.io/move and clusterctl.cluster.x-k8s.io/move-hierarchy labels could be applied to single objects or at the CRD level (the label applies to all the objects).

https://cluster-api.sigs.k8s.io/clusterctl/provider-contract.html?highlight=move-hier#move

@fabriziopandini
Copy link
Member

@fabriziopandini do you have thoughts on this?

I will suggest adding the label on the CRD definition, so it is done once and for all (no need to add on single CRs, reconcile it).

@Jont828
Copy link
Contributor Author

Jont828 commented Sep 7, 2023

How would we set a label on the CRD level? Would it be a kubebuilder tag?

@Jont828
Copy link
Contributor Author

Jont828 commented Sep 7, 2023

@fabriziopandini I tried adding the kubebuilder label based on the docs, but it doesn't seem to be working. Are there any examples of this being used?

// +kubebuilder:metadata:labels=["clusterctl.cluster.x-k8s.io/move-hierarchy: true"]

@fabriziopandini
Copy link
Member

How would we set a label on the CRD level? Would it be a kubebuilder tag?

You can add it by creating a kustomize patch similar to this one.
Make sure that [name]( name: helmchartproxies.addons.cluster.x-k8s.io) is the name of the CRD you want to patch, replace annotations with labels: and the label you want to add.

Make sure to add your next patch to the kustomization file

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 11, 2023
@Jont828
Copy link
Contributor Author

Jont828 commented Oct 11, 2023

@fabriziopandini I've followed your suggestion and added the label to the CRD definition such that I have the following output. However, the label doesn't appear on the resources when I run kubectl get and they do not appear in the output of clusterctl move. Am I doing something wrong?

$ kc describe crd helmchartproxies.addons.cluster.x-k8s.io
Name:         helmchartproxies.addons.cluster.x-k8s.io
Namespace:
Labels:       cluster.x-k8s.io/provider=helm
              clusterctl.cluster.x-k8s.io/move-hierarchy=true
Annotations:  cert-manager.io/inject-ca-from: caaph-system/caaph-serving-cert
              controller-gen.kubebuilder.io/version: v0.10.0
API Version:  apiextensions.k8s.io/v1
...
apiVersion: addons.cluster.x-k8s.io/v1alpha1
kind: HelmChartProxy
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"addons.cluster.x-k8s.io/v1alpha1","kind":"HelmChartProxy","metadata":{"annotations":{},"name":"calico-cni","namespace":"default"},"spec":{"chartName":"tigera-operator","clusterSelector":{"matchLabels":{}},"namespace":"kube-system","releaseName":"calico","repoURL":"https://docs.tigera.io/calico/charts","valuesTemplate":"installation:\n  cni:\n    type: Calico\n    ipam:\n      type: HostLocal\n  calicoNetwork:\n    bgp: Disabled\n    mtu: 1350\n    ipPools:{{range $i, $cidr := .Cluster.spec.clusterNetwork.pods.cidrBlocks }}\n    - cidr: {{ $cidr }}\n      encapsulation: None\n      natOutgoing: Enabled\n      nodeSelector: all(){{end}}\n"}}
  creationTimestamp: "2023-10-11T01:03:12Z"
  finalizers:
  - helmchartproxy.addons.cluster.x-k8s.io
  generation: 1
  name: calico-cni
  namespace: default
  resourceVersion: "1493"
  uid: 335bc313-c6df-4d04-b8f8-05cf70a04923

@Jont828 Jont828 changed the title 🌱 Set ClusterctlMoveHierarchyLabel on HelmChartProxy with controller 🌱 Set ClusterctlMoveHierarchyLabel on HelmChartProxy in CRD definition Oct 11, 2023
@Jont828
Copy link
Contributor Author

Jont828 commented Oct 11, 2023

@CecileRobertMichon @fabriziopandini I think I figured it out! The CRD label will only show up in the definition when it is installed through make release-manifests and not make generate-manifests, and it will only work with clusterctl move if the CRDs are installed through clusterctl init --addon helm.

Since that pulls from the GitHub releases, we will only know for sure that it works once this is merged and we cut a new CAAPH release. However, I tested that addon-components.yaml is produced to include the label, and that clusterctl move works once we manually edit the HelmChartProxy CRD definition to include the label, so I'm confident that this works and we can go ahead for review/merge!

@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment needs to be updated

@CecileRobertMichon
Copy link

one nit, otherwise lgtm

Copy link

@CecileRobertMichon CecileRobertMichon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 16, 2023
@k8s-ci-robot k8s-ci-robot merged commit 2832b10 into kubernetes-sigs:main Oct 16, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add support for "clusterctl move"
4 participants