Skip to content

Commit

Permalink
refactoring upgrade rollout strategy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raymond-zhang00 committed Jan 18, 2024
1 parent 959a1f7 commit b79b377
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 409 deletions.
27 changes: 27 additions & 0 deletions pkg/providers/docker/controlplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,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"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta1"
Expand Down Expand Up @@ -271,6 +272,32 @@ func TestControlPlaneSpecRegistryMirrorConfiguration(t *testing.T) {
}
}

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

cp, err := docker.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 testClusterSpec(opts ...test.ClusterSpecOpt) *cluster.Spec {
name := "test"
namespace := "test-namespace"
Expand Down
32 changes: 0 additions & 32 deletions pkg/providers/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,38 +327,6 @@ func TestProviderGenerateDeploymentFileSuccessUpdateMachineTemplate(t *testing.T
wantCPFile: "testdata/valid_deployment_cp_expected.yaml",
wantMDFile: "testdata/valid_autoscaler_deployment_md_expected.yaml",
},
{
testName: "valid config with rollout",
clusterSpec: test.NewClusterSpec(func(s *cluster.Spec) {
s.Cluster.Name = "test-cluster"
s.Cluster.Spec.KubernetesVersion = "1.19"
s.Cluster.Spec.ClusterNetwork.Pods.CidrBlocks = []string{"192.168.0.0/16"}
s.Cluster.Spec.ClusterNetwork.Services.CidrBlocks = []string{"10.128.0.0/12"}
s.Cluster.Spec.ControlPlaneConfiguration.Count = 3
s.Cluster.Spec.ControlPlaneConfiguration.UpgradeRolloutStrategy = &v1alpha1.ControlPlaneUpgradeRolloutStrategy{
Type: "RollingUpdate",
RollingUpdate: v1alpha1.ControlPlaneRollingUpdateParams{
MaxSurge: 1,
},
}
s.VersionsBundles["1.19"] = versionsBundle
s.Cluster.Spec.ExternalEtcdConfiguration = &v1alpha1.ExternalEtcdConfiguration{Count: 3}
s.Cluster.Spec.WorkerNodeGroupConfigurations = []v1alpha1.WorkerNodeGroupConfiguration{{
Count: ptr.Int(3),
MachineGroupRef: &v1alpha1.Ref{Name: "test-cluster"},
Name: "md-0",
UpgradeRolloutStrategy: &v1alpha1.WorkerNodesUpgradeRolloutStrategy{
Type: "RollingUpdate",
RollingUpdate: v1alpha1.WorkerNodesRollingUpdateParams{
MaxSurge: 1,
MaxUnavailable: 0,
},
},
}}
}),
wantCPFile: "testdata/valid_deployment_cp_rollout_expected.yaml",
wantMDFile: "testdata/valid_deployment_md_rollout_expected.yaml",
},
}

for _, tt := range tests {
Expand Down

This file was deleted.

Loading

0 comments on commit b79b377

Please sign in to comment.