Skip to content

Commit

Permalink
adding cloudstack upgrade rollout strategy (#7314)
Browse files Browse the repository at this point in the history
* adding cloudstack upgrade rollout strategy

* refactoring cloudstack upgrade rollout strategy tests
  • Loading branch information
raymond-zhang00 authored Jan 19, 2024
1 parent 1c57520 commit 55a883c
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 746 deletions.
12 changes: 0 additions & 12 deletions pkg/providers/cloudstack/cloudstack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,6 @@ func TestProviderGenerateCAPISpecForCreate(t *testing.T) {
wantCPFile: "testdata/expected_results_main_cp.yaml",
wantMDFile: "testdata/expected_results_main_md.yaml",
},
{
testName: "main with rollout strategies",
clusterconfigFile: "cluster_main_with_rollout_strategy.yaml",
wantCPFile: "testdata/expected_results_main_rollout_strategy_cp.yaml",
wantMDFile: "testdata/expected_results_main_rollout_strategy_md.yaml",
},
}
for _, tt := range tests {
t.Run(tt.testName, func(t *testing.T) {
Expand Down Expand Up @@ -1251,12 +1245,6 @@ func TestProviderGenerateCAPISpecForUpgradeUpdateMachineTemplateExternalEtcd(t *
wantCPFile: "testdata/expected_results_main_cp.yaml",
wantMDFile: "testdata/expected_results_main_node_labels_md.yaml",
},
{
testName: "main with rollout strategies",
clusterconfigFile: "cluster_main_with_rollout_strategy.yaml",
wantCPFile: "testdata/expected_results_main_rollout_strategy_cp.yaml",
wantMDFile: "testdata/expected_results_main_rollout_strategy_md.yaml",
},
{
testName: "main with cp node labels",
clusterconfigFile: "cluster_main_with_cp_node_labels.yaml",
Expand Down
8 changes: 4 additions & 4 deletions pkg/providers/cloudstack/config/template-md.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ spec:
name: {{.workloadTemplateName}}
version: {{.kubernetesVersion}}
{{- if .upgradeRolloutStrategy }}
strategy:
rollingUpdate:
maxSurge: {{.maxSurge}}
maxUnavailable: {{.maxUnavailable}}
strategy:
rollingUpdate:
maxSurge: {{.maxSurge}}
maxUnavailable: {{.maxUnavailable}}
{{- end }}
26 changes: 26 additions & 0 deletions pkg/providers/cloudstack/controlplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
cloudstackv1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta3"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
Expand Down Expand Up @@ -182,6 +183,31 @@ func TestControlPlaneSpecRegistryMirrorConfiguration(t *testing.T) {
}
}

func TestControlPlaneSpecWithUpgradeRolloutStrategy(t *testing.T) {
g := NewWithT(t)
logger := test.NewNullLogger()
ctx := context.Background()
client := test.NewFakeKubeClient()
spec := test.NewFullClusterSpec(t, testClusterConfigFilename)
spec.Cluster.Spec.ControlPlaneConfiguration.UpgradeRolloutStrategy = &anywherev1.ControlPlaneUpgradeRolloutStrategy{
RollingUpdate: anywherev1.ControlPlaneRollingUpdateParams{
MaxSurge: 1,
},
}

cp, err := ControlPlaneSpec(ctx, logger, client, spec)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(cp).NotTo(BeNil())
g.Expect(cp.KubeadmControlPlane).To(Equal(kubeadmControlPlane(func(k *controlplanev1.KubeadmControlPlane) {
maxSurge := intstr.FromInt(1)
k.Spec.RolloutStrategy = &controlplanev1.RolloutStrategy{
RollingUpdate: &controlplanev1.RollingUpdate{
MaxSurge: &maxSurge,
},
}
})))
}

func capiCluster() *clusterv1.Cluster {
return &clusterv1.Cluster{
TypeMeta: metav1.TypeMeta{
Expand Down
12 changes: 6 additions & 6 deletions pkg/providers/cloudstack/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ func (cs *TemplateBuilder) GenerateCAPISpecWorkers(clusterSpec *cluster.Spec, wo
values["workloadkubeadmconfigTemplateName"] = kubeadmconfigTemplateNames[workerNodeGroupConfiguration.Name]
values["autoscalingConfig"] = workerNodeGroupConfiguration.AutoScalingConfiguration

if workerNodeGroupConfiguration.UpgradeRolloutStrategy != nil {
values["upgradeRolloutStrategy"] = true
values["maxSurge"] = workerNodeGroupConfiguration.UpgradeRolloutStrategy.RollingUpdate.MaxSurge
values["maxUnavailable"] = workerNodeGroupConfiguration.UpgradeRolloutStrategy.RollingUpdate.MaxUnavailable
}

// TODO: Extract out worker MachineDeployments from templates to use apibuilder instead
bytes, err := templater.Execute(defaultClusterConfigMD, values)
if err != nil {
Expand Down Expand Up @@ -378,12 +384,6 @@ func buildTemplateMapMD(clusterSpec *cluster.Spec, workerNodeGroupConfiguration
fillProxyConfigurations(values, clusterSpec, endpoint)
}

if workerNodeGroupConfiguration.UpgradeRolloutStrategy != nil {
values["upgradeRolloutStrategy"] = true
values["maxSurge"] = workerNodeGroupConfiguration.UpgradeRolloutStrategy.RollingUpdate.MaxSurge
values["maxUnavailable"] = workerNodeGroupConfiguration.UpgradeRolloutStrategy.RollingUpdate.MaxUnavailable
}

return values, nil
}

Expand Down

This file was deleted.

Loading

0 comments on commit 55a883c

Please sign in to comment.