Skip to content
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
7 changes: 4 additions & 3 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package e2e

import (
"context"
"fmt"
"net/http"
"runtime"
"strings"
Expand Down Expand Up @@ -228,6 +227,7 @@ func TestE2E(t *testing.T) {
cleanupService := createServiceAndWait(t, ctx, e2e.client, tc.svc, 1)
defer cleanupPod()
defer cleanupService()
probeHTTP(t, e2e.url())

if tc.waitScaledDown {
waitUntilScaledDown(t, ctx, e2e.client, tc.pod)
Expand All @@ -251,7 +251,7 @@ func TestE2E(t *testing.T) {
c.Transport = &http.Transport{DisableKeepAlives: !tc.keepAlive}

before := time.Now()
resp, err := c.Get(fmt.Sprintf("http://127.0.0.1:%d", e2e.port))
resp, err := c.Get(e2e.url())
if err != nil {
t.Error(err)
return
Expand Down Expand Up @@ -372,11 +372,12 @@ func TestE2E(t *testing.T) {
cleanupService := createServiceAndWait(t, ctx, e2e.client, testService(8080), 1)
defer cleanupPod()
defer cleanupService()
probeHTTP(t, e2e.url())
// we expect it to scale down even though a constant livenessProbe is
// hitting it
waitUntilScaledDown(t, ctx, e2e.client, pod)
// make a real request and expect it to scale down again
resp, err := c.Get(fmt.Sprintf("http://127.0.0.1:%d", e2e.port))
resp, err := c.Get(e2e.url())
require.NoError(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
waitUntilScaledDown(t, ctx, e2e.client, pod)
Expand Down
1 change: 1 addition & 0 deletions e2e/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func TestMigration(t *testing.T) {
cleanupService := createServiceAndWait(t, ctx, e2e.client, tc.svc, 1)
defer cleanupPod()
defer cleanupService()
probeHTTP(t, e2e.url())

for range tc.migrationCount {
tc.beforeMigration(t)
Expand Down
37 changes: 28 additions & 9 deletions e2e/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func (e2e *e2eConfig) cleanup() error {
return os.RemoveAll(e2e.kubeconfigName)
}

func (e2e *e2eConfig) url() string {
return fmt.Sprintf("http://127.0.0.1:%d", e2e.port)
}

var images = []image{
{
tag: installerImage,
Expand Down Expand Up @@ -670,9 +674,6 @@ func waitForService(t testing.TB, ctx context.Context, c client.Client, svc *cor
printContainerdLogs(t, "zeropod-e2e-worker", "zeropod-e2e-worker2")
}
}
// we give it some more time before returning just to make sure it's
// really ready to receive requests.
time.Sleep(time.Millisecond * 500)
}

func endpointsReady(endpoints []discoveryv1.Endpoint) bool {
Expand All @@ -685,6 +686,20 @@ func endpointsReady(endpoints []discoveryv1.Endpoint) bool {
return ready == len(endpoints)
}

func probeHTTP(t testing.TB, addr string) {
c := &http.Client{
Timeout: time.Second * 1,
}
assert.Eventually(t, func() bool {
resp, err := c.Get(addr)
if err != nil {
return false
}
resp.Body.Close()
return true
}, time.Second*10, time.Millisecond*100)
}

func cordonNode(t testing.TB, ctx context.Context, client client.Client, name string) (uncordon func()) {
node := &corev1.Node{ObjectMeta: metav1.ObjectMeta{Name: name}}
assert.NoError(t, retry.RetryOnConflict(retry.DefaultRetry, func() error {
Expand Down Expand Up @@ -801,12 +816,16 @@ func restoreCount(t testing.TB, ctx context.Context, client client.Client, cfg *
}

func waitUntilScaledDown(t testing.TB, ctx context.Context, c client.Client, pod *corev1.Pod) {
for _, container := range pod.Spec.Containers {
require.Eventually(t, func() bool {
ok, err := isScaledDown(ctx, c, pod, container.Name)
t.Logf("scaled down: %v: %s", ok, pod.GetLabels()[path.Join(manager.StatusLabelKeyPrefix, container.Name)])
return err == nil && ok
}, time.Second*15, time.Second)
// we loop to ensure it is stable in scaled down state
for range 3 {
for _, container := range pod.Spec.Containers {
require.Eventually(t, func() bool {
ok, err := isScaledDown(ctx, c, pod, container.Name)
t.Logf("scaled down: %v: %s", ok, pod.GetLabels()[path.Join(manager.StatusLabelKeyPrefix, container.Name)])
return err == nil && ok
}, time.Second*15, time.Second)
}
time.Sleep(time.Second)
}
}

Expand Down
37 changes: 18 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ require (
github.com/prometheus/client_model v0.6.1
github.com/prometheus/common v0.62.0
github.com/prometheus/procfs v0.15.1
github.com/stretchr/testify v1.10.0
github.com/stretchr/testify v1.11.1
github.com/vishvananda/netlink v1.3.1
golang.org/x/sys v0.38.0
google.golang.org/protobuf v1.36.7
golang.org/x/sys v0.43.0
google.golang.org/protobuf v1.36.10
k8s.io/api v0.34.0
k8s.io/apimachinery v0.34.0
k8s.io/client-go v0.34.0
k8s.io/cri-api v0.34.0
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397
sigs.k8s.io/controller-runtime v0.20.0
sigs.k8s.io/controller-tools v0.19.0
sigs.k8s.io/kind v0.27.0
sigs.k8s.io/kind v0.31.0
sigs.k8s.io/kustomize/api v0.16.0
sigs.k8s.io/kustomize/kyaml v0.16.0
)
Expand Down Expand Up @@ -86,7 +86,6 @@ require (
github.com/google/btree v1.1.3 // indirect
github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
Expand All @@ -104,7 +103,7 @@ require (
github.com/mikelolasagasti/xz v1.0.1 // indirect
github.com/minio/minlz v1.0.1 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/spdystream v0.5.0 // indirect
github.com/moby/spdystream v0.5.1 // indirect
github.com/moby/sys/mountinfo v0.7.2 // indirect
github.com/moby/sys/sequential v0.6.0 // indirect
github.com/moby/sys/signal v0.7.1 // indirect
Expand All @@ -131,26 +130,26 @@ require (
github.com/x448/float16 v0.8.4 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect
go.opentelemetry.io/otel v1.35.0 // indirect
go.opentelemetry.io/otel/metric v1.35.0 // indirect
go.opentelemetry.io/otel/trace v1.35.0 // indirect
go.opentelemetry.io/otel v1.39.0 // indirect
go.opentelemetry.io/otel/metric v1.39.0 // indirect
go.opentelemetry.io/otel/trace v1.39.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
golang.org/x/mod v0.29.0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/oauth2 v0.28.0 // indirect
golang.org/x/sync v0.18.0 // indirect
golang.org/x/term v0.37.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/mod v0.30.0 // indirect
golang.org/x/net v0.48.0 // indirect
golang.org/x/oauth2 v0.34.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/term v0.38.0 // indirect
golang.org/x/text v0.32.0 // indirect
golang.org/x/time v0.9.0 // indirect
golang.org/x/tools v0.38.0 // indirect
golang.org/x/tools v0.39.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250324211829-b45e905df463 // indirect
google.golang.org/grpc v1.72.2 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect
google.golang.org/grpc v1.79.3 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/evanphx/json-patch.v5 v5.6.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
Loading
Loading