-
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
Add flag for IPV6 only NEG's #2763
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ import ( | |
"k8s.io/client-go/util/workqueue" | ||
"k8s.io/cloud-provider-gcp/providers/gce" | ||
"k8s.io/ingress-gce/pkg/annotations" | ||
"k8s.io/ingress-gce/pkg/flags" | ||
"k8s.io/ingress-gce/pkg/neg/metrics/metricscollector" | ||
"k8s.io/ingress-gce/pkg/neg/syncers/labels" | ||
negtypes "k8s.io/ingress-gce/pkg/neg/types" | ||
|
@@ -1500,11 +1501,12 @@ func TestServiceIPFamilies(t *testing.T) { | |
preferDualStack := apiv1.IPFamilyPolicyPreferDualStack | ||
requireDualStack := apiv1.IPFamilyPolicyRequireDualStack | ||
testCases := []struct { | ||
desc string | ||
serviceType v1.ServiceType | ||
ipFamilies []v1.IPFamily | ||
ipFamilyPolicy *apiv1.IPFamilyPolicy | ||
expectNil bool | ||
desc string | ||
serviceType v1.ServiceType | ||
ipFamilies []v1.IPFamily | ||
ipFamilyPolicy *apiv1.IPFamilyPolicy | ||
expectNil bool | ||
enableIPV6OnlyNEG bool | ||
}{ | ||
{ | ||
desc: "ipv6 only service with l7 load balancer, ipFamilyPolicy is singleStack", | ||
|
@@ -1513,6 +1515,14 @@ func TestServiceIPFamilies(t *testing.T) { | |
ipFamilyPolicy: &singleStack, | ||
expectNil: false, | ||
}, | ||
{ | ||
desc: "ipv6 only service with l7 load balancer, ipFamilyPolicy is singleStack, ipv6 neg enabled", | ||
serviceType: v1.ServiceTypeClusterIP, | ||
ipFamilies: []v1.IPFamily{v1.IPv6Protocol}, | ||
ipFamilyPolicy: &singleStack, | ||
expectNil: true, | ||
enableIPV6OnlyNEG: true, | ||
}, | ||
{ | ||
desc: "ipv4 only service with l7 load balancer, ipFamilyPolicy is singleStack", | ||
serviceType: v1.ServiceTypeClusterIP, | ||
|
@@ -1579,6 +1589,13 @@ func TestServiceIPFamilies(t *testing.T) { | |
} | ||
for _, tc := range testCases { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
if tc.enableIPV6OnlyNEG { | ||
origEnableIPV6OnlyNEG := flags.F.EnableIPV6OnlyNEG | ||
flags.F.EnableIPV6OnlyNEG = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this is a global variable, can you store the previous value and reset it in the defer. As the tests grow using this flag, I think that will be safer in terms of test pollution. Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good point. That is how we set env vars in gRPC-Go tests too. Thanks. |
||
defer func() { | ||
flags.F.EnableIPV6OnlyNEG = origEnableIPV6OnlyNEG | ||
}() | ||
} | ||
controller := newTestController(fake.NewSimpleClientset()) | ||
defer controller.stop() | ||
testService := newTestService(controller, false, []int32{80}) | ||
|
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'd just like to make sure the tests cover all the cases. Sorry if my comments are off, because I may not have all the context. A customer in a single stack IPv6 cluster could create a normal Service, where the Spec lacks
ipFamilies
oripFamilyPolicy
. Because the cluster is single stack IPv6 and IPv6 is the only family available, the Service will only have IPv6 addresses, and so the backends, and the NEGs would be only configured with an IPv6 address. So theoretically there is a case where these fields are not set, but a NEG in the end would only have an IPv6 address. I don't know if this matters, maybe it's not possible to add coverage just with unit tests. WDYT?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 see what you're saying. For the scope of this specific unit test, which tests at the validation boundary, I think what to test here would be for an unset IP family to pass validation.
However, I wonder how to test this e2e. It would require however we determine the GKE Cluster's stack type and see if IPV6 + unset, and see if unset spins up a IPv6.
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.
Hmm ok I'll add a test for unset ipFamilies and ipFamily policy at the unit test layer. I'm assuming that for IPV4 only it'll simply create an IPV4 NEG, just as in the case of IPV6 only cluster it's valid and we want it to create an IPV6 only NEG.
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.
Thanks @krzykwas, I wasn't aware about the "theoretically there is a case where these fields are not set, but a NEG in the end would only have an IPv6 address" case. Good to have become aware about this.
But yes, this unit test here will not be able to exercise this check and we'll either need some kind of an integration test, or write a standard e2e test.
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 sounds good. Let's leave this test to an integration or e2e test then.