Skip to content

Add details for field.Required #9198

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion pkg/authorization/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func validateRoleBindingSubject(subject kapi.ObjectReference, isNamespaced bool,
allErrs = append(allErrs, field.Invalid(fldPath.Child("name"), subject.Name, reason))
}
if !isNamespaced && len(subject.Namespace) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("namespace"), ""))
allErrs = append(allErrs, field.Required(fldPath.Child("namespace"), "Service account subjects for ClusterRoleBindings must have a namespace"))
}

case authorizationapi.UserKind:
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/server/api/validation/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func ValidateEtcdConnectionInfo(config api.EtcdConnectionInfo, server *api.EtcdC
// Require a client cert to connect to an etcd that requires client certs
if len(server.ServingInfo.ClientCA) > 0 {
if len(config.ClientCert.CertFile) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("certFile"), ""))
allErrs = append(allErrs, field.Required(fldPath.Child("certFile"), "A client certificate must be provided for this etcd server"))
}
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/cmd/server/api/validation/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,11 @@ func ValidateRequestHeaderIdentityProvider(provider *api.RequestHeaderIdentityPr
validationResults.AddErrors(field.Required(fieldPath.Child("provider", "headers"), ""))
}
if identityProvider.UseAsChallenger && len(provider.ChallengeURL) == 0 {
err := field.Required(fieldPath.Child("provider", "challengeURL"), "")
err.Detail = "challengeURL is required if challenge=true"
err := field.Required(fieldPath.Child("provider", "challengeURL"), "challengeURL is required if challenge is true")
validationResults.AddErrors(err)
}
if identityProvider.UseAsLogin && len(provider.LoginURL) == 0 {
err := field.Required(fieldPath.Child("provider", "loginURL"), "")
err.Detail = "loginURL is required if login=true"
err := field.Required(fieldPath.Child("provider", "loginURL"), "loginURL is required if login=true")
validationResults.AddErrors(err)
}

Expand Down
11 changes: 8 additions & 3 deletions pkg/cmd/server/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,20 @@ func ValidateHostPort(value string, fldPath *field.Path) field.ErrorList {
func ValidateCertInfo(certInfo api.CertInfo, required bool, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}

if required || len(certInfo.CertFile) > 0 || len(certInfo.KeyFile) > 0 {
if required {
if len(certInfo.CertFile) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("certFile"), ""))
allErrs = append(allErrs, field.Required(fldPath.Child("certFile"), "The certificate file must be provided"))
}
if len(certInfo.KeyFile) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("keyFile"), ""))
allErrs = append(allErrs, field.Required(fldPath.Child("keyFile"), "The certificate key must be provided"))
}
}

if (len(certInfo.CertFile) == 0) != (len(certInfo.KeyFile) == 0) {
allErrs = append(allErrs, field.Required(fldPath.Child("certFile"), "Both the certificate file and the certificate key must be provided together or not at all"))
allErrs = append(allErrs, field.Required(fldPath.Child("keyFile"), "Both the certificate file and the certificate key must be provided together or not at all"))
}

if len(certInfo.CertFile) > 0 {
allErrs = append(allErrs, ValidateFile(certInfo.CertFile, fldPath.Child("certFile"))...)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/image/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func ValidateImageStreamTagReference(tagRef api.TagReference, fldPath *field.Pat
var errs field.ErrorList
if tagRef.From != nil {
if len(tagRef.From.Name) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #8269

You asked me to remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think he meant the details string, not the entire check and error

errs = append(errs, field.Required(fldPath.Child("from", "name"), "name is required"))
errs = append(errs, field.Required(fldPath.Child("from", "name"), ""))
}
switch tagRef.From.Kind {
case "DockerImage":
Expand Down Expand Up @@ -293,7 +293,7 @@ func ValidateImageStreamImport(isi *api.ImageStreamImport) field.ErrorList {
switch from.Kind {
case "DockerImage":
if len(spec.From.Name) == 0 {
errs = append(errs, field.Required(repoPath.Child("from", "name"), ""))
errs = append(errs, field.Required(repoPath.Child("from", "name"), "Docker image references require a name"))
} else {
if ref, err := api.ParseDockerImageReference(from.Name); err != nil {
errs = append(errs, field.Invalid(repoPath.Child("from", "name"), from.Name, err.Error()))
Expand Down
4 changes: 2 additions & 2 deletions pkg/user/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ func ValidateIdentity(identity *api.Identity) field.ErrorList {
allErrs = append(allErrs, field.Invalid(userPath.Child("name"), identity.User.Name, msg))
}
if len(identity.User.Name) == 0 && len(identity.User.UID) != 0 {
allErrs = append(allErrs, field.Invalid(userPath.Child("uid"), identity.User.UID, "may not be set if user.name is empty"))
allErrs = append(allErrs, field.Invalid(userPath.Child("username"), "username is required when uid is provided"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

field.Required?

}
if len(identity.User.Name) != 0 && len(identity.User.UID) == 0 {
allErrs = append(allErrs, field.Required(userPath.Child("uid"), ""))
allErrs = append(allErrs, field.Required(userPath.Child("uid"), "uid is required when username is provided"))
}
return allErrs
}
Expand Down