Skip to content

feature: filter out internal build suffix #585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/product/common/api/mcr_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package api
import (
"errors"
"fmt"
"regexp"
"strings"

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

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

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

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

Expand Down
18 changes: 18 additions & 0 deletions pkg/product/common/api/mcr_config_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,21 @@ func Test_ValidateWildcardChannelVersionFIPS(t *testing.T) {

require.Nil(t, configFips.Validate(), "received unexpected error for valid MCR config which uses a wildcard version and specific channel w/ FIPS")
}

func Test_ValidateInternalBuild(t *testing.T) {
config := commonapi.MCRConfig{
Version: "25.0.12-tp1",
Channel: "test-25.0.12",
}

require.Nil(t, config.Validate(), "received unexpected error for valid MCR config which contains internal build suffix -tp1")
}

func Test_ValidateInternalBuildFIPS(t *testing.T) {
config := commonapi.MCRConfig{
Version: "25.0.12-rc2",
Channel: "test-25.0.12/fips",
}

require.Nil(t, config.Validate(), "received unexpected error for valid MCR config which contains internal build suffix -tp1 w/ FIPS")
}
Loading