From 42aee3bc7f3f808de86f130093863ec310d4a4e5 Mon Sep 17 00:00:00 2001 From: willie-yao Date: Mon, 11 Sep 2023 20:11:45 +0000 Subject: [PATCH] Add mp to quickstart templates --- docs/book/src/reference/owner_references.md | 6 +- .../main/bases/cluster-with-topology.yaml | 20 +++++++ .../main/clusterclass-quick-start.yaml | 60 +++++++++++++++++++ test/framework/ownerreference_helpers.go | 22 ++++--- 4 files changed, 96 insertions(+), 12 deletions(-) diff --git a/docs/book/src/reference/owner_references.md b/docs/book/src/reference/owner_references.md index 527ae234b493..bf01d4a9b8e2 100644 --- a/docs/book/src/reference/owner_references.md +++ b/docs/book/src/reference/owner_references.md @@ -51,7 +51,7 @@ These owner references are almost all tested in an [end-to-end test](https://git |----------------------------|--------------------|------------|--------------------------| | ClusterResourcesSet | None | | | | ClusterResourcesSetBinding | ClusterResourceSet | no | May have many CRS owners | -| MachinePool | Cluster | unknown | Not tested in e2e | +| MachinePool | Cluster | no | | ## KubeadmControlPlane types @@ -65,7 +65,7 @@ These owner references are almost all tested in an [end-to-end test](https://git | type | Owner | Controller | Note | |-----------------------|--------------|------------|-------------------------------------------------| | KubeadmConfig | Machine | yes | When created for Machine | -| KubeadmConfig | MachinePool | unknown | When created for MachinePool. Not tested in e2e | +| KubeadmConfig | MachinePool | yes | When created for MachinePool | | KubeadmConfigTemplate | Cluster | no | When referenced in MachineDeployment spec | | KubeadmConfigTemplate | ClusterClass | no | When referenced in ClusterClass | @@ -77,6 +77,6 @@ These owner references are almost all tested in an [end-to-end test](https://git | InfrastructureMachineTemplate | ClusterClass | no | When referenced in a ClusterClass | | InfrastructureCluster | Cluster | yes | | | InfrastructureClusterTemplate | ClusterClass | no | | -| InfrastructureMachinePool | MachinePool | unknown | Not tested in e2e | +| InfrastructureMachinePool | MachinePool | yes | | diff --git a/test/e2e/data/infrastructure-docker/main/bases/cluster-with-topology.yaml b/test/e2e/data/infrastructure-docker/main/bases/cluster-with-topology.yaml index 529fc15f69d2..c67097a69734 100644 --- a/test/e2e/data/infrastructure-docker/main/bases/cluster-with-topology.yaml +++ b/test/e2e/data/infrastructure-docker/main/bases/cluster-with-topology.yaml @@ -47,6 +47,26 @@ spec: rollingUpdate: maxSurge: "20%" maxUnavailable: 0 + machinePools: + - class: "default-worker" + name: "mp-0" + metadata: + labels: + Cluster.topology.machinePool.label: "Cluster.topology.machinePool.labelValue" + # Note: this label is propagated to Nodes. + Cluster.topology.machinePool.label.node.cluster.x-k8s.io: "Cluster.topology.machinePool.nodeLabelValue" + annotations: + Cluster.topology.machinePool.annotation: "Cluster.topology.machinePool.annotationValue" + nodeDeletionTimeout: "30s" + nodeVolumeDetachTimeout: "5m" + minReadySeconds: 5 + replicas: ${WORKER_MACHINE_COUNT} + failureDomains: + - fd4 + - fd5 + - fd6 + - fd7 + - fd8 variables: # We set an empty value to use the default tag kubeadm init is using. - name: etcdImageTag diff --git a/test/e2e/data/infrastructure-docker/main/clusterclass-quick-start.yaml b/test/e2e/data/infrastructure-docker/main/clusterclass-quick-start.yaml index 3d747dd49625..e5da91b45a88 100644 --- a/test/e2e/data/infrastructure-docker/main/clusterclass-quick-start.yaml +++ b/test/e2e/data/infrastructure-docker/main/clusterclass-quick-start.yaml @@ -54,6 +54,24 @@ spec: - type: e2e.remediation.condition status: "False" timeout: 20s + machinePools: + - class: default-worker + template: + metadata: + labels: + ClusterClass.machinePool.label: "ClusterClass.machinePool.labelValue" + annotations: + ClusterClass.machinePool.annotation: "ClusterClass.machinePool.annotationValue" + bootstrap: + ref: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 + kind: KubeadmConfigTemplate + name: quick-start-default-worker-bootstraptemplate + infrastructure: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + kind: DockerMachinePoolTemplate + name: quick-start-default-worker-machinepooltemplate variables: - name: lbImageRepository required: true @@ -182,6 +200,19 @@ spec: valueFrom: template: | kindest/node:{{ .builtin.controlPlane.version | replace "+" "_" }} + - selector: + apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 + kind: DockerMachinePoolTemplate + matchResources: + machinePoolClass: + names: + - default-worker + jsonPatches: + - op: add + path: "/spec/template/spec/template/customImage" + valueFrom: + template: | + kindest/node:{{ .builtin.machinePool.version | replace "+" "_" }} - name: preloadImages description: | Sets the container images to preload to the node that is used for running dockerMachines. @@ -264,6 +295,18 @@ spec: path: "/spec/template/spec/joinConfiguration/nodeRegistration/kubeletExtraArgs" value: cloud-provider: "external" + - selector: + apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 + kind: KubeadmConfigTemplate + matchResources: + machinePoolClass: + names: + - '*-worker' + jsonPatches: + - op: add + path: "/spec/template/spec/joinConfiguration/nodeRegistration/kubeletExtraArgs" + value: + cloud-provider: "external" - name: localEndpointIPv6 enabledIf: "{{ .ipv6Primary }}" description: "Configures KCP to use IPv6 for its localAPIEndpoint." @@ -440,21 +483,38 @@ spec: - containerPath: "/var/run/docker.sock" hostPath: "/var/run/docker.sock" --- +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: DockerMachinePoolTemplate +metadata: + name: quick-start-default-worker-machinepooltemplate + labels: + InfraMachineTemplate.machinePool.label: "InfraMachineTemplate.machinePool.labelValue" + annotations: + InfraMachineTemplate.machinePool.annotation: "InfraMachineTemplate.machinePool.annotationValue" +spec: + template: + spec: + template: {} +--- apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 kind: KubeadmConfigTemplate metadata: name: quick-start-default-worker-bootstraptemplate labels: BootstrapConfigTemplate.machineDeployment.label: "BootstrapConfigTemplate.machineDeployment.labelValue" + BootstrapConfigTemplate.machinePool.label: "BootstrapConfigTemplate.machinePool.labelValue" annotations: BootstrapConfigTemplate.machineDeployment.annotation: "BootstrapConfigTemplate.machineDeployment.annotationValue" + BootstrapConfigTemplate.machinePool.annotation: "BootstrapConfigTemplate.machinePool.annotationValue" spec: template: metadata: labels: BootstrapConfigTemplate.machineDeployment.template.label: "BootstrapConfigTemplate.machineDeployment.template.labelValue" + BootstrapConfigTemplate.machinePool.label: "BootstrapConfigTemplate.machinePool.labelValue" annotations: BootstrapConfigTemplate.machineDeployment.template.annotation: "BootstrapConfigTemplate.machineDeployment.template.annotationValue" + BootstrapConfigTemplate.machinePool.annotation: "BootstrapConfigTemplate.machinePool.annotationValue" spec: joinConfiguration: nodeRegistration: # node registration parameters are automatically injected by CAPD according to the kindest/node image in use. diff --git a/test/framework/ownerreference_helpers.go b/test/framework/ownerreference_helpers.go index 0b727891df58..17db27e2bb69 100644 --- a/test/framework/ownerreference_helpers.go +++ b/test/framework/ownerreference_helpers.go @@ -183,7 +183,6 @@ var ( clusterResourceSetBindingKind = "ClusterResourceSetBinding" machinePoolKind = "MachinePool" - machinePoolOwner = metav1.OwnerReference{Kind: machinePoolKind, APIVersion: expv1.GroupVersion.String()} machinePoolController = metav1.OwnerReference{Kind: machinePoolKind, APIVersion: expv1.GroupVersion.String(), Controller: pointer.Bool(true)} clusterResourceSetOwner = metav1.OwnerReference{Kind: clusterResourceSetKind, APIVersion: addonsv1.GroupVersion.String()} @@ -280,11 +279,12 @@ var KubeadmBootstrapOwnerReferenceAssertions = map[string]func([]metav1.OwnerRef // Kinds for types in the Docker infrastructure package. var ( - dockerMachineKind = "DockerMachine" - dockerMachineTemplateKind = "DockerMachineTemplate" - dockerMachinePoolKind = "DockerMachinePool" - dockerClusterKind = "DockerCluster" - dockerClusterTemplateKind = "DockerClusterTemplate" + dockerMachineKind = "DockerMachine" + dockerMachineTemplateKind = "DockerMachineTemplate" + dockerMachinePoolKind = "DockerMachinePool" + dockerMachinePoolTemplateKind = "DockerMachinePoolTemplate" + dockerClusterKind = "DockerCluster" + dockerClusterTemplateKind = "DockerClusterTemplate" ) // DockerInfraOwnerReferenceAssertions maps Docker Infrastructure types to functions which return an error if the passed @@ -310,8 +310,12 @@ var DockerInfraOwnerReferenceAssertions = map[string]func([]metav1.OwnerReferenc return HasExactOwners(owners, clusterClassOwner) }, dockerMachinePoolKind: func(owners []metav1.OwnerReference) error { - // DockerMachinePool must be owned by a MachinePool. - return HasExactOwners(owners, machinePoolOwner) + // DockerMachinePool must be owned and controlled by a MachinePool. + return HasExactOwners(owners, machinePoolController) + }, + dockerMachinePoolTemplateKind: func(owners []metav1.OwnerReference) error { + // DockerMachinePoolTemplate must be owned by a ClusterClass. + return HasExactOwners(owners, clusterClassOwner) }, } @@ -328,7 +332,7 @@ func HasExactOwners(gotOwners []metav1.OwnerReference, wantOwners ...metav1.Owne sort.Strings(wantComparable) if !reflect.DeepEqual(gotComparable, wantComparable) { - return fmt.Errorf("wanted %v, actual %v", wantOwners, gotOwners) + return fmt.Errorf("wanted %v, actual %v", wantComparable, gotComparable) } return nil }