Refactor helper image revision check

Both Docker and Kubernetes executor are checking what kind of revision
is being used so it can be used to pull in the right helper image,
extract that logic to `helperImage` package.
parent 81d8ab96
Pipeline #57925225 passed with stages
in 73 minutes and 28 seconds
......@@ -278,12 +278,7 @@ func (e *executor) getPrebuiltImage() (*types.ImageInspect, error) {
return e.getDockerImage(imageNameFromConfig)
}
revision := "latest"
if common.REVISION != "HEAD" {
revision = common.REVISION
}
helperImageInfo, err := helperimage.Get(revision, helperimage.Config{
helperImageInfo, err := helperimage.Get(common.REVISION, helperimage.Config{
OSType: e.info.OSType,
Architecture: e.info.Architecture,
OperatingSystem: e.info.OperatingSystem,
......
......@@ -680,12 +680,7 @@ func (s *executor) checkDefaults() error {
}
func createFn() common.Executor {
revision := "latest"
if common.REVISION != "HEAD" {
revision = common.REVISION
}
helperImageInfo, err := helperimage.Get(revision, helperimage.Config{
helperImageInfo, err := helperimage.Get(common.REVISION, helperimage.Config{
OSType: helperimage.OSTypeLinux,
Architecture: "amd64",
})
......
......@@ -1461,7 +1461,7 @@ func TestSetupBuildPod(t *testing.T) {
for testName, test := range tests {
t.Run(testName, func(t *testing.T) {
helperImageInfo, err := helperimage.Get("latest", helperimage.Config{
helperImageInfo, err := helperimage.Get(common.REVISION, helperimage.Config{
OSType: helperimage.OSTypeLinux,
Architecture: "amd64",
})
......
......@@ -11,6 +11,9 @@ const (
OSTypeWindows = "windows"
name = "gitlab/gitlab-runner-helper"
headRevision = "HEAD"
latestImageRevision = "latest"
)
type Info struct {
......@@ -47,5 +50,13 @@ func Get(revision string, cfg Config) (Info, error) {
return Info{}, errors.NewErrOSNotSupported(cfg.OSType)
}
return factory.Create(revision, cfg)
return factory.Create(imageRevision(revision), cfg)
}
func imageRevision(revision string) string {
if revision != headRevision {
return revision
}
return latestImageRevision
}
......@@ -21,7 +21,7 @@ func TestGetInfo(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.osType, func(t *testing.T) {
_, err := Get("HEAD", Config{OSType: testCase.osType})
_, err := Get(headRevision, Config{OSType: testCase.osType})
assert.Equal(t, testCase.expectedError, err)
})
......@@ -36,3 +36,26 @@ func TestContainerImage_String(t *testing.T) {
assert.Equal(t, "abc:1234", image.String())
}
func Test_imageRevision(t *testing.T) {
testCases := []struct {
revision string
expectedTag string
}{
{
revision: headRevision,
expectedTag: latestImageRevision,
},
{
revision: "1234",
expectedTag: "1234",
},
}
for _, testCase := range testCases {
t.Run(testCase.revision, func(t *testing.T) {
assert.Equal(t, testCase.expectedTag, imageRevision(testCase.revision))
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment