-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add PVC syncing support #179
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: galal-hussein <[email protected]>
ed83dd8
to
f2ca5d7
Compare
|
||
const ( | ||
pvcController = "pvc-syncer-controller" | ||
pvcFinalizerName = "pv.k3k.io/finalizer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be pvc.k3k.io/finalizer
?
pvcFinalizerName = "pv.k3k.io/finalizer" | |
pvcFinalizerName = "pvc.k3k.io/finalizer" |
HostScheme *runtime.Scheme | ||
logger *log.Logger | ||
Translater translate.ToHostTranslater | ||
//objs sets.Set[types.NamespacedName] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we drop the comment?
//objs sets.Set[types.NamespacedName] |
Complete(&reconciler) | ||
} | ||
|
||
func (v *PVCReconciler) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably a nit but I had some issues to understand what v
was. Maybe an r
for Reconciler` is clearer?
func (v *PVCReconciler) pvc(obj *v1.PersistentVolumeClaim) *v1.PersistentVolumeClaim { | ||
hostPVC := obj.DeepCopy() | ||
v.Translater.TranslateTo(hostPVC) | ||
// don't sync finalizers to the host |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean we are still missing to remove the finalizers here?
// deleting the synced service if exists | ||
if err := v.hostClient.Delete(ctx, syncedPVC); err != nil { | ||
return reconcile.Result{}, ctrlruntimeclient.IgnoreNotFound(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I think this could lead to some orphaned resource. I.e. what if the syncedPVC does not exist? This will error, and it will not be requed because of the IgnoreNotFound
.
Maybe it's better to return only if the error is a different one. In case of ErrNotFound we should continue the deletion of the virtual PVC.
if controllerutil.ContainsFinalizer(&virtPVC, pvcFinalizerName) { | ||
controllerutil.RemoveFinalizer(&virtPVC, pvcFinalizerName) | ||
if err := v.virtualClient.Update(ctx, &virtPVC); err != nil { | ||
return reconcile.Result{}, err | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be shortened using only the RemoveFinalizer
func. It does the same login of checking the finalizer, and it returns if the finalizer list was updated:
if controllerutil.ContainsFinalizer(&virtPVC, pvcFinalizerName) { | |
controllerutil.RemoveFinalizer(&virtPVC, pvcFinalizerName) | |
if err := v.virtualClient.Update(ctx, &virtPVC); err != nil { | |
return reconcile.Result{}, err | |
} | |
} | |
if controllerutil.RemoveFinalizer(&virtPVC, pvcFinalizerName) { | |
if err := v.virtualClient.Update(ctx, &virtPVC); err != nil { | |
return reconcile.Result{}, err | |
} | |
} |
Probably the Contains is useful when you need to check the existence and do some logic before actually remove it.
// Add finalizer if it does not exist | ||
if !controllerutil.ContainsFinalizer(&virtPVC, pvcFinalizerName) { | ||
controllerutil.AddFinalizer(&virtPVC, pvcFinalizerName) | ||
if err := v.virtualClient.Update(ctx, &virtPVC); err != nil { | ||
return reconcile.Result{}, err | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as before:
// Add finalizer if it does not exist | |
if !controllerutil.ContainsFinalizer(&virtPVC, pvcFinalizerName) { | |
controllerutil.AddFinalizer(&virtPVC, pvcFinalizerName) | |
if err := v.virtualClient.Update(ctx, &virtPVC); err != nil { | |
return reconcile.Result{}, err | |
} | |
} | |
// Add finalizer if it does not exist | |
if controllerutil.AddFinalizer(&virtPVC, pvcFinalizerName) { | |
if err := v.virtualClient.Update(ctx, &virtPVC); err != nil { | |
return reconcile.Result{}, err | |
} | |
} |
return reconcile.Result{}, err | ||
} | ||
} | ||
// create or update the pv on host |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// create or update the pv on host | |
// create or update the pvc on host |
webhookName = "nodename.podmutator.k3k.io" | ||
webhookTimeout = int32(10) | ||
webhookPort = "9443" | ||
webhookPath = "/mutate--v1-pod" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the --
a convention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments, it looks ok, I'm just not completely aware of the TLS/cert stuff, but just because I'm not an expert.
IIRC cert-manager
is a required dependency, or maybe not yet, and it will be required for the CAPI provider? Could it simplify that part?
spec.nodeName
to the virtual-kubelet node name.