Skip to content

Adds RKE2ControlPlane labels to Machines #611

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

Merged
merged 3 commits into from
Apr 2, 2025
Merged

Conversation

dharmit
Copy link
Contributor

@dharmit dharmit commented Mar 24, 2025

What this PR does / why we need it:
$subject. For details, refer #517.

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 #517

Special notes for your reviewer:

  1. This PR has two commits. First one modifies the function signature and requires a change at all places it's called. Second one uses a for loop to make changes only at the place where I think it's reuired. Please suggest which commit to keep of the two.

  2. I have tested this using the following manifest:

    manifest
    apiVersion: v1
    kind: Namespace
    metadata:
      name: example-docker
    ---
    apiVersion: cluster.x-k8s.io/v1beta1
    kind: Cluster
    metadata:
      name: rke2-docker
      namespace: example-docker
    spec:
      clusterNetwork:
        pods:
          cidrBlocks:
          - 10.45.0.0/16
        serviceDomain: cluster.local
        services:
          cidrBlocks:
          - 10.46.0.0/16
      controlPlaneRef:
        apiVersion: controlplane.cluster.x-k8s.io/v1beta1
        kind: RKE2ControlPlane
        name: rke2-docker-control-plane
      infrastructureRef:
        apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
        kind: DockerCluster
        name: rke2-docker
    ---
    apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
    kind: DockerCluster
    metadata:
      name: rke2-docker
      namespace: example-docker
    spec:
      loadBalancer:
        customHAProxyConfigTemplateRef:
          name: rke2-docker-lb-config
    ---
    apiVersion: controlplane.cluster.x-k8s.io/v1beta1
    kind: RKE2ControlPlane
    metadata:
      name: rke2-docker-control-plane
      namespace: example-docker
      labels:
        key: value
    spec:
      agentConfig: {}
      machineTemplate:
        infrastructureRef:
          apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
          kind: DockerMachineTemplate
          name: controlplane
        nodeDrainTimeout: 2m
      registrationMethod: control-plane-endpoint
      replicas: 1
      rolloutStrategy:
        rollingUpdate:
          maxSurge: 0
        type: RollingUpdate
      serverConfig:
        disableComponents:
          kubernetesComponents:
          - cloudController
        kubeAPIServer:
          extraArgs:
          - --anonymous-auth=true
      version: v1.30.2+rke2r1
    ---
    apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
    kind: DockerMachineTemplate
    metadata:
      name: controlplane
      namespace: example-docker
    spec:
      template:
        spec:
          bootstrapTimeout: 15m
          customImage: kindest/node:v1.30.0
    ---
    apiVersion: cluster.x-k8s.io/v1beta1
    kind: MachineDeployment
    metadata:
      name: worker-md-0
      namespace: example-docker
    spec:
      clusterName: rke2-docker
      replicas: 1
      selector:
        matchLabels:
          cluster.x-k8s.io/cluster-name: rke2-docker
      template:
        spec:
          bootstrap:
            configRef:
              apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
              kind: RKE2ConfigTemplate
              name: rke2-docker-agent
              namespace: example-docker
          clusterName: rke2-docker
          infrastructureRef:
            apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
            kind: DockerMachineTemplate
            name: worker
            namespace: example-docker
          version: v1.30.2+rke2r1
    ---
    apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
    kind: DockerMachineTemplate
    metadata:
      name: worker
      namespace: example-docker
    spec:
      template:
        spec:
          bootstrapTimeout: 15m
          customImage: kindest/node:v1.30.0
    ---
    apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
    kind: RKE2ConfigTemplate
    metadata:
      name: rke2-docker-agent
      namespace: example-docker
    spec:
      template:
        spec:
          agentConfig: {}
    ---
    apiVersion: v1
    data:
      value: |-
        # generated by kind
        global
          log /dev/log local0
          log /dev/log local1 notice
          daemon
          # limit memory usage to approximately 18 MB
          # (see https://github.com/kubernetes-sigs/kind/pull/3115)
          maxconn 100000
    
        resolvers docker
          nameserver dns 127.0.0.11:53
    
        defaults
          log global
          mode tcp
          option dontlognull
          # TODO: tune these
          timeout connect 5000
          timeout client 50000
          timeout server 50000
          # allow to boot despite dns don't resolve backends
          default-server init-addr none
    
        frontend stats
          mode http
          bind *:8404
          stats enable
          stats uri /stats
          stats refresh 1s
          stats admin if TRUE
    
        frontend control-plane
          bind *:{{ .FrontendControlPlanePort }}
          {{ if .IPv6 -}}
          bind :::{{ .FrontendControlPlanePort }};
          {{- end }}
          default_backend kube-apiservers
    
        backend kube-apiservers
          option httpchk GET /healthz
    
          {{range $server, $backend := .BackendServers}}
          server {{ $server }} {{ JoinHostPort $backend.Address $.BackendControlPlanePort }} check check-ssl verify none resolvers docker resolve-prefer {{ if $.IPv6 -}} ipv6 {{- else -}} ipv4 {{- end }}
          {{- end}}
    
        frontend rke2-join
          bind *:9345
          {{ if .IPv6 -}}
          bind :::9345;
          {{- end }}
          default_backend rke2-servers
    
        backend rke2-servers
          option httpchk GET /v1-rke2/readyz
          http-check expect status 403
          {{range $server, $backend := .BackendServers}}
          server {{ $server }} {{ $backend.Address }}:9345 check check-ssl verify none
          {{- end}}
    kind: ConfigMap
    metadata:
      name: rke2-docker-lb-config
      namespace: example-docker

    And then using below command:

    $ k get machines -o jsonpath='{range .items[*]}{.metadata.labels}' | jq
    {
      "cluster.x-k8s.io/cluster-name": "rke2-docker",
      "cluster.x-k8s.io/control-plane": "",
      "key": "value"
    }

Checklist:

  • squashed commits into logical changes
  • includes documentation
  • adds unit tests
  • adds or updates e2e tests

@dharmit dharmit added the kind/bug Something isn't working label Mar 24, 2025
@dharmit dharmit requested a review from a team as a code owner March 24, 2025 15:56
@dharmit dharmit moved this to PR to be reviewed in CAPI / Turtles Mar 24, 2025
@kkaempf kkaempf added this to the v0.14.0 milestone Mar 24, 2025
Copy link
Contributor

@mjura mjura left a comment

Choose a reason for hiding this comment

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

It looks good to me, but linter is yealing

return with no blank line before (nlreturn)

@alexander-demicev alexander-demicev moved this from PR to be reviewed to In Progress (8 max) in CAPI / Turtles Mar 25, 2025
@dharmit
Copy link
Contributor Author

dharmit commented Mar 25, 2025

It looks good to me, but linter is yealing

return with no blank line before (nlreturn)

@mjura I'll remove fix it if we decide to go with the first commit 694170f of this PR. If we choose the second commit, it's going to pass the CI just fine, I tihnk.

@kkaempf kkaempf moved this from In Progress (8 max) to PR to be reviewed in CAPI / Turtles Apr 1, 2025
anmazzotti
anmazzotti previously approved these changes Apr 1, 2025
anmazzotti
anmazzotti previously approved these changes Apr 2, 2025
Copy link
Contributor

@anmazzotti anmazzotti left a comment

Choose a reason for hiding this comment

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

Thank you!

@dharmit dharmit force-pushed the fix-517 branch 2 times, most recently from fcb5edc to e664e98 Compare April 2, 2025 12:57
@dharmit dharmit requested review from anmazzotti and mjura April 2, 2025 13:41
Copy link
Member

@alexander-demicev alexander-demicev left a comment

Choose a reason for hiding this comment

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

thanks!

@dharmit dharmit enabled auto-merge April 2, 2025 15:44
@dharmit dharmit removed the request for review from mjura April 2, 2025 15:45
@dharmit dharmit added this pull request to the merge queue Apr 2, 2025
Merged via the queue into rancher:main with commit ca6992b Apr 2, 2025
5 checks passed
@dharmit dharmit deleted the fix-517 branch April 2, 2025 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Additional Labels are not applied
5 participants