var NodePortRange … var errAllocated … type TestJig … // NewTestJig allocates and inits a new TestJig. func NewTestJig(client clientset.Interface, namespace, name string) *TestJig { … } // newServiceTemplate returns the default v1.Service template for this j, but // does not actually create the Service. The default Service has the same name // as the j and exposes the given port. func (j *TestJig) newServiceTemplate(proto v1.Protocol, port int32) *v1.Service { … } // CreateTCPServiceWithPort creates a new TCP Service with given port based on the // j's defaults. Callers can provide a function to tweak the Service object before // it is created. func (j *TestJig) CreateTCPServiceWithPort(ctx context.Context, tweak func(svc *v1.Service), port int32) (*v1.Service, error) { … } // CreateTCPService creates a new TCP Service based on the j's // defaults. Callers can provide a function to tweak the Service object before // it is created. func (j *TestJig) CreateTCPService(ctx context.Context, tweak func(svc *v1.Service)) (*v1.Service, error) { … } // CreateUDPService creates a new UDP Service based on the j's // defaults. Callers can provide a function to tweak the Service object before // it is created. func (j *TestJig) CreateUDPService(ctx context.Context, tweak func(svc *v1.Service)) (*v1.Service, error) { … } // CreateExternalNameService creates a new ExternalName type Service based on the j's defaults. // Callers can provide a function to tweak the Service object before it is created. func (j *TestJig) CreateExternalNameService(ctx context.Context, tweak func(svc *v1.Service)) (*v1.Service, error) { … } // ChangeServiceType updates the given service's ServiceType to the given newType. func (j *TestJig) ChangeServiceType(ctx context.Context, newType v1.ServiceType, timeout time.Duration) error { … } // CreateOnlyLocalNodePortService creates a NodePort service with // ExternalTrafficPolicy set to Local and sanity checks its nodePort. // If createPod is true, it also creates an RC with 1 replica of // the standard netexec container used everywhere in this test. func (j *TestJig) CreateOnlyLocalNodePortService(ctx context.Context, createPod bool) (*v1.Service, error) { … } // CreateOnlyLocalLoadBalancerService creates a loadbalancer service with // ExternalTrafficPolicy set to Local and waits for it to acquire an ingress IP. // If createPod is true, it also creates an RC with 1 replica of // the standard netexec container used everywhere in this test. func (j *TestJig) CreateOnlyLocalLoadBalancerService(ctx context.Context, timeout time.Duration, createPod bool, tweak func(svc *v1.Service)) (*v1.Service, error) { … } // CreateLoadBalancerService creates a loadbalancer service and waits // for it to acquire an ingress IP. func (j *TestJig) CreateLoadBalancerService(ctx context.Context, timeout time.Duration, tweak func(svc *v1.Service)) (*v1.Service, error) { … } // GetEndpointNodes returns a map of nodenames:external-ip on which the // endpoints of the Service are running. func (j *TestJig) GetEndpointNodes(ctx context.Context) (map[string][]string, error) { … } // GetEndpointNodesWithIP returns a map of nodenames:<ip of given type> on which the // endpoints of the Service are running. func (j *TestJig) GetEndpointNodesWithIP(ctx context.Context, addressType v1.NodeAddressType) (map[string][]string, error) { … } // ListNodesWithEndpoint returns a list of nodes on which the // endpoints of the given Service are running. func (j *TestJig) ListNodesWithEndpoint(ctx context.Context) ([]v1.Node, error) { … } // GetEndpointNodeNames returns a string set of node names on which the // endpoints of the given Service are running. func (j *TestJig) GetEndpointNodeNames(ctx context.Context) (sets.String, error) { … } // WaitForEndpointOnNode waits for a service endpoint on the given node. func (j *TestJig) WaitForEndpointOnNode(ctx context.Context, nodeName string) error { … } // waitForAvailableEndpoint waits for at least 1 endpoint to be available till timeout func (j *TestJig) waitForAvailableEndpoint(ctx context.Context, timeout time.Duration) error { … } // 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) { … } func needsNodePorts(svc *v1.Service) bool { … } // UpdateService fetches a service, calls the update function on it, and // then attempts to send the updated service. It tries up to 3 times in the // face of timeouts and conflicts. func (j *TestJig) UpdateService(ctx context.Context, update func(*v1.Service)) (*v1.Service, error) { … } // WaitForNewIngressIP waits for the given service to get a new ingress IP, or returns an error after the given timeout func (j *TestJig) WaitForNewIngressIP(ctx context.Context, existingIP string, timeout time.Duration) (*v1.Service, error) { … } // ChangeServiceNodePort changes node ports of the given service. func (j *TestJig) ChangeServiceNodePort(ctx context.Context, initial int) (*v1.Service, error) { … } // WaitForLoadBalancer waits the given service to have a LoadBalancer, or returns an error after the given timeout func (j *TestJig) WaitForLoadBalancer(ctx context.Context, timeout time.Duration) (*v1.Service, error) { … } // WaitForLoadBalancerDestroy waits the given service to destroy a LoadBalancer, or returns an error after the given timeout func (j *TestJig) WaitForLoadBalancerDestroy(ctx context.Context, ip string, port int, timeout time.Duration) (*v1.Service, error) { … } func (j *TestJig) waitForCondition(ctx context.Context, timeout time.Duration, message string, conditionFn func(*v1.Service) bool) (*v1.Service, error) { … } // newRCTemplate returns the default v1.ReplicationController object for // this j, but does not actually create the RC. The default RC has the same // name as the j and runs the "netexec" container. func (j *TestJig) newRCTemplate() *v1.ReplicationController { … } // AddRCAntiAffinity adds AntiAffinity to the given ReplicationController. func (j *TestJig) AddRCAntiAffinity(rc *v1.ReplicationController) { … } // CreatePDB returns a PodDisruptionBudget for the given ReplicationController, or returns an error if a PodDisruptionBudget isn't ready func (j *TestJig) CreatePDB(ctx context.Context, rc *v1.ReplicationController) (*policyv1.PodDisruptionBudget, error) { … } // newPDBTemplate returns the default policyv1.PodDisruptionBudget object for // this j, but does not actually create the PDB. The default PDB specifies a // MinAvailable of N-1 and matches the pods created by the RC. func (j *TestJig) newPDBTemplate(rc *v1.ReplicationController) *policyv1.PodDisruptionBudget { … } // Run creates a ReplicationController and Pod(s) and waits for the // Pod(s) to be running. Callers can provide a function to tweak the RC object // before it is created. func (j *TestJig) Run(ctx context.Context, tweak func(rc *v1.ReplicationController)) (*v1.ReplicationController, error) { … } // Scale scales pods to the given replicas func (j *TestJig) Scale(ctx context.Context, replicas int) error { … } func (j *TestJig) waitForPdbReady(ctx context.Context) error { … } func (j *TestJig) waitForPodsCreated(ctx context.Context, replicas int) ([]string, error) { … } func (j *TestJig) waitForPodsReady(ctx context.Context, pods []string) error { … } func testReachabilityOverServiceName(ctx context.Context, serviceName string, sp v1.ServicePort, execPod *v1.Pod) error { … } func testReachabilityOverClusterIP(ctx context.Context, clusterIP string, sp v1.ServicePort, execPod *v1.Pod) error { … } func testReachabilityOverExternalIP(ctx context.Context, externalIP string, sp v1.ServicePort, execPod *v1.Pod) error { … } func testReachabilityOverNodePorts(ctx context.Context, nodes *v1.NodeList, sp v1.ServicePort, pod *v1.Pod, clusterIP string, externalIPs bool) error { … } // isInvalidOrLocalhostAddress returns `true` if the provided `ip` is either not // parsable or the loopback address. Otherwise it will return `false`. func isInvalidOrLocalhostAddress(ip string) bool { … } // testEndpointReachability tests reachability to endpoints (i.e. IP, ServiceName) and ports. Test request is initiated from specified execPod. // TCP and UDP protocol based service are supported at this moment // TODO: add support to test SCTP Protocol based services. func testEndpointReachability(ctx context.Context, endpoint string, port int32, protocol v1.Protocol, execPod *v1.Pod) error { … } // checkClusterIPServiceReachability ensures that service of type ClusterIP is reachable over // - ServiceName:ServicePort, ClusterIP:ServicePort func (j *TestJig) checkClusterIPServiceReachability(ctx context.Context, svc *v1.Service, pod *v1.Pod) error { … } // checkNodePortServiceReachability ensures that service of type nodePort are reachable // - Internal clients should be reachable to service over - // ServiceName:ServicePort, ClusterIP:ServicePort and NodeInternalIPs:NodePort // - External clients should be reachable to service over - // NodePublicIPs:NodePort func (j *TestJig) checkNodePortServiceReachability(ctx context.Context, svc *v1.Service, pod *v1.Pod) error { … } // checkExternalServiceReachability ensures service of type externalName resolves to IP address and no fake externalName is set // FQDN of kubernetes is used as externalName(for air tight platforms). func (j *TestJig) checkExternalServiceReachability(ctx context.Context, svc *v1.Service, pod *v1.Pod) error { … } // CheckServiceReachability ensures that request are served by the services. Only supports Services with type ClusterIP, NodePort and ExternalName. func (j *TestJig) CheckServiceReachability(ctx context.Context, svc *v1.Service, pod *v1.Pod) error { … } // CreateServicePods creates a replication controller with the label same as service. Service listens to TCP and UDP. func (j *TestJig) CreateServicePods(ctx context.Context, replica int) error { … } // CreateSCTPServiceWithPort creates a new SCTP Service with given port based on the // j's defaults. Callers can provide a function to tweak the Service object before // it is created. func (j *TestJig) CreateSCTPServiceWithPort(ctx context.Context, tweak func(svc *v1.Service), port int32) (*v1.Service, error) { … } // CreateLoadBalancerServiceWaitForClusterIPOnly creates a loadbalancer service and waits // for it to acquire a cluster IP func (j *TestJig) CreateLoadBalancerServiceWaitForClusterIPOnly(tweak func(svc *v1.Service)) (*v1.Service, error) { … }