kubernetes-sigs / cluster-api-provider-azure

Cluster API implementation for Microsoft Azure
https://capz.sigs.k8s.io/
Apache License 2.0
287 stars 414 forks source link

Add AzureMachinePoolTemplate CRD to support ClusterClass with MachinePools #4927

Open mweibel opened 1 week ago

mweibel commented 1 week ago

/kind feature

Describe the solution you'd like I'd like to use ClusterClasses with MachinePools. ClusterClass requires for each infrastructure type a <name>Template CRD kind. Unmanaged MachinePools don't yet have such a kind.

Minimum reproducible example:

# minimized it so the issue becomes apparent
apiVersion: cluster.x-k8s.io/v1beta1
kind: ClusterClass
metadata:
  name: basic-001
  namespace: default
spec:
  controlPlane:
    ref:
      apiVersion: controlplane.cluster.x-k8s.io/v1beta1
      kind: KubeadmControlPlaneTemplate
      name: ctrl-plane-001
    machineInfrastructure:
      ref:
        kind: AzureMachineTemplate
        apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
        name: ctrl-plane-001
  infrastructure:
    ref:
      apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
      kind: AzureClusterTemplate
      name: azure-cluster
  workers:
    machinePools:
      - class: worker-001
        template:
          bootstrap:
            ref:
              apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
              kind: KubeadmConfigTemplate
              name: worker-001
          infrastructure:
            ref:
              apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
              kind: AzureMachinePool
              name: worker-001

Running this with clusterctl alpha topology plan gives an error:

 » clusterctl alpha topology plan --file test.yaml --output-directory test
Command "plan" is deprecated, it will be removed in one of the upcoming releases.

Detected a cluster with Cluster API installed. Will use it to fetch missing objects.
Error: failed defaulting and validation on input objects: failed to run defaulting and validation on ClusterClasses: failed validation of cluster.x-k8s.io/v1beta1, Kind=ClusterClass default/basic-001: ClusterClass.cluster.x-k8s.io "basic-001" is invalid: spec.workers.machinePools[0].template.infrastructure.ref.kind: Invalid value: "AzureMachinePool": template kind must be of form "<name>Template"

Anything else you would like to add: See https://github.com/kubernetes-sigs/cluster-api/issues/10768 for some more infromation.

I might contribute this myself - not sure when I can allocate the time atm.

Environment: