Skip to content

Commit 50cd7dd

Browse files
✨ Add rolloutAfter to cluster.spec.topology (#13391)
* Add rolloutAfter to cluster.spec.topology * Address comments
1 parent 44eca8a commit 50cd7dd

File tree

15 files changed

+256
-17
lines changed

15 files changed

+256
-17
lines changed

api/core/v1beta1/conversion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ func (src *Cluster) ConvertTo(dstRaw conversion.Hub) error {
7575

7676
if ok {
7777
dst.Spec.Topology.ControlPlane.HealthCheck.Checks.UnhealthyMachineConditions = restored.Spec.Topology.ControlPlane.HealthCheck.Checks.UnhealthyMachineConditions
78+
dst.Spec.Topology.ControlPlane.Rollout = restored.Spec.Topology.ControlPlane.Rollout
7879
for _, restoredMD := range restored.Spec.Topology.Workers.MachineDeployments {
7980
for i, dstMD := range dst.Spec.Topology.Workers.MachineDeployments {
8081
if restoredMD.Name == dstMD.Name {
8182
dst.Spec.Topology.Workers.MachineDeployments[i].HealthCheck.Checks.UnhealthyMachineConditions = restoredMD.HealthCheck.Checks.UnhealthyMachineConditions
83+
dst.Spec.Topology.Workers.MachineDeployments[i].Rollout.After = restoredMD.Rollout.After
8284
}
8385
}
8486
}

api/core/v1beta1/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/core/v1beta2/cluster_types.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,10 @@ type ControlPlaneTopology struct {
632632
// +optional
633633
Replicas *int32 `json:"replicas,omitempty"`
634634

635+
// rollout allows you to configure the behavior of rolling updates to the control plane.
636+
// +optional
637+
Rollout ControlPlaneTopologyRolloutSpec `json:"rollout,omitempty,omitzero"`
638+
635639
// healthCheck allows to enable, disable and override control plane health check
636640
// configuration from the ClusterClass for this control plane.
637641
// +optional
@@ -662,6 +666,18 @@ type ControlPlaneTopology struct {
662666
Variables ControlPlaneVariables `json:"variables,omitempty,omitzero"`
663667
}
664668

669+
// ControlPlaneTopologyRolloutSpec defines the rollout behavior.
670+
// +kubebuilder:validation:MinProperties=1
671+
type ControlPlaneTopologyRolloutSpec struct {
672+
// after is a field to indicate a rollout should be performed
673+
// after the specified time even if no changes have been made to the ControlPlane.
674+
// Example: In the YAML the time can be specified in the RFC3339 format.
675+
// To specify the rolloutAfter target as March 9, 2023, at 9 am UTC
676+
// use "2023-03-09T09:00:00Z".
677+
// +optional
678+
After metav1.Time `json:"after,omitempty,omitzero"`
679+
}
680+
665681
// ControlPlaneTopologyHealthCheck defines a MachineHealthCheck for control plane machines.
666682
// +kubebuilder:validation:MinProperties=1
667683
type ControlPlaneTopologyHealthCheck struct {
@@ -1107,6 +1123,15 @@ type MachineDeploymentTopologyMachineDeletionSpec struct {
11071123
// MachineDeploymentTopologyRolloutSpec defines the rollout behavior.
11081124
// +kubebuilder:validation:MinProperties=1
11091125
type MachineDeploymentTopologyRolloutSpec struct {
1126+
// after is a field to indicate a rollout should be performed
1127+
// after the specified time even if no changes have been made to the
1128+
// MachineDeployment.
1129+
// Example: In the YAML the time can be specified in the RFC3339 format.
1130+
// To specify the rolloutAfter target as March 9, 2023, at 9 am UTC
1131+
// use "2023-03-09T09:00:00Z".
1132+
// +optional
1133+
After metav1.Time `json:"after,omitempty,omitzero"`
1134+
11101135
// strategy specifies how to roll out control plane Machines.
11111136
// +optional
11121137
Strategy MachineDeploymentTopologyRolloutStrategy `json:"strategy,omitempty,omitzero"`

api/core/v1beta2/zz_generated.deepcopy.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/core/v1beta2/zz_generated.openapi.go

Lines changed: 37 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/cluster.x-k8s.io_clusters.yaml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/book/src/developer/providers/contracts/control-plane.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ repo or add an item to the agenda in the [Cluster API community meeting](https:/
6767
| [ControlPlane: replicas] | No | Mandatory if control plane has a notion of number of instances. |
6868
| [ControlPlane: version] | No | Mandatory if control plane allows direct management of the Kubernetes version in use; Mandatory for cluster class support. |
6969
| [ControlPlane: machines] | No | Mandatory if control plane instances are represented with a set of Cluster API Machines. |
70+
| [ControlPlane: rolloutAfter] | No | |
7071
| [ControlPlane: initialization completed] | Yes | |
7172
| [ControlPlane: in-place updates] | No | Only supported for control plane providers with control plane machines |
7273
| [ControlPlane: conditions] | No | |
@@ -598,6 +599,34 @@ can benefit from several Cluster API behaviours, for example:
598599
- Machine health checking
599600
- Machine drain and wait for volume detach during deletion
600601

602+
### ControlPlane: rolloutAfter
603+
604+
In case you are developing a control plane provider which supports scheduled rollout via
605+
the `rolloutAfter` field, following fields MUST be implemented in the ControlPlane `spec`.
606+
607+
```go
608+
type FooControlPlaneSpec struct {
609+
// rollout allows you to configure the behaviour of rolling updates to the control plane.
610+
// +optional
611+
Rollout FooControlPlaneRolloutSpec `json:"rollout,omitempty,omitzero"`
612+
613+
// See other rules for more details about mandatory/optional fields in ControlPlane status.
614+
// Other fields SHOULD be added based on the needs of your provider.
615+
}
616+
617+
// +kubebuilder:validation:MinProperties=1
618+
type FooControlPlaneRolloutSpec struct {
619+
// after is a field to indicate a rollout should be performed
620+
// after the specified time even if no changes have been made to the
621+
// FooControlPlane.
622+
// Example: In the YAML the time can be specified in the RFC3339 format.
623+
// To specify the rolloutAfter target as March 9, 2023, at 9 am UTC
624+
// use "2023-03-09T09:00:00Z".
625+
// +optional
626+
After metav1.Time `json:"after,omitempty,omitzero"`
627+
}
628+
```
629+
601630
### ControlPlane: initialization completed
602631

603632
Each ControlPlane MUST report when the Kubernetes control plane is initialized; usually a control plane is considered
@@ -934,6 +963,7 @@ is implemented in ControlPlane controllers:
934963
[ControlPlane: replicas]: #controlplane-replicas
935964
[scale]: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#subresources
936965
[ControlPlane: machines]: #controlplane-machines
966+
[ControlPlane: rolloutAfter]: #controlplane-rolloutafter
937967
[In place propagation of changes affecting Kubernetes objects only]: https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20221003-In-place-propagation-of-Kubernetes-objects-only-changes.md
938968
[ControlPlane: version]: #controlplane-version
939969
[ControlPlane: initialization completed]: #controlplane-initialization-completed

docs/book/src/developer/providers/migrations/v1.12-to-v1.13.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Any feedback or contributions to improve following documentation is welcome!
4545

4646
- A new, optional rule has been added to the control plane contract, defining what is required for implementing support
4747
for taints.
48+
- A new, optional rule has been added to the control plane contract, defining what is required for implementing support
49+
for rolloutAfter.
4850

4951
## Deprecation
5052

exp/topology/desiredstate/desired_state.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,13 @@ func (g *generator) computeControlPlane(ctx context.Context, s *scope.Scope, inf
433433
}
434434
}
435435

436+
// If it is required to manage rolloutAfter for the control plane, set the corresponding field.
437+
if !s.Blueprint.Topology.ControlPlane.Rollout.After.IsZero() {
438+
if err := contract.ControlPlane().RolloutAfter().Set(controlPlane, s.Blueprint.Topology.ControlPlane.Rollout.After); err != nil {
439+
return nil, errors.Wrapf(err, "failed to set %s in the ControlPlane object", contract.ControlPlane().RolloutAfter().Path())
440+
}
441+
}
442+
436443
// If it is required to manage the readinessGates for the control plane, set the corresponding field.
437444
// NOTE: If readinessGates value from both Cluster and ClusterClass is nil, it is assumed that the control plane controller
438445
// does not implement support for this field and the ControlPlane object is generated without readinessGates.
@@ -900,6 +907,7 @@ func (g *generator) computeMachineDeployment(ctx context.Context, s *scope.Scope
900907
}
901908
if !reflect.DeepEqual(machineDeploymentTopology.Rollout, clusterv1.MachineDeploymentTopologyRolloutSpec{}) {
902909
rollout = clusterv1.MachineDeploymentRolloutSpec{
910+
After: machineDeploymentTopology.Rollout.After,
903911
Strategy: clusterv1.MachineDeploymentRolloutStrategy{
904912
Type: machineDeploymentTopology.Rollout.Strategy.Type,
905913
RollingUpdate: clusterv1.MachineDeploymentRolloutStrategyRollingUpdate{

0 commit comments

Comments
 (0)