@@ -17,8 +17,8 @@ const (
1717
1818 OperatorGroupKind = "OperatorGroup"
1919
20- OperatorGroupLabelPrefix = "olm.operatorgroup/"
21- OperatorGroupLabelTemplate = OperatorGroupLabelPrefix + "%s.%s "
20+ OperatorGroupLabelPrefix = "olm.operatorgroup.uid /"
21+ OperatorGroupLabelTemplate = OperatorGroupLabelPrefix + "%s"
2222)
2323
2424// OperatorGroupSpec is the spec for an OperatorGroup resource.
@@ -108,35 +108,36 @@ func (o *OperatorGroup) HasServiceAccountSynced() bool {
108108 return false
109109}
110110
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-
118111// 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
121118}
122119
123120// 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 ) {
125122 if len (o .Spec .TargetNamespaces ) == 0 {
126123 // If no target namespaces are set, check if a selector exists.
127124 if o .Spec .Selector != nil {
128- return o .Spec .Selector
125+ return o .Spec .Selector , nil
129126 }
130127 // No selector exists, return nil which should be used to select EVERYTHING.
131- return nil
128+ return nil , nil
132129 }
133130 // 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+
135136 return & metav1.LabelSelector {
136137 MatchLabels : map [string ]string {
137138 ogKey : ogValue ,
138139 },
139- }
140+ }, nil
140141}
141142
142143// IsOperatorGroupLabel returns true if the label is an OperatorGroup label.
0 commit comments