func (j *TestJig) sanityCheckService(svc *v1.Service, svcType v1.ServiceType) (*v1.Service, error) {
	if svcType == "" {
		svcType = v1.ServiceTypeClusterIP
	}
	if svc.Spec.Type != svcType {
		return nil, fmt.Errorf("unexpected Spec.Type (%s) for service, expected %s", svc.Spec.Type, svcType)
	}

	if svcType != v1.ServiceTypeExternalName {
		if svc.Spec.ExternalName != "" {
			return nil, fmt.Errorf("unexpected Spec.ExternalName (%s) for service, expected empty", svc.Spec.ExternalName)
		}
		if svc.Spec.ClusterIP == "" {
			return nil, fmt.Errorf("didn't get ClusterIP for non-ExternalName service")
		}
	} else {
		if svc.Spec.ClusterIP != "" {
			return nil, fmt.Errorf("unexpected Spec.ClusterIP (%s) for ExternalName service, expected empty", svc.Spec.ClusterIP)
		}
	}

	expectNodePorts := false
	if svcType != v1.ServiceTypeClusterIP && svcType != v1.ServiceTypeExternalName {
		expectNodePorts = true
	}
	for i, port := range svc.Spec.Ports {
		hasNodePort := (port.NodePort != 0)
		if hasNodePort != expectNodePorts {
			return nil, fmt.Errorf("unexpected Spec.Ports[%d].NodePort (%d) for service", i, port.NodePort)
		}
		if hasNodePort {
			if !NodePortRange.Contains(int(port.NodePort)) {
				return nil, fmt.Errorf("out-of-range nodePort (%d) for service", port.NodePort)
			}
		}
	}

	// FIXME: this fails for tests that were changed from LoadBalancer to ClusterIP.
	// if svcType != v1.ServiceTypeLoadBalancer {
	// 	if len(svc.Status.LoadBalancer.Ingress) != 0 {
	// 		return nil, fmt.Errorf("unexpected Status.LoadBalancer.Ingress on non-LoadBalancer service")
	// 	}
	// }

	return svc, nil
}
// sanityCheckService performs sanity checks on the given service; in particular, ensuring
// that creating/updating a service allocates IPs, ports, etc, as needed. It does not
// check for ingress assignment as that happens asynchronously after the Service is created.
sanityCheckService performs sanity checks on the given service; in particular, ensuring
that creating/updating a service allocates IPs, ports, etc, as needed. It does not
check for ingress assignment as that happens asynchronously after the Service is created.
// sanityCheckService performs sanity checks on the given service ; in particular ensuring // that creating / updating a service allocates IPs ports etc as needed . It does not // check for ingress assignment as that happens asynchronously after the Service is created .
func (j *TestJig) sanityCheckService(svc *v1.Service, svcType v1.ServiceType) (*v1.Service, error) {
	if svcType == "" {
		svcType = v1.ServiceTypeClusterIP
	}
	if svc.Spec.Type != svcType {
		return nil, fmt.Errorf("unexpected Spec.Type (%s) for service, expected %s", svc.Spec.Type, svcType)
	}
	if svcType != v1.ServiceTypeExternalName {
		if svc.Spec.ExternalName != "" {
			return nil, fmt.Errorf("unexpected Spec.ExternalName (%s) for service, expected empty", svc.Spec.ExternalName)
		}
		if svc.Spec.ClusterIP == "" {
			return nil, fmt.Errorf("didn't get ClusterIP for non-ExternalName service")
		}
	} else {
		if svc.Spec.ClusterIP != "" {
			return nil, fmt.Errorf("unexpected Spec.ClusterIP (%s) for ExternalName service, expected empty", svc.Spec.ClusterIP)
		}
	}
	expectNodePorts := false
	if svcType != v1.ServiceTypeClusterIP && svcType != v1.ServiceTypeExternalName {
		expectNodePorts = true
	}
	for i, port := range svc.Spec.Ports {
		hasNodePort := (port.NodePort != 0)
		if hasNodePort != expectNodePorts {
			return nil, fmt.Errorf("unexpected Spec.Ports[%d].NodePort (%d) for service", i, port.NodePort)
		}
		if hasNodePort {
			if !NodePortRange.Contains(int(port.NodePort)) {
				return nil, fmt.Errorf("out-of-range nodePort (%d) for service", port.NodePort)
			}
		}
	}
	return svc, nil
}
func ( j * TestJig ) sanityCheckService ( svc * v1 . Service , svcType v1 . ServiceType ) ( * v1 . Service , error ) { if svcType == " " { svcType = v1 . ServiceTypeClusterIP } if svc . Spec . Type != svcType { return nil , fmt . Errorf ( " " , svc . Spec . Type , svcType ) } if svcType != v1 . ServiceTypeExternalName { if svc . Spec . ExternalName != " " { return nil , fmt . Errorf ( " " , svc . Spec . ExternalName ) } if svc . Spec . ClusterIP == " " { return nil , fmt . Errorf ( " " ) } } else { if svc . Spec . ClusterIP != " " { return nil , fmt . Errorf ( " " , svc . Spec . ClusterIP ) } } expectNodePorts := false if svcType != v1 . ServiceTypeClusterIP && svcType != v1 . ServiceTypeExternalName { expectNodePorts = true } for i , port := range svc . Spec . Ports { hasNodePort := ( port . NodePort != 0 ) if hasNodePort != expectNodePorts { return nil , fmt . Errorf ( " " , i , port . NodePort ) } if hasNodePort { if ! NodePortRange . Contains ( int ( port . NodePort ) ) { return nil , fmt . Errorf ( " " , port . NodePort ) } } } return svc , nil }
sanityCheckService performs sanity checks on the given service; in particular, ensuring
that creating/updating a service allocates IPs, ports, etc, as needed.
sanityCheckService performs sanity checks on the given service ; in particular ensuring that creating / updating a service allocates IPs ports etc as needed .
// FIXME: this fails for tests that were changed from LoadBalancer to ClusterIP. // if svcType != v1.ServiceTypeLoadBalancer { // 	if len(svc.Status.LoadBalancer.Ingress) != 0 { // 		return nil, fmt.Errorf("unexpected Status.LoadBalancer.Ingress on non-LoadBalancer service") // 	} // }