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

Add work apply controller #7

Merged
merged 3 commits into from
Apr 19, 2021

Conversation

qiujian16
Copy link
Contributor

@qiujian16 qiujian16 commented Mar 17, 2021

/hold

still need to add ut at least

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 17, 2021
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Mar 17, 2021
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 22, 2021
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Mar 22, 2021
@qiujian16
Copy link
Contributor Author

/assign @RainbowMango
/assign @pmorie

@RainbowMango
Copy link
Member

Good job!!! @qiujian16
I'll look at it ASAP.

Copy link
Member

@RainbowMango RainbowMango left a 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

// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Comment on lines 68 to 70
found := false
for i := range work.Finalizers {
if work.Finalizers[i] == workFinalizer {
found = true
break
}
}
if !found {
return ctrl.Result{}, nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this is neat.

Comment on lines 27 to 32
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"
Copy link
Member

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?

Copy link
Contributor Author

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err := r.client.Get(ctx, types.NamespacedName{Name: req.Name, Namespace: req.Namespace}, work)
err := r.client.Get(ctx, req.NamespacedName, work)

Comment on lines 54 to 61
newFinalizers := []string{}
for i := range work.Finalizers {
if work.Finalizers[i] == workFinalizer {
continue
}
newFinalizers = append(newFinalizers, work.Finalizers[i])
}
work.Finalizers = newFinalizers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

@RainbowMango
Copy link
Member

/lgtm
Left approval to @pmorie .

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 25, 2021
@RainbowMango
Copy link
Member

/approve
Let's move forward faster and iterate it later if there are any comments/issues.

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 19, 2021
@k8s-ci-robot k8s-ci-robot merged commit 0f3c910 into kubernetes-sigs:master Apr 19, 2021
@qiujian16 qiujian16 deleted the apply-controller branch April 19, 2021 12:29
Ealianis referenced this pull request in Azure/k8s-work-api Jun 6, 2022
Co-authored-by: Ryan Zhang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants