diff --git a/packages/apps/kubernetes/images/cluster-autoscaler/Dockerfile b/packages/apps/kubernetes/images/cluster-autoscaler/Dockerfile index e1303bc05..f93388996 100644 --- a/packages/apps/kubernetes/images/cluster-autoscaler/Dockerfile +++ b/packages/apps/kubernetes/images/cluster-autoscaler/Dockerfile @@ -16,6 +16,22 @@ RUN git clone https://github.com/kubernetes/autoscaler /src/autoscaler \ WORKDIR /src/autoscaler/cluster-autoscaler COPY fix-downscale.diff /fix-downscale.diff RUN git apply /fix-downscale.diff + +# go build never compiles a _test.go, so nothing else runs the tests of the +# packages the patch touches. Each package is tested from its own directory, +# below the clone root because the patch names paths from there: that finds +# the module it belongs to, and an empty list runs nothing. +# The list is read into a variable first: a for loop drops the exit status +# of a command substitution, so a patch git cannot read would leave the list +# empty and the step green. +# The stage sets GOOS and GOARCH to the target for the whole stage, so the +# tests drop them: a test binary built for another architecture cannot run +# on the build host without emulation. +RUN cd /src/autoscaler && files=$(git apply --numstat /fix-downscale.diff) || exit 1; \ + for dir in $(printf '%s\n' "$files" | cut -f3 | grep '\.go$' | xargs -r -n1 dirname | sort -u); do \ + (cd "$dir" && env -u GOOS -u GOARCH go test .) || exit 1; \ + done + RUN make build FROM $BASEIMAGE diff --git a/packages/apps/kubernetes/images/cluster-autoscaler/fix-downscale.diff b/packages/apps/kubernetes/images/cluster-autoscaler/fix-downscale.diff index 94c680bc1..fc276b1e1 100644 --- a/packages/apps/kubernetes/images/cluster-autoscaler/fix-downscale.diff +++ b/packages/apps/kubernetes/images/cluster-autoscaler/fix-downscale.diff @@ -11,3 +11,78 @@ index 4eec0e4bf..f28fd9241 100644 case nreplicas < r.minSize: return fmt.Errorf("size decrease too large - desired:%d min:%d", nreplicas, r.minSize) } +diff --git a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_nodegroup_test.go b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_nodegroup_test.go +--- a/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_nodegroup_test.go ++++ b/cluster-autoscaler/cloudprovider/clusterapi/clusterapi_nodegroup_test.go +@@ -241,11 +241,6 @@ + delta: -1, + initial: 3, + errorMsg: "size increase must be positive", +- }, { +- description: "errors because initial+delta > maxSize", +- delta: 8, +- initial: 3, +- errorMsg: "size increase too large - desired:11 max:10", + }} + + test := func(t *testing.T, tc *testCase, testConfig *testConfig) { +@@ -767,7 +762,59 @@ + ) + }) + } ++ ++// A group can stand above its max size, for one when the annotation is ++// lowered under it, and deleting a node from it must not be refused as an ++// increase. ++func TestNodeGroupDeleteNodesAboveMaxSize(t *testing.T) { ++ test := func(t *testing.T, testConfig *testConfig) { ++ controller, stop := mustCreateTestController(t, testConfig) ++ defer stop() ++ ++ nodegroups, err := controller.nodeGroups() ++ if err != nil { ++ t.Fatalf("unexpected error: %v", err) ++ } + ++ if l := len(nodegroups); l != 1 { ++ t.Fatalf("expected 1 nodegroup, got %d", l) ++ } ++ ++ ng := nodegroups[0].(*nodegroup) ++ if err := ng.DeleteNodes(testConfig.nodes[:1]); err != nil { ++ t.Fatalf("unexpected error: %v", err) ++ } ++ ++ gvr, err := ng.scalableResource.GroupVersionResource() ++ if err != nil { ++ t.Fatalf("unexpected error: %v", err) ++ } ++ ++ scalableResource, err := ng.machineController.managementScaleClient.Scales(testConfig.spec.namespace). ++ Get(context.TODO(), gvr.GroupResource(), ng.scalableResource.Name(), metav1.GetOptions{}) ++ if err != nil { ++ t.Fatalf("unexpected error: %v", err) ++ } ++ ++ if scalableResource.Spec.Replicas != 3 { ++ t.Errorf("expected 3, got %v", scalableResource.Spec.Replicas) ++ } ++ } ++ ++ annotations := map[string]string{ ++ nodeGroupMinSizeAnnotationKey: "1", ++ nodeGroupMaxSizeAnnotationKey: "2", ++ } ++ ++ t.Run("MachineSet", func(t *testing.T) { ++ test(t, createMachineSetTestConfig(RandomString(6), RandomString(6), RandomString(6), 4, annotations, nil)) ++ }) ++ ++ t.Run("MachineDeployment", func(t *testing.T) { ++ test(t, createMachineDeploymentTestConfig(RandomString(6), RandomString(6), RandomString(6), 4, annotations, nil)) ++ }) ++} ++ + func TestNodeGroupMachineSetDeleteNodesWithMismatchedNodes(t *testing.T) { + test := func(t *testing.T, expected int, testConfigs []*testConfig) { + testConfig0, testConfig1 := testConfigs[0], testConfigs[1] diff --git a/packages/apps/kubernetes/images/kubevirt-cloud-provider/Dockerfile b/packages/apps/kubernetes/images/kubevirt-cloud-provider/Dockerfile index d92f9dffc..971feccc4 100644 --- a/packages/apps/kubernetes/images/kubevirt-cloud-provider/Dockerfile +++ b/packages/apps/kubernetes/images/kubevirt-cloud-provider/Dockerfile @@ -19,6 +19,20 @@ RUN go get 'k8s.io/endpointslice/util@v0.28' 'k8s.io/apiserver@v0.28' RUN go mod tidy RUN go mod vendor +# go build never compiles a _test.go, so nothing else runs the tests of the +# packages the patches touch. Each package is tested from its own directory: +# that finds the module it belongs to, and an empty list runs nothing. +# The list is read into a variable first: a for loop drops the exit status +# of a command substitution, so a patch git cannot read would leave the list +# empty and the step green. +# The stage sets GOOS and GOARCH to the target for the whole stage, so the +# tests drop them: a test binary built for another architecture cannot run +# on the build host without emulation. +RUN files=$(git apply --numstat /patches/*.diff) || exit 1; \ + for dir in $(printf '%s\n' "$files" | cut -f3 | grep '\.go$' | xargs -r -n1 dirname | sort -u); do \ + (cd "$dir" && env -u GOOS -u GOARCH go test -mod=vendor .) || exit 1; \ + done + RUN CGO_ENABLED=0 go build -mod=vendor -ldflags="-s -w" -o bin/kubevirt-cloud-controller-manager ./cmd/kubevirt-cloud-controller-manager FROM scratch