@@ -17,8 +17,8 @@ const (
17
17
18
18
OperatorGroupKind = "OperatorGroup"
19
19
20
- OperatorGroupLabelPrefix = "olm.operatorgroup/"
21
- OperatorGroupLabelTemplate = OperatorGroupLabelPrefix + "%s.%s "
20
+ OperatorGroupLabelPrefix = "olm.operatorgroup.uid /"
21
+ OperatorGroupLabelTemplate = OperatorGroupLabelPrefix + "%s"
22
22
)
23
23
24
24
// OperatorGroupSpec is the spec for an OperatorGroup resource.
@@ -108,35 +108,36 @@ func (o *OperatorGroup) HasServiceAccountSynced() bool {
108
108
return false
109
109
}
110
110
111
- // GetLabel returns a label that is applied to Namespaces to signify that the
112
- // namespace is a part of the OperatorGroup using selectors.
113
- func (o * OperatorGroup ) GetLabel () string {
114
- key , _ := o .OGLabelKeyAndValue ()
115
- return key
116
- }
117
-
118
111
// OGLabelKeyAndValue returns a key and value that should be applied to namespaces listed in the OperatorGroup.
119
- func (o * OperatorGroup ) OGLabelKeyAndValue () (string , string ) {
120
- return fmt .Sprintf (OperatorGroupLabelTemplate , o .GetNamespace (), o .GetName ()), ""
112
+ // If the UID is not set an error is returned.
113
+ func (o * OperatorGroup ) OGLabelKeyAndValue () (string , string , error ) {
114
+ if string (o .GetUID ()) == "" {
115
+ return "" , "" , fmt .Errorf ("Missing UID" )
116
+ }
117
+ return fmt .Sprintf (OperatorGroupLabelTemplate , o .GetUID ()), "" , nil
121
118
}
122
119
123
120
// NamespaceLabelSelector provides a selector that can be used to filter namespaces that belong to the OperatorGroup.
124
- func (o * OperatorGroup ) NamespaceLabelSelector () * metav1.LabelSelector {
121
+ func (o * OperatorGroup ) NamespaceLabelSelector () ( * metav1.LabelSelector , error ) {
125
122
if len (o .Spec .TargetNamespaces ) == 0 {
126
123
// If no target namespaces are set, check if a selector exists.
127
124
if o .Spec .Selector != nil {
128
- return o .Spec .Selector
125
+ return o .Spec .Selector , nil
129
126
}
130
127
// No selector exists, return nil which should be used to select EVERYTHING.
131
- return nil
128
+ return nil , nil
132
129
}
133
130
// Return a label that should be present on all namespaces defined in the OperatorGroup.Spec.TargetNamespaces field.
134
- ogKey , ogValue := o .OGLabelKeyAndValue ()
131
+ ogKey , ogValue , err := o .OGLabelKeyAndValue ()
132
+ if err != nil {
133
+ return nil , err
134
+ }
135
+
135
136
return & metav1.LabelSelector {
136
137
MatchLabels : map [string ]string {
137
138
ogKey : ogValue ,
138
139
},
139
- }
140
+ }, nil
140
141
}
141
142
142
143
// IsOperatorGroupLabel returns true if the label is an OperatorGroup label.
0 commit comments