Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions config/crds/hive_v1alpha1_clusterdeployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/hive/v1alpha1/machinepools.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions pkg/controller/remotemachineset/remotemachineset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package remotemachineset
import (
"context"
"fmt"
"reflect"

log "github.com/sirupsen/logrus"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand Down