Skip to content

Commit 0f873c1

Browse files
committed
Move constants of ClusterStatusConditionType into one place
We cannot keep them in `pkg/cvo/status.go` as it would create dependency cycles.
1 parent 667bc63 commit 0f873c1

5 files changed

Lines changed: 63 additions & 43 deletions

File tree

pkg/cvo/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ func (m *operatorMetrics) Collect(ch chan<- prometheus.Metric) {
518518
}
519519

520520
// answers "if we are failing, are we updating or reconciling"
521-
failing := resourcemerge.FindOperatorStatusCondition(cv.Status.Conditions, ClusterStatusFailing)
521+
failing := resourcemerge.FindOperatorStatusCondition(cv.Status.Conditions, internal.ClusterStatusFailing)
522522
if failing != nil && failing.Status == configv1.ConditionTrue {
523523
if update := cv.Spec.DesiredUpdate; update != nil && update.Image != current.Image {
524524
g = m.version.WithLabelValues("failure", update.Version, update.Image, completed.Version)

pkg/cvo/status.go

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,11 @@ import (
2424

2525
"github.com/openshift/cluster-version-operator/lib/resourcemerge"
2626
"github.com/openshift/cluster-version-operator/pkg/featuregates"
27+
"github.com/openshift/cluster-version-operator/pkg/internal"
2728
"github.com/openshift/cluster-version-operator/pkg/payload"
2829
)
2930

3031
const (
31-
// ClusterStatusFailing is set on the ClusterVersion status when a cluster
32-
// cannot reach the desired state. It is considered more serious than Degraded
33-
// and indicates the cluster is not healthy.
34-
ClusterStatusFailing = configv1.ClusterStatusConditionType("Failing")
35-
3632
// ConditionalUpdateConditionTypeRecommended is a type of the condition present on a conditional update
3733
// that indicates whether the conditional update is recommended or not
3834
ConditionalUpdateConditionTypeRecommended = "Recommended"
@@ -159,21 +155,6 @@ func mergeOperatorHistory(cvStatus *configv1.ClusterVersionStatus, desired confi
159155
cvStatus.Desired = desired
160156
}
161157

162-
// ClusterVersionInvalid indicates that the cluster version has an error that prevents the server from
163-
// taking action. The cluster version operator will only reconcile the current state as long as this
164-
// condition is set.
165-
const ClusterVersionInvalid configv1.ClusterStatusConditionType = "Invalid"
166-
167-
// DesiredReleaseAccepted indicates whether the requested (desired) release payload was successfully loaded
168-
// and no failures occurred during image verification and precondition checking.
169-
const DesiredReleaseAccepted configv1.ClusterStatusConditionType = "ReleaseAccepted"
170-
171-
// ImplicitlyEnabledCapabilities is True if there are enabled capabilities which the user is not currently
172-
// requesting via spec.capabilities, because the cluster version operator does not support uninstalling
173-
// capabilities if any associated resources were previously managed by the CVO or disabling previously
174-
// enabled capabilities.
175-
const ImplicitlyEnabledCapabilities configv1.ClusterStatusConditionType = "ImplicitlyEnabledCapabilities"
176-
177158
// syncStatus calculates the new status of the ClusterVersion based on the current sync state and any
178159
// validation errors found. We allow the caller to pass the original object to avoid DeepCopying twice.
179160
func (optr *Operator) syncStatus(ctx context.Context, original, config *configv1.ClusterVersion, status *SyncWorkerStatus, validationErrs field.ErrorList) error {
@@ -265,14 +246,14 @@ func updateClusterVersionStatus(cvStatus *configv1.ClusterVersionStatus, status
265246
reason = "InvalidClusterVersion"
266247

267248
resourcemerge.SetOperatorStatusCondition(&cvStatus.Conditions, configv1.ClusterOperatorStatusCondition{
268-
Type: ClusterVersionInvalid,
249+
Type: internal.ClusterVersionInvalid,
269250
Status: configv1.ConditionTrue,
270251
Reason: reason,
271252
Message: buf.String(),
272253
LastTransitionTime: now,
273254
})
274255
} else {
275-
resourcemerge.RemoveOperatorStatusCondition(&cvStatus.Conditions, ClusterVersionInvalid)
256+
resourcemerge.RemoveOperatorStatusCondition(&cvStatus.Conditions, internal.ClusterVersionInvalid)
276257
}
277258

278259
// set the implicitly enabled capabilities condition
@@ -318,7 +299,7 @@ func updateClusterVersionStatus(cvStatus *configv1.ClusterVersionStatus, status
318299

319300
// set the failing condition
320301
failingCondition := configv1.ClusterOperatorStatusCondition{
321-
Type: ClusterStatusFailing,
302+
Type: internal.ClusterStatusFailing,
322303
Status: configv1.ConditionFalse,
323304
LastTransitionTime: now,
324305
}
@@ -482,15 +463,15 @@ func setImplicitlyEnabledCapabilitiesCondition(cvStatus *configv1.ClusterVersion
482463
message = message + strings.Join([]string(caps), ", ")
483464

484465
resourcemerge.SetOperatorStatusCondition(&cvStatus.Conditions, configv1.ClusterOperatorStatusCondition{
485-
Type: ImplicitlyEnabledCapabilities,
466+
Type: internal.ImplicitlyEnabledCapabilities,
486467
Status: configv1.ConditionTrue,
487468
Reason: "CapabilitiesImplicitlyEnabled",
488469
Message: message,
489470
LastTransitionTime: now,
490471
})
491472
} else {
492473
resourcemerge.SetOperatorStatusCondition(&cvStatus.Conditions, configv1.ClusterOperatorStatusCondition{
493-
Type: ImplicitlyEnabledCapabilities,
474+
Type: internal.ImplicitlyEnabledCapabilities,
494475
Status: configv1.ConditionFalse,
495476
Reason: "AsExpected",
496477
Message: "Capabilities match configured spec",
@@ -502,7 +483,7 @@ func setImplicitlyEnabledCapabilitiesCondition(cvStatus *configv1.ClusterVersion
502483
func setDesiredReleaseAcceptedCondition(cvStatus *configv1.ClusterVersionStatus, status LoadPayloadStatus, now metav1.Time) {
503484
if status.Step == "PayloadLoaded" {
504485
resourcemerge.SetOperatorStatusCondition(&cvStatus.Conditions, configv1.ClusterOperatorStatusCondition{
505-
Type: DesiredReleaseAccepted,
486+
Type: internal.DesiredReleaseAccepted,
506487
Status: configv1.ConditionTrue,
507488
Reason: status.Step,
508489
Message: status.Message,
@@ -511,15 +492,15 @@ func setDesiredReleaseAcceptedCondition(cvStatus *configv1.ClusterVersionStatus,
511492
} else if status.Step != "" {
512493
if status.Failure != nil {
513494
resourcemerge.SetOperatorStatusCondition(&cvStatus.Conditions, configv1.ClusterOperatorStatusCondition{
514-
Type: DesiredReleaseAccepted,
495+
Type: internal.DesiredReleaseAccepted,
515496
Status: configv1.ConditionFalse,
516497
Reason: status.Step,
517498
Message: status.Message,
518499
LastTransitionTime: now,
519500
})
520501
} else {
521502
resourcemerge.SetOperatorStatusCondition(&cvStatus.Conditions, configv1.ClusterOperatorStatusCondition{
522-
Type: DesiredReleaseAccepted,
503+
Type: internal.DesiredReleaseAccepted,
523504
Status: configv1.ConditionUnknown,
524505
Reason: status.Step,
525506
Message: status.Message,
@@ -644,7 +625,7 @@ func (optr *Operator) syncFailingStatus(ctx context.Context, original *configv1.
644625

645626
// reset the failing message
646627
resourcemerge.SetOperatorStatusCondition(&config.Status.Conditions, configv1.ClusterOperatorStatusCondition{
647-
Type: ClusterStatusFailing,
628+
Type: internal.ClusterStatusFailing,
648629
Status: configv1.ConditionTrue,
649630
Message: ierr.Error(),
650631
LastTransitionTime: now,

pkg/cvo/upgradeable.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ import (
2727
)
2828

2929
const (
30-
adminAckGateFmt string = "^ack-[4-5][.]([0-9]{1,})-[^-]"
31-
upgradeableAdminAckRequired = configv1.ClusterStatusConditionType("UpgradeableAdminAckRequired")
30+
adminAckGateFmt string = "^ack-[4-5][.]([0-9]{1,})-[^-]"
3231
)
3332

3433
var adminAckGateRegexp = regexp.MustCompile(adminAckGateFmt)
@@ -187,7 +186,7 @@ type clusterOperatorsUpgradeable struct {
187186

188187
func (check *clusterOperatorsUpgradeable) Check() *configv1.ClusterOperatorStatusCondition {
189188
cond := &configv1.ClusterOperatorStatusCondition{
190-
Type: configv1.ClusterStatusConditionType("UpgradeableClusterOperators"),
189+
Type: internal.UpgradeableClusterOperators,
191190
Status: configv1.ConditionFalse,
192191
}
193192
ops, err := check.coLister.List(labels.Everything())
@@ -239,7 +238,7 @@ type clusterVersionOverridesUpgradeable struct {
239238

240239
func (check *clusterVersionOverridesUpgradeable) Check() *configv1.ClusterOperatorStatusCondition {
241240
cond := &configv1.ClusterOperatorStatusCondition{
242-
Type: configv1.ClusterStatusConditionType("UpgradeableClusterVersionOverrides"),
241+
Type: internal.UpgradeableClusterVersionOverrides,
243242
Status: configv1.ConditionFalse,
244243
}
245244

@@ -296,7 +295,7 @@ type clusterManifestDeleteInProgressUpgradeable struct {
296295

297296
func (check *clusterManifestDeleteInProgressUpgradeable) Check() *configv1.ClusterOperatorStatusCondition {
298297
cond := &configv1.ClusterOperatorStatusCondition{
299-
Type: configv1.ClusterStatusConditionType("UpgradeableDeletesInProgress"),
298+
Type: internal.UpgradeableDeletesInProgress,
300299
Status: configv1.ConditionFalse,
301300
}
302301
if deletes := resourcedelete.DeletesInProgress(); len(deletes) > 0 {
@@ -360,7 +359,7 @@ func (check *clusterAdminAcksCompletedUpgradeable) Check() *configv1.ClusterOper
360359
message := fmt.Sprintf("Unable to get ClusterVersion, err=%v.", err)
361360
klog.Error(message)
362361
return &configv1.ClusterOperatorStatusCondition{
363-
Type: upgradeableAdminAckRequired,
362+
Type: internal.UpgradeableAdminAckRequired,
364363
Status: configv1.ConditionFalse,
365364
Reason: "UnableToGetClusterVersion",
366365
Message: message,
@@ -384,7 +383,7 @@ func (check *clusterAdminAcksCompletedUpgradeable) Check() *configv1.ClusterOper
384383
}
385384
klog.Error(message)
386385
return &configv1.ClusterOperatorStatusCondition{
387-
Type: upgradeableAdminAckRequired,
386+
Type: internal.UpgradeableAdminAckRequired,
388387
Status: configv1.ConditionFalse,
389388
Reason: "UnableToAccessAdminGatesConfigMap",
390389
Message: message,
@@ -400,7 +399,7 @@ func (check *clusterAdminAcksCompletedUpgradeable) Check() *configv1.ClusterOper
400399
}
401400
klog.Error(message)
402401
return &configv1.ClusterOperatorStatusCondition{
403-
Type: upgradeableAdminAckRequired,
402+
Type: internal.UpgradeableAdminAckRequired,
404403
Status: configv1.ConditionFalse,
405404
Reason: "UnableToAccessAdminAcksConfigMap",
406405
Message: message,
@@ -421,15 +420,15 @@ func (check *clusterAdminAcksCompletedUpgradeable) Check() *configv1.ClusterOper
421420
}
422421
if len(reasons) == 1 {
423422
return &configv1.ClusterOperatorStatusCondition{
424-
Type: upgradeableAdminAckRequired,
423+
Type: internal.UpgradeableAdminAckRequired,
425424
Status: configv1.ConditionFalse,
426425
Reason: reason,
427426
Message: messages[0],
428427
}
429428
} else if len(reasons) > 1 {
430429
sort.Strings(messages)
431430
return &configv1.ClusterOperatorStatusCondition{
432-
Type: upgradeableAdminAckRequired,
431+
Type: internal.UpgradeableAdminAckRequired,
433432
Status: configv1.ConditionFalse,
434433
Reason: "MultipleReasons",
435434
Message: strings.Join(messages, " "),
@@ -531,7 +530,7 @@ func (optr *Operator) adminGatesEventHandler() cache.ResourceEventHandler {
531530
//
532531
// The cv parameter is expected to be non-nil.
533532
func (intervals *upgradeableCheckIntervals) throttlePeriod(cv *configv1.ClusterVersion) time.Duration {
534-
if cond := resourcemerge.FindOperatorStatusCondition(cv.Status.Conditions, DesiredReleaseAccepted); cond != nil {
533+
if cond := resourcemerge.FindOperatorStatusCondition(cv.Status.Conditions, internal.DesiredReleaseAccepted); cond != nil {
535534
deadline := cond.LastTransitionTime.Time.Add(intervals.afterPreconditionsFailed)
536535
if cond.Reason == "PreconditionChecks" && cond.Status == configv1.ConditionFalse && time.Now().Before(deadline) {
537536
return intervals.minOnFailedPreconditions

pkg/internal/constants.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package internal
22

3-
import "k8s.io/klog/v2"
3+
import (
4+
"k8s.io/klog/v2"
5+
6+
configv1 "github.com/openshift/api/config/v1"
7+
)
48

59
const (
610
ConfigNamespace = "openshift-config"
@@ -29,3 +33,38 @@ var (
2933
// amounts of logs. In kube, this is probably glog=8.
3034
TraceAll klog.Level = 8
3135
)
36+
37+
const (
38+
// ClusterStatusFailing is set on the ClusterVersion status when a cluster
39+
// cannot reach the desired state. It is considered more serious than Degraded
40+
// and indicates the cluster is not healthy.
41+
ClusterStatusFailing configv1.ClusterStatusConditionType = "Failing"
42+
43+
// ClusterVersionInvalid indicates that the cluster version has an error that prevents the server from
44+
// taking action. The cluster version operator will only reconcile the current state as long as this
45+
// condition is set.
46+
ClusterVersionInvalid configv1.ClusterStatusConditionType = "Invalid"
47+
48+
// DesiredReleaseAccepted indicates whether the requested (desired) release payload was successfully loaded
49+
// and no failures occurred during image verification and precondition checking.
50+
DesiredReleaseAccepted configv1.ClusterStatusConditionType = "ReleaseAccepted"
51+
52+
// ImplicitlyEnabledCapabilities is True if there are enabled capabilities which the user is not currently
53+
// requesting via spec.capabilities, because the cluster version operator does not support uninstalling
54+
// capabilities if any associated resources were previously managed by the CVO or disabling previously
55+
// enabled capabilities.
56+
ImplicitlyEnabledCapabilities configv1.ClusterStatusConditionType = "ImplicitlyEnabledCapabilities"
57+
58+
// UpgradeableAdminAckRequired is False if there is API removed from the Kubernetes API server which requires admin
59+
// consideration, and thus update to the next minor version is blocked.
60+
UpgradeableAdminAckRequired configv1.ClusterStatusConditionType = "UpgradeableAdminAckRequired"
61+
// UpgradeableDeletesInProgress is False if deleting resources is in progress, and thus update to the next minor
62+
// version is blocked.
63+
UpgradeableDeletesInProgress configv1.ClusterStatusConditionType = "UpgradeableDeletesInProgress"
64+
// UpgradeableClusterOperators is False if something is wrong with Cluster Operators, and thus update to the next minor
65+
// version is blocked.
66+
UpgradeableClusterOperators configv1.ClusterStatusConditionType = "UpgradeableClusterOperators"
67+
// UpgradeableClusterVersionOverrides is False if there are overrides in the Cluster Version, and thus update to the next minor
68+
// version is blocked.
69+
UpgradeableClusterVersionOverrides configv1.ClusterStatusConditionType = "UpgradeableClusterVersionOverrides"
70+
)

pkg/payload/precondition/clusterversion/upgradeable.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"k8s.io/klog/v2"
1414

1515
"github.com/openshift/cluster-version-operator/lib/resourcemerge"
16+
"github.com/openshift/cluster-version-operator/pkg/internal"
1617
"github.com/openshift/cluster-version-operator/pkg/payload/precondition"
1718
)
1819

@@ -33,7 +34,7 @@ func ClusterVersionOverridesCondition(cv *configv1.ClusterVersion) *configv1.Clu
3334
for _, override := range cv.Spec.Overrides {
3435
if override.Unmanaged {
3536
condition := configv1.ClusterOperatorStatusCondition{
36-
Type: configv1.ClusterStatusConditionType("UpgradeableClusterVersionOverrides"),
37+
Type: internal.UpgradeableClusterVersionOverrides,
3738
Status: configv1.ConditionFalse,
3839
Reason: "ClusterVersionOverridesSet",
3940
Message: "Disabling ownership via cluster version overrides prevents upgrades. Please remove overrides before continuing.",

0 commit comments

Comments
 (0)