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
7 changes: 4 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec:
additionalPrinterColumns:
- name: Version
type: string
JSONPath: .status.current.version
JSONPath: .status.desired.version
- name: Available
type: string
JSONPath: .status.conditions[?(@.type=="Available")].status
Expand Down
42 changes: 42 additions & 0 deletions lib/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,53 @@ func ValidateClusterVersion(config *configv1.ClusterVersion) field.ErrorList {
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[-...])"))
case len(u.Version) > 0 && len(u.Payload) == 0:
switch countPayloadsForVersion(config, u.Version) {
case 0:
errs = append(errs, field.Invalid(field.NewPath("spec", "desiredUpdate", "version"), u.Version, "when payload is empty the update must be a previous version or an available update"))
case 1:
default:
errs = append(errs, field.Invalid(field.NewPath("spec", "desiredUpdate", "version"), u.Version, "there are multiple possible payloads for this version, specify the exact payload"))
}
}
}
return errs
}

func countPayloadsForVersion(config *configv1.ClusterVersion, version string) int {
count := 0
for _, update := range config.Status.AvailableUpdates {
if update.Version == version && len(update.Payload) > 0 {
count++
}
}
if count > 0 {
return count
}
for _, history := range config.Status.History {
if history.Version == version {
if len(history.Payload) > 0 {
return 1
}
}
}
return 0
}

func hasAmbiguousPayloadForVersion(config *configv1.ClusterVersion, version string) bool {
for _, update := range config.Status.AvailableUpdates {
if update.Version == version {
return len(update.Payload) > 0
}
}
for _, history := range config.Status.History {
if history.Version == version {
return len(history.Payload) > 0
}
}
return false
}

func ClearInvalidFields(config *configv1.ClusterVersion, errs field.ErrorList) *configv1.ClusterVersion {
if len(errs) == 0 {
return config
Expand Down
42 changes: 23 additions & 19 deletions pkg/cvo/cvo.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func (optr *Operator) sync(key string) error {
glog.V(2).Infof("Reconciling cluster to version %s and image %s (hash=%s)", update.Version, update.Payload, payload.ManifestHash)
} else {
glog.V(2).Infof("Updating the cluster to version %s and image %s (hash=%s)", update.Version, update.Payload, payload.ManifestHash)
if err := optr.syncProgressingStatus(original); err != nil {
if err := optr.syncProgressingStatus(original, update); err != nil {
return err
}
}
Expand Down Expand Up @@ -429,7 +429,6 @@ func (optr *Operator) getOrCreateClusterVersion() (*configv1.ClusterVersion, boo
// for fields that have meaning that are incomplete, clear them
// prevents us from loading clearly malformed payloads
obj = validation.ClearInvalidFields(obj, errs)

return obj, changed, nil
}

Expand Down Expand Up @@ -465,11 +464,14 @@ func (optr *Operator) getOrCreateClusterVersion() (*configv1.ClusterVersion, boo

// versionString returns a string describing the current version.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ques: .status.desired and .status.history[0] both give us current version that CVO is reconciling towards, correct? and we have the .status.desired as that is easy to show in oc get clusterversion ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes and yes.

func (optr *Operator) currentVersionString(config *configv1.ClusterVersion) string {
if s := config.Status.Current.Version; len(s) > 0 {
return s
}
if s := config.Status.Current.Payload; len(s) > 0 {
return s
if len(config.Status.History) > 0 {
last := config.Status.History[0]
if s := last.Version; len(s) > 0 {
return s
}
if s := last.Payload; len(s) > 0 {
return s
}
}
if s := optr.releaseVersion; len(s) > 0 {
return s
Expand All @@ -480,21 +482,23 @@ func (optr *Operator) currentVersionString(config *configv1.ClusterVersion) stri
return "<unknown>"
}

// desiredVersion returns the update that is currently targeted by the config.
func (optr *Operator) desiredVersion(config *configv1.ClusterVersion) configv1.Update {
if update := config.Spec.DesiredUpdate; update != nil {
return *update
}
return optr.currentVersion()
}

// versionString returns a string describing the desired version.
func (optr *Operator) desiredVersionString(config *configv1.ClusterVersion) string {
var s string
if v := config.Spec.DesiredUpdate; v != nil {
if len(v.Payload) > 0 {
s = v.Payload
}
if len(v.Version) > 0 {
s = v.Version
}
func versionString(update configv1.Update) string {
if len(update.Version) > 0 {
return update.Version
}
if len(s) == 0 {
s = optr.currentVersionString(config)
if len(update.Payload) > 0 {
return update.Payload
}
return s
return "<unknown>"
}

// currentVersion returns an update object describing the current known cluster version.
Expand Down
Loading