|
| 1 | +// +build linux |
| 2 | + |
| 3 | +/* |
| 4 | + Copyright The containerd Authors. |
| 5 | +
|
| 6 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + you may not use this file except in compliance with the License. |
| 8 | + You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, software |
| 13 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + See the License for the specific language governing permissions and |
| 16 | + limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +package integration |
| 20 | + |
| 21 | +import ( |
| 22 | + "fmt" |
| 23 | + "io/ioutil" |
| 24 | + |
| 25 | + "github.com/pelletier/go-toml" |
| 26 | + "github.com/sirupsen/logrus" |
| 27 | + cri "k8s.io/cri-api/pkg/apis" |
| 28 | +) |
| 29 | + |
| 30 | +// ImageList holds public image references |
| 31 | +type ImageList struct { |
| 32 | + Alpine string |
| 33 | + BusyBox string |
| 34 | + Pause string |
| 35 | + VolumeCopyUp string |
| 36 | + VolumeOwnership string |
| 37 | +} |
| 38 | + |
| 39 | +var ( |
| 40 | + imageService cri.ImageManagerService |
| 41 | + imageMap map[int]string |
| 42 | + imageList ImageList |
| 43 | + pauseImage string // This is the same with default sandbox image |
| 44 | +) |
| 45 | + |
| 46 | +func initImages(imageListFile string) { |
| 47 | + imageList = ImageList{ |
| 48 | + Alpine: "docker.io/library/alpine:latest", |
| 49 | + BusyBox: "docker.io/library/busybox:latest", |
| 50 | + Pause: "k8s.gcr.io/pause:3.5", |
| 51 | + VolumeCopyUp: "gcr.io/k8s-cri-containerd/volume-copy-up:2.0", |
| 52 | + VolumeOwnership: "gcr.io/k8s-cri-containerd/volume-ownership:2.0", |
| 53 | + } |
| 54 | + |
| 55 | + if imageListFile != "" { |
| 56 | + fileContent, err := ioutil.ReadFile(imageListFile) |
| 57 | + if err != nil { |
| 58 | + panic(fmt.Errorf("Error reading '%v' file contents: %v", imageList, err)) |
| 59 | + } |
| 60 | + |
| 61 | + err = toml.Unmarshal(fileContent, &imageList) |
| 62 | + if err != nil { |
| 63 | + panic(fmt.Errorf("Error unmarshalling '%v' TOML file: %v", imageList, err)) |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + logrus.Infof("Using the following image list: %+v", imageList) |
| 68 | + |
| 69 | + imageMap = initImageMap(imageList) |
| 70 | + pauseImage = GetImage(Pause) |
| 71 | +} |
| 72 | + |
| 73 | +const ( |
| 74 | + // None is to be used for unset/default images |
| 75 | + None = iota |
| 76 | + // Alpine image |
| 77 | + Alpine |
| 78 | + // BusyBox image |
| 79 | + BusyBox |
| 80 | + // Pause image |
| 81 | + Pause |
| 82 | + // VolumeCopyUp image |
| 83 | + VolumeCopyUp |
| 84 | + // VolumeOwnership image |
| 85 | + VolumeOwnership |
| 86 | +) |
| 87 | + |
| 88 | +func initImageMap(imageList ImageList) map[int]string { |
| 89 | + images := map[int]string{} |
| 90 | + images[Alpine] = imageList.Alpine |
| 91 | + images[BusyBox] = imageList.BusyBox |
| 92 | + images[Pause] = imageList.Pause |
| 93 | + images[VolumeCopyUp] = imageList.VolumeCopyUp |
| 94 | + images[VolumeOwnership] = imageList.VolumeOwnership |
| 95 | + return images |
| 96 | +} |
| 97 | + |
| 98 | +// GetImage returns the fully qualified URI to an image (including version) |
| 99 | +func GetImage(image int) string { |
| 100 | + return imageMap[image] |
| 101 | +} |
0 commit comments