mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 20:23:39 +09:00
build(kubernetes): run the tests of the packages the patches touch
The cluster-autoscaler and kubevirt-cloud-provider image builds ran go build only, and go build never compiles a _test.go, so nothing ran the tests of the code the patches change. Run go test in the builder stage on the packages the patches touch. The list is read from the patches themselves, so a new patch is covered without an edit to the Dockerfile. Both builder stages export GOOS and GOARCH for the target, so the tests unset them: a local make image builds amd64 and arm64 by default, and a test binary for the other architecture runs on the build host only under binfmt emulation. The first run of that step on cluster-autoscaler found the carried downscale patch out of step with the upstream tests it leaves in place: SetSize no longer refuses a size above maxSize, while one case of TestNodeGroupIncreaseSizeErrors still expected that refusal. The patch now drops that case, and carries a test for the downscale it is named for instead. DeleteNodes lowers a group one node at a time through SetSize, so with the refusal in place a group standing above its max size could not shed a node at all. The new test deletes a node from such a group and expects the replica count to drop; against the unpatched SetSize it fails with the refusal the patch removes. Scale-up past maxSize stays bounded by the core scale-up orchestrator, which skips a node group already at MaxSize. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <f@lex.la>
This commit is contained in:
3 files changed
+105
No files matched your search
@@ -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
|
||||
|
||||
@@ -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]
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user