mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Automatic merge from submit-queue Fix port range checking, port should not be greater than 65535. When passing flag `--proxy-port-range` to kube-proxy with an invalid range which is greater than 65535, the proxy doesn't exit. That's not what we want. Should we fix this in v1.3? /cc @thockin @mikedanese @resouer Before fixing: ``` root@vm:/home/paas/zxp# kube-proxy --master=172.16.1.11:8080 --logtostderr=false --log-dir=/home/user/log/kube --proxy-port-range=65536-65599 & [6] 6671 root@vm:/home/paas/zxp# ps -ef | grep kube-proxy root 6671 13507 0 03:48 pts/1 00:00:00 kube-proxy --master=172.16.1.11:8080 --logtostderr=false --log-dir=/home/user/log/kube --proxy-port-range=65536-65599 ``` After: ``` root@vm:/home/paas/zxp# kube-proxy --master=172.16.1.11:8080 --logtostderr=false --log-dir=/home/user/log/kube --proxy-port-range=65536-65599 & [6] 6725 root@vm:/home/paas/zxp# invalid argument "65536-65599" for --proxy-port-range=65536-65599: "65536-65599" is not a valid port range: the port range cannot be greater than 65535: 65536-65599 .............. [6]+ Exit 2 kube-proxy --master=172.16.1.11:8080 --logtostderr=false --log-dir=/home/user/log/kube --proxy-port-range=65536-65599 ``` ``` root@vm:/home/paas/zxp# kube-proxy --master=172.16.1.11:8080 --logtostderr=false --log-dir=/home/user/log/kube --proxy-port-range=6000-65599 & [6] 6732 root@vm:/home/paas/zxp# invalid argument "6000-65599" for --proxy-port-range=6000-65599: "6000-65599" is not a valid port range: the port range cannot be greater than 65535: 6000-65599 .............. [6]+ Exit 2 kube-proxy --master=172.16.1.11:8080 --logtostderr=false --log-dir=/home/user/log/kube --proxy-port-range=6000-65599 ```
		
			
				
	
	
		
			70 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
/*
 | 
						|
Copyright 2015 The Kubernetes Authors.
 | 
						|
 | 
						|
Licensed under the Apache License, Version 2.0 (the "License");
 | 
						|
you may not use this file except in compliance with the License.
 | 
						|
You may obtain a copy of the License at
 | 
						|
 | 
						|
    http://www.apache.org/licenses/LICENSE-2.0
 | 
						|
 | 
						|
Unless required by applicable law or agreed to in writing, software
 | 
						|
distributed under the License is distributed on an "AS IS" BASIS,
 | 
						|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
						|
See the License for the specific language governing permissions and
 | 
						|
limitations under the License.
 | 
						|
*/
 | 
						|
 | 
						|
package net
 | 
						|
 | 
						|
import (
 | 
						|
	"testing"
 | 
						|
 | 
						|
	flag "github.com/spf13/pflag"
 | 
						|
)
 | 
						|
 | 
						|
func TestPortRange(t *testing.T) {
 | 
						|
	testCases := []struct {
 | 
						|
		input    string
 | 
						|
		success  bool
 | 
						|
		expected string
 | 
						|
		included int
 | 
						|
		excluded int
 | 
						|
	}{
 | 
						|
		{"100-200", true, "100-200", 200, 201},
 | 
						|
		{" 100-200 ", true, "100-200", 200, 201},
 | 
						|
		{"0-0", true, "0-0", 0, 1},
 | 
						|
		{"", true, "", -1, 0},
 | 
						|
		{"100", false, "", -1, -1},
 | 
						|
		{"100 - 200", false, "", -1, -1},
 | 
						|
		{"-100", false, "", -1, -1},
 | 
						|
		{"100-", false, "", -1, -1},
 | 
						|
		{"200-100", false, "", -1, -1},
 | 
						|
		{"60000-70000", false, "", -1, -1},
 | 
						|
		{"70000-80000", false, "", -1, -1},
 | 
						|
	}
 | 
						|
 | 
						|
	for i := range testCases {
 | 
						|
		tc := &testCases[i]
 | 
						|
		pr := &PortRange{}
 | 
						|
		var f flag.Value = pr
 | 
						|
		err := f.Set(tc.input)
 | 
						|
		if err != nil && tc.success == true {
 | 
						|
			t.Errorf("expected success, got %q", err)
 | 
						|
			continue
 | 
						|
		} else if err == nil && tc.success == false {
 | 
						|
			t.Errorf("expected failure")
 | 
						|
			continue
 | 
						|
		} else if tc.success {
 | 
						|
			if f.String() != tc.expected {
 | 
						|
				t.Errorf("expected %q, got %q", tc.expected, f.String())
 | 
						|
			}
 | 
						|
			if tc.included >= 0 && !pr.Contains(tc.included) {
 | 
						|
				t.Errorf("expected %q to include %d", f.String(), tc.included)
 | 
						|
			}
 | 
						|
			if tc.excluded >= 0 && pr.Contains(tc.excluded) {
 | 
						|
				t.Errorf("expected %q to exclude %d", f.String(), tc.excluded)
 | 
						|
			}
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 |