-
Notifications
You must be signed in to change notification settings - Fork 19
/
writer.go
39 lines (31 loc) · 1.03 KB
/
writer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package clusteroperator
import (
"context"
configv1 "github.com/openshift/api/config/v1"
"k8s.io/apimachinery/pkg/api/equality"
"sigs.k8s.io/controller-runtime/pkg/client"
)
// From https://github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorstatus/writer.go
// NewWriter returns a new instance of Writer.
func NewWriter(client client.Client) *Writer {
return &Writer{
Client: client,
}
}
// Writer encapsulates logic for cluster operator object API. It is used to
// update ClusterOperator resource.
type Writer struct {
client.Client
}
// UpdateStatus updates the clusteroperator object with the new status specified.
func (w *Writer) UpdateStatus(ctx context.Context, existingCO *configv1.ClusterOperator, newStatus configv1.ClusterOperatorStatus) error {
if existingCO == nil {
panic("BUG: existingCO parameter was nil")
}
existingStatus := existingCO.Status
if equality.Semantic.DeepEqual(existingStatus, newStatus) {
return nil
}
existingCO.Status = newStatus
return w.Status().Update(ctx, existingCO)
}