diff --git a/config/crds/hive_v1alpha1_clusterdeployment.yaml b/config/crds/hive_v1alpha1_clusterdeployment.yaml index bab954bd9e9..f1fead7ec1a 100644 --- a/config/crds/hive_v1alpha1_clusterdeployment.yaml +++ b/config/crds/hive_v1alpha1_clusterdeployment.yaml @@ -56,6 +56,12 @@ spec: nodes that need to be installed. items: properties: + labels: + description: Map of label string keys and values that will be + applied to the created MachineSet's MachineSpec. This list will + overwrite any modifications made to Node labels on an ongoing + basis. + type: object name: description: Name is the name of the machine pool. type: string @@ -158,6 +164,13 @@ spec: pool. Default is 1. format: int64 type: integer + taints: + description: List of taints that will be applied to the created + MachineSet's MachineSpec. This list will overwrite any modifications + made to Node taints on an ongoing basis. + items: + type: object + type: array required: - name - replicas @@ -168,6 +181,11 @@ spec: description: ControlPlane is the MachinePool containing control plane nodes that need to be installed. properties: + labels: + description: Map of label string keys and values that will be applied + to the created MachineSet's MachineSpec. This list will overwrite + any modifications made to Node labels on an ongoing basis. + type: object name: description: Name is the name of the machine pool. type: string @@ -269,6 +287,13 @@ spec: pool. Default is 1. format: int64 type: integer + taints: + description: List of taints that will be applied to the created + MachineSet's MachineSpec. This list will overwrite any modifications + made to Node taints on an ongoing basis. + items: + type: object + type: array required: - name - replicas diff --git a/pkg/apis/hive/v1alpha1/machinepools.go b/pkg/apis/hive/v1alpha1/machinepools.go index cde5ef0d8d8..24583accfbd 100644 --- a/pkg/apis/hive/v1alpha1/machinepools.go +++ b/pkg/apis/hive/v1alpha1/machinepools.go @@ -1,5 +1,9 @@ package v1alpha1 +import ( + corev1 "k8s.io/api/core/v1" +) + // MachinePool is a pool of machines to be installed. type MachinePool struct { // Name is the name of the machine pool. @@ -11,6 +15,17 @@ type MachinePool struct { // Platform is configuration for machine pool specific to the platfrom. Platform MachinePoolPlatform `json:"platform"` + + // Map of label string keys and values that will be applied to the created MachineSet's + // MachineSpec. This list will overwrite any modifications made to Node labels on an + // ongoing basis. + // +optional + Labels map[string]string `json:"labels,omitempty"` + + // List of taints that will be applied to the created MachineSet's MachineSpec. + // This list will overwrite any modifications made to Node taints on an ongoing basis. + // +optional + Taints []corev1.Taint `json:"taints,omitempty"` } // MachinePoolPlatform is the platform-specific configuration for a machine diff --git a/pkg/controller/remotemachineset/remotemachineset_controller.go b/pkg/controller/remotemachineset/remotemachineset_controller.go index c1e88857e36..51e269236d6 100644 --- a/pkg/controller/remotemachineset/remotemachineset_controller.go +++ b/pkg/controller/remotemachineset/remotemachineset_controller.go @@ -19,6 +19,7 @@ package remotemachineset import ( "context" "fmt" + "reflect" log "github.com/sirupsen/logrus" @@ -209,6 +210,16 @@ func (r *ReconcileRemoteMachineSet) syncMachineSets(cd *hivev1.ClusterDeployment objectModified = true } + if !reflect.DeepEqual(rMS.Spec.Template.Spec.Labels, ms.Spec.Template.Spec.Labels) { + rMS.Spec.Template.Spec.Labels = ms.Spec.Template.Spec.Labels + objectModified = true + } + + if !reflect.DeepEqual(rMS.Spec.Template.Spec.Taints, ms.Spec.Template.Spec.Taints) { + rMS.Spec.Template.Spec.Taints = ms.Spec.Template.Spec.Taints + objectModified = true + } + if *objectMetaModified || objectModified { rMS.Generation++ machineSetsToUpdate = append(machineSetsToUpdate, &rMS) @@ -312,7 +323,18 @@ func (r *ReconcileRemoteMachineSet) generateMachineSetsFromClusterDeployment(cd if err != nil { return nil, err } + hivePool := findHiveMachinePool(cd, workerPool.Name) for _, ms := range icMachineSets { + // Apply hive MachinePool labels to MachineSet MachineSpec. + ms.Spec.Template.Spec.ObjectMeta.Labels = map[string]string{} + for key, value := range hivePool.Labels { + ms.Spec.Template.Spec.ObjectMeta.Labels[key] = value + } + + // Apply hive MachinePool taints to MachineSet MachineSpec. + ms.Spec.Template.Spec.Taints = hivePool.Taints + + // Re-use existing AWS resources for generated MachineSets. updateMachineSetAWSMachineProviderConfig(ms, ic.ObjectMeta.Name) installerMachineSets = append(installerMachineSets, *ms) } diff --git a/pkg/controller/remotemachineset/remotemachineset_controller_test.go b/pkg/controller/remotemachineset/remotemachineset_controller_test.go index 18c5ff817c8..1e138b4729c 100644 --- a/pkg/controller/remotemachineset/remotemachineset_controller_test.go +++ b/pkg/controller/remotemachineset/remotemachineset_controller_test.go @@ -365,10 +365,16 @@ func TestRemoteMachineSetReconcile(t *testing.T) { assert.Equal(t, *eMS.Spec.Replicas, *rMS.Spec.Replicas) assert.Equal(t, eMS.Generation, rMS.Generation) if !reflect.DeepEqual(eMS.ObjectMeta.Labels, rMS.ObjectMeta.Labels) { - t.Errorf("machineset %v has unexpected labels:\nexpected: %v\nactual: %v", eMS.Name, eMS.ObjectMeta.Labels, rMS.ObjectMeta.Labels) + t.Errorf("machineset %v has unexpected labels:\nexpected: %v\nactual: %v", eMS.Name, eMS.Labels, rMS.Labels) } if !reflect.DeepEqual(eMS.ObjectMeta.Annotations, rMS.ObjectMeta.Annotations) { - t.Errorf("machineset %v has unexpected annotations:\nexpected: %v\nactual: %v", eMS.Name, eMS.ObjectMeta.Labels, rMS.ObjectMeta.Labels) + t.Errorf("machineset %v has unexpected annotations:\nexpected: %v\nactual: %v", eMS.Name, eMS.Labels, rMS.Labels) + } + if !reflect.DeepEqual(eMS.Spec.Template.Spec.Labels, rMS.Spec.Template.Spec.Labels) { + t.Errorf("machineset %v machinespec has unexpected labels:\nexpected: %v\nactual: %v", eMS.Name, eMS.Spec.Template.Spec.Labels, rMS.Spec.Template.Spec.Labels) + } + if !reflect.DeepEqual(eMS.Spec.Template.Spec.Taints, rMS.Spec.Template.Spec.Taints) { + t.Errorf("machineset %v has unexpected taints:\nexpected: %v\nactual: %v", eMS.Name, eMS.Spec.Template.Spec.Taints, rMS.Spec.Template.Spec.Taints) } } } @@ -404,6 +410,16 @@ func testMachinePool(name string, replicas int, zones []string) hivev1.MachinePo InstanceType: "m4.large", }, }, + Labels: map[string]string{ + "infra": "true", + }, + Taints: []corev1.Taint{ + { + Key: "foo", + Value: "bar", + Effect: corev1.TaintEffectNoSchedule, + }, + }, } if len(zones) != 0 { @@ -428,6 +444,22 @@ func testMachineSet(name string, machineType string, unstompedAnnotation bool, r }, Spec: machineapi.MachineSetSpec{ Replicas: &msReplicas, + Template: machineapi.MachineTemplateSpec{ + Spec: machineapi.MachineSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{ + "infra": "true", + }, + }, + Taints: []corev1.Taint{ + { + Key: "foo", + Value: "bar", + Effect: corev1.TaintEffectNoSchedule, + }, + }, + }, + }, }, } // Add a pre-existing annotation which we will ensure remains in updated machinesets.