Go version

go1.24-3b96eebcbd Wed Aug 7 16:07:33 2024 +0000 linux/amd64

Output of go env in your module/workspace:

[root@raji-x86-workspace1 kubernetes]# go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/root/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/root/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.24-3b96eebcbd Wed Aug 7 16:07:33 2024 +0000'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/root/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='0'
GOMOD='/root/kubernetes/go.mod'
GOWORK='/root/kubernetes/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3393143619=/tmp/go-build -gno-record-gcc-switches'
[root@raji-x86-workspace1 kubernetes]#

What did you do?

This piece of code in k8s UT is failing:

for i := int32(1); i <= collectionSize; i++ {
        pod, _ := newPod(t, fmt.Sprintf("quux %d", i))
        updatePodOwnerToRc(t, pod, rc)
        pods = append(pods, pod)
        pod.Labels = rcLabels
        if i <= unavailablePods {
            pod.Status.Conditions = []v1.PodCondition{}
        }
        add(t, dc.podStore, pod)
        dc.sync(ctx, pdbName)
        if i <= unavailablePods {
            ps.VerifyPdbStatus(t, pdbName, 0, 0, minimumOne, collectionSize, map[string]metav1.Time{})
        } else if i-unavailablePods <= minimumOne {
            ps.VerifyPdbStatus(t, pdbName, 0, i-unavailablePods, minimumOne, collectionSize, map[string]metav1.Time{})
        } else {
            ps.VerifyPdbStatus(t, pdbName, 1, i-unavailablePods, minimumOne, collectionSize, map[string]metav1.Time{})
        }
    }

Run k8s UT using golang after commit https://github.com/golang/go/commit/3b96eebcbdf472326b9d6e46c373992bac9f72bb

Setup golang version go1.24-3b96eebcbd Wed Aug 7 16:07:33 2024 +0000 linux/amd64 1. git clone https://github.com/kubernetes/kubernetes/ 2. cd kubernetes 3. go test k8s.io/kubernetes/pkg/controller/disruption

What did you see happen?

k8s.io/kubernetes/pkg/controller: disruption    6s
{Failed;  === RUN   TestTwoControllers
I0807 21:19:56.167621   55865 reflector.go:311] Stopping reflector *v1.PodDisruptionBudget (0s) from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.167346   55865 watch.go:195] Stopping fake watcher.
I0807 21:19:56.167646   55865 reflector.go:311] Stopping reflector *v1.StatefulSet (0s) from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.167382   55865 watch.go:195] Stopping fake watcher.
I0807 21:19:56.167763   55865 reflector.go:311] Stopping reflector *v1.ReplicaSet (0s) from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.167372   55865 watch.go:195] Stopping fake watcher.
I0807 21:19:56.167479   55865 watch.go:195] Stopping fake watcher.
I0807 21:19:56.167930   55865 reflector.go:311] Stopping reflector *v1.Pod (0s) from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.167821   55865 reflector.go:311] Stopping reflector *v1.ReplicationController (0s) from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.168066   55865 reflector.go:311] Stopping reflector *v1.Deployment (0s) from k8s.io/client-go/informers/factory.go:160
W0807 21:19:56.168961   55865 mutation_detector.go:53] Mutation detector is enabled, this will result in memory leakage.
W0807 21:19:56.169144   55865 mutation_detector.go:53] Mutation detector is enabled, this will result in memory leakage.
W0807 21:19:56.169272   55865 mutation_detector.go:53] Mutation detector is enabled, this will result in memory leakage.
W0807 21:19:56.169360   55865 mutation_detector.go:53] Mutation detector is enabled, this will result in memory leakage.
W0807 21:19:56.169464   55865 mutation_detector.go:53] Mutation detector is enabled, this will result in memory leakage.
W0807 21:19:56.169566   55865 mutation_detector.go:53] Mutation detector is enabled, this will result in memory leakage.
I0807 21:19:56.169893   55865 reflector.go:305] Starting reflector *v1.Pod (0s) from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.169955   55865 reflector.go:305] Starting reflector *v1.ReplicaSet (0s) from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.169990   55865 reflector.go:305] Starting reflector *v1.Deployment (0s) from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.170039   55865 reflector.go:305] Starting reflector *v1.PodDisruptionBudget (0s) from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.170001   55865 reflector.go:341] Listing and watching *v1.Pod from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.170062   55865 reflector.go:341] Listing and watching *v1.ReplicaSet from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.170118   55865 reflector.go:305] Starting reflector *v1.ReplicationController (0s) from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.170077   55865 reflector.go:341] Listing and watching *v1.Deployment from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.170274   55865 reflector.go:341] Listing and watching *v1.ReplicationController from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.170128   55865 reflector.go:341] Listing and watching *v1.PodDisruptionBudget from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.170496   55865 reflector.go:368] Caches populated for *v1.Deployment from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.170406   55865 reflector.go:368] Caches populated for *v1.Pod from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.170588   55865 reflector.go:368] Caches populated for *v1.ReplicaSet from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.170689   55865 reflector.go:368] Caches populated for *v1.ReplicationController from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.170867   55865 reflector.go:305] Starting reflector *v1.StatefulSet (0s) from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.170876   55865 reflector.go:368] Caches populated for *v1.PodDisruptionBudget from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.170961   55865 reflector.go:341] Listing and watching *v1.StatefulSet from k8s.io/client-go/informers/factory.go:160
I0807 21:19:56.171256   55865 reflector.go:368] Caches populated for *v1.StatefulSet from k8s.io/client-go/informers/factory.go:160
    disruption.go:691: I0807 21:19:56.271270] Finished syncing PodDisruptionBudget key="default/foobar" duration="0s"
    disruption.go:691: I0807 21:19:56.272519] Finished syncing PodDisruptionBudget key="default/foobar" duration="0s"
    disruption.go:691: I0807 21:19:56.273534] Finished syncing PodDisruptionBudget key="default/foobar" duration="0s"
    disruption.go:691: I0807 21:19:56.274572] Finished syncing PodDisruptionBudget key="default/foobar" duration="0s"
    disruption.go:691: I0807 21:19:56.275606] Finished syncing PodDisruptionBudget key="default/foobar" duration="0s"
    disruption.go:691: I0807 21:19:56.276701] Finished syncing PodDisruptionBudget key="default/foobar" duration="0s"
    disruption.go:691: I0807 21:19:56.277762] Finished syncing PodDisruptionBudget key="default/foobar" duration="0s"
    disruption.go:691: I0807 21:19:56.278884] Finished syncing PodDisruptionBudget key="default/foobar" duration="0s"
    disruption.go:691: I0807 21:19:56.279961] Finished syncing PodDisruptionBudget key="default/foobar" duration="0s"
    disruption.go:691: I0807 21:19:56.281018] Finished syncing PodDisruptionBudget key="default/foobar" duration="0s"
    disruption.go:691: I0807 21:19:56.282005] Finished syncing PodDisruptionBudget key="default/foobar" duration="0s"
    disruption.go:691: I0807 21:19:56.283015] Finished syncing PodDisruptionBudget key="default/foobar" duration="0s"
    disruption_test.go:957: PDB "default/foobar" status mismatch (-want,+got):
          v1.PodDisruptionBudgetStatus{
            ObservedGeneration: 0,
            DisruptedPods:      {},
        -   DisruptionsAllowed: 0,
        +   DisruptionsAllowed: 1,
            CurrentHealthy:     5,
            DesiredHealthy:     4,
            ... // 2 identical fields
          }
--- FAIL: TestTwoControllers (0.12s)
I0807 21:19:56.284874   55865 watch.go:195] Stopping fake watcher.
;}

What did you expect to see?

The test was PASSING before the commit https://github.com/golang/go/commit/3b96eebcbdf472326b9d6e46c373992bac9f72bb

Comment From: gabyhelp

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: seankhliao

cc @randall77

Comment From: randall77

Thanks for the bug.

Here's a simple reproducer:

package main

func main() {
    cnt := 0
    for i := int32(1); i <= 11; i++ {
        if i-6 > 4 {
            cnt++
        }
    }
    if cnt != 1 {
        panic("bad")
    }
}

Comment From: gopherbot

Change https://go.dev/cl/604100 mentions this issue: cmd/compile: fix off-by-one error in prove pass