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

Clean up Endpoint kind of ResourceExport #3652

Merged
merged 1 commit into from Apr 26, 2022
Merged

Conversation

luolanzone
Copy link
Contributor

@luolanzone luolanzone commented Apr 18, 2022

If Service is deleted after it's exported successfully, Endpoint kind
of ResourceExport is not deleted. Fix this bug to delete both Service
and Endpoint kinds of ResourceExport when a Service is deleted but
ServiceExport is still kept.

Signed-off-by: Lan Luo luola@vmware.com

@luolanzone luolanzone added the area/multi-cluster Issues or PRs related to multi cluster. label Apr 18, 2022
@luolanzone
Copy link
Contributor Author

/test-multicluster-integration
/test-multicluster-e2e

@codecov-commenter
Copy link

codecov-commenter commented Apr 18, 2022

Codecov Report

Merging #3652 (b019ee4) into main (ac49f47) will decrease coverage by 7.43%.
The diff coverage is 26.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3652      +/-   ##
==========================================
- Coverage   64.63%   57.19%   -7.44%     
==========================================
  Files         278      392     +114     
  Lines       39360    54807   +15447     
==========================================
+ Hits        25439    31347    +5908     
- Misses      11945    21003    +9058     
- Partials     1976     2457     +481     
Flag Coverage Δ
integration-tests 38.33% <ø> (?)
kind-e2e-tests 52.27% <ø> (-0.03%) ⬇️
unit-tests 43.84% <26.66%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ntrollers/multicluster/serviceexport_controller.go 64.37% <26.66%> (-0.08%) ⬇️
pkg/agent/nodeportlocal/k8s/annotations.go 84.44% <0.00%> (-15.56%) ⬇️
pkg/apiserver/storage/ram/watch.go 90.66% <0.00%> (-2.67%) ⬇️
pkg/agent/client.go 76.74% <0.00%> (-1.17%) ⬇️
pkg/agent/controller/egress/egress_controller.go 73.67% <0.00%> (-0.86%) ⬇️
...ntroller/networkpolicy/networkpolicy_controller.go 70.39% <0.00%> (-0.66%) ⬇️
pkg/controller/networkpolicy/status_controller.go 71.37% <0.00%> (-0.41%) ⬇️
pkg/agent/flowexporter/exporter/exporter.go 71.03% <0.00%> (-0.25%) ⬇️
pkg/agent/openflow/client.go 71.97% <0.00%> (-0.16%) ⬇️
... and 120 more

Copy link
Contributor

@jianjuns jianjuns left a comment

Choose a reason for hiding this comment

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

In commit description:

of ResourceExport is not deleted, fix this bug to delete both Service

. Fix

Could you pay attention to such basic grammar?

}

if err := r.Client.Get(ctx, req.NamespacedName, &svcExport); err != nil {
klog.V(2).ErrorS(err, "Unable to fetch ServiceExport", "serviceexport", req.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

Why V(2)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it's unnecessary to print by default considering the returned error will be recorded by log, I change it to default klog.ErrorS.

return nil
}

if err := r.Client.Get(ctx, req.NamespacedName, &svcExport); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a Get call? If we watch ServiceExport, then we should have a Lister to get the ServiceExport from cache?

The same question for other Gets in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's limited by the the whole framework which is generated by kube-builder. It doesn't provide a Lister. If we write our own controller to watch events, we may use a Lister.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you saying all kube-builder controllers act like this? But a Get call is expensive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the main logic is in Reconcile(ctx context.Context, req ctrl.Request). https://book.kubebuilder.io/cronjob-tutorial/controller-overview.html
I think the manager optimize the scenario and use cache by default.

Reconcile actually performs the reconciling for a single named object. Our [Request](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/reconcile?tab=doc#Request) just has a name, but we can use the client to fetch that object from the cache.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Seems the client indeed reads from cache.

}

if err := r.Client.Get(ctx, req.NamespacedName, &svcExport); err != nil {
klog.ErrorS(err, "Unable to fetch ServiceExport", "serviceexport", req.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, if it is logged in the caller, I am fine not to log here (and we should not log not found as an error if it is not).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

move it after !apierrors.IsNotFound(err)

return nil
}

if err := r.Client.Get(ctx, req.NamespacedName, &svcExport); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you saying all kube-builder controllers act like this? But a Get call is expensive.

If Service is deleted after it's exported successfully, Endpoint kind
of ResourceExport is not deleted. Fix this bug to delete both Service
and Endpoint kinds of ResourceExport when a Service is deleted but
ServiceExport is still kept.

Signed-off-by: Lan Luo <luola@vmware.com>
@tnqn
Copy link
Member

tnqn commented Apr 25, 2022

/test-multicluster-e2e
/test-multicluster-integration
/skip-all

@tnqn tnqn added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Apr 26, 2022
@tnqn tnqn merged commit be1116e into antrea-io:main Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/multi-cluster Issues or PRs related to multi cluster. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants