Skip to content

Commit 7f76609

Browse files
committed
Review fixes v4
1 parent 5f79290 commit 7f76609

File tree

4 files changed

+59
-50
lines changed

4 files changed

+59
-50
lines changed

internal/controllers/machine/machine_controller_noderef_test.go

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -85,40 +85,44 @@ func TestReconcileNode(t *testing.T) {
8585
}
8686

8787
testCases := []struct {
88-
name string
89-
machine *clusterv1.Machine
90-
node *corev1.Node
91-
nodeGetErr bool
92-
expectResult ctrl.Result
93-
expectError bool
94-
expected func(g *WithT, m *clusterv1.Machine)
95-
expectNodeGetError bool
96-
expectedNode func(g *WithT, m *corev1.Node)
88+
name string
89+
machine *clusterv1.Machine
90+
node *corev1.Node
91+
featureGateMachineTaintsEnabled bool
92+
nodeGetErr bool
93+
expectResult ctrl.Result
94+
expectError bool
95+
expected func(g *WithT, m *clusterv1.Machine)
96+
expectNodeGetError bool
97+
expectedNode func(g *WithT, m *corev1.Node)
9798
}{
9899
{
99-
name: "No op if provider ID is not set",
100-
machine: &clusterv1.Machine{},
101-
node: nil,
102-
nodeGetErr: false,
103-
expectResult: ctrl.Result{},
104-
expectError: false,
100+
name: "No op if provider ID is not set",
101+
machine: &clusterv1.Machine{},
102+
node: nil,
103+
featureGateMachineTaintsEnabled: false,
104+
nodeGetErr: false,
105+
expectResult: ctrl.Result{},
106+
expectError: false,
105107
},
106108
{
107-
name: "err reading node (something different than not found), it should return error",
108-
machine: defaultMachine.DeepCopy(),
109-
node: nil,
110-
nodeGetErr: true,
111-
expectResult: ctrl.Result{},
112-
expectError: true,
113-
expectNodeGetError: true,
109+
name: "err reading node (something different than not found), it should return error",
110+
machine: defaultMachine.DeepCopy(),
111+
node: nil,
112+
featureGateMachineTaintsEnabled: false,
113+
nodeGetErr: true,
114+
expectResult: ctrl.Result{},
115+
expectError: true,
116+
expectNodeGetError: true,
114117
},
115118
{
116-
name: "waiting for the node to exist, no op",
117-
machine: defaultMachine.DeepCopy(),
118-
node: nil,
119-
nodeGetErr: false,
120-
expectResult: ctrl.Result{},
121-
expectError: false,
119+
name: "waiting for the node to exist, no op",
120+
machine: defaultMachine.DeepCopy(),
121+
node: nil,
122+
featureGateMachineTaintsEnabled: false,
123+
nodeGetErr: false,
124+
expectResult: ctrl.Result{},
125+
expectError: false,
122126
},
123127
{
124128
name: "node found, should surface info",
@@ -146,9 +150,10 @@ func TestReconcileNode(t *testing.T) {
146150
},
147151
},
148152
},
149-
nodeGetErr: false,
150-
expectResult: ctrl.Result{},
151-
expectError: false,
153+
featureGateMachineTaintsEnabled: false,
154+
nodeGetErr: false,
155+
expectResult: ctrl.Result{},
156+
expectError: false,
152157
expected: func(g *WithT, m *clusterv1.Machine) {
153158
g.Expect(m.Status.NodeRef.Name).To(Equal("test-node-1"))
154159
g.Expect(m.Status.NodeInfo).ToNot(BeNil())
@@ -174,10 +179,11 @@ func TestReconcileNode(t *testing.T) {
174179
},
175180
},
176181
},
177-
node: nil,
178-
nodeGetErr: false,
179-
expectResult: ctrl.Result{},
180-
expectError: true,
182+
node: nil,
183+
featureGateMachineTaintsEnabled: false,
184+
nodeGetErr: false,
185+
expectResult: ctrl.Result{},
186+
expectError: true,
181187
},
182188
{
183189
name: "node not found is tolerated when machine is deleting",
@@ -200,10 +206,11 @@ func TestReconcileNode(t *testing.T) {
200206
},
201207
},
202208
},
203-
node: nil,
204-
nodeGetErr: false,
205-
expectResult: ctrl.Result{},
206-
expectError: false,
209+
node: nil,
210+
featureGateMachineTaintsEnabled: false,
211+
nodeGetErr: false,
212+
expectResult: ctrl.Result{},
213+
expectError: false,
207214
},
208215
{
209216
name: "node found, should propagate taints",
@@ -227,9 +234,10 @@ func TestReconcileNode(t *testing.T) {
227234
},
228235
},
229236
},
230-
nodeGetErr: false,
231-
expectResult: ctrl.Result{},
232-
expectError: false,
237+
featureGateMachineTaintsEnabled: true,
238+
nodeGetErr: false,
239+
expectResult: ctrl.Result{},
240+
expectError: false,
233241
expectedNode: func(g *WithT, n *corev1.Node) {
234242
g.Expect(n.Spec.Taints).To(BeComparableTo([]corev1.Taint{
235243
{
@@ -248,7 +256,7 @@ func TestReconcileNode(t *testing.T) {
248256
},
249257
{
250258
name: "node found, should not add taints annotation if taints feature gate is disabled",
251-
machine: defaultMachine.DeepCopy(), // The test only enables the feature gate if machine has taints.
259+
machine: defaultMachineWithTaints.DeepCopy(), // The test only enables the feature gate if machine has taints.
252260
node: &corev1.Node{
253261
ObjectMeta: metav1.ObjectMeta{
254262
Name: "test-node-1",
@@ -268,9 +276,10 @@ func TestReconcileNode(t *testing.T) {
268276
},
269277
},
270278
},
271-
nodeGetErr: false,
272-
expectResult: ctrl.Result{},
273-
expectError: false,
279+
featureGateMachineTaintsEnabled: false,
280+
nodeGetErr: false,
281+
expectResult: ctrl.Result{},
282+
expectError: false,
274283
expectedNode: func(g *WithT, n *corev1.Node) {
275284
g.Expect(n.Spec.Taints).To(BeEmpty())
276285
g.Expect(n.Annotations).ToNot(HaveKey(clusterv1.TaintsFromMachineAnnotation))
@@ -282,7 +291,7 @@ func TestReconcileNode(t *testing.T) {
282291
t.Run(tc.name, func(t *testing.T) {
283292
g := NewWithT(t)
284293

285-
if tc.machine.Spec.Taints != nil {
294+
if tc.featureGateMachineTaintsEnabled {
286295
utilfeature.SetFeatureGateDuringTest(t, feature.Gates, feature.MachineTaintPropagation, true)
287296
}
288297

internal/controllers/machinedeployment/machinedeployment_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ func TestMachineDeploymentReconciler(t *testing.T) {
422422

423423
// Update the taints of the MachineDeployment,
424424
// expect the Reconcile to be called and the MachineSet to be updated in-place.
425-
t.Log("Updating deletion.order on the MachineDeployment")
425+
t.Log("Updating template.spec.taints on the MachineDeployment")
426426
additionalTaint := clusterv1.MachineTaint{
427427
Key: "additional-taint-key",
428428
Value: "additional-taint-value",

internal/webhooks/machinepool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (webhook *MachinePool) validate(oldObj, newObj *clusterv1.MachinePool) erro
192192
if len(newObj.Spec.Template.Spec.Taints) > 0 {
193193
allErrs = append(allErrs, field.Forbidden(specPath.Child("taints"), "taints feature for MachinePools is not yet implemented"))
194194
if !feature.Gates.Enabled(feature.MachineTaintPropagation) {
195-
allErrs = append(allErrs, field.Forbidden(specPath.Child("taints"), "taints are not allowed to be set when the feature gate MachineTaintPropagation is disabled"))
195+
allErrs = append(allErrs, field.Forbidden(specPath.Child("taints"), "taints are not allowed to be set when the feature gate MachineTaintPropagation is disabled"))
196196
}
197197
}
198198

internal/webhooks/test/machine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func TestMachineTaintValidation(t *testing.T) {
178178
expectErr: true,
179179
},
180180
{
181-
name: "should block taint key with multuple slashes",
181+
name: "should block taint key with multiple slashes",
182182
featureEnabled: true,
183183
machine: m.DeepCopy().WithTaints(clusterv1.MachineTaint{
184184
Key: "one/two/with-prefix", Effect: corev1.TaintEffectNoSchedule, Propagation: clusterv1.MachineTaintPropagationAlways,

0 commit comments

Comments
 (0)