Skip to content

Commit b8b56a5

Browse files
hardikdrprashanth26
authored andcommitted
Bugfix: Existing machine-object now adopts node-labels (#265)
1 parent 9e544fe commit b8b56a5

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

pkg/controller/machine.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,26 @@ func (c *controller) updateMachineState(machine *v1alpha1.Machine) (*v1alpha1.Ma
308308
return machine, err
309309
}
310310

311-
clone, err := c.updateMachineConditions(machine, node.Status.Conditions)
311+
machine, err = c.updateMachineConditions(machine, node.Status.Conditions)
312312
if err != nil {
313313
return machine, err
314314
}
315-
return clone, nil
315+
316+
clone := machine.DeepCopy()
317+
if clone.Labels == nil {
318+
clone.Labels = make(map[string]string)
319+
}
320+
321+
if _, ok := clone.Labels["node"]; !ok {
322+
clone.Labels["node"] = machine.Status.Node
323+
machine, err = c.controlMachineClient.Machines(clone.Namespace).Update(clone)
324+
if err != nil {
325+
glog.Warningf("Machine update failed. Retrying, error: %s", err)
326+
return machine, err
327+
}
328+
}
329+
330+
return machine, nil
316331
}
317332

318333
/*

pkg/controller/machine_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,12 @@ var _ = Describe("machine", func() {
10701070
Expect(actual.Status.LastOperation.Type).To(Equal(data.expect.machine.Status.LastOperation.Type))
10711071
Expect(actual.Status.LastOperation.Description).To(Equal(data.expect.machine.Status.LastOperation.Description))
10721072

1073+
if data.expect.machine.Labels != nil {
1074+
if _, ok := data.expect.machine.Labels["node"]; ok {
1075+
Expect(actual.Labels["node"]).To(Equal(data.expect.machine.Labels["node"]))
1076+
}
1077+
}
1078+
10731079
for i := range actual.Status.Conditions {
10741080
Expect(actual.Status.Conditions[i].Type).To(Equal(data.expect.machine.Status.Conditions[i].Type))
10751081
Expect(actual.Status.Conditions[i].Status).To(Equal(data.expect.machine.Status.Conditions[i].Status))
@@ -1243,6 +1249,38 @@ var _ = Describe("machine", func() {
12431249
}, nil, nil, nil),
12441250
},
12451251
}),
1252+
Entry("Machine object does not have node-label and node exists", &data{
1253+
setup: setup{
1254+
machines: newMachines(1, &machinev1.MachineTemplateSpec{
1255+
ObjectMeta: *newObjectMeta(objMeta, 0),
1256+
}, &machinev1.MachineStatus{
1257+
Node: "node",
1258+
}, nil, nil, nil),
1259+
nodes: []*corev1.Node{
1260+
&corev1.Node{
1261+
ObjectMeta: metav1.ObjectMeta{
1262+
Name: "node-0",
1263+
},
1264+
},
1265+
},
1266+
},
1267+
action: action{
1268+
machine: machineName,
1269+
},
1270+
expect: expect{
1271+
machine: newMachine(&machinev1.MachineTemplateSpec{
1272+
ObjectMeta: metav1.ObjectMeta{
1273+
Name: "machine-0",
1274+
},
1275+
}, &machinev1.MachineStatus{
1276+
Node: "node",
1277+
}, nil, nil,
1278+
map[string]string{
1279+
"node": "node-0",
1280+
},
1281+
),
1282+
},
1283+
}),
12461284
)
12471285
})
12481286

0 commit comments

Comments
 (0)