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