From 28150078b89f5eb5926d6a6ad4a0a5e26da78499 Mon Sep 17 00:00:00 2001 From: Jan Jansen Date: Fri, 7 Oct 2022 13:45:24 +0200 Subject: [PATCH] :sparkles: Add topology field for MinReadySeconds Signed-off-by: Jan Jansen --- api/v1alpha4/conversion.go | 1 + api/v1alpha4/zz_generated.conversion.go | 1 + api/v1beta1/cluster_types.go | 7 +++++++ api/v1beta1/zz_generated.deepcopy.go | 5 +++++ api/v1beta1/zz_generated.openapi.go | 7 +++++++ config/crd/bases/cluster.x-k8s.io_clusters.yaml | 6 ++++++ internal/controllers/topology/cluster/desired_state.go | 3 ++- .../controllers/topology/cluster/desired_state_test.go | 3 +++ .../v1beta1/main/bases/cluster-with-topology.yaml | 1 + 9 files changed, 33 insertions(+), 1 deletion(-) diff --git a/api/v1alpha4/conversion.go b/api/v1alpha4/conversion.go index feea4a6f9786..e3bc041d1bc0 100644 --- a/api/v1alpha4/conversion.go +++ b/api/v1alpha4/conversion.go @@ -69,6 +69,7 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error { dst.Spec.Topology.Workers.MachineDeployments[i].NodeDrainTimeout = restored.Spec.Topology.Workers.MachineDeployments[i].NodeDrainTimeout dst.Spec.Topology.Workers.MachineDeployments[i].NodeVolumeDetachTimeout = restored.Spec.Topology.Workers.MachineDeployments[i].NodeVolumeDetachTimeout dst.Spec.Topology.Workers.MachineDeployments[i].NodeDeletionTimeout = restored.Spec.Topology.Workers.MachineDeployments[i].NodeDeletionTimeout + dst.Spec.Topology.Workers.MachineDeployments[i].MinReadySeconds = restored.Spec.Topology.Workers.MachineDeployments[i].MinReadySeconds dst.Spec.Topology.Workers.MachineDeployments[i].MachineHealthCheck = restored.Spec.Topology.Workers.MachineDeployments[i].MachineHealthCheck } } diff --git a/api/v1alpha4/zz_generated.conversion.go b/api/v1alpha4/zz_generated.conversion.go index d412b2bc17d0..24ad4934fb73 100644 --- a/api/v1alpha4/zz_generated.conversion.go +++ b/api/v1alpha4/zz_generated.conversion.go @@ -1248,6 +1248,7 @@ func autoConvert_v1beta1_MachineDeploymentTopology_To_v1alpha4_MachineDeployment // WARNING: in.NodeDrainTimeout requires manual conversion: does not exist in peer-type // WARNING: in.NodeVolumeDetachTimeout requires manual conversion: does not exist in peer-type // WARNING: in.NodeDeletionTimeout requires manual conversion: does not exist in peer-type + // WARNING: in.MinReadySeconds requires manual conversion: does not exist in peer-type // WARNING: in.Variables requires manual conversion: does not exist in peer-type return nil } diff --git a/api/v1beta1/cluster_types.go b/api/v1beta1/cluster_types.go index 1d6cd1553f38..757271369f5b 100644 --- a/api/v1beta1/cluster_types.go +++ b/api/v1beta1/cluster_types.go @@ -199,6 +199,13 @@ type MachineDeploymentTopology struct { // +optional NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"` + // Minimum number of seconds for which a newly created machine should + // be ready. + // Defaults to 0 (machine will be considered available as soon as it + // is ready) + // +optional + MinReadySeconds *int32 `json:"minReadySeconds,omitempty"` + // Variables can be used to customize the MachineDeployment through patches. // +optional Variables *MachineDeploymentVariables `json:"variables,omitempty"` diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index ac42871e7b67..f44fbe34a77e 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -992,6 +992,11 @@ func (in *MachineDeploymentTopology) DeepCopyInto(out *MachineDeploymentTopology *out = new(metav1.Duration) **out = **in } + if in.MinReadySeconds != nil { + in, out := &in.MinReadySeconds, &out.MinReadySeconds + *out = new(int32) + **out = **in + } if in.Variables != nil { in, out := &in.Variables, &out.Variables *out = new(MachineDeploymentVariables) diff --git a/api/v1beta1/zz_generated.openapi.go b/api/v1beta1/zz_generated.openapi.go index 66578cbdbd45..447988e82e4d 100644 --- a/api/v1beta1/zz_generated.openapi.go +++ b/api/v1beta1/zz_generated.openapi.go @@ -1708,6 +1708,13 @@ func schema_sigsk8sio_cluster_api_api_v1beta1_MachineDeploymentTopology(ref comm Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Duration"), }, }, + "minReadySeconds": { + SchemaProps: spec.SchemaProps{ + Description: "Minimum number of seconds for which a newly created machine should be ready. Defaults to 0 (machine will be considered available as soon as it is ready)", + Type: []string{"integer"}, + Format: "int32", + }, + }, "variables": { SchemaProps: spec.SchemaProps{ Description: "Variables can be used to customize the MachineDeployment through patches.", diff --git a/config/crd/bases/cluster.x-k8s.io_clusters.yaml b/config/crd/bases/cluster.x-k8s.io_clusters.yaml index 2ea4025ae191..4f52e6dc2a44 100644 --- a/config/crd/bases/cluster.x-k8s.io_clusters.yaml +++ b/config/crd/bases/cluster.x-k8s.io_clusters.yaml @@ -1211,6 +1211,12 @@ spec: controllers and services. More info: http://kubernetes.io/docs/user-guide/labels' type: object type: object + minReadySeconds: + description: Minimum number of seconds for which a newly + created machine should be ready. Defaults to 0 (machine + will be considered available as soon as it is ready) + format: int32 + type: integer name: description: Name is the unique identifier for this MachineDeploymentTopology. The value is used with diff --git a/internal/controllers/topology/cluster/desired_state.go b/internal/controllers/topology/cluster/desired_state.go index 733e00be25c4..8fb7f608dc65 100644 --- a/internal/controllers/topology/cluster/desired_state.go +++ b/internal/controllers/topology/cluster/desired_state.go @@ -601,7 +601,8 @@ func computeMachineDeployment(_ context.Context, s *scope.Scope, desiredControlP Namespace: s.Current.Cluster.Namespace, }, Spec: clusterv1.MachineDeploymentSpec{ - ClusterName: s.Current.Cluster.Name, + ClusterName: s.Current.Cluster.Name, + MinReadySeconds: machineDeploymentTopology.MinReadySeconds, Template: clusterv1.MachineTemplateSpec{ ObjectMeta: clusterv1.ObjectMeta{ Labels: mergeMap(machineDeploymentTopology.Metadata.Labels, machineDeploymentBlueprint.Metadata.Labels), diff --git a/internal/controllers/topology/cluster/desired_state_test.go b/internal/controllers/topology/cluster/desired_state_test.go index 230868165caf..db64ce89452f 100644 --- a/internal/controllers/topology/cluster/desired_state_test.go +++ b/internal/controllers/topology/cluster/desired_state_test.go @@ -1328,6 +1328,7 @@ func TestComputeMachineDeployment(t *testing.T) { nodeDrainTimeout := metav1.Duration{Duration: 10 * time.Second} nodeVolumeDetachTimeout := metav1.Duration{Duration: 10 * time.Second} nodeDeletionTimeout := metav1.Duration{Duration: 10 * time.Second} + minReadySeconds := int32(5) mdTopology := clusterv1.MachineDeploymentTopology{ Metadata: clusterv1.ObjectMeta{ Labels: map[string]string{"foo": "baz"}, @@ -1339,6 +1340,7 @@ func TestComputeMachineDeployment(t *testing.T) { NodeDrainTimeout: &nodeDrainTimeout, NodeVolumeDetachTimeout: &nodeVolumeDetachTimeout, NodeDeletionTimeout: &nodeDeletionTimeout, + MinReadySeconds: &minReadySeconds, } t.Run("Generates the machine deployment and the referenced templates", func(t *testing.T) { @@ -1365,6 +1367,7 @@ func TestComputeMachineDeployment(t *testing.T) { actualMd := actual.Object g.Expect(*actualMd.Spec.Replicas).To(Equal(replicas)) + g.Expect(*actualMd.Spec.MinReadySeconds).To(Equal(minReadySeconds)) g.Expect(*actualMd.Spec.Template.Spec.FailureDomain).To(Equal(failureDomain)) g.Expect(*actualMd.Spec.Template.Spec.NodeDrainTimeout).To(Equal(nodeDrainTimeout)) g.Expect(*actualMd.Spec.Template.Spec.NodeDeletionTimeout).To(Equal(nodeDeletionTimeout)) diff --git a/test/e2e/data/infrastructure-docker/v1beta1/main/bases/cluster-with-topology.yaml b/test/e2e/data/infrastructure-docker/v1beta1/main/bases/cluster-with-topology.yaml index edcf3bd7ae91..8b27e5eba1f6 100644 --- a/test/e2e/data/infrastructure-docker/v1beta1/main/bases/cluster-with-topology.yaml +++ b/test/e2e/data/infrastructure-docker/v1beta1/main/bases/cluster-with-topology.yaml @@ -26,6 +26,7 @@ spec: name: "md-0" nodeDeletionTimeout: "30s" nodeVolumeDetachTimeout: "5m" + minReadySeconds: 5 replicas: ${WORKER_MACHINE_COUNT} failureDomain: fd4 variables: