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 controller for leader cluster to GC MemberClusterAnnounce #4054

Merged
merged 1 commit into from
Aug 9, 2022

Conversation

hjiajing
Copy link
Contributor

@hjiajing hjiajing commented Jul 24, 2022

Add a role argument for the StaleController so that it can run in both
leader and member clusters. When it runs in a member cluster, the
controller will GC Service, ACNP, and CI resources. When it runs in a
leader cluster, the controller will GC MemberClusterAnnounces.

Signed-off-by: hujiajing hjiajing@vmware.com

@codecov
Copy link

codecov bot commented Jul 24, 2022

Codecov Report

Merging #4054 (9d66812) into main (694fc39) will increase coverage by 1.43%.
The diff coverage is 52.09%.

❗ Current head 9d66812 differs from pull request most recent head c32fd04. Consider uploading reports for the commit c32fd04 to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4054      +/-   ##
==========================================
+ Coverage   64.39%   65.82%   +1.43%     
==========================================
  Files         293      307      +14     
  Lines       43669    44618     +949     
==========================================
+ Hits        28121    29371    +1250     
+ Misses      13263    12871     -392     
- Partials     2285     2376      +91     
Flag Coverage Δ *Carryforward flag
e2e-tests 58.60% <41.84%> (?)
kind-e2e-tests 50.91% <14.07%> (+0.16%) ⬆️ Carriedforward from 2a37aec
unit-tests 44.35% <50.05%> (+0.19%) ⬆️ Carriedforward from 2a37aec

*This pull request uses carry forward flags. Click here to find out more.

Impacted Files Coverage Δ
...uster/controllers/multicluster/controller_utils.go 62.22% <ø> (+34.67%) ⬆️
...llers/multicluster/leader_clusterset_controller.go 82.35% <ø> (+18.32%) ⬆️
pkg/agent/openflow/client.go 67.50% <0.00%> (+0.97%) ⬆️
pkg/agent/openflow/multicast.go 0.00% <0.00%> (ø)
pkg/agent/openflow/pipeline.go 73.13% <0.00%> (+<0.01%) ⬆️
pkg/agent/util/iptables/iptables.go 43.52% <ø> (ø)
pkg/ovs/openflow/ofctrl_group.go 47.82% <0.00%> (-2.95%) ⬇️
pkg/agent/route/route_linux.go 45.70% <7.14%> (-2.97%) ⬇️
...apis/multicluster/v1alpha2/clusterclaim_webhook.go 24.13% <11.11%> (ø)
pkg/util/k8s/node.go 80.90% <30.76%> (-6.72%) ⬇️
... and 80 more

multicluster/controllers/multicluster/stale_controller.go Outdated Show resolved Hide resolved
}
}
if !exist {
klog.InfoS("Cleaning up stale MemberClusterAnnounce. It does exist in the member cluster list", "MemberClusterAnnounce", klog.KObj(&memberClusterAnnounce))
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't use &memberClusterAnnounce here, you need a line to assign it to a new variable and use it in the loop. You may google why it's needed.

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 knew in the for...each range. The value always uses the same address. But the process is serial, maybe using the same address is okay? I'm not sure, added a new variable to avoid the risk.

multicluster/controllers/multicluster/stale_controller.go Outdated Show resolved Hide resolved
for _, memberClusterAnnounce := range memberClusterAnnounceList.Items {
var exist bool
var needToDelete bool
if len(clusterSetList.Items) != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can move this check out of loop, and get the members info before this loop.

multicluster/controllers/multicluster/stale_controller.go Outdated Show resolved Hide resolved
@luolanzone luolanzone added the area/multi-cluster Issues or PRs related to multi cluster. label Jul 25, 2022
@hjiajing hjiajing force-pushed the stale-controller branch 2 times, most recently from 213aaf8 to 1a3ad19 Compare July 25, 2022 11:44
multicluster/controllers/multicluster/stale_controller.go Outdated Show resolved Hide resolved
multicluster/controllers/multicluster/stale_controller.go Outdated Show resolved Hide resolved
needToDelete = true
} else {
lastUpdateTime, err := time.Parse(time.RFC3339, memberClusterAnnounce.Annotations[commonarea.TimestampAnnotationKey])
if err == nil && time.Now().Sub(lastUpdateTime) < 5*time.Minute {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please define a constant, like memberClusterAnnounceStaleTime

}
}
if !exist {
klog.InfoS("Cleaning up stale MemberClusterAnnounce. It does not exist in the member cluster list", "MemberClusterAnnounce", klog.KObj(&memberClusterAnnounce))
Copy link
Contributor

Choose a reason for hiding this comment

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

But why we delete MemberAnnounce if it is not in the ClusterSet. It is possible leader cluster has not processed the update yet?

I feel we just check timestamp to delete stale members.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FIxed. Just check the timestamp and delete the outdated resources.

Copy link
Contributor

@luolanzone luolanzone left a comment

Choose a reason for hiding this comment

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

LGTM overall, a few nits

multicluster/controllers/multicluster/stale_controller.go Outdated Show resolved Hide resolved
multicluster/controllers/multicluster/stale_controller.go Outdated Show resolved Hide resolved
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.

Nits.

multicluster/controllers/multicluster/stale_controller.go Outdated Show resolved Hide resolved

for _, m := range memberClusterAnnounceList.Items {
var needToDelete bool
memberClusterAnnounce := m
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not get why you need this line. If you like to use "memberClusterAnnounce" rather than "m", you can just change "m" to "memberClusterAnnounce" in line 306.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

use memberClusterAnnounce now.

Copy link
Contributor

Choose a reason for hiding this comment

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

@hjiajing I recalled that you added this line because of a golang ci failure, please run make golangci to double check it locally first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the temporary variable back. And removed the next "else" block because there's a "continue" above it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could I know what failure we get if we remove memberClusterAnnounce := m?

Copy link
Contributor

Choose a reason for hiding this comment

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

The error will be like 'Implicit memory aliasing in for loop'. This is also one of common mistake in golang, and the wiki provide the solution like @hjiajing did here. https://github.com/golang/go/wiki/CommonMistakes#using-reference-to-loop-iterator-variable

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. That makes sense to me now. Thanks for clarification!

@tnqn tnqn added this to the Antrea v1.8 release milestone Jul 28, 2022
@luolanzone luolanzone changed the title Add stale controller for leader cluster to GC MemberClusterAnnounce Add controller for leader cluster to GC MemberClusterAnnounce Jul 29, 2022
Signed-off-by: hujiajing <hjiajing@vmware.com>
Copy link
Contributor

@luolanzone luolanzone left a comment

Choose a reason for hiding this comment

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

LGTM

@jianjuns
Copy link
Contributor

jianjuns commented Aug 5, 2022

@hjiajing : a reminder about my last question: #4054 (comment)

@hjiajing
Copy link
Contributor Author

hjiajing commented Aug 5, 2022

@jianjuns Sorry for the late reply. If not set the m, there will be an error when Golang checks. So I have to use a temporary variable to avoid it.

@jianjuns
Copy link
Contributor

jianjuns commented Aug 5, 2022

/test-multicluster-e2e
/skip-all

@jianjuns
Copy link
Contributor

jianjuns commented Aug 5, 2022

/test-integration

1 similar comment
@luolanzone
Copy link
Contributor

/test-integration

@jianjuns jianjuns merged commit 46e54ce into antrea-io:main Aug 9, 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants