Skip to content

Commit

Permalink
Add mps to handler & topology test
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed Mar 19, 2024
1 parent a79442a commit ec6cff1
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ spec:
controlPlane:
metadata: {}
replicas: 1
workers:
machinePools:
- class: "default-worker"
name: "mp-0"
replicas: 1
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerCluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,24 @@ metadata:
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
labels:
cluster.x-k8s.io/provider: control-plane-kubeadm
cluster.x-k8s.io/v1beta1: v1beta1
name: kubeadmconfigtemplates.bootstrap.cluster.x-k8s.io
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
labels:
cluster.x-k8s.io/provider: infrastructure-docker
cluster.x-k8s.io/v1beta1: v1beta1
name: dockermachinetemplates.infrastructure.cluster.x-k8s.io
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
labels:
cluster.x-k8s.io/provider: infrastructure-docker
cluster.x-k8s.io/v1beta1: v1beta1
name: dockermachinetemplates.infrastructure.cluster.x-k8s.io
name: dockermachinepooltemplates.infrastructure.cluster.x-k8s.io
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachinePoolTemplate
metadata:
name: "docker-worker-machinepooltemplate"
namespace: default
spec:
template:
metadata:
labels:
docker-machinepool-template: test-template-worker
spec:
extraMounts:
- containerPath: "/var/run/docker.sock"
hostPath: "/var/run/docker.sock"
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ spec:
kind: DockerClusterTemplate
name: my-cluster
namespace: default
workers:
machinePools:
- class: "default-worker"
template:
bootstrap:
ref:
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KubeadmConfigTemplate
name: docker-worker-bootstraptemplate
namespace: default
infrastructure:
ref:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachinePoolTemplate
name: docker-worker-machinepooltemplate
namespace: default
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerClusterTemplate
Expand Down Expand Up @@ -71,3 +87,26 @@ spec:
extraMounts:
- containerPath: "/var/run/docker.sock"
hostPath: "/var/run/docker.sock"
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachinePoolTemplate
metadata:
name: "docker-worker-machinepooltemplate"
namespace: default
spec:
template:
spec:
extraMounts:
- containerPath: "/var/run/docker.sock"
hostPath: "/var/run/docker.sock"
---
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KubeadmConfigTemplate
metadata:
name: "docker-worker-bootstraptemplate"
namespace: default
spec:
template:
spec:
joinConfiguration:
nodeRegistration: {} # node registration parameters are automatically injected by CAPD according to the kindest/node image in use.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ spec:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
name: docker-worker-machinetemplate
machinePools:
- class: "default-worker"
template:
bootstrap:
ref:
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KubeadmConfigTemplate
name: docker-worker-bootstraptemplate
infrastructure:
ref:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachinePoolTemplate
name: docker-worker-machinepooltemplate
- class: "default-worker-2"
template:
bootstrap:
ref:
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KubeadmConfigTemplate
name: docker-worker-bootstraptemplate
infrastructure:
ref:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachinePoolTemplate
name: docker-worker-machinepooltemplate
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerClusterTemplate
Expand Down Expand Up @@ -125,6 +150,17 @@ spec:
preLoadImages:
- gcr.io/kakaraparthy-devel/kindest/kindnetd:0.5.4
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachinePoolTemplate
metadata:
name: "docker-worker-machinepooltemplate"
namespace: default
spec:
template:
spec:
preLoadImages:
- gcr.io/kakaraparthy-devel/kindest/kindnetd:0.5.4
---
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KubeadmConfigTemplate
metadata:
Expand Down Expand Up @@ -165,3 +201,10 @@ spec:
- class: "default-worker"
name: "md-1"
replicas: 1
machinePools:
- class: "default-worker"
name: "mp-0"
replicas: 1
- class: "default-worker"
name: "mp-1"
replicas: 1
70 changes: 69 additions & 1 deletion cmd/clusterctl/client/cluster/topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ var (
//go:embed assets/topology-test/modified-my-cluster.yaml
modifiedMyClusterYAML []byte

// modifiedDockerMachineTemplateYAML adds metadat to the docker machine used by the control plane template..
// modifiedDockerMachineTemplateYAML adds metadata to the docker machine used by the control plane template..
//go:embed assets/topology-test/modified-CP-dockermachinetemplate.yaml
modifiedDockerMachineTemplateYAML []byte

// modifiedDockerMachinePoolTemplateYAML adds metadata to the docker machine pool used by the control plane template..
//go:embed assets/topology-test/modified-CP-dockermachinepooltemplate.yaml
modifiedDockerMachinePoolTemplateYAML []byte

//go:embed assets/topology-test/objects-in-different-namespaces.yaml
objsInDifferentNamespacesYAML []byte
)
Expand Down Expand Up @@ -97,11 +101,15 @@ func Test_topologyClient_Plan(t *testing.T) {
{kind: "DockerMachineTemplate", namespace: "default", namePrefix: "my-cluster-md-0-"},
{kind: "DockerMachineTemplate", namespace: "default", namePrefix: "my-cluster-md-1-"},
{kind: "DockerMachineTemplate", namespace: "default", namePrefix: "my-cluster-"},
{kind: "DockerMachinePool", namespace: "default", namePrefix: "my-cluster-mp-0-"},
{kind: "DockerMachinePool", namespace: "default", namePrefix: "my-cluster-mp-1-"},
{kind: "KubeadmConfigTemplate", namespace: "default", namePrefix: "my-cluster-md-0-"},
{kind: "KubeadmConfigTemplate", namespace: "default", namePrefix: "my-cluster-md-1-"},
{kind: "KubeadmControlPlane", namespace: "default", namePrefix: "my-cluster-"},
{kind: "MachineDeployment", namespace: "default", namePrefix: "my-cluster-md-0-"},
{kind: "MachineDeployment", namespace: "default", namePrefix: "my-cluster-md-1-"},
{kind: "MachinePool", namespace: "default", namePrefix: "my-cluster-mp-0-"},
{kind: "MachinePool", namespace: "default", namePrefix: "my-cluster-mp-1-"},
},
modified: []item{
{kind: "Cluster", namespace: "default", namePrefix: "my-cluster"},
Expand Down Expand Up @@ -205,6 +213,35 @@ func Test_topologyClient_Plan(t *testing.T) {
},
wantErr: false,
},
{
name: "Modifying an existing DockerMachinePoolTemplate. Affects multiple clusters. Target Cluster not specified.",
existingObjects: mustToUnstructured(
mockCRDsYAML,
existingMyClusterClassYAML,
existingMyClusterYAML,
existingMySecondClusterYAML,
),
args: args{
in: &TopologyPlanInput{
Objs: mustToUnstructured(modifiedDockerMachinePoolTemplateYAML),
},
},
want: out{
affectedClusters: func() []client.ObjectKey {
cluster := client.ObjectKey{Namespace: "default", Name: "my-cluster"}
cluster2 := client.ObjectKey{Namespace: "default", Name: "my-second-cluster"}
return []client.ObjectKey{cluster, cluster2}
}(),
affectedClusterClasses: func() []client.ObjectKey {
cc := client.ObjectKey{Namespace: "default", Name: "my-cluster-class"}
return []client.ObjectKey{cc}
}(),
modified: []item{},
created: []item{},
reconciledCluster: nil,
},
wantErr: false,
},
{
name: "Modifying an existing DockerMachineTemplate. Affects multiple clusters. Target Cluster specified.",
existingObjects: mustToUnstructured(
Expand Down Expand Up @@ -241,6 +278,37 @@ func Test_topologyClient_Plan(t *testing.T) {
},
wantErr: false,
},
{
name: "Modifying an existing DockerMachinePoolTemplate. Affects multiple clusters. Target Cluster specified.",
existingObjects: mustToUnstructured(
mockCRDsYAML,
existingMyClusterClassYAML,
existingMyClusterYAML,
existingMySecondClusterYAML,
),
args: args{
in: &TopologyPlanInput{
Objs: mustToUnstructured(modifiedDockerMachinePoolTemplateYAML),
TargetClusterName: "my-cluster",
},
},
want: out{
affectedClusters: func() []client.ObjectKey {
cluster := client.ObjectKey{Namespace: "default", Name: "my-cluster"}
cluster2 := client.ObjectKey{Namespace: "default", Name: "my-second-cluster"}
return []client.ObjectKey{cluster, cluster2}
}(),
affectedClusterClasses: func() []client.ObjectKey {
cc := client.ObjectKey{Namespace: "default", Name: "my-cluster-class"}
return []client.ObjectKey{cc}
}(),
created: []item{
{kind: "DockerMachinePool", namespace: "default", namePrefix: "my-cluster-"},
},
reconciledCluster: &client.ObjectKey{Namespace: "default", Name: "my-cluster"},
},
wantErr: false,
},
{
name: "Input with objects in different namespaces should return error",
args: args{
Expand Down
Loading

0 comments on commit ec6cff1

Please sign in to comment.