-
Notifications
You must be signed in to change notification settings - Fork 303
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
Multi networking neg controller #2023
Multi networking neg controller #2023
Conversation
Hi @mmamczur. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/ok-to-test |
9cae185
to
2aed49d
Compare
a0458bd
to
b55f03a
Compare
b4ffb2b
to
14322fc
Compare
pkg/neg/controller.go
Outdated
@@ -572,8 +589,12 @@ func (c *Controller) mergeVmIpNEGsPortInfo(service *apiv1.Service, name types.Na | |||
onlyLocal := helpers.RequestsOnlyLocalTraffic(service) | |||
// Update usage metrics. | |||
negUsage.VmIpNeg = usageMetrics.NewVmIpNegType(onlyLocal) | |||
networkInfo, err := multinetwork.ServiceNetwork(service, c.networkLister, c.gkeNetworkParamSetLister, c.cloud) |
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.
so, this will be a noop if --multi-network flag is not enabled
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.
yes, that was the point, nil means default network
I'm thinking of redoing this. Always populating this network info, with default network URLs if no multinetworking is needed. Would be nicer than having nil checks everywhere.
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.
I reworked this
with the current version when --multi-network flag is not enabled the NetworkInfo should be present anyway but will contain the default network information.
pkg/multinetwork/multinetwork.go
Outdated
networkingGKEGroup = "networking.gke.io" | ||
gkeNetworkParamSetKind = "gkenetworkparamset" | ||
networkSelector = "networking.gke.io/network" |
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.
it these things are defined in some place and are official we should export them on the origin , these are official APIs, otherwise there is a risk of drifting defining it in different places
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.
I tried to replicate whatever way this is done in our other multinet code. for selector a constant named NetworkAnnotationKey
is used (a bit confusing but ok). Seems that there is no good constant for GKENetworkParamSet exported anywhere. Not sure, should we add it upstream?
14322fc
to
0b2af7a
Compare
0b2af7a
to
03071ec
Compare
03071ec
to
38abfa6
Compare
d6d56be
to
4b5325d
Compare
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.
I am reviewing network_test.go yet
@@ -112,3 +112,11 @@ func (a *cloudProviderAdapter) NetworkURL() string { | |||
func (a *cloudProviderAdapter) SubnetworkURL() string { | |||
return a.subnetworkURL | |||
} | |||
|
|||
func (a *cloudProviderAdapter) NetworkProjectID() string { | |||
return a.c.NetworkProjectID() |
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.
'c'?
😭
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.
maybe they meant a for adapter?
I don't know what is the approach, we can also have 'cpa', should we change all these to 'c'?
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.
"cpa" would be a good name for receiver (as for golang)
"cloud" instead of c" would a better field name
just mark it resolved, let's not jump into refactoring-rabbit-hole while implementing new features
pkg/network/network.go
Outdated
// All nodes are connected to the default network. | ||
// For non default networks the result is based on the data from | ||
// the 'networking.gke.io/north-interfaces' node annotation. | ||
func (ni *NetworkInfo) NodeConnected(node *apiv1.Node) bool { |
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.
comment regarding the NetworkInfo struct
isnt; it better to have positive IsDefault or Default than negated field name IsNonDefault?
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.
the reason I did this is that false is the default when you don't specify any value, you can do ni := NetworkInfo{}
and it will act as default
Then again it won't know the actual Network/subnetwork URLs so that's not great either
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.
for this case
ni := NetworkInfo{}
you can define a variable in the network package
var DefaultNetworkInfo = &NetworkInfo{
IsDefault: true,
K8sNetwork: networkv1.DefaultPodNetworkName,
}
and use
L4ClusterEndpointCalculator := NewClusterL4ILBEndpointsCalculator(listers.NewNodeLister(nodeLister), zoneGetter, svcKey, klog.TODO(), network.DefaultNetworkInfo)
instead of
L4ClusterEndpointCalculator := NewClusterL4ILBEndpointsCalculator(listers.NewNodeLister(nodeLister), zoneGetter, svcKey, klog.TODO(), &network.NetworkInfo{})
or you can create a method for the same purpose
func DefaultNetworkInfo() *NetworkInfo{
return &NetworkInfo{
IsDefault: true,
K8sNetwork: networkv1.DefaultPodNetworkName,
}
}
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.
oh, there is such method....
but requires cloudProvider arg
I still prefer positive variable IsDefault or just Default
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.
ok I changed the bool to IsDefault instead of IsNonDefault
}, nil | ||
} | ||
|
||
func defaultNetwork(cloudProvider cloudNetworkProvider) *NetworkInfo { |
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.
does cloudProvider ever change?
or this returns same NetworkInfo every time?
if the latter is true then you can store NetworkInfo in private var in this file and only initialize it at first execution of this func
you don't even need to worry about race when initializing this var (as in singleton pattern), initializing multiple times will break nothing (same NetworkInfo struct)
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.
there are 2 actual structs that can be used here:
- cloudProviderAdapter from pkg/neg/types/cloudprovideradapter.go - used in NEG controller
- Cloud imported cloud-provider-gcp - used in the ILB controller
I wanted this code to work with both
as for the values, I don't know if they change tbh, we could do lazy init probably.
Previously we never stored the network and subnetwork URL, always took them from these Clouds
}, | ||
want: false, | ||
}, | ||
{ |
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.
this case:
{
desc: "2 always connected to the default network",
networkInfo: NetworkInfo{
IsNonDefault: true,
K8sNetwork: "default",
},
node: &apiv1.Node{
ObjectMeta: metav1.ObjectMeta{Name: "test-node", Annotations: map[string]string{}},
},
want: false,
},
would pass either
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.
which feels weird
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.
yea, it's made so that whenever IsNonDefault is set to true then there is multinet logic involved, even if the name is set to "default".
Having the flag in addition to name is convenient since you can create empty NetworkInfo and it will represent default (but not always so this is tricky)
4b5325d
to
3416001
Compare
3416001
to
e51bfc8
Compare
e51bfc8
to
77366c0
Compare
/hold /assign @swetharepakula |
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.
This mostly looks good to me. A few nits and cleanup comments.
Can we separate out the vendor changes into its own commit?
pkg/neg/syncers/subsets_test.go
Outdated
@@ -219,6 +285,39 @@ func makeNodes(startIndex, count int) []*v1.Node { | |||
return nodes | |||
} | |||
|
|||
func makeNodeWithNetwork(t *testing.T, name string, networksAndIPs ...string) *v1.Node { |
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.
nit: add a comment on how networksAndIPs should be populated when using this function
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.
added, maybe we should change this to something else now that I'm looking at it?
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.
perhaps a map?
pkg/network/network_test.go
Outdated
ObjectMeta: metav1.ObjectMeta{Name: "test-node", Annotations: map[string]string{ | ||
networkv1.NorthInterfacesAnnotationKey: northInterfacesAnnotation(t, networkv1.NorthInterfacesAnnotation{ | ||
{ | ||
Network: "default", |
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.
will the default network also be on the node like this?
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.
no, it won't contain the default network
I changed the "default" name here not to create confusion (although it's not relevant for this test)
77366c0
to
d7a438d
Compare
d7a438d
to
0a95e68
Compare
I've split commits (both in this PR) |
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.
/approve
Only lingering comment is about cleanup in the test function to make it more understandable. I am okay for this to merge as is, and we can have followups to clean. Or if you want to address in this that is fine too.
pkg/neg/syncers/subsets_test.go
Outdated
@@ -219,6 +285,39 @@ func makeNodes(startIndex, count int) []*v1.Node { | |||
return nodes | |||
} | |||
|
|||
func makeNodeWithNetwork(t *testing.T, name string, networksAndIPs ...string) *v1.Node { |
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.
perhaps a map?
0a95e68
to
dbc0dcb
Compare
changed it to use a map. it makes invocations a bit more verbose with all these |
/unhold |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cezarygerard, mmamczur, swetharepakula 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 |
Support for multi-networking in the NEG controller.