e2e registry: have SetupRegistry() return registry address

This commit is contained in:
Stanislav Láznička
2025-10-09 14:22:46 +02:00
committed by Stanislav Láznička
parent ee777bef91
commit 135b46974a
3 changed files with 21 additions and 21 deletions

View File

@@ -19,7 +19,6 @@ package node
import (
"context"
"fmt"
"net"
"os"
"path"
"time"
@@ -260,15 +259,16 @@ while true; do sleep 1; done
})
framework.Context("when running a container with a new image", framework.WithSerial(), func() {
var registrySetup bool
registryAddress := net.JoinHostPort("localhost", "5000")
var registryAddress string
ginkgo.BeforeEach(func(ctx context.Context) {
_, err := e2eregistry.SetupRegistry(ctx, f, false)
var err error
registryAddress, _, err = e2eregistry.SetupRegistry(ctx, f, false)
framework.ExpectNoError(err)
})
ginkgo.AfterEach(func(ctx context.Context) {
if !registrySetup {
if len(registryAddress) == 0 {
return
}
f.DeleteNamespace(ctx, f.Namespace.Name) // we need to wait for the registry to be removed and so we need to delete the whole NS early (before the actual cleanup)

View File

@@ -56,17 +56,18 @@ const (
// the Node Conformance test suite).
//
// This function returns:
// - the node-local address of the registry
// - set of node names that the registry runs on, mostly useful only in the podOnly case
// - an error
//
// TODO: once https://github.com/kubernetes/kubernetes/issues/132955 is
// addressed, we might be able to proxy a single endpoint from the cluster to each
// node's localhost port instead of using DaemonSets.
func SetupRegistry(ctx context.Context, f *framework.Framework, podOnly bool) ([]string, error) {
func SetupRegistry(ctx context.Context, f *framework.Framework, podOnly bool) (string, []string, error) {
podTestLabel := "test-registry-pod-" + f.UniqueName
pod, err := podManifest(podTestLabel)
if err != nil {
return nil, err
return "", nil, err
}
if podOnly {
@@ -81,31 +82,31 @@ func SetupRegistry(ctx context.Context, f *framework.Framework, podOnly bool) ([
daemonset, err = f.ClientSet.AppsV1().DaemonSets(f.Namespace.Name).Create(ctx, daemonset, metav1.CreateOptions{})
if err != nil {
return nil, err
return "", nil, err
}
err = wait.PollUntilContextTimeout(ctx, 1*time.Second, 120*time.Second, true, func(ctx context.Context) (done bool, err error) {
return e2edaemonset.CheckRunningOnAllNodes(ctx, f, daemonset)
})
if err != nil {
return nil, err
return "", nil, err
}
}
pods, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).List(ctx, metav1.ListOptions{LabelSelector: "kube-e2e=" + podTestLabel})
if err != nil {
return nil, err
return "", nil, err
}
podNodes := make([]string, 0, len(pods.Items))
for _, pod := range pods.Items {
podNodes = append(podNodes, pod.Spec.NodeName)
}
return podNodes, nil
return "localhost:5000", podNodes, nil
}
func podManifest(podTestLabel string) (*v1.Pod, error) {
pod, err := test.GetMinimalValidLinuxPod(api.LevelRestricted, api.MajorMinorVersion(1, 22))
pod, err := test.GetMinimalValidPod(api.LevelRestricted, api.MajorMinorVersion(1, 25))
if err != nil {
return nil, err
}

View File

@@ -42,8 +42,6 @@ var _ = SIGDescribe("Container Runtime Conformance Test", func() {
ginkgo.Describe("container runtime conformance blackbox test", func() {
ginkgo.Context("when running a container with a new image", func() {
registryAddress := "localhost:5000"
auth := e2eregistry.User1DockerSecret(registryAddress).Data[v1.DockerConfigJsonKey]
// The following images are not added into NodePrePullImageList, because this test is
// testing image pulling, these images don't need to be prepulled. The ImagePullPolicy
// is v1.PullAlways, so it won't be blocked by framework image pre-pull list check.
@@ -56,25 +54,25 @@ var _ = SIGDescribe("Container Runtime Conformance Test", func() {
}{
{
description: "should be able to pull from private registry with credential provider",
image: registryAddress + "/pause:testing",
image: "pause:testing",
setupRegisty: true,
phase: v1.PodRunning,
waiting: false,
},
} {
var registryAddress string
var podNodes []string
ginkgo.BeforeEach(func(ctx context.Context) {
var err error
if testCase.setupRegisty {
podNodes, err = e2eregistry.SetupRegistry(ctx, f, true)
registryAddress, podNodes, err = e2eregistry.SetupRegistry(ctx, f, true)
framework.ExpectNoError(err)
}
})
ginkgo.AfterEach(func(ctx context.Context) {
if !testCase.setupRegisty {
return
if testCase.setupRegisty {
f.DeleteNamespace(ctx, f.Namespace.Name) // we need to wait for the registry to be removed and so we need to delete the whole NS early (before the actual cleanup)
}
f.DeleteNamespace(ctx, f.Namespace.Name) // we need to wait for the registry to be removed and so we need to delete the whole NS early (before the actual cleanup)
})
f.It(testCase.description+"", f.WithNodeConformance(), func(ctx context.Context) {
@@ -83,7 +81,7 @@ var _ = SIGDescribe("Container Runtime Conformance Test", func() {
PodClient: e2epod.NewPodClient(f),
Container: v1.Container{
Name: name,
Image: testCase.image,
Image: registryAddress + "/" + testCase.image,
// PullAlways makes sure that the image will always be pulled even if it is present before the test.
ImagePullPolicy: v1.PullAlways,
},
@@ -93,10 +91,11 @@ var _ = SIGDescribe("Container Runtime Conformance Test", func() {
container.NodeName = podNodes[0]
}
auth := e2eregistry.User1DockerSecret(registryAddress).Data[v1.DockerConfigJsonKey]
configFile := filepath.Join(services.KubeletRootDirectory, "config.json")
err := os.WriteFile(configFile, []byte(auth), 0644)
framework.ExpectNoError(err)
defer func() { framework.ExpectNoError(os.Remove(configFile)) }()
ginkgo.DeferCleanup(func() { framework.ExpectNoError(os.Remove(configFile)) })
// checkContainerStatus checks whether the container status matches expectation.
checkContainerStatus := func(ctx context.Context) error {