-
Notifications
You must be signed in to change notification settings - Fork 213
api: Update to objects from openshift/api #55
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
Merged
openshift-merge-robot
merged 4 commits into
openshift:master
from
smarterclayton:update_api
Nov 21, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ea85015
vendor: Update the client-go and api libraries to pick up new config …
smarterclayton 9519fc4
crd: Set ClusterOperator to cluster scoped
smarterclayton 286641d
api: Update to objects from openshift/api
smarterclayton ab4d84a
cvo: Validate the CVO prior to acting on it
smarterclayton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package validation | ||
|
|
||
| import ( | ||
| "net/url" | ||
| "strings" | ||
|
|
||
| "github.com/blang/semver" | ||
| "github.com/google/uuid" | ||
|
|
||
| apivalidation "k8s.io/apimachinery/pkg/api/validation" | ||
| "k8s.io/apimachinery/pkg/util/validation/field" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
| ) | ||
|
|
||
| func ValidateClusterVersion(config *configv1.ClusterVersion) field.ErrorList { | ||
| errs := apivalidation.ValidateObjectMeta(&config.ObjectMeta, false, apivalidation.NameIsDNS1035Label, nil) | ||
|
|
||
| if len(config.Spec.Upstream) > 0 { | ||
| if _, err := url.Parse(string(config.Spec.Upstream)); err != nil { | ||
| errs = append(errs, field.Invalid(field.NewPath("spec", "upstream"), config.Spec.Upstream, "must be a valid URL or empty")) | ||
| } | ||
| } | ||
| if len(config.Spec.ClusterID) > 0 { | ||
| id, _ := uuid.Parse(string(config.Spec.ClusterID)) | ||
| switch { | ||
| case id.Variant() != uuid.RFC4122: | ||
| errs = append(errs, field.Invalid(field.NewPath("spec", "clusterID"), config.Spec.ClusterID, "must be an RFC4122-variant UUID")) | ||
| case id.Version() != 4: | ||
| errs = append(errs, field.Invalid(field.NewPath("spec", "clusterID"), config.Spec.ClusterID, "must be a version-4 UUID")) | ||
| } | ||
| } | ||
| if u := config.Spec.DesiredUpdate; u != nil { | ||
| switch { | ||
| case len(u.Version) == 0 && len(u.Payload) == 0: | ||
| errs = append(errs, field.Required(field.NewPath("spec", "desiredUpdate", "version"), "must specify version or payload")) | ||
| case len(u.Version) > 0 && !validSemVer(u.Version): | ||
| errs = append(errs, field.Invalid(field.NewPath("spec", "desiredUpdate", "version"), u.Version, "must be a semantic version (1.2.3[-...])")) | ||
| } | ||
| } | ||
| return errs | ||
| } | ||
|
|
||
| func ClearInvalidFields(config *configv1.ClusterVersion, errs field.ErrorList) *configv1.ClusterVersion { | ||
| if len(errs) == 0 { | ||
| return config | ||
| } | ||
| copied := config.DeepCopy() | ||
| for _, err := range errs { | ||
| switch { | ||
| case strings.HasPrefix(err.Field, "spec.desiredUpdate."): | ||
| copied.Spec.DesiredUpdate = nil | ||
| case err.Field == "spec.upstream": | ||
| // TODO: invalid means, don't fetch updates | ||
| copied.Spec.Upstream = "" | ||
| case err.Field == "spec.clusterID": | ||
| copied.Spec.ClusterID = "" | ||
| } | ||
| } | ||
| return copied | ||
| } | ||
|
|
||
| func validSemVer(version string) bool { | ||
| _, err := semver.Parse(version) | ||
| return err == nil | ||
| } |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 file should no longer exist in CVO. openshift/library-go#97 seems like better place for these functions. For now its okay as-is