Skip to content

Commit

Permalink
Add failureDomains in MachineDeploymentTopology
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Dec 13, 2021
1 parent c698e19 commit 0ec83f3
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 18 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,9 @@ func Convert_v1beta1_Topology_To_v1alpha4_Topology(in *clusterv1.Topology, out *
// spec.topology.variables has been added with v1beta1.
return autoConvert_v1beta1_Topology_To_v1alpha4_Topology(in, out, s)
}

// Convert_v1beta1_MachineDeploymentTopology_To_v1alpha4_MachineDeploymentTopology is an autogenerated conversion function.
func Convert_v1beta1_MachineDeploymentTopology_To_v1alpha4_MachineDeploymentTopology(in *clusterv1.MachineDeploymentTopology, out *MachineDeploymentTopology, s apiconversion.Scope) error {
// MachineDeploymentTopology.FailureDomain has been added with v1beta1.
return autoConvert_v1beta1_MachineDeploymentTopology_To_v1alpha4_MachineDeploymentTopology(in, out, s)
}
60 changes: 46 additions & 14 deletions api/v1alpha4/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions api/v1beta1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ type MachineDeploymentTopology struct {
// the values are hashed together.
Name string `json:"name"`

// FailureDomain is the failure domain the machines will be created in.
// Must match a key in the FailureDomains map stored on the cluster object.
// +optional
FailureDomain *string `json:"failureDomain,omitempty"`

// Replicas is the number of worker nodes belonging to this set.
// If the value is nil, the MachineDeployment is created without the number of Replicas (defaulting to zero)
// and it's assumed that an external entity (like cluster autoscaler) is responsible for the management
Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions config/crd/bases/cluster.x-k8s.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,11 @@ spec:
ClusterClass object mentioned in the `Cluster.Spec.Class`
field.
type: string
failureDomain:
description: FailureDomain is the failure domain the
machines will be created in. Must match a key in the
FailureDomains map stored on the cluster object.
type: string
metadata:
description: Metadata is the metadata applied to the
machines of the MachineDeployment. At runtime this
Expand Down
1 change: 1 addition & 0 deletions controllers/topology/desired_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ func computeMachineDeployment(_ context.Context, s *scope.Scope, desiredControlP
Version: pointer.String(version),
Bootstrap: clusterv1.Bootstrap{ConfigRef: contract.ObjToRef(desiredMachineDeployment.BootstrapTemplate)},
InfrastructureRef: *contract.ObjToRef(desiredMachineDeployment.InfrastructureMachineTemplate),
FailureDomain: machineDeploymentTopology.FailureDomain,
},
},
},
Expand Down
12 changes: 8 additions & 4 deletions controllers/topology/desired_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func TestComputeControlPlane(t *testing.T) {
clusterClass := builder.ClusterClass(metav1.NamespaceDefault, "class1").
WithControlPlaneMetadata(labels, annotations).
WithControlPlaneTemplate(controlPlaneTemplate).Build()
//TODO: Replace with object builder.
// TODO: Replace with object builder.
// current cluster objects
version := "v1.21.2"
replicas := int32(3)
Expand Down Expand Up @@ -722,13 +722,15 @@ func TestComputeMachineDeployment(t *testing.T) {
}

replicas := int32(5)
failureDomain := "always-up-region"
mdTopology := clusterv1.MachineDeploymentTopology{
Metadata: clusterv1.ObjectMeta{
Labels: map[string]string{"foo": "baz"},
},
Class: "linux-worker",
Name: "big-pool-of-machines",
Replicas: &replicas,
Class: "linux-worker",
Name: "big-pool-of-machines",
Replicas: &replicas,
FailureDomain: &failureDomain,
}

t.Run("Generates the machine deployment and the referenced templates", func(t *testing.T) {
Expand All @@ -755,6 +757,7 @@ func TestComputeMachineDeployment(t *testing.T) {

actualMd := actual.Object
g.Expect(*actualMd.Spec.Replicas).To(Equal(replicas))
g.Expect(*actualMd.Spec.Template.Spec.FailureDomain).To(Equal(failureDomain))
g.Expect(actualMd.Spec.ClusterName).To(Equal("cluster1"))
g.Expect(actualMd.Name).To(ContainSubstring("cluster1"))
g.Expect(actualMd.Name).To(ContainSubstring("big-pool-of-machines"))
Expand Down Expand Up @@ -810,6 +813,7 @@ func TestComputeMachineDeployment(t *testing.T) {
actualMd := actual.Object

g.Expect(*actualMd.Spec.Replicas).NotTo(Equal(currentReplicas))
g.Expect(*actualMd.Spec.Template.Spec.FailureDomain).To(Equal(failureDomain))
g.Expect(actualMd.Name).To(Equal("existing-deployment-1"))

g.Expect(actualMd.Labels).To(HaveKeyWithValue(clusterv1.ClusterTopologyMachineDeploymentLabelName, "big-pool-of-machines"))
Expand Down

0 comments on commit 0ec83f3

Please sign in to comment.