Skip to content

Commit c942e0d

Browse files
committed
feature: filter out internal build suffix
Signed-off-by: Eiichi Kitagawa <eiichi.kitagawa@docker.com>
1 parent fd80698 commit c942e0d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

pkg/product/common/api/mcr_config.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package api
33
import (
44
"errors"
55
"fmt"
6+
"regexp"
67
"strings"
78

89
"github.com/Mirantis/launchpad/pkg/constant"
@@ -15,7 +16,8 @@ var (
1516
minVersionNeedsMatchingChannel, _ = version.NewVersion("25.0.0")
1617
ErrChannelDoesntMatchVersion = errors.New("MCR version and channel don't match, which is required for versions >= 25.0.0")
1718

18-
fipsChannelSuffix = "/fips" // this suffix is removed from channels for version comparison testing
19+
fipsChannelSuffix = "/fips" // this suffix is removed from channels for version comparison testing
20+
suffixPattern = regexp.MustCompile(`-(tp|rc)\d+$`) // this filters out internal build suffix like -tp1
1921
)
2022

2123
type DockerInfo struct {
@@ -125,7 +127,8 @@ func processVersionChannelMatch(config *MCRConfig) error {
125127
return fmt.Errorf("%w; channel parts could not be interpreted", ErrChannelDoesntMatchVersion)
126128
}
127129

128-
if !strings.HasPrefix(chanParts[1], config.Version) {
130+
configVerNum := suffixPattern.ReplaceAllString(config.Version, "") // remove build number
131+
if !strings.HasPrefix(chanParts[1], configVerNum) {
129132
return fmt.Errorf("%w; MCR version does not match channel-version '%s' vs '%s'", ErrChannelDoesntMatchVersion, chanParts[1], config.Version)
130133
}
131134

pkg/product/common/api/mcr_config_validate_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,21 @@ func Test_ValidateWildcardChannelVersionFIPS(t *testing.T) {
145145

146146
require.Nil(t, configFips.Validate(), "received unexpected error for valid MCR config which uses a wildcard version and specific channel w/ FIPS")
147147
}
148+
149+
func Test_ValidateInternalBuild(t *testing.T) {
150+
config := commonapi.MCRConfig{
151+
Version: "25.0.12-tp1",
152+
Channel: "test-25.0.12",
153+
}
154+
155+
require.Nil(t, config.Validate(), "received unexpected error for valid MCR config which contains internal build suffix -tp1")
156+
}
157+
158+
func Test_ValidateInternalBuildFIPS(t *testing.T) {
159+
config := commonapi.MCRConfig{
160+
Version: "25.0.12-rc2",
161+
Channel: "test-25.0.12/fips",
162+
}
163+
164+
require.Nil(t, config.Validate(), "received unexpected error for valid MCR config which contains internal build suffix -tp1 w/ FIPS")
165+
}

0 commit comments

Comments
 (0)