sigs.k8s.io/cluster-api@v1.7.1/util/labels/helpers.go (about) 1 /* 2 Copyright 2021 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // Package labels implements label utility functions. 18 package labels 19 20 import ( 21 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 23 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" 24 ) 25 26 // IsTopologyOwned returns true if the object has the `topology.cluster.x-k8s.io/owned` label. 27 func IsTopologyOwned(o metav1.Object) bool { 28 _, ok := o.GetLabels()[clusterv1.ClusterTopologyOwnedLabel] 29 return ok 30 } 31 32 // IsMachinePoolOwned returns true if the object has the `cluster.x-k8s.io/pool-name` label or is owned by a MachinePool. 33 func IsMachinePoolOwned(o metav1.Object) bool { 34 if _, ok := o.GetLabels()[clusterv1.MachinePoolNameLabel]; ok { 35 return true 36 } 37 38 for _, owner := range o.GetOwnerReferences() { 39 if owner.Kind == "MachinePool" { 40 return true 41 } 42 } 43 44 return false 45 } 46 47 // HasWatchLabel returns true if the object has a label with the WatchLabel key matching the given value. 48 func HasWatchLabel(o metav1.Object, labelValue string) bool { 49 val, ok := o.GetLabels()[clusterv1.WatchLabel] 50 if !ok { 51 return false 52 } 53 return val == labelValue 54 }