Skip to content

Commit

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

* refactor nutanix upgrade rollout strategy tests
  • Loading branch information
raymond-zhang00 authored Jan 19, 2024
1 parent 66db899 commit 003a554
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/providers/nutanix/config/cp-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ spec:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: NutanixMachineTemplate
name: "{{.controlPlaneTemplateName}}"
{{- if .upgradeRolloutStrategy }}
rolloutStrategy:
rollingUpdate:
maxSurge: {{.maxSurge}}
{{- end }}
kubeadmConfigSpec:
clusterConfiguration:
imageRepository: "{{.kubernetesRepository}}"
Expand Down
6 changes: 6 additions & 0 deletions pkg/providers/nutanix/config/md-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ spec:
kind: NutanixMachineTemplate
name: "{{.workloadTemplateName}}"
version: "{{.kubernetesVersion}}"
{{- if .upgradeRolloutStrategy }}
strategy:
rollingUpdate:
maxSurge: {{.maxSurge}}
maxUnavailable: {{.maxUnavailable}}
{{- end }}
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: NutanixMachineTemplate
Expand Down
18 changes: 18 additions & 0 deletions pkg/providers/nutanix/controlplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/aws/eks-anywhere/internal/test"
"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/constants"
)

Expand All @@ -20,3 +21,20 @@ func TestControlPlaneSpec(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, cp)
}

func TestControlPlaneSpecWithUpgradeRolloutStrategy(t *testing.T) {
t.Setenv(constants.EksaNutanixUsernameKey, "admin")
t.Setenv(constants.EksaNutanixPasswordKey, "password")
logger := test.NewNullLogger()
client := test.NewFakeKubeClient()
spec := test.NewFullClusterSpec(t, "testdata/eksa-cluster.yaml")
spec.Cluster.Spec.ControlPlaneConfiguration.UpgradeRolloutStrategy = &v1alpha1.ControlPlaneUpgradeRolloutStrategy{
RollingUpdate: v1alpha1.ControlPlaneRollingUpdateParams{
MaxSurge: 1,
},
}
cp, err := ControlPlaneSpec(context.TODO(), logger, client, spec)
assert.NoError(t, err)
assert.NotNil(t, cp)
assert.Equal(t, int32(1), cp.KubeadmControlPlane.Spec.RolloutStrategy.RollingUpdate.MaxSurge.IntVal)
}
11 changes: 11 additions & 0 deletions pkg/providers/nutanix/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ func (ntb *TemplateBuilder) GenerateCAPISpecWorkers(clusterSpec *cluster.Spec, w
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
}

bytes, err := templater.Execute(defaultClusterConfigMD, values)
if err != nil {
return nil, err
Expand Down Expand Up @@ -259,6 +265,11 @@ func buildTemplateMapCP(
values["additionalCategories"] = controlPlaneMachineSpec.AdditionalCategories
}

if clusterSpec.Cluster.Spec.ControlPlaneConfiguration.UpgradeRolloutStrategy != nil {
values["upgradeRolloutStrategy"] = true
values["maxSurge"] = clusterSpec.Cluster.Spec.ControlPlaneConfiguration.UpgradeRolloutStrategy.RollingUpdate.MaxSurge
}

return values, nil
}

Expand Down
31 changes: 31 additions & 0 deletions pkg/providers/nutanix/workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"github.com/stretchr/testify/require"

"github.com/aws/eks-anywhere/internal/test"
"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/constants"
"github.com/aws/eks-anywhere/pkg/utils/ptr"
)

func TestWorkersSpec(t *testing.T) {
Expand All @@ -22,3 +24,32 @@ func TestWorkersSpec(t *testing.T) {
require.NoError(t, err)
assert.Len(t, workers.Groups, 2)
}

func TestWorkersSpecWithUpgradeRolloutStrategy(t *testing.T) {
t.Setenv(constants.EksaNutanixUsernameKey, "admin")
t.Setenv(constants.EksaNutanixPasswordKey, "password")

logger := test.NewNullLogger()
client := test.NewFakeKubeClient()
spec := test.NewFullClusterSpec(t, "testdata/eksa-cluster.yaml")
spec.Cluster.Spec.WorkerNodeGroupConfigurations = []v1alpha1.WorkerNodeGroupConfiguration{
{
Count: ptr.Int(4),
MachineGroupRef: &v1alpha1.Ref{
Name: "eksa-unit-test",
},
Name: "eksa-unit-test",
UpgradeRolloutStrategy: &v1alpha1.WorkerNodesUpgradeRolloutStrategy{
RollingUpdate: v1alpha1.WorkerNodesRollingUpdateParams{
MaxSurge: 1,
MaxUnavailable: 0,
},
},
},
}
workers, err := WorkersSpec(context.TODO(), logger, client, spec)
require.NoError(t, err)
assert.Len(t, workers.Groups, 1)
assert.Equal(t, int32(1), workers.Groups[0].MachineDeployment.Spec.Strategy.RollingUpdate.MaxSurge.IntVal)
assert.Equal(t, int32(0), workers.Groups[0].MachineDeployment.Spec.Strategy.RollingUpdate.MaxUnavailable.IntVal)
}

0 comments on commit 003a554

Please sign in to comment.