Skip to content

Commit

Permalink
test/e2e: do not use global variable for image
Browse files Browse the repository at this point in the history
We have "-kube-test-repo-list" command line flag to override the image registry. If we store it in global variable, then that overriding cannot take effect.

And this can cause puzzling bugs, e.g.: containerIsUnused() function will compare incorrect image address.
  • Loading branch information
huww98 committed Apr 22, 2024
1 parent 8946348 commit 6ec421e
Show file tree
Hide file tree
Showing 30 changed files with 81 additions and 104 deletions.
2 changes: 1 addition & 1 deletion test/e2e/apimachinery/etcd_failure.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func etcdFailTest(ctx context.Context, f *framework.Framework, failCommand, fixC

checkExistingRCRecovers(ctx, f)

apps.TestReplicationControllerServeImageOrFail(ctx, f, "basic", framework.ServeHostnameImage)
apps.TestReplicationControllerServeImageOrFail(ctx, f, "basic", imageutils.GetE2EImage(imageutils.Agnhost))
}

// For this duration, etcd will be failed by executing a failCommand on the master.
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/apps/rc.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var _ = SIGDescribe("ReplicationController", func() {
Description: Replication Controller MUST create a Pod with Basic Image and MUST run the service with the provided image. Image MUST be tested by dialing into the service listening through TCP, UDP and HTTP.
*/
framework.ConformanceIt("should serve a basic image on each replica with a public image", func(ctx context.Context) {
TestReplicationControllerServeImageOrFail(ctx, f, "basic", framework.ServeHostnameImage)
TestReplicationControllerServeImageOrFail(ctx, f, "basic", imageutils.GetE2EImage(imageutils.Agnhost))
})

ginkgo.It("should serve a basic image on each replica with a private image", func(ctx context.Context) {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/apps/replica_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var _ = SIGDescribe("ReplicaSet", func() {
Description: Create a ReplicaSet with a Pod and a single Container. Make sure that the Pod is running. Pod SHOULD send a valid response when queried.
*/
framework.ConformanceIt("should serve a basic image on each replica with a public image", func(ctx context.Context) {
testReplicaSetServeImageOrFail(ctx, f, "basic", framework.ServeHostnameImage)
testReplicaSetServeImageOrFail(ctx, f, "basic", imageutils.GetE2EImage(imageutils.Agnhost))
})

ginkgo.It("should serve a basic image on each replica with a private image", func(ctx context.Context) {
Expand Down
7 changes: 4 additions & 3 deletions test/e2e/common/node/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/kubernetes/test/e2e/framework"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
imageutils "k8s.io/kubernetes/test/utils/image"
admissionapi "k8s.io/pod-security-admission/api"

"github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -58,7 +59,7 @@ var _ = SIGDescribe("Kubelet", func() {
RestartPolicy: v1.RestartPolicyNever,
Containers: []v1.Container{
{
Image: framework.BusyBoxImage,
Image: imageutils.GetE2EImage(imageutils.BusyBox),
Name: podName,
Command: []string{"sh", "-c", "echo 'Hello World' ; sleep 240"},
},
Expand Down Expand Up @@ -92,7 +93,7 @@ var _ = SIGDescribe("Kubelet", func() {
RestartPolicy: v1.RestartPolicyNever,
Containers: []v1.Container{
{
Image: framework.BusyBoxImage,
Image: imageutils.GetE2EImage(imageutils.BusyBox),
Name: podName,
Command: []string{"/bin/false"},
},
Expand Down Expand Up @@ -191,7 +192,7 @@ var _ = SIGDescribe("Kubelet", func() {
RestartPolicy: v1.RestartPolicyNever,
Containers: []v1.Container{
{
Image: framework.BusyBoxImage,
Image: imageutils.GetE2EImage(imageutils.BusyBox),
Name: podName,
Command: []string{"/bin/sh", "-c", "echo test > /file; sleep 240"},
SecurityContext: &v1.SecurityContext{
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/common/node/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ var _ = SIGDescribe("Pods", func() {
Containers: []v1.Container{
{
Name: "srv",
Image: framework.ServeHostnameImage,
Image: imageutils.GetE2EImage(imageutils.Agnhost),
Ports: []v1.ContainerPort{{ContainerPort: 9376}},
},
},
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/common/node/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var _ = SIGDescribe("Container Runtime", func() {
restartCountVolumeName := "restart-count"
restartCountVolumePath := "/restart-count"
testContainer := v1.Container{
Image: framework.BusyBoxImage,
Image: imageutils.GetE2EImage(imageutils.BusyBox),
VolumeMounts: []v1.VolumeMount{
{
MountPath: restartCountVolumePath,
Expand Down Expand Up @@ -173,7 +173,7 @@ while true; do sleep 1; done

f.It("should report termination message if TerminationMessagePath is set", f.WithNodeConformance(), func(ctx context.Context) {
container := v1.Container{
Image: framework.BusyBoxImage,
Image: imageutils.GetE2EImage(imageutils.BusyBox),
Command: []string{"/bin/sh", "-c"},
Args: []string{"/bin/echo -n DONE > /dev/termination-log"},
TerminationMessagePath: "/dev/termination-log",
Expand All @@ -194,7 +194,7 @@ while true; do sleep 1; done
*/
framework.ConformanceIt("should report termination message if TerminationMessagePath is set as non-root user and at a non-default path", f.WithNodeConformance(), func(ctx context.Context) {
container := v1.Container{
Image: framework.BusyBoxImage,
Image: imageutils.GetE2EImage(imageutils.BusyBox),
Command: []string{"/bin/sh", "-c"},
Args: []string{"/bin/echo -n DONE > /dev/termination-custom-log"},
TerminationMessagePath: "/dev/termination-custom-log",
Expand All @@ -215,7 +215,7 @@ while true; do sleep 1; done
*/
framework.ConformanceIt("should report termination message from log output if TerminationMessagePolicy FallbackToLogsOnError is set", f.WithNodeConformance(), func(ctx context.Context) {
container := v1.Container{
Image: framework.BusyBoxImage,
Image: imageutils.GetE2EImage(imageutils.BusyBox),
Command: []string{"/bin/sh", "-c"},
Args: []string{"/bin/echo -n DONE; /bin/false"},
TerminationMessagePath: "/dev/termination-log",
Expand All @@ -231,7 +231,7 @@ while true; do sleep 1; done
*/
framework.ConformanceIt("should report termination message as empty when pod succeeds and TerminationMessagePolicy FallbackToLogsOnError is set", f.WithNodeConformance(), func(ctx context.Context) {
container := v1.Container{
Image: framework.BusyBoxImage,
Image: imageutils.GetE2EImage(imageutils.BusyBox),
Command: []string{"/bin/sh", "-c"},
Args: []string{"/bin/echo -n DONE; /bin/true"},
TerminationMessagePath: "/dev/termination-log",
Expand All @@ -247,7 +247,7 @@ while true; do sleep 1; done
*/
framework.ConformanceIt("should report termination message from file when pod succeeds and TerminationMessagePolicy FallbackToLogsOnError is set", f.WithNodeConformance(), func(ctx context.Context) {
container := v1.Container{
Image: framework.BusyBoxImage,
Image: imageutils.GetE2EImage(imageutils.BusyBox),
Command: []string{"/bin/sh", "-c"},
Args: []string{"/bin/echo -n OK > /dev/termination-log; /bin/echo DONE; /bin/true"},
TerminationMessagePath: "/dev/termination-log",
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/common/node/security_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ var _ = SIGDescribe("Security Context", func() {
createAndWaitUserPod := func(ctx context.Context, userid int64) {
podName := fmt.Sprintf("busybox-user-%d-%s", userid, uuid.NewUUID())
podClient.Create(ctx, makeUserPod(podName,
framework.BusyBoxImage,
imageutils.GetE2EImage(imageutils.BusyBox),
[]string{"sh", "-c", fmt.Sprintf("test $(id -u) -eq %d", userid)},
userid,
))
Expand Down Expand Up @@ -454,7 +454,7 @@ var _ = SIGDescribe("Security Context", func() {
createAndWaitUserPod := func(ctx context.Context, readOnlyRootFilesystem bool) string {
podName := fmt.Sprintf("busybox-readonly-%v-%s", readOnlyRootFilesystem, uuid.NewUUID())
podClient.Create(ctx, makeUserPod(podName,
framework.BusyBoxImage,
imageutils.GetE2EImage(imageutils.BusyBox),
[]string{"sh", "-c", "touch checkfile"},
readOnlyRootFilesystem,
))
Expand Down Expand Up @@ -515,7 +515,7 @@ var _ = SIGDescribe("Security Context", func() {
createAndWaitUserPod := func(ctx context.Context, privileged bool) string {
podName := fmt.Sprintf("busybox-privileged-%v-%s", privileged, uuid.NewUUID())
podClient.Create(ctx, makeUserPod(podName,
framework.BusyBoxImage,
imageutils.GetE2EImage(imageutils.BusyBox),
[]string{"sh", "-c", "ip link add dummy0 type dummy || true"},
privileged,
))
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func NewRCByName(c clientset.Interface, ns, name string, replicas int32, gracePe
}

return c.CoreV1().ReplicationControllers(ns).Create(context.TODO(), rcByNamePort(
name, replicas, framework.ServeHostnameImage, containerArgs, 9376, v1.ProtocolTCP, map[string]string{}, gracePeriod), metav1.CreateOptions{})
name, replicas, imageutils.GetE2EImage(imageutils.Agnhost), containerArgs, 9376, v1.ProtocolTCP, map[string]string{}, gracePeriod), metav1.CreateOptions{})
}

// RestartNodes restarts specific nodes.
Expand Down
8 changes: 2 additions & 6 deletions test/e2e/framework/autoscaling/autoscaling_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ const (
crdNamePlural = "testcrds"
)

var (
resourceConsumerImage = imageutils.GetE2EImage(imageutils.ResourceConsumer)
)

var (
// KindRC is the GVK for ReplicationController
KindRC = schema.GroupVersionKind{Version: "v1", Kind: "ReplicationController"}
Expand Down Expand Up @@ -144,7 +140,7 @@ func NewDynamicResourceConsumer(ctx context.Context, name, nsName string, kind s
func getSidecarContainer(name string, cpuLimit, memLimit int64) v1.Container {
container := v1.Container{
Name: name + "-sidecar",
Image: resourceConsumerImage,
Image: imageutils.GetE2EImage(imageutils.ResourceConsumer),
Command: []string{"/consumer", "-port=8081"},
Ports: []v1.ContainerPort{{ContainerPort: 80}},
}
Expand Down Expand Up @@ -628,7 +624,7 @@ func runServiceAndWorkloadForResourceConsumer(ctx context.Context, c clientset.I

rcConfig := testutils.RCConfig{
Client: c,
Image: resourceConsumerImage,
Image: imageutils.GetE2EImage(imageutils.ResourceConsumer),
Name: name,
Namespace: ns,
Timeout: timeoutRC,
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/framework/job/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewTestJobOnNode(behavior, name string, rPol v1.RestartPolicy, parallelism,
Containers: []v1.Container{
{
Name: "c",
Image: framework.BusyBoxImage,
Image: imageutils.GetE2EImage(imageutils.BusyBox),
Command: []string{},
VolumeMounts: []v1.VolumeMount{
{
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/framework/network/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ const (
echoHostname = "hostname"
)

// NetexecImageName is the image name for agnhost.
var NetexecImageName = imageutils.GetE2EImage(imageutils.Agnhost)

// Option is used to configure the NetworkingTest object
type Option func(*NetworkingTestConfig)

Expand Down Expand Up @@ -587,7 +584,7 @@ func (config *NetworkingTestConfig) createNetShellPodSpec(podName, hostname stri
Containers: []v1.Container{
{
Name: "webserver",
Image: NetexecImageName,
Image: imageutils.GetE2EImage(imageutils.Agnhost),
ImagePullPolicy: v1.PullIfNotPresent,
Args: netexecArgs,
Ports: []v1.ContainerPort{
Expand Down Expand Up @@ -657,7 +654,7 @@ func (config *NetworkingTestConfig) createTestPodSpec() *v1.Pod {
Containers: []v1.Container{
{
Name: "webserver",
Image: NetexecImageName,
Image: imageutils.GetE2EImage(imageutils.Agnhost),
ImagePullPolicy: v1.PullIfNotPresent,
Args: []string{
"netexec",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/framework/service/jig.go
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ func (j *TestJig) CreateServicePods(ctx context.Context, replica int) error {
config := testutils.RCConfig{
Client: j.Client,
Name: j.Name,
Image: framework.ServeHostnameImage,
Image: imageutils.GetE2EImage(imageutils.Agnhost),
Command: []string{"/agnhost", "serve-hostname", "--http=false", "--tcp", "--udp"},
Namespace: j.Namespace,
Labels: j.Labels,
Expand Down
7 changes: 0 additions & 7 deletions test/e2e/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import (
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
watchtools "k8s.io/client-go/tools/watch"
imageutils "k8s.io/kubernetes/test/utils/image"
netutils "k8s.io/utils/net"
)

Expand Down Expand Up @@ -132,14 +131,8 @@ const (
)

var (
// BusyBoxImage is the image URI of BusyBox.
BusyBoxImage = imageutils.GetE2EImage(imageutils.BusyBox)

// ProvidersWithSSH are those providers where each node is accessible with SSH
ProvidersWithSSH = []string{"gce", "gke", "aws", "local", "azure"}

// ServeHostnameImage is a serve hostname image name.
ServeHostnameImage = imageutils.GetE2EImage(imageutils.Agnhost)
)

// RunID is a unique identifier of the e2e run.
Expand Down
Loading

0 comments on commit 6ec421e

Please sign in to comment.