mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
Use typed ImageID for imageutils images
This commit is contained in:
parent
af99c75390
commit
ab29782d24
@ -28,11 +28,6 @@ import (
|
||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||
)
|
||||
|
||||
var (
|
||||
// BusyBoxImage is the image URI of BusyBox.
|
||||
BusyBoxImage = imageutils.GetE2EImage(imageutils.BusyBox)
|
||||
)
|
||||
|
||||
// Config is a struct containing all arguments for creating a pod.
|
||||
// SELinux testing requires to pass HostIPC and HostPID as boolean arguments.
|
||||
type Config struct {
|
||||
@ -47,7 +42,7 @@ type Config struct {
|
||||
SeLinuxLabel *v1.SELinuxOptions
|
||||
FsGroup *int64
|
||||
NodeSelection NodeSelection
|
||||
ImageID int
|
||||
ImageID imageutils.ImageID
|
||||
PodFSGroupChangePolicy *v1.PodFSGroupChangePolicy
|
||||
}
|
||||
|
||||
|
@ -56,14 +56,14 @@ func GetDefaultTestImage() string {
|
||||
// If the node OS is windows, currently we return Agnhost image for Windows node
|
||||
// due to the issue of #https://github.com/kubernetes-sigs/windows-testing/pull/35.
|
||||
// If the node OS is linux, return busybox image
|
||||
func GetDefaultTestImageID() int {
|
||||
func GetDefaultTestImageID() imageutils.ImageID {
|
||||
return GetTestImageID(imageutils.BusyBox)
|
||||
}
|
||||
|
||||
// GetTestImage returns the image name with the given input
|
||||
// If the Node OS is windows, currently we return Agnhost image for Windows node
|
||||
// due to the issue of #https://github.com/kubernetes-sigs/windows-testing/pull/35.
|
||||
func GetTestImage(id int) string {
|
||||
func GetTestImage(id imageutils.ImageID) string {
|
||||
if NodeOSDistroIs("windows") {
|
||||
return imageutils.GetE2EImage(imageutils.Agnhost)
|
||||
}
|
||||
@ -73,7 +73,7 @@ func GetTestImage(id int) string {
|
||||
// GetTestImageID returns the image id with the given input
|
||||
// If the Node OS is windows, currently we return Agnhost image for Windows node
|
||||
// due to the issue of #https://github.com/kubernetes-sigs/windows-testing/pull/35.
|
||||
func GetTestImageID(id int) int {
|
||||
func GetTestImageID(id imageutils.ImageID) imageutils.ImageID {
|
||||
if NodeOSDistroIs("windows") {
|
||||
return imageutils.Agnhost
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/yaml"
|
||||
"k8s.io/kubernetes/test/e2e/testing-manifests"
|
||||
e2etestingmanifests "k8s.io/kubernetes/test/e2e/testing-manifests"
|
||||
)
|
||||
|
||||
// All of the image tags are of the format k8s.gcr.io/sig-storage/hostpathplugin:v1.7.3.
|
||||
@ -33,11 +33,11 @@ var imageRE = regexp.MustCompile(`^(.*)/([^/:]*):(.*)$`)
|
||||
// appendCSIImageConfigs extracts image repo, name and version from
|
||||
// the YAML files under test/e2e/testing-manifests/storage-csi and
|
||||
// creates new config entries for them.
|
||||
func appendCSIImageConfigs(configs map[int]Config) {
|
||||
embeddedFS := testing_manifests.GetE2ETestingManifestsFS().EmbeddedFS
|
||||
func appendCSIImageConfigs(configs map[ImageID]Config) {
|
||||
embeddedFS := e2etestingmanifests.GetE2ETestingManifestsFS().EmbeddedFS
|
||||
|
||||
// We add our images with index numbers that start after the highest existing number.
|
||||
index := 0
|
||||
// We add our images with ImageID numbers that start after the highest existing number.
|
||||
index := ImageID(0)
|
||||
for i := range configs {
|
||||
if i > index {
|
||||
index = i
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCSIImageConfigs(t *testing.T) {
|
||||
configs := map[int]Config{}
|
||||
configs := map[ImageID]Config{}
|
||||
appendCSIImageConfigs(configs)
|
||||
|
||||
// We expect at least one entry for each of these images. There may be
|
||||
|
@ -141,9 +141,11 @@ var (
|
||||
imageConfigs, originalImageConfigs = initImageConfigs(registry)
|
||||
)
|
||||
|
||||
type ImageID int
|
||||
|
||||
const (
|
||||
// None is to be used for unset/default images
|
||||
None = iota
|
||||
None ImageID = iota
|
||||
// Agnhost image
|
||||
Agnhost
|
||||
// AgnhostPrivate image
|
||||
@ -229,8 +231,8 @@ const (
|
||||
WindowsServer
|
||||
)
|
||||
|
||||
func initImageConfigs(list RegistryList) (map[int]Config, map[int]Config) {
|
||||
configs := map[int]Config{}
|
||||
func initImageConfigs(list RegistryList) (map[ImageID]Config, map[ImageID]Config) {
|
||||
configs := map[ImageID]Config{}
|
||||
configs[Agnhost] = Config{list.PromoterE2eRegistry, "agnhost", "2.36"}
|
||||
configs[AgnhostPrivate] = Config{list.PrivateRegistry, "agnhost", "2.6"}
|
||||
configs[AuthenticatedAlpine] = Config{list.GcAuthenticatedRegistry, "alpine", "3.7"}
|
||||
@ -274,7 +276,7 @@ func initImageConfigs(list RegistryList) (map[int]Config, map[int]Config) {
|
||||
configs[VolumeRBDServer] = Config{list.PromoterE2eRegistry, "volume/rbd", "1.0.4"}
|
||||
configs[WindowsServer] = Config{list.MicrosoftRegistry, "windows", "1809"}
|
||||
|
||||
// This adds more config entries. Those have no pre-defined index number,
|
||||
// This adds more config entries. Those have no pre-defined ImageID number,
|
||||
// but will be used via ReplaceRegistryInImageURL when deploying
|
||||
// CSI drivers (test/e2e/storage/util/create.go).
|
||||
appendCSIImageConfigs(configs)
|
||||
@ -290,8 +292,8 @@ func initImageConfigs(list RegistryList) (map[int]Config, map[int]Config) {
|
||||
|
||||
// GetMappedImageConfigs returns the images if they were mapped to the provided
|
||||
// image repository.
|
||||
func GetMappedImageConfigs(originalImageConfigs map[int]Config, repo string) map[int]Config {
|
||||
configs := make(map[int]Config)
|
||||
func GetMappedImageConfigs(originalImageConfigs map[ImageID]Config, repo string) map[ImageID]Config {
|
||||
configs := make(map[ImageID]Config)
|
||||
for i, config := range originalImageConfigs {
|
||||
switch i {
|
||||
case InvalidRegistryImage, AuthenticatedAlpine,
|
||||
@ -303,7 +305,7 @@ func GetMappedImageConfigs(originalImageConfigs map[int]Config, repo string) map
|
||||
continue
|
||||
}
|
||||
|
||||
// Build a new tag with a the index, a hash of the image spec (to be unique) and
|
||||
// Build a new tag with the ImageID, a hash of the image spec (to be unique) and
|
||||
// shorten and make the pull spec "safe" so it will fit in the tag
|
||||
configs[i] = getRepositoryMappedConfig(i, config, repo)
|
||||
}
|
||||
@ -316,11 +318,11 @@ var (
|
||||
)
|
||||
|
||||
// getRepositoryMappedConfig maps an existing image to the provided repo, generating a
|
||||
// tag that is unique with the input config. The tag will contain the index, a hash of
|
||||
// tag that is unique with the input config. The tag will contain the imageID, a hash of
|
||||
// the image spec (to be unique) and shorten and make the pull spec "safe" so it will
|
||||
// fit in the tag to allow a human to recognize the value. If index is -1, then no
|
||||
// index will be added to the tag.
|
||||
func getRepositoryMappedConfig(index int, config Config, repo string) Config {
|
||||
// fit in the tag to allow a human to recognize the value. If imageID is None, then no
|
||||
// imageID will be added to the tag.
|
||||
func getRepositoryMappedConfig(imageID ImageID, config Config, repo string) Config {
|
||||
parts := strings.SplitN(repo, "/", 2)
|
||||
registry, name := parts[0], parts[1]
|
||||
|
||||
@ -337,10 +339,10 @@ func getRepositoryMappedConfig(index int, config Config, repo string) Config {
|
||||
shortName = shortName[len(shortName)-maxLength:]
|
||||
}
|
||||
var version string
|
||||
if index == -1 {
|
||||
if imageID == None {
|
||||
version = fmt.Sprintf("e2e-%s-%s", shortName, hash)
|
||||
} else {
|
||||
version = fmt.Sprintf("e2e-%d-%s-%s", index, shortName, hash)
|
||||
version = fmt.Sprintf("e2e-%d-%s-%s", imageID, shortName, hash)
|
||||
}
|
||||
|
||||
return Config{
|
||||
@ -351,22 +353,22 @@ func getRepositoryMappedConfig(index int, config Config, repo string) Config {
|
||||
}
|
||||
|
||||
// GetOriginalImageConfigs returns the configuration before any mapping rules.
|
||||
func GetOriginalImageConfigs() map[int]Config {
|
||||
func GetOriginalImageConfigs() map[ImageID]Config {
|
||||
return originalImageConfigs
|
||||
}
|
||||
|
||||
// GetImageConfigs returns the map of imageConfigs
|
||||
func GetImageConfigs() map[int]Config {
|
||||
func GetImageConfigs() map[ImageID]Config {
|
||||
return imageConfigs
|
||||
}
|
||||
|
||||
// GetConfig returns the Config object for an image
|
||||
func GetConfig(image int) Config {
|
||||
func GetConfig(image ImageID) Config {
|
||||
return imageConfigs[image]
|
||||
}
|
||||
|
||||
// GetE2EImage returns the fully qualified URI to an image (including version)
|
||||
func GetE2EImage(image int) string {
|
||||
func GetE2EImage(image ImageID) string {
|
||||
return fmt.Sprintf("%s/%s:%s", imageConfigs[image].registry, imageConfigs[image].name, imageConfigs[image].version)
|
||||
}
|
||||
|
||||
@ -394,10 +396,10 @@ func replaceRegistryInImageURLWithList(imageURL string, reg RegistryList) (strin
|
||||
registryAndUser := strings.Join(parts[:countParts-1], "/")
|
||||
|
||||
if repo := os.Getenv("KUBE_TEST_REPO"); len(repo) > 0 {
|
||||
index := -1
|
||||
imageID := None
|
||||
for i, v := range originalImageConfigs {
|
||||
if v.GetE2EImage() == imageURL {
|
||||
index = i
|
||||
imageID = i
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -405,7 +407,7 @@ func replaceRegistryInImageURLWithList(imageURL string, reg RegistryList) (strin
|
||||
if len(last) == 1 {
|
||||
return "", fmt.Errorf("image %q is required to be in an image:tag format", imageURL)
|
||||
}
|
||||
config := getRepositoryMappedConfig(index, Config{
|
||||
config := getRepositoryMappedConfig(imageID, Config{
|
||||
registry: parts[0],
|
||||
name: strings.Join([]string{strings.Join(parts[1:countParts-1], "/"), last[0]}, "/"),
|
||||
version: last[1],
|
||||
|
@ -163,8 +163,8 @@ func TestGetOriginalImageConfigs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetMappedImageConfigs(t *testing.T) {
|
||||
originals := map[int]Config{
|
||||
0: {registry: "docker.io", name: "source/repo", version: "1.0"},
|
||||
originals := map[ImageID]Config{
|
||||
10: {registry: "docker.io", name: "source/repo", version: "1.0"},
|
||||
}
|
||||
mapping := GetMappedImageConfigs(originals, "quay.io/repo/for-test")
|
||||
|
||||
@ -174,7 +174,7 @@ func TestGetMappedImageConfigs(t *testing.T) {
|
||||
actual[source.GetE2EImage()] = mapping.GetE2EImage()
|
||||
}
|
||||
expected := map[string]string{
|
||||
"docker.io/source/repo:1.0": "quay.io/repo/for-test:e2e-0-docker-io-source-repo-1-0-72R4aXm7YnxQ4_ek",
|
||||
"docker.io/source/repo:1.0": "quay.io/repo/for-test:e2e-10-docker-io-source-repo-1-0-72R4aXm7YnxQ4_ek",
|
||||
}
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Fatal(diff.ObjectReflectDiff(expected, actual))
|
||||
|
Loading…
Reference in New Issue
Block a user