Skip to content

Commit

Permalink
Merge pull request #9802 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…9791-to-release-1.6

[release-1.6] 🌱 Use SSA Patch to create machines in MP controller
  • Loading branch information
k8s-ci-robot authored Dec 4, 2023
2 parents cb515e4 + 5bc1b1a commit aaba1ef
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 203 deletions.
5 changes: 5 additions & 0 deletions exp/internal/controllers/machinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ import (
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io;bootstrap.cluster.x-k8s.io,resources=*,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=machinepools;machinepools/status;machinepools/finalizers,verbs=get;list;watch;create;update;patch;delete

var (
// machinePoolKind contains the schema.GroupVersionKind for the MachinePool type.
machinePoolKind = clusterv1.GroupVersion.WithKind("MachinePool")
)

const (
// MachinePoolControllerName defines the controller used when creating clients.
MachinePoolControllerName = "machinepool-controller"
Expand Down
4 changes: 2 additions & 2 deletions exp/internal/controllers/machinepool_controller_phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func (r *MachinePoolReconciler) createOrUpdateMachines(ctx context.Context, mp *
log.Info("Creating new Machine for infraMachine", "infraMachine", klog.KObj(infraMachine))
machine := computeDesiredMachine(mp, infraMachine, nil)

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

0 comments on commit aaba1ef

Please sign in to comment.