github.com/operator-framework/operator-lifecycle-manager@v0.30.0/pkg/controller/operators/openshift/clusteroperator.go (about) 1 package openshift 2 3 import ( 4 "context" 5 6 configv1 "github.com/openshift/api/config/v1" 7 utilerrors "k8s.io/apimachinery/pkg/util/errors" 8 ) 9 10 func NewClusterOperator(name string) *ClusterOperator { 11 co := &ClusterOperator{ClusterOperator: &configv1.ClusterOperator{}} 12 co.SetName(name) 13 return co 14 } 15 16 type ClusterOperator struct { 17 *configv1.ClusterOperator 18 } 19 20 func (c *ClusterOperator) GetOperatorVersion() string { 21 for _, v := range c.Status.Versions { 22 if v.Name == "operator" { 23 return v.Version 24 } 25 } 26 27 return "" 28 } 29 30 func (c *ClusterOperator) GetCondition(conditionType configv1.ClusterStatusConditionType) *configv1.ClusterOperatorStatusCondition { 31 for _, cond := range c.Status.Conditions { 32 if cond.Type == conditionType { 33 return &cond 34 } 35 } 36 37 return nil 38 } 39 40 func (c *ClusterOperator) SetCondition(condition *configv1.ClusterOperatorStatusCondition) { 41 // Filter dups 42 conditions := []configv1.ClusterOperatorStatusCondition{} 43 for _, c := range c.Status.Conditions { 44 if c.Type != condition.Type { 45 conditions = append(conditions, c) 46 } 47 } 48 49 c.Status.Conditions = append(conditions, *condition) 50 } 51 52 type Mutator interface { 53 Mutate(context.Context, *ClusterOperator) error 54 } 55 56 type MutateFunc func(context.Context, *ClusterOperator) error 57 58 func (m MutateFunc) Mutate(ctx context.Context, co *ClusterOperator) error { 59 return m(ctx, co) 60 } 61 62 type SerialMutations []Mutator 63 64 func (s SerialMutations) Mutate(ctx context.Context, co *ClusterOperator) error { 65 var errs []error 66 for _, m := range s { 67 if err := m.Mutate(ctx, co); err != nil { 68 errs = append(errs, err) 69 } 70 } 71 72 return utilerrors.NewAggregate(errs) 73 }