From cbe94df8c6b6f0bc478eaee4d420a65e20aa4482 Mon Sep 17 00:00:00 2001 From: Laszlo Janosi Date: Sun, 26 Aug 2018 19:37:11 +0000 Subject: [PATCH] gofmt update --- pkg/apis/core/validation/validation.go | 2 +- pkg/apis/core/validation/validation_test.go | 2 +- pkg/apis/networking/validation/validation.go | 4 +- .../networking/validation/validation_test.go | 8 +-- .../providers/azure/azure_loadbalancer.go | 2 +- pkg/features/kube_features.go | 3 -- .../network/hostport/hostport_manager.go | 4 +- .../network/hostport/hostport_manager_test.go | 54 +++++++++---------- .../network/hostport/hostport_syncer.go | 6 +-- pkg/proxy/iptables/proxier_test.go | 8 +-- pkg/proxy/ipvs/ipset.go | 2 +- pkg/proxy/ipvs/proxier.go | 10 ++-- pkg/util/ipset/ipset_test.go | 8 +-- pkg/util/ipvs/ipvs_linux.go | 2 +- 14 files changed, 55 insertions(+), 60 deletions(-) diff --git a/pkg/apis/core/validation/validation.go b/pkg/apis/core/validation/validation.go index 1dd422589a..52b1cb9708 100644 --- a/pkg/apis/core/validation/validation.go +++ b/pkg/apis/core/validation/validation.go @@ -3826,7 +3826,7 @@ func validateServicePort(sp *core.ServicePort, requireName, isHeadlessService bo for _, msg := range validation.IsValidPortNum(int(sp.Port)) { allErrs = append(allErrs, field.Invalid(fldPath.Child("port"), sp.Port, msg)) } - + if len(sp.Protocol) == 0 { allErrs = append(allErrs, field.Required(fldPath.Child("protocol"), "")) } else if !utilfeature.DefaultFeatureGate.Enabled(features.SCTPSupport) && sp.Protocol == core.ProtocolSCTP { diff --git a/pkg/apis/core/validation/validation_test.go b/pkg/apis/core/validation/validation_test.go index e28ba1a639..4456729349 100644 --- a/pkg/apis/core/validation/validation_test.go +++ b/pkg/apis/core/validation/validation_test.go @@ -8592,7 +8592,7 @@ func makeValidService() core.Service { func TestValidateService(t *testing.T) { defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.SCTPSupport, true)() - + testCases := []struct { name string tweakSvc func(svc *core.Service) // given a basic valid service, each test case can customize it diff --git a/pkg/apis/networking/validation/validation.go b/pkg/apis/networking/validation/validation.go index 6d2f069af3..0e012f3664 100644 --- a/pkg/apis/networking/validation/validation.go +++ b/pkg/apis/networking/validation/validation.go @@ -23,10 +23,10 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/validation" "k8s.io/apimachinery/pkg/util/validation/field" + utilfeature "k8s.io/apiserver/pkg/util/feature" api "k8s.io/kubernetes/pkg/apis/core" apivalidation "k8s.io/kubernetes/pkg/apis/core/validation" "k8s.io/kubernetes/pkg/apis/networking" - utilfeature "k8s.io/apiserver/pkg/util/feature" "k8s.io/kubernetes/pkg/features" ) @@ -44,7 +44,7 @@ func ValidateNetworkPolicyPort(port *networking.NetworkPolicyPort, portPath *fie allErrs = append(allErrs, field.NotSupported(portPath.Child("protocol"), *port.Protocol, []string{string(api.ProtocolTCP), string(api.ProtocolUDP), string(api.ProtocolSCTP)})) } } else if port.Protocol != nil && *port.Protocol != api.ProtocolTCP && *port.Protocol != api.ProtocolUDP { - allErrs = append(allErrs, field.NotSupported(portPath.Child("protocol"), *port.Protocol, []string{string(api.ProtocolTCP), string(api.ProtocolUDP)})) + allErrs = append(allErrs, field.NotSupported(portPath.Child("protocol"), *port.Protocol, []string{string(api.ProtocolTCP), string(api.ProtocolUDP)})) } if port.Port != nil { if port.Port.Type == intstr.Int { diff --git a/pkg/apis/networking/validation/validation_test.go b/pkg/apis/networking/validation/validation_test.go index 74bdd57ec1..bacffbfa38 100644 --- a/pkg/apis/networking/validation/validation_test.go +++ b/pkg/apis/networking/validation/validation_test.go @@ -21,10 +21,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - api "k8s.io/kubernetes/pkg/apis/core" - "k8s.io/kubernetes/pkg/apis/networking" utilfeature "k8s.io/apiserver/pkg/util/feature" utilfeaturetesting "k8s.io/apiserver/pkg/util/feature/testing" + api "k8s.io/kubernetes/pkg/apis/core" + "k8s.io/kubernetes/pkg/apis/networking" "k8s.io/kubernetes/pkg/features" ) @@ -33,7 +33,7 @@ func TestValidateNetworkPolicy(t *testing.T) { protocolUDP := api.ProtocolUDP protocolICMP := api.Protocol("ICMP") protocolSCTP := api.ProtocolSCTP - + defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.SCTPSupport, true)() successCases := []networking.NetworkPolicy{ @@ -284,7 +284,7 @@ func TestValidateNetworkPolicy(t *testing.T) { } // Success cases are expected to pass validation. - + for k, v := range successCases { if errs := ValidateNetworkPolicy(&v); len(errs) != 0 { t.Errorf("Expected success for %d, got %v", k, errs) diff --git a/pkg/cloudprovider/providers/azure/azure_loadbalancer.go b/pkg/cloudprovider/providers/azure/azure_loadbalancer.go index 18434371b5..904c8c3067 100644 --- a/pkg/cloudprovider/providers/azure/azure_loadbalancer.go +++ b/pkg/cloudprovider/providers/azure/azure_loadbalancer.go @@ -736,7 +736,7 @@ func (az *Cloud) reconcileLoadBalancer(clusterName string, service *v1.Service, // compatible with UDP (it uses an HTTP check) return nil, fmt.Errorf("services requiring health checks are incompatible with UDP ports") } - + if port.Protocol == v1.ProtocolSCTP { // ERROR: this isn't supported // health check (aka source ip preservation) is not diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index d9e71feba7..7e3a2bb945 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -422,11 +422,8 @@ var defaultKubernetesFeatureGates = map[utilfeature.Feature]utilfeature.FeatureS ResourceQuotaScopeSelectors: {Default: true, PreRelease: utilfeature.Beta}, CSIBlockVolume: {Default: false, PreRelease: utilfeature.Alpha}, RuntimeClass: {Default: false, PreRelease: utilfeature.Alpha}, -<<<<<<< HEAD NodeLease: {Default: false, PreRelease: utilfeature.Alpha}, -======= SCTPSupport: {Default: false, PreRelease: utilfeature.Alpha}, ->>>>>>> Changes according to the approved KEP. SCTP is supported for HostPort and LoadBalancer. Alpha feature flag SCTPSupport controls the support of SCTP. Kube-proxy config parameter is removed. // inherited features from generic apiserver, relisted here to get a conflict if it is changed // unintentionally on either side: diff --git a/pkg/kubelet/dockershim/network/hostport/hostport_manager.go b/pkg/kubelet/dockershim/network/hostport/hostport_manager.go index cfd232a658..70bfd16dab 100644 --- a/pkg/kubelet/dockershim/network/hostport/hostport_manager.go +++ b/pkg/kubelet/dockershim/network/hostport/hostport_manager.go @@ -264,12 +264,12 @@ func (hm *hostportManager) openHostports(podPortMapping *PodPortMapping) (map[ho if pm.HostPort <= 0 { continue } - + // We do not open host ports for SCTP ports, as we agreed in the Support of SCTP KEP if pm.Protocol == v1.ProtocolSCTP { continue } - + hp := portMappingToHostport(pm) socket, err := hm.portOpener(&hp) if err != nil { diff --git a/pkg/kubelet/dockershim/network/hostport/hostport_manager_test.go b/pkg/kubelet/dockershim/network/hostport/hostport_manager_test.go index 2841c6cb72..e8b2c070bf 100644 --- a/pkg/kubelet/dockershim/network/hostport/hostport_manager_test.go +++ b/pkg/kubelet/dockershim/network/hostport/hostport_manager_test.go @@ -203,10 +203,10 @@ func TestHostportManager(t *testing.T) { Protocol: v1.ProtocolUDP, }, { - HostPort: 8083, - ContainerPort: 83, - Protocol: v1.ProtocolSCTP, - }, + HostPort: 8083, + ContainerPort: 83, + Protocol: v1.ProtocolSCTP, + }, }, }, expectError: false, @@ -287,29 +287,29 @@ func TestHostportManager(t *testing.T) { lines := strings.Split(string(raw.Bytes()), "\n") expectedLines := map[string]bool{ `*nat`: true, - `:KUBE-HOSTPORTS - [0:0]`: true, - `:OUTPUT - [0:0]`: true, - `:PREROUTING - [0:0]`: true, - `:POSTROUTING - [0:0]`: true, - `:KUBE-HP-IJHALPHTORMHHPPK - [0:0]`: true, - `:KUBE-HP-63UPIDJXVRSZGSUZ - [0:0]`: true, - `:KUBE-HP-WFBOALXEP42XEMJK - [0:0]`: true, - `:KUBE-HP-XU6AWMMJYOZOFTFZ - [0:0]`: true, - "-A KUBE-HOSTPORTS -m comment --comment \"pod3_ns1 hostport 8443\" -m tcp -p tcp --dport 8443 -j KUBE-HP-WFBOALXEP42XEMJK": true, - "-A KUBE-HOSTPORTS -m comment --comment \"pod1_ns1 hostport 8081\" -m udp -p udp --dport 8081 -j KUBE-HP-63UPIDJXVRSZGSUZ": true, - "-A KUBE-HOSTPORTS -m comment --comment \"pod1_ns1 hostport 8080\" -m tcp -p tcp --dport 8080 -j KUBE-HP-IJHALPHTORMHHPPK": true, - "-A KUBE-HOSTPORTS -m comment --comment \"pod1_ns1 hostport 8083\" -m sctp -p sctp --dport 8083 -j KUBE-HP-XU6AWMMJYOZOFTFZ": true, - "-A OUTPUT -m comment --comment \"kube hostport portals\" -m addrtype --dst-type LOCAL -j KUBE-HOSTPORTS": true, - "-A PREROUTING -m comment --comment \"kube hostport portals\" -m addrtype --dst-type LOCAL -j KUBE-HOSTPORTS": true, - "-A POSTROUTING -m comment --comment \"SNAT for localhost access to hostports\" -o cbr0 -s 127.0.0.0/8 -j MASQUERADE": true, - "-A KUBE-HP-IJHALPHTORMHHPPK -m comment --comment \"pod1_ns1 hostport 8080\" -s 10.1.1.2/32 -j KUBE-MARK-MASQ": true, - "-A KUBE-HP-IJHALPHTORMHHPPK -m comment --comment \"pod1_ns1 hostport 8080\" -m tcp -p tcp -j DNAT --to-destination 10.1.1.2:80": true, - "-A KUBE-HP-63UPIDJXVRSZGSUZ -m comment --comment \"pod1_ns1 hostport 8081\" -s 10.1.1.2/32 -j KUBE-MARK-MASQ": true, - "-A KUBE-HP-63UPIDJXVRSZGSUZ -m comment --comment \"pod1_ns1 hostport 8081\" -m udp -p udp -j DNAT --to-destination 10.1.1.2:81": true, - "-A KUBE-HP-XU6AWMMJYOZOFTFZ -m comment --comment \"pod1_ns1 hostport 8083\" -s 10.1.1.2/32 -j KUBE-MARK-MASQ": true, - "-A KUBE-HP-XU6AWMMJYOZOFTFZ -m comment --comment \"pod1_ns1 hostport 8083\" -m sctp -p sctp -j DNAT --to-destination 10.1.1.2:83": true, - "-A KUBE-HP-WFBOALXEP42XEMJK -m comment --comment \"pod3_ns1 hostport 8443\" -s 10.1.1.4/32 -j KUBE-MARK-MASQ": true, - "-A KUBE-HP-WFBOALXEP42XEMJK -m comment --comment \"pod3_ns1 hostport 8443\" -m tcp -p tcp -j DNAT --to-destination 10.1.1.4:443": true, + `:KUBE-HOSTPORTS - [0:0]`: true, + `:OUTPUT - [0:0]`: true, + `:PREROUTING - [0:0]`: true, + `:POSTROUTING - [0:0]`: true, + `:KUBE-HP-IJHALPHTORMHHPPK - [0:0]`: true, + `:KUBE-HP-63UPIDJXVRSZGSUZ - [0:0]`: true, + `:KUBE-HP-WFBOALXEP42XEMJK - [0:0]`: true, + `:KUBE-HP-XU6AWMMJYOZOFTFZ - [0:0]`: true, + "-A KUBE-HOSTPORTS -m comment --comment \"pod3_ns1 hostport 8443\" -m tcp -p tcp --dport 8443 -j KUBE-HP-WFBOALXEP42XEMJK": true, + "-A KUBE-HOSTPORTS -m comment --comment \"pod1_ns1 hostport 8081\" -m udp -p udp --dport 8081 -j KUBE-HP-63UPIDJXVRSZGSUZ": true, + "-A KUBE-HOSTPORTS -m comment --comment \"pod1_ns1 hostport 8080\" -m tcp -p tcp --dport 8080 -j KUBE-HP-IJHALPHTORMHHPPK": true, + "-A KUBE-HOSTPORTS -m comment --comment \"pod1_ns1 hostport 8083\" -m sctp -p sctp --dport 8083 -j KUBE-HP-XU6AWMMJYOZOFTFZ": true, + "-A OUTPUT -m comment --comment \"kube hostport portals\" -m addrtype --dst-type LOCAL -j KUBE-HOSTPORTS": true, + "-A PREROUTING -m comment --comment \"kube hostport portals\" -m addrtype --dst-type LOCAL -j KUBE-HOSTPORTS": true, + "-A POSTROUTING -m comment --comment \"SNAT for localhost access to hostports\" -o cbr0 -s 127.0.0.0/8 -j MASQUERADE": true, + "-A KUBE-HP-IJHALPHTORMHHPPK -m comment --comment \"pod1_ns1 hostport 8080\" -s 10.1.1.2/32 -j KUBE-MARK-MASQ": true, + "-A KUBE-HP-IJHALPHTORMHHPPK -m comment --comment \"pod1_ns1 hostport 8080\" -m tcp -p tcp -j DNAT --to-destination 10.1.1.2:80": true, + "-A KUBE-HP-63UPIDJXVRSZGSUZ -m comment --comment \"pod1_ns1 hostport 8081\" -s 10.1.1.2/32 -j KUBE-MARK-MASQ": true, + "-A KUBE-HP-63UPIDJXVRSZGSUZ -m comment --comment \"pod1_ns1 hostport 8081\" -m udp -p udp -j DNAT --to-destination 10.1.1.2:81": true, + "-A KUBE-HP-XU6AWMMJYOZOFTFZ -m comment --comment \"pod1_ns1 hostport 8083\" -s 10.1.1.2/32 -j KUBE-MARK-MASQ": true, + "-A KUBE-HP-XU6AWMMJYOZOFTFZ -m comment --comment \"pod1_ns1 hostport 8083\" -m sctp -p sctp -j DNAT --to-destination 10.1.1.2:83": true, + "-A KUBE-HP-WFBOALXEP42XEMJK -m comment --comment \"pod3_ns1 hostport 8443\" -s 10.1.1.4/32 -j KUBE-MARK-MASQ": true, + "-A KUBE-HP-WFBOALXEP42XEMJK -m comment --comment \"pod3_ns1 hostport 8443\" -m tcp -p tcp -j DNAT --to-destination 10.1.1.4:443": true, `COMMIT`: true, } for _, line := range lines { diff --git a/pkg/kubelet/dockershim/network/hostport/hostport_syncer.go b/pkg/kubelet/dockershim/network/hostport/hostport_syncer.go index 1775ec2457..1f9df7e9b9 100644 --- a/pkg/kubelet/dockershim/network/hostport/hostport_syncer.go +++ b/pkg/kubelet/dockershim/network/hostport/hostport_syncer.go @@ -27,9 +27,9 @@ import ( "github.com/golang/glog" + "k8s.io/api/core/v1" iptablesproxy "k8s.io/kubernetes/pkg/proxy/iptables" utiliptables "k8s.io/kubernetes/pkg/util/iptables" - "k8s.io/api/core/v1" ) // HostportSyncer takes a list of PodPortMappings and implements hostport all at once @@ -75,12 +75,12 @@ func (h *hostportSyncer) openHostports(podHostportMapping *PodPortMapping) error // Assume hostport is not specified in this portmapping. So skip continue } - + // We do not open host ports for SCTP ports, as we agreed in the Support of SCTP KEP if port.Protocol == v1.ProtocolSCTP { continue } - + hp := hostport{ port: port.HostPort, protocol: strings.ToLower(string(port.Protocol)), diff --git a/pkg/proxy/iptables/proxier_test.go b/pkg/proxy/iptables/proxier_test.go index 5dbf327532..fd711552f6 100644 --- a/pkg/proxy/iptables/proxier_test.go +++ b/pkg/proxy/iptables/proxier_test.go @@ -161,8 +161,8 @@ func newFakeServiceInfo(service proxy.ServicePortName, ip net.IP, port int, prot func TestDeleteEndpointConnections(t *testing.T) { const ( - UDP = v1.ProtocolUDP - TCP = v1.ProtocolTCP + UDP = v1.ProtocolUDP + TCP = v1.ProtocolTCP SCTP = v1.ProtocolSCTP ) testCases := []struct { @@ -189,14 +189,14 @@ func TestDeleteEndpointConnections(t *testing.T) { svcPort: 80, protocol: TCP, endpoint: "10.240.0.4:80", - },{ + }, { description: "V4 SCTP", svcName: "v4-sctp", svcIP: "10.96.3.3", svcPort: 80, protocol: SCTP, endpoint: "10.240.0.5:80", - },{ + }, { description: "V4 UDP, nothing to delete, benign error", svcName: "v4-udp-nothing-to-delete", svcIP: "10.96.1.1", diff --git a/pkg/proxy/ipvs/ipset.go b/pkg/proxy/ipvs/ipset.go index b5fd17cc35..99bdc6d154 100644 --- a/pkg/proxy/ipvs/ipset.go +++ b/pkg/proxy/ipvs/ipset.go @@ -64,7 +64,7 @@ const ( kubeNodePortLocalSetUDPComment = "Kubernetes nodeport UDP port with externalTrafficPolicy=local" kubeNodePortLocalSetUDP = "KUBE-NODE-PORT-LOCAL-UDP" - + kubeNodePortSetSCTPComment = "Kubernetes nodeport SCTP port for masquerade purpose" kubeNodePortSetSCTP = "KUBE-NODE-PORT-SCTP" diff --git a/pkg/proxy/ipvs/proxier.go b/pkg/proxy/ipvs/proxier.go index 7c27ff28e1..d1f90874fb 100644 --- a/pkg/proxy/ipvs/proxier.go +++ b/pkg/proxy/ipvs/proxier.go @@ -47,8 +47,6 @@ import ( utilnet "k8s.io/kubernetes/pkg/util/net" utilsysctl "k8s.io/kubernetes/pkg/util/sysctl" utilexec "k8s.io/utils/exec" - - ) const ( @@ -811,8 +809,8 @@ func (proxier *Proxier) syncProxyRules() { for _, externalIP := range svcInfo.ExternalIPs { if local, err := utilproxy.IsLocalIP(externalIP); err != nil { glog.Errorf("can't determine if IP is local, assuming not: %v", err) - // We do not start listening on SCTP ports, according to our agreement in the - // SCTP support KEP + // We do not start listening on SCTP ports, according to our agreement in the + // SCTP support KEP } else if local && (svcInfo.GetProtocol() != v1.ProtocolSCTP) { lp := utilproxy.LocalPort{ Description: "externalIP for " + svcNameString, @@ -1012,8 +1010,8 @@ func (proxier *Proxier) syncProxyRules() { if proxier.portsMap[lp] != nil { glog.V(4).Infof("Port %s was open before and is still needed", lp.String()) replacementPortsMap[lp] = proxier.portsMap[lp] - // We do not start listening on SCTP ports, according to our agreement in the - // SCTP support KEP + // We do not start listening on SCTP ports, according to our agreement in the + // SCTP support KEP } else if svcInfo.GetProtocol() != v1.ProtocolSCTP { socket, err := proxier.portMapper.OpenLocalPort(&lp) if err != nil { diff --git a/pkg/util/ipset/ipset_test.go b/pkg/util/ipset/ipset_test.go index b089a62999..f5b95da0d2 100644 --- a/pkg/util/ipset/ipset_test.go +++ b/pkg/util/ipset/ipset_test.go @@ -1425,11 +1425,11 @@ func TestValidateEntry(t *testing.T) { }, { // case[19] entry: &Entry{ - SetType: HashIPPortIP, - IP: "10.20.30.40", + SetType: HashIPPortIP, + IP: "10.20.30.40", Protocol: ProtocolSCTP, - Port: 8090, - IP2: "10.20.30.41", + Port: 8090, + IP2: "10.20.30.41", }, set: &IPSet{ Name: "sctp", diff --git a/pkg/util/ipvs/ipvs_linux.go b/pkg/util/ipvs/ipvs_linux.go index 02f9dce776..47c640c183 100644 --- a/pkg/util/ipvs/ipvs_linux.go +++ b/pkg/util/ipvs/ipvs_linux.go @@ -252,7 +252,7 @@ func stringToProtocol(protocol string) uint16 { return uint16(syscall.IPPROTO_TCP) case "udp": return uint16(syscall.IPPROTO_UDP) - case "sctp": + case "sctp": return uint16(syscall.IPPROTO_SCTP) } return uint16(0)