Skip to content

Commit

Permalink
Fix SSA patching in etcd snapshot restore
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev committed Sep 25, 2024
1 parent 8a64dbd commit dd2d089
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion exp/etcdrestore/controllers/etcdsnapshot_secret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ func secretFilter(obj client.Object) bool {
return found && !owned
}

func setKind(cl client.Client, obj client.Object) error {
kinds, _, err := cl.Scheme().ObjectKinds(obj)
if err != nil {
return err
} else if len(kinds) > 0 {
obj.GetObjectKind().SetGroupVersionKind(kinds[0])
}

return nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *ETCDSnapshotSecretReconciler) SetupWithManager(_ context.Context, mgr ctrl.Manager, _ controller.Options) error {
err := ctrl.NewControllerManagedBy(mgr).
Expand Down Expand Up @@ -100,7 +111,18 @@ func (r *ETCDSnapshotSecretReconciler) Reconcile(ctx context.Context, secret *co
UID: rke2Config.UID,
})

if err := r.Client.Patch(ctx, secret, client.Apply); err != nil {
if err := setKind(r, secret); err != nil {
log.Error(err, "Unable to set default secret kind")

return ctrl.Result{}, err
}

secret.SetManagedFields(nil)

if err := r.Client.Patch(ctx, secret, client.Apply, []client.PatchOption{
client.ForceOwnership,
client.FieldOwner("clusterctl-controller"),
}...); err != nil {
log.Error(err, "Unable to patch Secret with RKE2Config ownership")

return ctrl.Result{}, err
Expand Down

0 comments on commit dd2d089

Please sign in to comment.