Merge pull request #94847 from eddiezane/automated-cherry-pick-of-#94728-upstream-release-1.19
Automated cherry pick of #94728: portforward: Fix UDP-only ports calculation Kubernetes-commit: 269612089a13b1296598f4cb86485fe8a4f9faf3
This commit is contained in:
commit
28d699c230
|
@ -756,7 +756,7 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/api",
|
||||
"Rev": "21b59c1ded36"
|
||||
"Rev": "50fcaa748a4b"
|
||||
},
|
||||
{
|
||||
"ImportPath": "k8s.io/apimachinery",
|
||||
|
|
4
go.mod
4
go.mod
|
@ -34,7 +34,7 @@ require (
|
|||
github.com/xlab/handysort v0.0.0-20150421192137-fb3537ed64a1 // indirect
|
||||
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4
|
||||
gopkg.in/yaml.v2 v2.2.8
|
||||
k8s.io/api v0.0.0-20200821172135-21b59c1ded36
|
||||
k8s.io/api v0.0.0-20201006170643-50fcaa748a4b
|
||||
k8s.io/apimachinery v0.0.0-20200821171749-b63a0c883fbf
|
||||
k8s.io/cli-runtime v0.0.0-20200821180036-613970382155
|
||||
k8s.io/client-go v0.0.0-20200904053452-bb0bc934b5b4
|
||||
|
@ -49,7 +49,7 @@ require (
|
|||
)
|
||||
|
||||
replace (
|
||||
k8s.io/api => k8s.io/api v0.0.0-20200821172135-21b59c1ded36
|
||||
k8s.io/api => k8s.io/api v0.0.0-20201006170643-50fcaa748a4b
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200821171749-b63a0c883fbf
|
||||
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20200821180036-613970382155
|
||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20200904053452-bb0bc934b5b4
|
||||
|
|
2
go.sum
2
go.sum
|
@ -508,7 +508,7 @@ honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWh
|
|||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
k8s.io/api v0.0.0-20200821172135-21b59c1ded36/go.mod h1:WXzrXjAr+IgCMGkIbOU4i87rvN7UWNGsyNmBEkW9rx8=
|
||||
k8s.io/api v0.0.0-20201006170643-50fcaa748a4b/go.mod h1:WXzrXjAr+IgCMGkIbOU4i87rvN7UWNGsyNmBEkW9rx8=
|
||||
k8s.io/apimachinery v0.0.0-20200821171749-b63a0c883fbf/go.mod h1:DnPGDnARWFvYa3pMHgSxtbZb7gpzzAZ1pTfaUNDVlmA=
|
||||
k8s.io/cli-runtime v0.0.0-20200821180036-613970382155/go.mod h1:IVVYq4ZROvROdTjn96acqGoWsk3dgHOCXL9jT7rkDi4=
|
||||
k8s.io/client-go v0.0.0-20200904053452-bb0bc934b5b4/go.mod h1:SnLtmp6F+NMdYHYqnSKVWW81iA2wv5QfXXncW8aWuKc=
|
||||
|
|
|
@ -260,35 +260,37 @@ func checkUDPPorts(udpOnlyPorts sets.Int, ports []string, obj metav1.Object) err
|
|||
// checkUDPPortInService returns an error if remote port in Service is a UDP port
|
||||
// TODO: remove this check after #47862 is solved
|
||||
func checkUDPPortInService(ports []string, svc *corev1.Service) error {
|
||||
udpOnlyPorts := sets.NewInt()
|
||||
udpPorts := sets.NewInt()
|
||||
tcpPorts := sets.NewInt()
|
||||
for _, port := range svc.Spec.Ports {
|
||||
portNum := int(port.Port)
|
||||
switch port.Protocol {
|
||||
case corev1.ProtocolUDP:
|
||||
udpOnlyPorts.Insert(portNum)
|
||||
udpPorts.Insert(portNum)
|
||||
case corev1.ProtocolTCP:
|
||||
udpOnlyPorts.Delete(portNum)
|
||||
tcpPorts.Insert(portNum)
|
||||
}
|
||||
}
|
||||
return checkUDPPorts(udpOnlyPorts, ports, svc)
|
||||
return checkUDPPorts(udpPorts.Difference(tcpPorts), ports, svc)
|
||||
}
|
||||
|
||||
// checkUDPPortInPod returns an error if remote port in Pod is a UDP port
|
||||
// TODO: remove this check after #47862 is solved
|
||||
func checkUDPPortInPod(ports []string, pod *corev1.Pod) error {
|
||||
udpOnlyPorts := sets.NewInt()
|
||||
udpPorts := sets.NewInt()
|
||||
tcpPorts := sets.NewInt()
|
||||
for _, ct := range pod.Spec.Containers {
|
||||
for _, ctPort := range ct.Ports {
|
||||
portNum := int(ctPort.ContainerPort)
|
||||
switch ctPort.Protocol {
|
||||
case corev1.ProtocolUDP:
|
||||
udpOnlyPorts.Insert(portNum)
|
||||
udpPorts.Insert(portNum)
|
||||
case corev1.ProtocolTCP:
|
||||
udpOnlyPorts.Delete(portNum)
|
||||
tcpPorts.Insert(portNum)
|
||||
}
|
||||
}
|
||||
}
|
||||
return checkUDPPorts(udpOnlyPorts, ports, pod)
|
||||
return checkUDPPorts(udpPorts.Difference(tcpPorts), ports, pod)
|
||||
}
|
||||
|
||||
// Complete completes all the required options for port-forward cmd.
|
||||
|
|
|
@ -880,7 +880,7 @@ func TestCheckUDPPort(t *testing.T) {
|
|||
expectError: true,
|
||||
},
|
||||
{
|
||||
name: "Pod has ports with both TCP and UDP protocol",
|
||||
name: "Pod has ports with both TCP and UDP protocol (UDP first)",
|
||||
pod: &corev1.Pod{
|
||||
Spec: corev1.PodSpec{
|
||||
Containers: []corev1.Container{
|
||||
|
@ -895,6 +895,22 @@ func TestCheckUDPPort(t *testing.T) {
|
|||
},
|
||||
ports: []string{":53"},
|
||||
},
|
||||
{
|
||||
name: "Pod has ports with both TCP and UDP protocol (TCP first)",
|
||||
pod: &corev1.Pod{
|
||||
Spec: corev1.PodSpec{
|
||||
Containers: []corev1.Container{
|
||||
{
|
||||
Ports: []corev1.ContainerPort{
|
||||
{Protocol: corev1.ProtocolTCP, ContainerPort: 53},
|
||||
{Protocol: corev1.ProtocolUDP, ContainerPort: 53},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
ports: []string{":53"},
|
||||
},
|
||||
|
||||
{
|
||||
name: "forward to a UDP port in a Service",
|
||||
|
@ -921,7 +937,7 @@ func TestCheckUDPPort(t *testing.T) {
|
|||
expectError: true,
|
||||
},
|
||||
{
|
||||
name: "Service has ports with both TCP and UDP protocol",
|
||||
name: "Service has ports with both TCP and UDP protocol (UDP first)",
|
||||
service: &corev1.Service{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
|
@ -932,6 +948,18 @@ func TestCheckUDPPort(t *testing.T) {
|
|||
},
|
||||
ports: []string{"53"},
|
||||
},
|
||||
{
|
||||
name: "Service has ports with both TCP and UDP protocol (TCP first)",
|
||||
service: &corev1.Service{
|
||||
Spec: corev1.ServiceSpec{
|
||||
Ports: []corev1.ServicePort{
|
||||
{Protocol: corev1.ProtocolTCP, Port: 53},
|
||||
{Protocol: corev1.ProtocolUDP, Port: 53},
|
||||
},
|
||||
},
|
||||
},
|
||||
ports: []string{"53"},
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
var err error
|
||||
|
|
Loading…
Reference in New Issue