k8s.io/kubernetes@v1.29.3/test/e2e_node/image_id_test.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package e2enode
    18  
    19  import (
    20  	"context"
    21  
    22  	v1 "k8s.io/api/core/v1"
    23  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    24  	"k8s.io/apimachinery/pkg/util/dump"
    25  	"k8s.io/kubernetes/test/e2e/framework"
    26  	e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
    27  	"k8s.io/kubernetes/test/e2e/nodefeature"
    28  	admissionapi "k8s.io/pod-security-admission/api"
    29  
    30  	"github.com/onsi/ginkgo/v2"
    31  	"github.com/onsi/gomega"
    32  )
    33  
    34  var _ = SIGDescribe("ImageID", nodefeature.ImageID, func() {
    35  
    36  	busyBoxImage := "registry.k8s.io/e2e-test-images/busybox@sha256:a9155b13325b2abef48e71de77bb8ac015412a566829f621d06bfae5c699b1b9"
    37  
    38  	f := framework.NewDefaultFramework("image-id-test")
    39  	f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged
    40  
    41  	ginkgo.It("should be set to the manifest digest (from RepoDigests) when available", func(ctx context.Context) {
    42  		podDesc := &v1.Pod{
    43  			ObjectMeta: metav1.ObjectMeta{
    44  				Name: "pod-with-repodigest",
    45  			},
    46  			Spec: v1.PodSpec{
    47  				Containers: []v1.Container{{
    48  					Name:    "test",
    49  					Image:   busyBoxImage,
    50  					Command: []string{"sh"},
    51  				}},
    52  				RestartPolicy: v1.RestartPolicyNever,
    53  			},
    54  		}
    55  
    56  		pod := e2epod.NewPodClient(f).Create(ctx, podDesc)
    57  
    58  		framework.ExpectNoError(e2epod.WaitTimeoutForPodNoLongerRunningInNamespace(ctx,
    59  			f.ClientSet, pod.Name, f.Namespace.Name, framework.PodStartTimeout))
    60  		runningPod, err := e2epod.NewPodClient(f).Get(ctx, pod.Name, metav1.GetOptions{})
    61  		framework.ExpectNoError(err)
    62  
    63  		status := runningPod.Status
    64  		gomega.Expect(status.ContainerStatuses).To(gomega.HaveLen(1), dump.Pretty(status))
    65  		gomega.Expect(status.ContainerStatuses[0].ImageID).To(
    66  			gomega.SatisfyAny(
    67  				gomega.Equal(busyBoxImage),
    68  				gomega.MatchRegexp(`[[:xdigit:]]{64}`),
    69  			),
    70  		)
    71  	})
    72  })