@@ -261,7 +261,7 @@ func (c *Cluster) waitStatefulsetReady() error {
261261 return retryutil .Retry (c .OpConfig .ResourceCheckInterval , c .OpConfig .ResourceCheckTimeout ,
262262 func () (bool , error ) {
263263 listOptions := metav1.ListOptions {
264- LabelSelector : c .labelsSet ().String (),
264+ LabelSelector : c .labelsSet (false ).String (),
265265 }
266266 ss , err := c .KubeClient .StatefulSets (c .Namespace ).List (listOptions )
267267 if err != nil {
@@ -277,7 +277,7 @@ func (c *Cluster) waitStatefulsetReady() error {
277277}
278278
279279func (c * Cluster ) waitPodLabelsReady () error {
280- ls := c .labelsSet ()
280+ ls := c .labelsSet (false )
281281 namespace := c .Namespace
282282
283283 listOptions := metav1.ListOptions {
@@ -337,18 +337,26 @@ func (c *Cluster) waitStatefulsetPodsReady() error {
337337 return nil
338338}
339339
340- func (c * Cluster ) labelsSet () labels.Set {
340+ // Returns labels used to create or list k8s objects such as pods
341+ // For backward compatability, shouldAddExtraLabels must be false
342+ // when listing k8s objects. See operator PR #252
343+ func (c * Cluster ) labelsSet (shouldAddExtraLabels bool ) labels.Set {
341344 lbls := make (map [string ]string )
342345 for k , v := range c .OpConfig .ClusterLabels {
343346 lbls [k ] = v
344347 }
345348 lbls [c .OpConfig .ClusterNameLabel ] = c .Name
346349
350+ if shouldAddExtraLabels {
351+ // enables filtering resources owned by a team
352+ lbls ["team" ] = c .Postgresql .Spec .TeamID
353+ }
354+
347355 return labels .Set (lbls )
348356}
349357
350358func (c * Cluster ) roleLabelsSet (role PostgresRole ) labels.Set {
351- lbls := c .labelsSet ()
359+ lbls := c .labelsSet (false )
352360 lbls [c .OpConfig .PodRoleLabel ] = string (role )
353361 return lbls
354362}
0 commit comments