-
Notifications
You must be signed in to change notification settings - Fork 316
WIP L3 NetLB experiment #2976
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
base: master
Are you sure you want to change the base?
WIP L3 NetLB experiment #2976
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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package l3 | ||
|
|
||
| import ( | ||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/ingress-gce/pkg/flags" | ||
| ) | ||
|
|
||
| // ExperimentAnnotation is the key for enabling experimental L3 support for NetLB services. | ||
| // Note that the controller must have the flag for the experiment also enabled. | ||
| const ExperimentAnnotation = "networking.gke.io/l3-experiment" | ||
|
|
||
| // Wants determines if the service should use experimental L3 GCE resources. | ||
| // Controller must be run with experimental feature flag enabled for the annotation to take effect. | ||
| func Wants(svc *corev1.Service) bool { | ||
|
Contributor
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. Golint comments: exported function Wants should have comment or be unexported. More info. |
||
| if !flags.F.EnableL3NetLBOptIn { | ||
| return false | ||
| } | ||
|
|
||
| acceptableValues := map[string]struct{}{ | ||
| "true": {}, "enabled": {}, "enable": {}, | ||
| "on": {}, "yes": {}, "True": {}, | ||
| } | ||
|
|
||
| val, ok := svc.Annotations[ExperimentAnnotation] | ||
| if !ok { | ||
| return false | ||
| } | ||
| _, ok = acceptableValues[val] | ||
| return ok | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package l3_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/ingress-gce/pkg/flags" | ||
| "k8s.io/ingress-gce/pkg/loadbalancers/l3" | ||
| ) | ||
|
|
||
| func TestWants(t *testing.T) { | ||
| flagVal := flags.F.EnableL3NetLBOptIn | ||
| defer func() { | ||
| flags.F.EnableL3NetLBOptIn = flagVal | ||
| }() | ||
| testCases := []struct { | ||
| desc string | ||
| svc corev1.Service | ||
| want bool | ||
| }{ | ||
| { | ||
| desc: "empty", | ||
| svc: corev1.Service{}, | ||
| want: false, | ||
| }, | ||
| { | ||
| desc: "enabled", | ||
| svc: corev1.Service{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Annotations: map[string]string{ | ||
| "networking.gke.io/l3-experiment": "enabled", | ||
| }, | ||
| }, | ||
| }, | ||
| want: true, | ||
| }, | ||
| { | ||
| desc: "true", | ||
| svc: corev1.Service{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Annotations: map[string]string{ | ||
| "networking.gke.io/l3-experiment": "true", | ||
| }, | ||
| }, | ||
| }, | ||
| want: true, | ||
| }, | ||
| { | ||
| desc: "false", | ||
| svc: corev1.Service{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Annotations: map[string]string{ | ||
| "networking.gke.io/l3-experiment": "false", | ||
| }, | ||
| }, | ||
| }, | ||
| want: false, | ||
| }, | ||
| } | ||
| for _, tC := range testCases { | ||
| t.Run(tC.desc, func(t *testing.T) { | ||
| flags.F.EnableL3NetLBOptIn = true | ||
| got := l3.Wants(&tC.svc) | ||
| if got != tC.want { | ||
| t.Errorf("WantsL3NetLB(%+v) = %v, want %v", tC.svc, got, tC.want) | ||
| } | ||
| }) | ||
| t.Run(tC.desc+" flag disabled", func(t *testing.T) { | ||
| flags.F.EnableL3NetLBOptIn = false | ||
| got := l3.Wants(&tC.svc) | ||
| if got != false { | ||
| t.Errorf("WantsL3NetLB(%+v) = %v, want %v", tC.svc, got, false) | ||
| } | ||
| }) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,6 +38,7 @@ import ( | |||||||
| "k8s.io/ingress-gce/pkg/forwardingrules" | ||||||||
| "k8s.io/ingress-gce/pkg/healthchecksl4" | ||||||||
| "k8s.io/ingress-gce/pkg/l4lb/metrics" | ||||||||
| "k8s.io/ingress-gce/pkg/loadbalancers/l3" | ||||||||
| "k8s.io/ingress-gce/pkg/network" | ||||||||
| "k8s.io/ingress-gce/pkg/utils" | ||||||||
| "k8s.io/ingress-gce/pkg/utils/namer" | ||||||||
|
|
@@ -353,11 +354,6 @@ func (l4netlb *L4NetLB) provideBackendService(syncResult *L4NetLBSyncResult, hcL | |||||||
| bsName := l4netlb.namer.L4Backend(l4netlb.Service.Namespace, l4netlb.Service.Name) | ||||||||
| servicePorts := l4netlb.Service.Spec.Ports | ||||||||
|
|
||||||||
| protocol := string(utils.GetProtocol(servicePorts)) | ||||||||
| if l4netlb.enableMixedProtocol { | ||||||||
| protocol = backends.GetProtocol(servicePorts) | ||||||||
| } | ||||||||
|
|
||||||||
| localityLbPolicy := l4netlb.determineBackendServiceLocalityPolicy() | ||||||||
|
|
||||||||
| connectionTrackingPolicy := l4netlb.connectionTrackingPolicy() | ||||||||
|
|
@@ -376,7 +372,7 @@ func (l4netlb *L4NetLB) provideBackendService(syncResult *L4NetLBSyncResult, hcL | |||||||
| backendParams := backends.L4BackendServiceParams{ | ||||||||
| Name: bsName, | ||||||||
| HealthCheckLink: hcLink, | ||||||||
| Protocol: protocol, | ||||||||
| Protocol: l4netlb.backendProtocol(servicePorts), | ||||||||
| SessionAffinity: string(l4netlb.Service.Spec.SessionAffinity), | ||||||||
| Scheme: string(cloud.SchemeExternal), | ||||||||
| NamespacedName: l4netlb.NamespacedName, | ||||||||
|
|
@@ -405,6 +401,17 @@ func (l4netlb *L4NetLB) provideBackendService(syncResult *L4NetLBSyncResult, hcL | |||||||
| return bs.SelfLink | ||||||||
| } | ||||||||
|
|
||||||||
| func (l4netlb *L4NetLB) backendProtocol(servicePorts []corev1.ServicePort) string { | ||||||||
| switch { | ||||||||
| case l3.Wants(l4netlb.Service): | ||||||||
| return backends.ProtocolL3 | ||||||||
| case l4netlb.enableMixedProtocol: | ||||||||
| return backends.GetProtocol(servicePorts) | ||||||||
| default: | ||||||||
| return string(utils.GetProtocol(servicePorts)) | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| func (l4netlb *L4NetLB) ensureDualStackResources(result *L4NetLBSyncResult, nodeNames []string, bsLink string) { | ||||||||
| if utils.NeedsIPv4(l4netlb.Service) { | ||||||||
| l4netlb.ensureIPv4Resources(result, nodeNames, bsLink) | ||||||||
|
|
@@ -422,7 +429,7 @@ func (l4netlb *L4NetLB) ensureDualStackResources(result *L4NetLBSyncResult, node | |||||||
| // - IPv4 Forwarding Rule | ||||||||
| // - IPv4 Firewall | ||||||||
| func (l4netlb *L4NetLB) ensureIPv4Resources(result *L4NetLBSyncResult, nodeNames []string, bsLink string) { | ||||||||
| if l4netlb.enableMixedProtocol && forwardingrules.NeedsMixed(l4netlb.Service.Spec.Ports) { | ||||||||
| if !l3.Wants(l4netlb.Service) && l4netlb.enableMixedProtocol && forwardingrules.NeedsMixed(l4netlb.Service.Spec.Ports) { | ||||||||
| l4netlb.ensureIPv4MixedResources(result, nodeNames, bsLink) | ||||||||
| return | ||||||||
| } | ||||||||
|
|
@@ -436,11 +443,7 @@ func (l4netlb *L4NetLB) ensureIPv4Resources(result *L4NetLBSyncResult, nodeNames | |||||||
| result.MetricsLegacyState.IsUserError = IsUserError(err) | ||||||||
| return | ||||||||
| } | ||||||||
| if fr.IPProtocol == string(corev1.ProtocolTCP) { | ||||||||
| result.Annotations[annotations.TCPForwardingRuleKey] = fr.Name | ||||||||
| } else { | ||||||||
| result.Annotations[annotations.UDPForwardingRuleKey] = fr.Name | ||||||||
| } | ||||||||
| result.Annotations[forwardingRuleAnnotationKey(fr)] = fr.Name | ||||||||
| result.MetricsLegacyState.IsManagedIP = ipAddrType == address.IPAddrManaged | ||||||||
| result.MetricsLegacyState.IsPremiumTier = fr.NetworkTier == cloud.NetworkTierPremium.ToGCEValue() | ||||||||
|
|
||||||||
|
|
@@ -453,6 +456,33 @@ func (l4netlb *L4NetLB) ensureIPv4Resources(result *L4NetLBSyncResult, nodeNames | |||||||
| result.Status = utils.AddIPToLBStatus(result.Status, fr.IPAddress) | ||||||||
| } | ||||||||
|
|
||||||||
| func forwardingRuleAnnotationKey(fr *composite.ForwardingRule) string { | ||||||||
| m := map[string]map[string]string{ | ||||||||
| "IPV4": { | ||||||||
| forwardingrules.ProtocolL3: annotations.L3ForwardingRuleKey, | ||||||||
| forwardingrules.ProtocolTCP: annotations.TCPForwardingRuleKey, | ||||||||
| forwardingrules.ProtocolUDP: annotations.UDPForwardingRuleKey, | ||||||||
| }, | ||||||||
| "IPV6": { | ||||||||
| forwardingrules.ProtocolL3: annotations.L3ForwardingRuleIPv6Key, | ||||||||
| forwardingrules.ProtocolTCP: annotations.TCPForwardingRuleIPv6Key, | ||||||||
| forwardingrules.ProtocolUDP: annotations.UDPForwardingRuleIPv6Key, | ||||||||
| }, | ||||||||
| } | ||||||||
|
|
||||||||
| version := fr.IpVersion | ||||||||
| if version == "" { | ||||||||
| version = "IPV4" | ||||||||
|
||||||||
| } | ||||||||
|
|
||||||||
| protocol := fr.IPProtocol | ||||||||
| if protocol == "" { | ||||||||
| protocol = "UDP" | ||||||||
|
Comment on lines
+479
to
+480
|
||||||||
| if protocol == "" { | |
| protocol = "UDP" | |
| protocol = forwardingrules.ProtocolUDP |
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.
Golint comments: exported const ExperimentAnnotation should have comment or be unexported. More info.