Skip to content

Commit 6cec878

Browse files
authored
Propagate RemoteMachine labels and annotations to the Machine (#1289)
Signed-off-by: Alexey Makhov <[email protected]> Signed-off-by: makhov <[email protected]>
1 parent 0cdbb93 commit 6cec878

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

internal/controller/infrastructure/remote_machine_controller.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,19 @@ func (r *RemoteMachineController) Reconcile(ctx context.Context, req ctrl.Reques
282282
Address: rm.Spec.Address,
283283
},
284284
}
285+
for l := range rm.Labels {
286+
if _, ok := m.Labels[l]; !ok {
287+
m.Labels[l] = rm.Labels[l]
288+
}
289+
}
290+
for k := range rm.Annotations {
291+
if _, ok := m.Annotations[k]; !ok {
292+
m.Annotations[k] = rm.Annotations[k]
293+
}
294+
}
285295

286296
err = retry.RetryOnConflict(retry.DefaultBackoff, func() error {
287-
return r.Status().Patch(ctx, m, client.MergeFrom(machine))
297+
return r.Patch(ctx, m, client.MergeFrom(machine))
288298
})
289299
if err != nil {
290300
log.Error(err, "Failed to update Machine")
@@ -335,6 +345,8 @@ func (r *RemoteMachineController) reservePooledMachine(ctx context.Context, rm *
335345
}
336346
}
337347

348+
rm.Labels = foundPooledMachine.Labels
349+
rm.Annotations = foundPooledMachine.Annotations
338350
rm.Spec.Address = foundPooledMachine.Spec.Machine.Address
339351
rm.Spec.Port = foundPooledMachine.Spec.Machine.Port
340352
rm.Spec.User = foundPooledMachine.Spec.Machine.User

inttest/capi-remote-machine-template/capi_remote_machine_template_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ func (s *RemoteMachineTemplateSuite) TestCAPIRemoteMachine() {
167167

168168
controlPlaneMachineName = machines[0].GetName()
169169

170+
if machines[0].Labels["my-custom-label"] != "my-custom-value" {
171+
return false, nil
172+
}
173+
170174
rm, err := s.getRemoteMachine(controlPlaneMachineName, "default")
171175
if err != nil {
172176
s.T().Log(err)
@@ -359,6 +363,8 @@ kind: PooledRemoteMachine
359363
metadata:
360364
name: remote-test-0
361365
namespace: default
366+
labels:
367+
my-custom-label: my-custom-value
362368
spec:
363369
pool: default
364370
machine:

0 commit comments

Comments
 (0)