sigs.k8s.io/cluster-api@v1.7.1/internal/topology/selectors/selectors.go (about) 1 /* 2 Copyright 2023 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 selectors contains selectors utils. 18 package selectors 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 // ForMachineDeploymentMHC generates a selector for MachineDeployment MHCs. 27 func ForMachineDeploymentMHC(md *clusterv1.MachineDeployment) *metav1.LabelSelector { 28 // The selector returned here is the minimal common selector for all MachineSets belonging to a MachineDeployment. 29 // It does not include any labels set in ClusterClass, Cluster Topology or elsewhere. 30 return &metav1.LabelSelector{MatchLabels: map[string]string{ 31 clusterv1.ClusterTopologyOwnedLabel: "", 32 clusterv1.ClusterTopologyMachineDeploymentNameLabel: md.Spec.Selector.MatchLabels[clusterv1.ClusterTopologyMachineDeploymentNameLabel], 33 }, 34 } 35 } 36 37 // ForControlPlaneMHC generates a selector for control plane MHCs. 38 func ForControlPlaneMHC() *metav1.LabelSelector { 39 // The selector returned here is the minimal common selector for all Machines belonging to the ControlPlane. 40 // It does not include any labels set in ClusterClass, Cluster Topology or elsewhere. 41 return &metav1.LabelSelector{ 42 MatchLabels: map[string]string{ 43 clusterv1.ClusterTopologyOwnedLabel: "", 44 clusterv1.MachineControlPlaneLabel: "", 45 }, 46 } 47 }