Skip to content

Commit a51131e

Browse files
Merge pull request #174 from bison/status-conditions
Set all expected ClusterOperator status conditions
2 parents 46166ee + 4000ff8 commit a51131e

File tree

2 files changed

+104
-22
lines changed

2 files changed

+104
-22
lines changed

pkg/operator/status.go

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,92 @@ import (
1010
"k8s.io/utils/pointer"
1111
)
1212

13+
// StatusReason is a MixedCaps string representing the reason for a
14+
// status condition change.
15+
type StatusReason string
16+
17+
// The default set of status change reasons.
18+
const (
19+
ReasonEmpty StatusReason = ""
20+
ReasonSyncing StatusReason = "SyncingResources"
21+
ReasonSyncFailed StatusReason = "SyncingFailed"
22+
)
23+
24+
// statusProgressing sets the Progressing condition to True, with the given
25+
// reason and message, and sets both the Available and Failing conditions to
26+
// False.
27+
func (optr *Operator) statusProgressing(reason StatusReason, message string) error {
28+
conds := []osconfigv1.ClusterOperatorStatusCondition{
29+
{
30+
Type: osconfigv1.OperatorProgressing,
31+
Status: osconfigv1.ConditionTrue,
32+
Reason: string(reason),
33+
Message: message,
34+
},
35+
{
36+
Type: osconfigv1.OperatorAvailable,
37+
Status: osconfigv1.ConditionFalse,
38+
},
39+
{
40+
Type: osconfigv1.OperatorFailing,
41+
Status: osconfigv1.ConditionFalse,
42+
},
43+
}
44+
45+
return optr.syncStatus(conds)
46+
}
47+
48+
// statusAvailable sets the Available condition to True, with the given reason
49+
// and message, and sets both the Progressing and Failing conditions to False.
50+
func (optr *Operator) statusAvailable(reason StatusReason, message string) error {
51+
conds := []osconfigv1.ClusterOperatorStatusCondition{
52+
{
53+
Type: osconfigv1.OperatorAvailable,
54+
Status: osconfigv1.ConditionTrue,
55+
Reason: string(reason),
56+
Message: message,
57+
},
58+
{
59+
Type: osconfigv1.OperatorProgressing,
60+
Status: osconfigv1.ConditionFalse,
61+
},
62+
63+
{
64+
Type: osconfigv1.OperatorFailing,
65+
Status: osconfigv1.ConditionFalse,
66+
},
67+
}
68+
69+
return optr.syncStatus(conds)
70+
}
71+
72+
// statusFailing sets the Failing condition to True, with the given reason and
73+
// message, and sets the Progressing condition to False, and the Available
74+
// condition to True. This indicates that the operator is present and may be
75+
// partially functioning, but is in a degraded or failing state.
76+
func (optr *Operator) statusFailing(reason StatusReason, message string) error {
77+
conds := []osconfigv1.ClusterOperatorStatusCondition{
78+
{
79+
Type: osconfigv1.OperatorFailing,
80+
Status: osconfigv1.ConditionTrue,
81+
Reason: string(reason),
82+
Message: message,
83+
},
84+
{
85+
Type: osconfigv1.OperatorProgressing,
86+
Status: osconfigv1.ConditionFalse,
87+
},
88+
{
89+
Type: osconfigv1.OperatorAvailable,
90+
Status: osconfigv1.ConditionTrue,
91+
},
92+
}
93+
94+
return optr.syncStatus(conds)
95+
}
96+
1397
//syncStatus applies the new condition to the mao ClusterOperator object.
14-
func (optr *Operator) syncStatus(cond osconfigv1.ClusterOperatorStatusCondition) error {
98+
func (optr *Operator) syncStatus(conds []osconfigv1.ClusterOperatorStatusCondition) error {
1599
// to report the status of all the managed components.
16100
clusterOperator := &osconfigv1.ClusterOperator{
17101
ObjectMeta: metav1.ObjectMeta{
@@ -22,7 +106,11 @@ func (optr *Operator) syncStatus(cond osconfigv1.ClusterOperatorStatusCondition)
22106
Version: version.Raw,
23107
},
24108
}
25-
cvoresourcemerge.SetOperatorStatusCondition(&clusterOperator.Status.Conditions, cond)
109+
110+
for _, c := range conds {
111+
cvoresourcemerge.SetOperatorStatusCondition(&clusterOperator.Status.Conditions, c)
112+
}
113+
26114
_, _, err := ApplyClusterOperator(optr.osClient.ConfigV1(), clusterOperator)
27115
return err
28116
}

pkg/operator/sync.go

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1111
"k8s.io/apimachinery/pkg/util/wait"
1212

13-
osconfigv1 "github.com/openshift/api/config/v1"
13+
"path/filepath"
14+
1415
"github.com/openshift/cluster-version-operator/lib/resourceapply"
1516
"github.com/openshift/cluster-version-operator/lib/resourceread"
16-
"path/filepath"
1717
)
1818

1919
const (
@@ -24,36 +24,30 @@ const (
2424
func (optr *Operator) syncAll(config OperatorConfig) error {
2525
glog.Infof("Syncing ClusterOperatorStatus")
2626

27-
if err := optr.syncStatus(osconfigv1.ClusterOperatorStatusCondition{
28-
Type: osconfigv1.OperatorProgressing,
29-
Status: osconfigv1.ConditionTrue,
30-
Message: "Running sync functions",
31-
}); err != nil {
27+
if err := optr.statusProgressing(ReasonSyncing, "Running sync functions"); err != nil {
3228
glog.Errorf("Error synching ClusterOperatorStatus: %v", err)
3329
return fmt.Errorf("error syncing ClusterOperatorStatus: %v", err)
3430
}
3531

36-
err := optr.syncClusterAPIController(config)
37-
if err != nil {
32+
if err := optr.syncClusterAPIController(config); err != nil {
33+
if err := optr.statusFailing(ReasonSyncFailed, err.Error()); err != nil {
34+
// Just log the error here. We still want to
35+
// return the outer error.
36+
glog.Errorf("Error synching ClusterOperatorStatus: %v", err)
37+
}
38+
3839
glog.Errorf("Failed sync-up cluster api controller: %v", err)
3940
return err
4041
}
42+
4143
glog.Info("Synched up cluster api controller")
4244

43-
// TODO(alberto): create funcs to for atomic conds changes
44-
if err := optr.syncStatus(osconfigv1.ClusterOperatorStatusCondition{
45-
Type: osconfigv1.OperatorProgressing,
46-
Status: osconfigv1.ConditionFalse,
47-
Message: "Running sync functions",
48-
}); err != nil {
45+
if err := optr.statusAvailable(ReasonEmpty, "cluster-api ready"); err != nil {
4946
glog.Errorf("Error synching ClusterOperatorStatus: %v", err)
5047
return fmt.Errorf("error syncing ClusterOperatorStatus: %v", err)
5148
}
52-
return optr.syncStatus(osconfigv1.ClusterOperatorStatusCondition{
53-
Type: osconfigv1.OperatorAvailable,
54-
Status: osconfigv1.ConditionTrue,
55-
Message: "Done running sync functions",
56-
})
49+
50+
return nil
5751
}
5852

5953
func (optr *Operator) syncClusterAPIController(config OperatorConfig) error {

0 commit comments

Comments
 (0)