Skip to content

Commit

Permalink
Add flag for IPV6 only NEG's
Browse files Browse the repository at this point in the history
  • Loading branch information
zasweq committed Dec 10, 2024
1 parent 53f357a commit 27ace0d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 2 additions & 0 deletions pkg/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ var F = struct {
ClusterSliceAPIGroup string
EnableL4ILBMixedProtocol bool
EnableL4NetLBMixedProtocol bool
EnableIPV6NEG bool
}{
GCERateLimitScale: 1.0,
}
Expand Down Expand Up @@ -334,6 +335,7 @@ L7 load balancing. CSV values accepted. Example: -node-port-ranges=80,8080,400-5
flag.BoolVar(&F.EnableL4ILBMixedProtocol, "enable-l4ilb-mixed-protocol", false, "Enable support for mixed protocol L4 internal load balancers.")
flag.BoolVar(&F.EnableL4NetLBMixedProtocol, "enable-l4netlb-mixed-protocol", false, "Enable support for mixed protocol L4 external load balancers.")
flag.StringVar(&F.ClusterSliceAPIGroup, "cluster-slice-api-group", "", "The API group for the ClusterSlice CRD.")
flag.BoolVar(&F.EnableIPV6NEG, "enable-ipv6-neg", false, "Enable support for IPV6 NEG's.")
}

func Validate() {
Expand Down
8 changes: 5 additions & 3 deletions pkg/neg/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,12 @@ func (c *Controller) processService(key string) error {
}
if len(svcPortInfoMap) != 0 {
c.logger.V(2).Info("Syncing service", "service", key)
// TODO(cheungdavid): Remove this validation when single stack ipv6 endpoint is supported
if service.Spec.Type != apiv1.ServiceTypeLoadBalancer && isSingleStackIPv6Service(service) {
return fmt.Errorf("NEG is not supported for ipv6 only service (%T)", service)
if !flags.F.EnableIPV6NEG {
if service.Spec.Type != apiv1.ServiceTypeLoadBalancer && isSingleStackIPv6Service(service) {
return fmt.Errorf("NEG is not supported for ipv6 only service (%T)", service)
}
}

if err = c.syncNegStatusAnnotation(namespace, name, svcPortInfoMap); err != nil {
return err
}
Expand Down
26 changes: 21 additions & 5 deletions pkg/neg/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -1579,6 +1589,12 @@ func TestServiceIPFamilies(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
if tc.enableIPV6OnlyNEG {
flags.F.EnableIPV6NEG = true
defer func() {
flags.F.EnableIPV6NEG = false
}()
}
controller := newTestController(fake.NewSimpleClientset())
defer controller.stop()
testService := newTestService(controller, false, []int32{80})
Expand Down

0 comments on commit 27ace0d

Please sign in to comment.