-
Notifications
You must be signed in to change notification settings - Fork 22
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 work apply controller #7
Add work apply controller #7
Conversation
f32ed01
to
06daf1d
Compare
06daf1d
to
ef27668
Compare
ef27668
to
d9c3fc6
Compare
d9c3fc6
to
230b39c
Compare
/assign @RainbowMango |
Good job!!! @qiujian16 |
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.
Just some nits, otherwise LGTM.
Great job! Thanks again! @qiujian16
pkg/controllers/apply_controller.go
Outdated
// Reconcile implement the control loop logic for Work object. | ||
func (r *ApplyWorkReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
work := &workv1alpha1.Work{} | ||
err := r.client.Get(ctx, types.NamespacedName{Name: req.Name, Namespace: req.Namespace}, work) |
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.
err := r.client.Get(ctx, types.NamespacedName{Name: req.Name, Namespace: req.Namespace}, work) | |
err := r.client.Get(ctx, req.NamespacedName, work) |
We don't need to rebuild a NamespaceName here.
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.
updated
pkg/controllers/apply_controller.go
Outdated
found := false | ||
for i := range work.Finalizers { | ||
if work.Finalizers[i] == workFinalizer { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
return ctrl.Result{}, nil | ||
} |
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.
found := false | |
for i := range work.Finalizers { | |
if work.Finalizers[i] == workFinalizer { | |
found = true | |
break | |
} | |
} | |
if !found { | |
return ctrl.Result{}, nil | |
} | |
if !controllerutil.ContainsFinalizer(work, workFinalizer) { | |
return ctrl.Result{}, nil | |
} |
Maybe we can use ContainsFinalizer to simply this logic.
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.
yeah, this is neat.
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
utilrand "k8s.io/apimachinery/pkg/util/rand" | ||
workv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1" |
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.
Do you want to group imports?
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.
updated
// Reconcile implement the control loop logic for finalizing Work object. | ||
func (r *FinalizeWorkReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
work := &workv1alpha1.Work{} | ||
err := r.client.Get(ctx, types.NamespacedName{Name: req.Name, Namespace: req.Namespace}, work) |
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.
err := r.client.Get(ctx, types.NamespacedName{Name: req.Name, Namespace: req.Namespace}, work) | |
err := r.client.Get(ctx, req.NamespacedName, work) |
newFinalizers := []string{} | ||
for i := range work.Finalizers { | ||
if work.Finalizers[i] == workFinalizer { | ||
continue | ||
} | ||
newFinalizers = append(newFinalizers, work.Finalizers[i]) | ||
} | ||
work.Finalizers = newFinalizers |
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.
newFinalizers := []string{} | |
for i := range work.Finalizers { | |
if work.Finalizers[i] == workFinalizer { | |
continue | |
} | |
newFinalizers = append(newFinalizers, work.Finalizers[i]) | |
} | |
work.Finalizers = newFinalizers | |
if controllerutil.ContainsFinalizer(work, workFinalizer) { | |
controllerutil.RemoveFinalizer(work, workFinalizer) | |
} |
Does this work too?
21ff2e1
to
a390c74
Compare
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: qiujian16, RainbowMango The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Co-authored-by: Ryan Zhang <[email protected]>
/hold
still need to add ut at least