Skip to content

Commit bfb09ac

Browse files
authored
✨ Add scale from/to 0 support for CAPD (#12572)
* Add scale from 0 support for CAPD * Add devcluster template reconciler
1 parent 8334992 commit bfb09ac

23 files changed

+456
-43
lines changed

test/e2e/autoscaler.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,7 @@ func AutoscalerSpec(ctx context.Context, inputGetter func() AutoscalerSpecInput)
260260
By("Scaling the MachineDeployment scale up deployment to zero")
261261
framework.ScaleScaleUpDeploymentAndWait(ctx, framework.ScaleScaleUpDeploymentAndWaitInput{
262262
ClusterProxy: workloadClusterProxy,
263-
// We need to sum up the expected number of MachineDeployment replicas and the current
264-
// number of MachinePool replicas because otherwise the pods get scheduled on the MachinePool nodes.
265-
Replicas: mpOriginalReplicas + 0,
263+
Replicas: 0,
266264
}, input.E2EConfig.GetIntervals(specName, "wait-autoscaler")...)
267265

268266
By("Checking the MachineDeployment finished scaling down to zero")

test/e2e/autoscaler_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ var _ = Describe("When using the autoscaler with Cluster API using ClusterClass
3636
InfrastructureMachinePoolTemplateKind: "dockermachinepooltemplates",
3737
InfrastructureMachinePoolKind: "dockermachinepools",
3838
Flavor: ptr.To("topology-autoscaler"),
39-
AutoscalerVersion: "v1.33.0",
39+
AutoscalerVersion: "v1.32.1",
40+
ScaleToAndFromZero: true,
4041
}
4142
})
4243
})

test/e2e/config/docker.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ variables:
401401
CAPI_INSECURE_DIAGNOSTICS: "true"
402402

403403
intervals:
404-
default/wait-controllers: ["3m", "10s"]
404+
default/wait-controllers: ["4m", "10s"]
405405
default/wait-cluster: ["5m", "10s"]
406406
default/wait-control-plane: ["10m", "10s"]
407407
default/wait-worker-nodes: ["5m", "10s"]

test/e2e/data/autoscaler/autoscaler-to-workload-workload.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ spec:
198198
# Note: The E2E test should only go up to 4 (assuming it starts with a min node group size of 2).
199199
# Using 6 for additional some buffer and to allow different starting min node group sizes.
200200
- --max-nodes-total=6
201+
# Set the log verbosity
202+
- --v=4
201203
env:
202204
# Per default autoscaler uses the preferred apiVersion to retrieve MachineDeployments.
203205
# If that apiVersion is v1beta2 the current autoscaler implementation is not able
@@ -208,6 +210,13 @@ spec:
208210
- name: kubeconfig-management-cluster
209211
mountPath: /management-cluster
210212
readOnly: true
213+
# Run the autoscaler on control plane Machines to avoid disruptions when scaling to 0.
214+
nodeSelector:
215+
node-role.kubernetes.io/control-plane: ""
216+
tolerations:
217+
- key: node-role.kubernetes.io/control-plane
218+
effect: NoSchedule
219+
operator: Exists
211220
serviceAccountName: cluster-autoscaler
212221
terminationGracePeriodSeconds: 10
213222
volumes:

test/infrastructure/container/docker.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func NewDockerClient() (Runtime, error) {
6464
if err != nil {
6565
return nil, errors.Wrapf(err, "failed to created docker runtime client")
6666
}
67+
6768
return &dockerRuntime{
6869
dockerClient: dockerClient,
6970
}, nil
@@ -544,6 +545,11 @@ func (d *dockerRuntime) RunContainer(ctx context.Context, runConfig *RunContaine
544545
return nil
545546
}
546547

548+
// GetSystemInfo will return the docker system info.
549+
func (d *dockerRuntime) GetSystemInfo(ctx context.Context) (dockersystem.Info, error) {
550+
return d.dockerClient.Info(ctx)
551+
}
552+
547553
// needsDevMapper checks whether we need to mount /dev/mapper.
548554
// This is required when the docker storage driver is Btrfs or ZFS.
549555
// https://github.com/kubernetes-sigs/kind/pull/1464

test/infrastructure/container/fake.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package container
1919
import (
2020
"context"
2121
"io"
22+
23+
dockersystem "github.com/docker/docker/api/types/system"
2224
)
2325

2426
var runContainerCallLog []RunContainerArgs
@@ -170,3 +172,8 @@ func (f *FakeRuntime) RunContainerCalls() []RunContainerArgs {
170172
func (f *FakeRuntime) ResetRunContainerCallLogs() {
171173
runContainerCallLog = []RunContainerArgs{}
172174
}
175+
176+
// GetSystemInfo returns empty docker system info.
177+
func (f *FakeRuntime) GetSystemInfo(_ context.Context) (dockersystem.Info, error) {
178+
return dockersystem.Info{}, nil
179+
}

test/infrastructure/container/interface.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"net"
2424

2525
dockercontainer "github.com/docker/docker/api/types/container"
26+
dockersystem "github.com/docker/docker/api/types/system"
2627
"github.com/pkg/errors"
2728

2829
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
@@ -46,6 +47,7 @@ type Runtime interface {
4647
ContainerDebugInfo(ctx context.Context, containerName string, w io.Writer) error
4748
DeleteContainer(ctx context.Context, containerName string) error
4849
KillContainer(ctx context.Context, containerName, signal string) error
50+
GetSystemInfo(ctx context.Context) (dockersystem.Info, error)
4951
}
5052

5153
// Mount contains mount details.

test/infrastructure/docker/api/v1alpha3/conversion.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func (src *DockerMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
165165

166166
if ok {
167167
RestoreDockerMachineTemplateSpec(&restored.Spec, &dst.Spec)
168+
dst.Status = restored.Status
168169
}
169170

170171
return nil
@@ -350,3 +351,7 @@ func Convert_v1alpha3_DockerClusterSpec_To_v1beta2_DockerClusterSpec(in *DockerC
350351

351352
return nil
352353
}
354+
355+
func Convert_v1beta2_DockerMachineTemplate_To_v1alpha3_DockerMachineTemplate(in *infrav1.DockerMachineTemplate, out *DockerMachineTemplate, s apiconversion.Scope) error {
356+
return autoConvert_v1beta2_DockerMachineTemplate_To_v1alpha3_DockerMachineTemplate(in, out, s)
357+
}

test/infrastructure/docker/api/v1alpha3/zz_generated.conversion.go

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/infrastructure/docker/api/v1alpha4/conversion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func (src *DockerMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
196196

197197
if ok {
198198
RestoreDockerMachineTemplateSpec(&restored.Spec, &dst.Spec)
199+
dst.Status = restored.Status
199200
}
200201

201202
return nil

0 commit comments

Comments
 (0)