Skip to content

Commit

Permalink
Add backported rolloutStrategy to KCP v1alpha3
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer [email protected]
  • Loading branch information
sbueringer committed Sep 15, 2021
1 parent f8c3205 commit 7084de3
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 3 deletions.
1 change: 0 additions & 1 deletion controlplane/kubeadm/api/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func (src *KubeadmControlPlane) ConvertTo(destRaw conversion.Hub) error {
return err
}

dest.Spec.RolloutStrategy = restored.Spec.RolloutStrategy
dest.Spec.MachineTemplate.ObjectMeta = restored.Spec.MachineTemplate.ObjectMeta
dest.Status.Version = restored.Status.Version

Expand Down
42 changes: 42 additions & 0 deletions controlplane/kubeadm/api/v1alpha3/kubeadm_control_plane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ package v1alpha3
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"

cabpkv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3"
"sigs.k8s.io/cluster-api/errors"
)

// RolloutStrategyType defines the rollout strategies for a KubeadmControlPlane.
type RolloutStrategyType string

const (
// RollingUpdateStrategyType replaces the old control planes by new one using rolling update
// i.e. gradually scale up or down the old control planes and scale up or down the new one.
RollingUpdateStrategyType RolloutStrategyType = "RollingUpdate"
)

const (
// KubeadmControlPlaneFinalizer is the finalizer applied to KubeadmControlPlane resources
// by its managing controller.
Expand Down Expand Up @@ -77,6 +87,38 @@ type KubeadmControlPlaneSpec struct {
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
// +optional
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`

// The RolloutStrategy to use to replace control plane machines with
// new ones.
// +optional
RolloutStrategy *RolloutStrategy `json:"rolloutStrategy,omitempty"`
}

// RolloutStrategy describes how to replace existing machines
// with new ones.
type RolloutStrategy struct {
// Type of rollout. Currently the only supported strategy is
// "RollingUpdate".
// Default is RollingUpdate.
// +optional
Type RolloutStrategyType `json:"type,omitempty"`

// Rolling update config params. Present only if
// RolloutStrategyType = RollingUpdate.
// +optional
RollingUpdate *RollingUpdate `json:"rollingUpdate,omitempty"`
}

// RollingUpdate is used to control the desired behavior of rolling update.
type RollingUpdate struct {
// The maximum number of control planes that can be scheduled above or under the
// desired number of control planes.
// Value can be an absolute number 1 or 0.
// Defaults to 1.
// Example: when this is set to 1, the control plane can be scaled
// up immediately when the rolling update starts.
// +optional
MaxSurge *intstr.IntOrString `json:"maxSurge,omitempty"`
}

// KubeadmControlPlaneStatus defines the observed state of KubeadmControlPlane.
Expand Down
66 changes: 65 additions & 1 deletion controlplane/kubeadm/api/v1alpha3/zz_generated.conversion.go

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

46 changes: 46 additions & 0 deletions controlplane/kubeadm/api/v1alpha3/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,30 @@ spec:
This is a pointer to distinguish between explicit zero and not specified.
format: int32
type: integer
rolloutStrategy:
description: The RolloutStrategy to use to replace control plane machines
with new ones.
properties:
rollingUpdate:
description: Rolling update config params. Present only if RolloutStrategyType
= RollingUpdate.
properties:
maxSurge:
anyOf:
- type: integer
- type: string
description: 'The maximum number of control planes that can
be scheduled above or under the desired number of control
planes. Value can be an absolute number 1 or 0. Defaults
to 1. Example: when this is set to 1, the control plane
can be scaled up immediately when the rolling update starts.'
x-kubernetes-int-or-string: true
type: object
type:
description: Type of rollout. Currently the only supported strategy
is "RollingUpdate". Default is RollingUpdate.
type: string
type: object
upgradeAfter:
description: UpgradeAfter is a field to indicate an upgrade should
be performed after the specified time even if no changes have been
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/clusterctl_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg

framework.DumpAllResources(ctx, framework.DumpAllResourcesInput{
Lister: managementClusterProxy.GetClient(),
Namespace: managementClusterNamespace.Name,
Namespace: testNamespace.Name,
LogPath: filepath.Join(input.ArtifactFolder, "clusters", managementClusterResources.Cluster.Name, "resources"),
})

Expand Down

0 comments on commit 7084de3

Please sign in to comment.