mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Make sure the ports is valid when parsing portString
This commit is contained in:
		@@ -89,14 +89,25 @@ func parsePorts(portString string) (int32, intstr.IntOrString, error) {
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return 0, intstr.FromInt(0), err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if errs := validation.IsValidPortNum(port); len(errs) != 0 {
 | 
			
		||||
		return 0, intstr.FromInt(0), fmt.Errorf(strings.Join(errs, ","))
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(portStringSlice) == 1 {
 | 
			
		||||
		return int32(port), intstr.FromInt(int(port)), nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var targetPort intstr.IntOrString
 | 
			
		||||
	if portNum, err := strconv.Atoi(portStringSlice[1]); err != nil {
 | 
			
		||||
		if errs := validation.IsValidPortName(portStringSlice[1]); len(errs) != 0 {
 | 
			
		||||
			return 0, intstr.FromInt(0), fmt.Errorf(strings.Join(errs, ","))
 | 
			
		||||
		}
 | 
			
		||||
		targetPort = intstr.FromString(portStringSlice[1])
 | 
			
		||||
	} else {
 | 
			
		||||
		if errs := validation.IsValidPortNum(portNum); len(errs) != 0 {
 | 
			
		||||
			return 0, intstr.FromInt(0), fmt.Errorf(strings.Join(errs, ","))
 | 
			
		||||
		}
 | 
			
		||||
		targetPort = intstr.FromInt(portNum)
 | 
			
		||||
	}
 | 
			
		||||
	return int32(port), targetPort, nil
 | 
			
		||||
 
 | 
			
		||||
@@ -115,6 +115,20 @@ func TestServiceBasicGenerate(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
			expectErr: false,
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name:        "invalid-port",
 | 
			
		||||
			tcp:         []string{"65536"},
 | 
			
		||||
			clusterip:   "None",
 | 
			
		||||
			serviceType: v1.ServiceTypeClusterIP,
 | 
			
		||||
			expectErr:   true,
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name:        "invalid-port-mapping",
 | 
			
		||||
			tcp:         []string{"8080:-abc"},
 | 
			
		||||
			clusterip:   "None",
 | 
			
		||||
			serviceType: v1.ServiceTypeClusterIP,
 | 
			
		||||
			expectErr:   true,
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			expectErr: true,
 | 
			
		||||
		},
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user