Skip to content

Commit

Permalink
adding nutanix upgrade rollout strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
raymond-zhang00 committed Jan 17, 2024
1 parent 82d0a0a commit 04e35e3
Show file tree
Hide file tree
Showing 7 changed files with 592 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
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
34 changes: 34 additions & 0 deletions pkg/providers/nutanix/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,40 @@ func TestTemplateBuilder_CertSANs(t *testing.T) {
}
}

func TestNewNutanixTemplateBuilderRolloutStrategy(t *testing.T) {
dcConf, machineConf, workerConfs := minimalNutanixConfigSpec(t)

t.Setenv(constants.EksaNutanixUsernameKey, "admin")
t.Setenv(constants.EksaNutanixPasswordKey, "password")
creds := GetCredsFromEnv()
builder := NewNutanixTemplateBuilder(&dcConf.Spec, &machineConf.Spec, &machineConf.Spec, workerConfs, creds, time.Now)
assert.NotNil(t, builder)

buildSpec := test.NewFullClusterSpec(t, "testdata/eksa-cluster-rollout.yaml")

cpSpec, err := builder.GenerateCAPISpecControlPlane(buildSpec)
assert.NoError(t, err)
assert.NotNil(t, cpSpec)

expectedControlPlaneSpec, err := os.ReadFile("testdata/expected_results_rollout.yaml")
require.NoError(t, err)
assert.Equal(t, expectedControlPlaneSpec, cpSpec)

workloadTemplateNames := map[string]string{
"eksa-unit-test": "eksa-unit-test",
}
kubeadmconfigTemplateNames := map[string]string{
"eksa-unit-test": "eksa-unit-test",
}
workerSpec, err := builder.GenerateCAPISpecWorkers(buildSpec, workloadTemplateNames, kubeadmconfigTemplateNames)
assert.NoError(t, err)
assert.NotNil(t, workerSpec)

expectedWorkersSpec, err := os.ReadFile("testdata/expected_results_rollout_md.yaml")
require.NoError(t, err)
assert.Equal(t, expectedWorkersSpec, workerSpec)
}

func minimalNutanixConfigSpec(t *testing.T) (*anywherev1.NutanixDatacenterConfig, *anywherev1.NutanixMachineConfig, map[string]anywherev1.NutanixMachineConfigSpec) {
dcConf := &anywherev1.NutanixDatacenterConfig{}
err := yaml.Unmarshal([]byte(nutanixDatacenterConfigSpec), dcConf)
Expand Down
84 changes: 84 additions & 0 deletions pkg/providers/nutanix/testdata/eksa-cluster-rollout.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
kind: Cluster
metadata:
name: eksa-unit-test
namespace: default
spec:
kubernetesVersion: "1.19"
controlPlaneConfiguration:
name: eksa-unit-test
count: 3
endpoint:
host: test-ip
machineGroupRef:
name: eksa-unit-test
kind: NutanixMachineConfig
upgradeRolloutStrategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
workerNodeGroupConfigurations:
- count: 4
name: eksa-unit-test
machineGroupRef:
name: eksa-unit-test
kind: NutanixMachineConfig
upgradeRolloutStrategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
externalEtcdConfiguration:
name: eksa-unit-test
count: 3
machineGroupRef:
name: eksa-unit-test
kind: NutanixMachineConfig
datacenterRef:
kind: NutanixDatacenterConfig
name: eksa-unit-test
clusterNetwork:
cni: "cilium"
pods:
cidrBlocks:
- 192.168.0.0/16
services:
cidrBlocks:
- 10.96.0.0/12
---
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
kind: NutanixDatacenterConfig
metadata:
name: eksa-unit-test
namespace: default
spec:
endpoint: "prism.nutanix.com"
port: 9440
credentialRef:
kind: Secret
name: "nutanix-credentials"
---
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
kind: NutanixMachineConfig
metadata:
name: eksa-unit-test
namespace: default
spec:
vcpusPerSocket: 1
vcpuSockets: 4
memorySize: 8Gi
image:
type: "name"
name: "prism-image-1-19"
cluster:
type: "name"
name: "prism-cluster"
subnet:
type: "name"
name: "prism-subnet"
systemDiskSize: 40Gi
osFamily: "ubuntu"
users:
- name: "mySshUsername"
sshAuthorizedKeys:
- "mySshAuthorizedKey"
Loading

0 comments on commit 04e35e3

Please sign in to comment.