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

[WIP] Egress policy #1987

Closed
wants to merge 6 commits into from
Closed

Conversation

ceclinux
Copy link
Contributor

No description provided.

@codecov-io
Copy link

codecov-io commented Mar 24, 2021

Codecov Report

Merging #1987 (bbf81dd) into main (9b8440d) will decrease coverage by 7.36%.
The diff coverage is 11.04%.

❗ Current head bbf81dd differs from pull request most recent head 44b5abc. Consider uploading reports for the commit 44b5abc to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1987      +/-   ##
==========================================
- Coverage   65.39%   58.03%   -7.37%     
==========================================
  Files         197      203       +6     
  Lines       17217    18069     +852     
==========================================
- Hits        11259    10486     -773     
- Misses       4785     6472    +1687     
+ Partials     1173     1111      -62     
Flag Coverage Δ
kind-e2e-tests 43.98% <7.59%> (-12.54%) ⬇️
unit-tests 40.77% <6.40%> (-1.10%) ⬇️

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

Impacted Files Coverage Δ
pkg/agent/controller/egress/egress_controller.go 0.00% <0.00%> (ø)
...gent/controller/networkpolicy/status_controller.go 64.38% <0.00%> (-10.96%) ⬇️
pkg/agent/openflow/pipeline.go 66.84% <0.00%> (-5.90%) ⬇️
pkg/agent/openflow/pipeline_other.go 50.00% <0.00%> (-16.67%) ⬇️
pkg/agent/util/iptables/iptables.go 38.88% <0.00%> (-7.34%) ⬇️
pkg/apis/controlplane/v1beta1/conversion.go 81.00% <ø> (ø)
pkg/controller/egress/store/egressgroup.go 0.00% <0.00%> (ø)
pkg/controller/types/networkpolicy.go 100.00% <ø> (ø)
pkg/features/antrea_features.go 16.66% <ø> (ø)
pkg/ovs/openflow/ofctrl_action.go 47.63% <0.00%> (-0.21%) ⬇️
... and 61 more

@ceclinux ceclinux force-pushed the egress-controlplane branch 3 times, most recently from 23393d3 to ba64e3c Compare March 25, 2021 12:06
@tnqn tnqn mentioned this pull request Mar 25, 2021
5 tasks
}
c.ReplaceEgressGroups(policies)
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

The above function variables seem useless? It can be just inline code like:

func (c *Controller) watch() {
	klog.Info("Starting watch for EgressGroup")
	antreaClient, err := c.antreaClientProvider.GetAntreaClient()
        ...
	watcher, err := antreaClient.ControlplaneV1beta1().EgressGroups().Watch(context.TODO(), options)
        ...
        for {
		select {
		case event, ok := <-watcher.ResultChan():
			if !ok {
				return
			}
			switch event.Type {
			case watch.Added:
				klog.V(2).Infof("Added EgressGroup (%#v)", event.Object)
				c.addEgressGroup(...)

The abstract class in networkpolicy is to share code for 3 watchers, which doesn't make sense here, unless you extract the abstract class from networkpolicy controller to a common package, but I would defer its refactoring before other essential changes are finished.

Copy link
Member

Choose a reason for hiding this comment

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

this is not resolved?

) *Controller {
c := &Controller{
kubeClient: kubeClient,
nodeIP: nodeIP,
Copy link
Member

Choose a reason for hiding this comment

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

The SNAT IP can be any IP configured on the node, not only the Node IP in K8s Node IP.
If you are not sure how to get it, I could provide an interface like LocalIPDetector.IsLocalIP(ip string) bool for you to consume.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I will try to implement LocalIPDetector.IsLocalIP(ip string) bool by myself 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.

I have added IsLocalIP(ip string) in this PR. Please check if it is correct, thanks

@tnqn
Copy link
Member

tnqn commented Mar 30, 2021

Can you squash your commits into one so that it's easy to review changes of this PR? I mean the commits except the ones merged from other PRs.

}
c.ReplaceEgressGroups(policies)
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

this is not resolved?

pkg/agent/controller/egress/egress_controller.go Outdated Show resolved Hide resolved
func (c *Controller) AddEgressGroup(group *v1beta1.EgressGroup) error {
c.setByGroupLock.Lock()
defer c.setByGroupLock.Unlock()
klog.Infof("%#v", group)
Copy link
Member

Choose a reason for hiding this comment

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

Can you polish logging in this file? Currently they will be unreadable and unnecessarily verbose

pkg/agent/controller/egress/egress_controller.go Outdated Show resolved Hide resolved

}
if isLocalIP(newEgressIP) {
id, errAllocate := c.IPAllocator.allocateForIP(newEgressIP)
Copy link
Member

Choose a reason for hiding this comment

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

The usage of the IPAllocatorLock is not right. What if the oldEgressIP is not local IP? is allocateForIP thread-safe? Typically lock should be inside the called function

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 the logic. should checkif isLocalIP(newEgressIP) { and if isLocalIP(oldEgressIP) { as well

klog.Infof("%#v\n", c.IPAllocator)

if errAllocate != nil {
c.IPAllocator.allocateForIP(oldEgressIP)
Copy link
Member

Choose a reason for hiding this comment

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

Is this kind of retry? Doesn't seem elegant to me. And many error handling is missing here as well as other places in this file.


klog.Infof("%#v", gm.Member)
klog.Infof("%#v", interfaces)
klog.Infof("%t", isInterfaceOnPod(interfaces))
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Member: group,
}
klog.Infof("%#v", groupMember)
c.queue.Add(groupMember)
Copy link
Member

Choose a reason for hiding this comment

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

This is not the correct usage pattern of workqueue. This is nothing different from just using a channel. Keys won't be merged as they key may be different even the IP and the pod's namespace and name is same. And it will have race condition if one pod is processed by two workers in parallel.
It should be the "Egress" name being the item enqueued to the workqueue in my mind. All egress and egressGroup handlers just enqueue affected egresses and syncHandler called by worker is the only one that will do the ID allocation and calls the underlying interfaces based on the eventual state at the moment the function is called.

pkg/agent/controller/egress/ip_allocator.go Show resolved Hide resolved
@antoninbas antoninbas added this to the Antrea v1.0 release milestone Mar 30, 2021
@ceclinux ceclinux force-pushed the egress-controlplane branch 4 times, most recently from 418051a to 669395e Compare March 31, 2021 08:43
jianjuns and others added 5 commits March 31, 2021 16:52
Add types for egress policy CRDs, including Egress for the egress
policy definition, and a common AppliedTo struct for defining the scope
to which a policy is applied.
Add types for egress policy CRDs, including Egress for the egress
policy definition, and a common AppliedTo struct for defining the scope
to which a policy is applied.
@ceclinux ceclinux force-pushed the egress-controlplane branch 2 times, most recently from 47d3c96 to 4c0c149 Compare March 31, 2021 10:23
@ceclinux
Copy link
Contributor Author

ceclinux commented Mar 31, 2021

Can you squash your commits into one so that it's easy to review changes of this PR? I mean the commits except the ones merged from other PRs.

squashed. I think there are files I have handled incorrectly in the git history, but it looks better now and I will organize my commits again after other works are merged.

@jianjuns jianjuns self-requested a review April 1, 2021 18:32
@tnqn
Copy link
Member

tnqn commented Apr 7, 2021

superseded by #2026, closing it

@tnqn tnqn closed this Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants