mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Service with type=NodePortr and clusterIP=None is not allowed
This commit is contained in:
		
				
					committed by
					
						
						Derek Carr
					
				
			
			
				
	
			
			
			
						parent
						
							6fa4042211
						
					
				
				
					commit
					023bf87c38
				
			@@ -2455,6 +2455,10 @@ func validateServiceFields(service *api.Service) field.ErrorList {
 | 
				
			|||||||
		if service.Spec.ClusterIP == "None" {
 | 
							if service.Spec.ClusterIP == "None" {
 | 
				
			||||||
			allErrs = append(allErrs, field.Invalid(specPath.Child("clusterIP"), service.Spec.ClusterIP, "may not be set to 'None' for LoadBalancer services"))
 | 
								allErrs = append(allErrs, field.Invalid(specPath.Child("clusterIP"), service.Spec.ClusterIP, "may not be set to 'None' for LoadBalancer services"))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						case api.ServiceTypeNodePort:
 | 
				
			||||||
 | 
							if service.Spec.ClusterIP == "None" {
 | 
				
			||||||
 | 
								allErrs = append(allErrs, field.Invalid(specPath.Child("clusterIP"), service.Spec.ClusterIP, "may not be set to 'None' for NodePort services"))
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	case api.ServiceTypeExternalName:
 | 
						case api.ServiceTypeExternalName:
 | 
				
			||||||
		if service.Spec.ClusterIP != "" {
 | 
							if service.Spec.ClusterIP != "" {
 | 
				
			||||||
			allErrs = append(allErrs, field.Invalid(specPath.Child("clusterIP"), service.Spec.ClusterIP, "must be empty for ExternalName services"))
 | 
								allErrs = append(allErrs, field.Invalid(specPath.Child("clusterIP"), service.Spec.ClusterIP, "must be empty for ExternalName services"))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5474,6 +5474,15 @@ func TestValidateService(t *testing.T) {
 | 
				
			|||||||
			},
 | 
								},
 | 
				
			||||||
			numErrs: 1,
 | 
								numErrs: 1,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name: "invalid node port with clusterIP None",
 | 
				
			||||||
 | 
								tweakSvc: func(s *api.Service) {
 | 
				
			||||||
 | 
									s.Spec.Type = api.ServiceTypeNodePort
 | 
				
			||||||
 | 
									s.Spec.Ports = append(s.Spec.Ports, api.ServicePort{Name: "q", Port: 1, Protocol: "TCP", NodePort: 1, TargetPort: intstr.FromInt(1)})
 | 
				
			||||||
 | 
									s.Spec.ClusterIP = "None"
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								numErrs: 1,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, tc := range testCases {
 | 
						for _, tc := range testCases {
 | 
				
			||||||
@@ -7069,6 +7078,20 @@ func TestValidateServiceUpdate(t *testing.T) {
 | 
				
			|||||||
			},
 | 
								},
 | 
				
			||||||
			numErrs: 0,
 | 
								numErrs: 0,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								name: "invalid node port with clusterIP None",
 | 
				
			||||||
 | 
								tweakSvc: func(oldSvc, newSvc *api.Service) {
 | 
				
			||||||
 | 
									oldSvc.Spec.Type = api.ServiceTypeNodePort
 | 
				
			||||||
 | 
									newSvc.Spec.Type = api.ServiceTypeNodePort
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									oldSvc.Spec.Ports = append(oldSvc.Spec.Ports, api.ServicePort{Name: "q", Port: 1, Protocol: "TCP", NodePort: 1, TargetPort: intstr.FromInt(1)})
 | 
				
			||||||
 | 
									newSvc.Spec.Ports = append(newSvc.Spec.Ports, api.ServicePort{Name: "q", Port: 1, Protocol: "TCP", NodePort: 1, TargetPort: intstr.FromInt(1)})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									oldSvc.Spec.ClusterIP = ""
 | 
				
			||||||
 | 
									newSvc.Spec.ClusterIP = "None"
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								numErrs: 1,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, tc := range testCases {
 | 
						for _, tc := range testCases {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user