Skip to content
Merged
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
12 changes: 12 additions & 0 deletions pkg/types/validation/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,18 @@ func validateImageContentSources(groups []types.ImageContentSource, fldPath *fie
func validateNamedRepository(r string) error {
ref, err := dockerref.ParseNamed(r)
if err != nil {
// If a mirror name is provided without the named reference,
// then the name is not considered canonical and will cause
// an error. e.g. registry.lab.redhat.com:5000 will result
// in an error. Instead we will check whether the input is
// a valid hostname as a workaround.
if err == dockerref.ErrNameNotCanonical {
Comment thread
kirankt marked this conversation as resolved.
Outdated
Comment thread
kirankt marked this conversation as resolved.
Outdated
_, err := url.ParseRequestURI(r)
if err != nil {
return fmt.Errorf("the repository provided is invalid")
Comment thread
kirankt marked this conversation as resolved.
Outdated
}
return nil
}
return errors.Wrap(err, "failed to parse")
}
if !dockerref.IsNameOnly(ref) {
Expand Down
19 changes: 15 additions & 4 deletions pkg/types/validation/installconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,18 +1038,18 @@ func TestValidateInstallConfig(t *testing.T) {
expectedError: `^credentialsMode: Unsupported value: "Mint": supported values: "Manual"$`,
},
{
name: "release image source is not canonical",
name: "release image source is not valid",
installConfig: func() *types.InstallConfig {
c := validInstallConfig()
c.ImageContentSources = []types.ImageContentSource{{
Source: "ocp/release-x.y",
}}
return c
}(),
expectedError: `^imageContentSources\[0\]\.source: Invalid value: "ocp/release-x\.y": failed to parse: repository name must be canonical$`,
expectedError: `^imageContentSources\[0\]\.source: Invalid value: "ocp/release-x\.y": the repository provided is invalid$`,
},
{
name: "release image source's mirror is not canonical",
name: "release image source's mirror is not valid",
installConfig: func() *types.InstallConfig {
c := validInstallConfig()
c.ImageContentSources = []types.ImageContentSource{{
Expand All @@ -1058,7 +1058,18 @@ func TestValidateInstallConfig(t *testing.T) {
}}
return c
}(),
expectedError: `^imageContentSources\[0\]\.mirrors\[0\]: Invalid value: "ocp/openshift-x\.y": failed to parse: repository name must be canonical$`,
expectedError: `^imageContentSources\[0\]\.mirrors\[0\]: Invalid value: "ocp/openshift-x.y": the repository provided is invalid$`,
},
{
name: "release image source's mirror is valid",
installConfig: func() *types.InstallConfig {
c := validInstallConfig()
c.ImageContentSources = []types.ImageContentSource{{
Source: "q.io/ocp/release-x.y",
Mirrors: []string{"mirror.example.com:5000"},
}}
return c
}(),
},
{
name: "release image source is not repository but reference by digest",
Expand Down