Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding docker upgrade rollout strategy #7315

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/providers/docker/config/template-cp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ spec:
- systemctl restart containerd
{{- end }}
replicas: {{.control_plane_replicas}}
{{- if .upgradeRolloutStrategy }}
rolloutStrategy:
rollingUpdate:
maxSurge: {{.maxSurge}}
{{- end }}
version: {{.kubernetesVersion}}
{{- if .externalEtcd }}
---
Expand Down
6 changes: 6 additions & 0 deletions pkg/providers/docker/config/template-md.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ spec:
name: {{.workloadTemplateName}}
namespace: {{.eksaSystemNamespace}}
version: {{.kubernetesVersion}}
{{- if .upgradeRolloutStrategy }}
strategy:
rollingUpdate:
maxSurge: {{.maxSurge}}
maxUnavailable: {{.maxUnavailable}}
{{- end }}
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
Expand Down
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
11 changes: 11 additions & 0 deletions pkg/providers/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ func (d *DockerTemplateBuilder) GenerateCAPISpecWorkers(clusterSpec *cluster.Spe
values["workloadTemplateName"] = workloadTemplateNames[workerNodeGroupConfiguration.Name]
values["workloadkubeadmconfigTemplateName"] = kubeadmconfigTemplateNames[workerNodeGroupConfiguration.Name]

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

bytes, err := templater.Execute(defaultCAPIConfigMD, values)
if err != nil {
return nil, err
Expand Down Expand Up @@ -316,6 +322,11 @@ func buildTemplateMapCP(clusterSpec *cluster.Spec) (map[string]interface{}, erro
}
}

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

return values, nil
}

Expand Down
45 changes: 45 additions & 0 deletions pkg/providers/docker/workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ 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"
dockerv1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1beta1"

"github.com/aws/eks-anywhere/internal/test"
anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/clients/kubernetes"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/clusterapi"
"github.com/aws/eks-anywhere/pkg/controller/clientutil"
"github.com/aws/eks-anywhere/pkg/providers/docker"
Expand Down Expand Up @@ -334,6 +336,49 @@ func TestWorkersSpecRegistryMirrorConfiguration(t *testing.T) {
}
}

func TestWorkersSpecUpgradeRolloutStrategy(t *testing.T) {
g := NewWithT(t)
logger := test.NewNullLogger()
ctx := context.Background()
spec := testClusterSpec(func(s *cluster.Spec) {
s.Cluster.Spec.WorkerNodeGroupConfigurations = []anywherev1.WorkerNodeGroupConfiguration{
{
Count: ptr.Int(3),
MachineGroupRef: &anywherev1.Ref{Name: "test"},
Name: "md-0",
UpgradeRolloutStrategy: &anywherev1.WorkerNodesUpgradeRolloutStrategy{
RollingUpdate: anywherev1.WorkerNodesRollingUpdateParams{
MaxSurge: 1,
MaxUnavailable: 0,
},
},
},
}
})
client := test.NewFakeKubeClient()

workers, err := docker.WorkersSpec(ctx, logger, client, spec)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(workers).NotTo(BeNil())
g.Expect(workers.Groups).To(HaveLen(1))
g.Expect(workers.Groups).To(ConsistOf(
clusterapi.WorkerGroup[*dockerv1.DockerMachineTemplate]{
KubeadmConfigTemplate: kubeadmConfigTemplate(),
MachineDeployment: machineDeployment(func(m *clusterv1.MachineDeployment) {
maxSurge := intstr.FromInt(1)
maxUnavailable := intstr.FromInt(0)
m.Spec.Strategy = &clusterv1.MachineDeploymentStrategy{
RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{
MaxSurge: &maxSurge,
MaxUnavailable: &maxUnavailable,
},
}
}),
ProviderMachineTemplate: dockerMachineTemplate("test-md-0-1"),
},
))
}

func kubeadmConfigTemplate(opts ...func(*bootstrapv1.KubeadmConfigTemplate)) *bootstrapv1.KubeadmConfigTemplate {
o := &bootstrapv1.KubeadmConfigTemplate{
TypeMeta: metav1.TypeMeta{
Expand Down