Skip to content

Commit b6023ec

Browse files
authored
Merge pull request kubernetes-sigs#9791 from CecileRobertMichon/ssa-patch
🌱 Use SSA Patch to create machines in MP controller
2 parents 6cba8c2 + 033cabc commit b6023ec

File tree

3 files changed

+207
-203
lines changed

3 files changed

+207
-203
lines changed

exp/internal/controllers/machinepool_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ import (
5555
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io;bootstrap.cluster.x-k8s.io,resources=*,verbs=get;list;watch;create;update;patch;delete
5656
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=machinepools;machinepools/status;machinepools/finalizers,verbs=get;list;watch;create;update;patch;delete
5757

58+
var (
59+
// machinePoolKind contains the schema.GroupVersionKind for the MachinePool type.
60+
machinePoolKind = clusterv1.GroupVersion.WithKind("MachinePool")
61+
)
62+
5863
const (
5964
// MachinePoolControllerName defines the controller used when creating clients.
6065
MachinePoolControllerName = "machinepool-controller"

exp/internal/controllers/machinepool_controller_phases.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ func (r *MachinePoolReconciler) createOrUpdateMachines(ctx context.Context, mp *
413413
log.Info("Creating new Machine for infraMachine", "infraMachine", klog.KObj(infraMachine))
414414
machine := computeDesiredMachine(mp, infraMachine, nil)
415415

416-
if err := r.Client.Create(ctx, machine); err != nil {
416+
if err := ssa.Patch(ctx, r.Client, MachinePoolControllerName, machine); err != nil {
417417
errs = append(errs, errors.Wrapf(err, "failed to create new Machine for infraMachine %q in namespace %q", infraMachine.GetName(), infraMachine.GetNamespace()))
418418
continue
419419
}
@@ -445,7 +445,7 @@ func computeDesiredMachine(mp *expv1.MachinePool, infraMachine *unstructured.Uns
445445
ObjectMeta: metav1.ObjectMeta{
446446
Name: names.SimpleNameGenerator.GenerateName(fmt.Sprintf("%s-", mp.Name)),
447447
// Note: by setting the ownerRef on creation we signal to the Machine controller that this is not a stand-alone Machine.
448-
OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(mp, mp.GroupVersionKind())},
448+
OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(mp, machinePoolKind)},
449449
Namespace: mp.Namespace,
450450
Labels: make(map[string]string),
451451
Annotations: make(map[string]string),

0 commit comments

Comments
 (0)