Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SSA patching in etcd snapshot restore secret sync #754

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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