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
OpenStack: add clusterOSImage validations #3964
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,11 @@ package validation | |
import ( | ||
"errors" | ||
"fmt" | ||
"net/url" | ||
|
||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
|
||
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images" | ||
"github.com/openshift/installer/pkg/types" | ||
"github.com/openshift/installer/pkg/types/openstack" | ||
) | ||
|
@@ -27,6 +29,9 @@ func ValidatePlatform(p *openstack.Platform, n *types.Networking, ci *CloudInfo) | |
// validate floating ips | ||
allErrs = append(allErrs, validateFloatingIPs(p, ci, fldPath)...) | ||
|
||
// validate custom cluster os image | ||
allErrs = append(allErrs, validateClusterOSImage(p, ci, fldPath)...) | ||
|
||
if p.DefaultMachinePlatform != nil { | ||
allErrs = append(allErrs, ValidateMachinePool(p.DefaultMachinePlatform, ci, true, fldPath.Child("defaultMachinePlatform"))...) | ||
} | ||
|
@@ -127,3 +132,33 @@ func validateFloatingIPs(p *openstack.Platform, ci *CloudInfo, fldPath *field.Pa | |
} | ||
return allErrs | ||
} | ||
|
||
// validateExternalNetwork validates the user's input for the clusterOSImage and returns a list of all validation errors | ||
func validateClusterOSImage(p *openstack.Platform, ci *CloudInfo, fldPath *field.Path) (allErrs field.ErrorList) { | ||
if p.ClusterOSImage == "" { | ||
return | ||
} | ||
|
||
// For URLs we support only 'http(s)' and 'file' schemes | ||
if uri, err := url.ParseRequestURI(p.ClusterOSImage); err == nil { | ||
switch uri.Scheme { | ||
case "http", "https", "file": | ||
default: | ||
allErrs = append(allErrs, field.Invalid(fldPath.Child("clusterOSImage"), p.ClusterOSImage, fmt.Sprintf("URL scheme should be either http(s) or file but it is '%v'", uri.Scheme))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Go has fmt directive %q which will quote the string |
||
} | ||
return | ||
} | ||
|
||
// Image should exist in OpenStack Glance | ||
if ci.OSImage == nil { | ||
allErrs = append(allErrs, field.NotFound(fldPath.Child("clusterOSImage"), p.ClusterOSImage)) | ||
return allErrs | ||
} | ||
|
||
// Image should have "active" status | ||
if ci.OSImage.Status != images.ImageStatusActive { | ||
allErrs = append(allErrs, field.Invalid(fldPath.Child("clusterOSImage"), p.ClusterOSImage, fmt.Sprintf("OS image must be active but its status is '%s'", ci.OSImage.Status))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Go has fmt directive %q which will quote the string |
||
} | ||
|
||
return allErrs | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this err here is not handled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh... my bad :( thanks for noticing!