Documentation
¶
Index ¶
- Constants
- Variables
- func CleanupServiceResources(ctx context.Context, c clientset.Interface, ...)
- func CreateServiceForSimpleApp(ctx context.Context, c clientset.Interface, contPort, svcPort int, ...) *v1.Service
- func CreateServiceForSimpleAppWithPods(ctx context.Context, c clientset.Interface, contPort int, svcPort int, ...) (*v1.Service, error)
- func CreateServiceSpec(serviceName, externalName string, isHeadless bool, selector map[string]string) *v1.Service
- func GetIngressPoint(ing *v1.LoadBalancerIngress) string
- func GetServiceLoadBalancerCreationTimeout(ctx context.Context, cs clientset.Interface) time.Duration
- func GetServiceLoadBalancerPropagationTimeout(ctx context.Context, cs clientset.Interface) time.Duration
- func GetServicesProxyRequest(c clientset.Interface, request *restclient.Request) (*restclient.Request, error)
- func GetUnusedStaticNodePort() (int32, error)
- func ReleaseStaticNodePort(port int32)
- func ReserveStaticNodePort(port int32) bool
- func TestReachableHTTP(ctx context.Context, host string, port int, timeout time.Duration)
- func TestReachableHTTPWithRetriableErrorCodes(ctx context.Context, host string, port int, retriableErrCodes []int, ...)
- func UpdateService(ctx context.Context, c clientset.Interface, namespace, serviceName string, ...) (*v1.Service, error)
- func WaitForServiceDeletedWithFinalizer(ctx context.Context, cs clientset.Interface, namespace, name string)
- func WaitForServiceUpdatedWithFinalizer(ctx context.Context, cs clientset.Interface, namespace, name string, ...)
- type TestJig
- func (j *TestJig) AddDeploymentAntiAffinity(deployment *appsv1.Deployment)
- func (j *TestJig) ChangeServiceNodePort(ctx context.Context, initial int) (*v1.Service, error)
- func (j *TestJig) ChangeServiceType(ctx context.Context, newType v1.ServiceType, timeout time.Duration) error
- func (j *TestJig) CheckServiceReachability(ctx context.Context, svc *v1.Service, pod *v1.Pod) error
- func (j *TestJig) CreateExternalNameService(ctx context.Context, tweak func(svc *v1.Service)) (*v1.Service, error)
- func (j *TestJig) CreateLoadBalancerService(ctx context.Context, timeout time.Duration, tweak func(svc *v1.Service)) (*v1.Service, error)
- func (j *TestJig) CreateLoadBalancerServiceWaitForClusterIPOnly(tweak func(svc *v1.Service)) (*v1.Service, error)
- func (j *TestJig) CreateOnlyLocalLoadBalancerService(ctx context.Context, timeout time.Duration, createPod bool, ...) (*v1.Service, error)
- func (j *TestJig) CreateOnlyLocalNodePortService(ctx context.Context, createPod bool) (*v1.Service, error)
- func (j *TestJig) CreatePDB(ctx context.Context, deployment *appsv1.Deployment) (*policyv1.PodDisruptionBudget, error)
- func (j *TestJig) CreateSCTPServiceWithPort(ctx context.Context, tweak func(svc *v1.Service), port int32) (*v1.Service, error)
- func (j *TestJig) CreateServicePods(ctx context.Context, replica int) error
- func (j *TestJig) CreateTCPService(ctx context.Context, tweak func(svc *v1.Service)) (*v1.Service, error)
- func (j *TestJig) CreateTCPServiceWithPort(ctx context.Context, tweak func(svc *v1.Service), port int32) (*v1.Service, error)
- func (j *TestJig) CreateUDPService(ctx context.Context, tweak func(svc *v1.Service)) (*v1.Service, error)
- func (j *TestJig) GetEndpointNodeNames(ctx context.Context) (sets.String, error)
- func (j *TestJig) GetEndpointNodes(ctx context.Context) (map[string][]string, error)
- func (j *TestJig) GetEndpointNodesWithIP(ctx context.Context, addressType v1.NodeAddressType) (map[string][]string, error)
- func (j *TestJig) ListNodesWithEndpoint(ctx context.Context) ([]v1.Node, error)
- func (j *TestJig) Run(ctx context.Context, tweak func(rc *appsv1.Deployment)) (*appsv1.Deployment, error)
- func (j *TestJig) Scale(replicas int) error
- func (j *TestJig) UpdateService(ctx context.Context, update func(*v1.Service)) (*v1.Service, error)
- func (j *TestJig) WaitForEndpointOnNode(ctx context.Context, nodeName string) error
- func (j *TestJig) WaitForLoadBalancer(ctx context.Context, timeout time.Duration) (*v1.Service, error)
- func (j *TestJig) WaitForLoadBalancerDestroy(ctx context.Context, ip string, port int, timeout time.Duration) (*v1.Service, error)
- func (j *TestJig) WaitForNewIngressIP(ctx context.Context, existingIP string, timeout time.Duration) (*v1.Service, error)
Constants ¶
const ( // RespondingTimeout is how long to wait for a service to be responding. RespondingTimeout = 2 * time.Minute // MaxNodesForEndpointsTests is the max number for testing endpoints. // Don't test with more than 3 nodes. // Many tests create an endpoint per node, in large clusters, this is // resource and time intensive. MaxNodesForEndpointsTests = 3 // KubeProxyLagTimeout is the maximum time a kube-proxy daemon on a node is allowed // to not notice a Service update, such as type=NodePort. // TODO: This timeout should be O(10s), observed values are O(1m), 2m is very // liberal. Fix tracked in #20567. KubeProxyLagTimeout = 2 * time.Minute // KubeProxyEndpointLagTimeout is the maximum time a kube-proxy daemon on a node is allowed // to not notice an Endpoint update. KubeProxyEndpointLagTimeout = 30 * time.Second // LoadBalancerLagTimeoutDefault is the maximum time a load balancer is allowed to // not respond after creation. LoadBalancerLagTimeoutDefault = 2 * time.Minute // LoadBalancerLagTimeoutAWS is the delay between ELB creation and serving traffic // on AWS. A few minutes is typical, so use 10m. LoadBalancerLagTimeoutAWS = 10 * time.Minute // LoadBalancerCleanupTimeout is the time required by the loadbalancer to cleanup, proportional to numApps/Ing. // Bring the cleanup timeout back down to 5m once b/33588344 is resolved. LoadBalancerCleanupTimeout = 15 * time.Minute // LoadBalancerPollInterval is the interval value in which the loadbalancer polls. LoadBalancerPollInterval = 30 * time.Second // LargeClusterMinNodesNumber is the number of nodes which a large cluster consists of. LargeClusterMinNodesNumber = 100 // TestTimeout is used for most polling/waiting activities TestTimeout = 60 * time.Second // ServiceEndpointsTimeout is the maximum time in which endpoints for the service should be created. ServiceEndpointsTimeout = 2 * time.Minute // ServiceReachabilityShortPollTimeout is the maximum time in which service must be reachable during polling. ServiceReachabilityShortPollTimeout = 2 * time.Minute )
Variables ¶
var NodePortRange = utilnet.PortRange{Base: 30000, Size: 2768}
NodePortRange should match whatever the default/configured range is
Functions ¶
func CleanupServiceResources ¶
func CleanupServiceResources(ctx context.Context, c clientset.Interface, loadBalancerName, region, zone string)
CleanupServiceResources cleans up service Type=LoadBalancer resources.
func CreateServiceForSimpleApp ¶ added in v1.19.0
func CreateServiceForSimpleApp(ctx context.Context, c clientset.Interface, contPort, svcPort int, namespace, appName string) *v1.Service
CreateServiceForSimpleApp returns a service that selects/exposes pods (send -1 ports if no exposure needed) with an app label.
func CreateServiceForSimpleAppWithPods ¶ added in v1.19.0
func CreateServiceForSimpleAppWithPods(ctx context.Context, c clientset.Interface, contPort int, svcPort int, namespace, appName string, podSpec func(n v1.Node) v1.PodSpec, count int, block bool) (*v1.Service, error)
CreateServiceForSimpleAppWithPods is a convenience wrapper to create a service and its matching pods all at once.
func CreateServiceSpec ¶
func CreateServiceSpec(serviceName, externalName string, isHeadless bool, selector map[string]string) *v1.Service
CreateServiceSpec returns a Service object for testing.
func GetIngressPoint ¶
func GetIngressPoint(ing *v1.LoadBalancerIngress) string
GetIngressPoint returns a host on which ingress serves.
func GetServiceLoadBalancerCreationTimeout ¶
func GetServiceLoadBalancerCreationTimeout(ctx context.Context, cs clientset.Interface) time.Duration
GetServiceLoadBalancerCreationTimeout returns a timeout value for creating a load balancer of a service.
func GetServiceLoadBalancerPropagationTimeout ¶ added in v1.19.0
func GetServiceLoadBalancerPropagationTimeout(ctx context.Context, cs clientset.Interface) time.Duration
GetServiceLoadBalancerPropagationTimeout returns a timeout value for propagating a load balancer of a service.
func GetServicesProxyRequest ¶
func GetServicesProxyRequest(c clientset.Interface, request *restclient.Request) (*restclient.Request, error)
GetServicesProxyRequest returns a request for a service proxy.
func GetUnusedStaticNodePort ¶
GetUnusedStaticNodePort returns a free port in static range and a nil value If no port in static range is available it returns -1 and an error value Note that it is not guaranteed that the returned port is actually available on the apiserver; You must allocate a port, then attempt to create the service, then call ReserveStaticNodePort.
func ReleaseStaticNodePort ¶
func ReleaseStaticNodePort(port int32)
ReleaseStaticNodePort releases the specified port. The corresponding service should have already been deleted, to ensure that the port allocator doesn't try to reuse it before the apiserver considers it available.
func ReserveStaticNodePort ¶
ReserveStaticNodePort reserves the port provided as input. It is guaranteed that no other test will receive this port from GetUnusedStaticNodePort until after you call ReleaseStaticNodePort.
port must have been previously allocated by GetUnusedStaticNodePort, and then successfully used as a NodePort or HealthCheckNodePort when creating a service. Trying to reserve a port that was not allocated by GetUnusedStaticNodePort, or reserving it before creating the associated service may cause other e2e tests to fail.
If an invalid port was provided or if the port is already reserved, it returns false
func TestReachableHTTP ¶ added in v1.17.0
TestReachableHTTP tests that the given host serves HTTP on the given port.
func TestReachableHTTPWithRetriableErrorCodes ¶ added in v1.17.0
func TestReachableHTTPWithRetriableErrorCodes(ctx context.Context, host string, port int, retriableErrCodes []int, timeout time.Duration)
TestReachableHTTPWithRetriableErrorCodes tests that the given host serves HTTP on the given port with the given retriableErrCodes.
func UpdateService ¶
func UpdateService(ctx context.Context, c clientset.Interface, namespace, serviceName string, update func(*v1.Service)) (*v1.Service, error)
UpdateService fetches a service, calls the update function on it, and then attempts to send the updated service. It retries up to 2 times in the face of timeouts and conflicts.
Types ¶
type TestJig ¶
type TestJig struct { Client clientset.Interface Namespace string Name string ID string Labels map[string]string // ExternalIPs should be false for Conformance test // Don't check nodeport on external addrs in conformance test, but in e2e test. ExternalIPs bool }
TestJig is a test jig to help service testing.
func NewTestJig ¶
NewTestJig allocates and inits a new TestJig.
func (*TestJig) AddDeploymentAntiAffinity ¶
func (j *TestJig) AddDeploymentAntiAffinity(deployment *appsv1.Deployment)
AddDeploymentAntiAffinity adds AntiAffinity to the given Deployment.
func (*TestJig) ChangeServiceNodePort ¶ added in v1.17.0
ChangeServiceNodePort changes node ports of the given service.
func (*TestJig) ChangeServiceType ¶
func (j *TestJig) ChangeServiceType(ctx context.Context, newType v1.ServiceType, timeout time.Duration) error
ChangeServiceType updates the given service's ServiceType to the given newType.
func (*TestJig) CheckServiceReachability ¶
CheckServiceReachability ensures that request are served by the services. Only supports Services with type ClusterIP, NodePort and ExternalName.
func (*TestJig) CreateExternalNameService ¶ added in v1.17.0
func (j *TestJig) CreateExternalNameService(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 (*TestJig) CreateLoadBalancerService ¶
func (j *TestJig) CreateLoadBalancerService(ctx context.Context, timeout time.Duration, tweak func(svc *v1.Service)) (*v1.Service, error)
CreateLoadBalancerService creates a loadbalancer service and waits for it to acquire an ingress IP.
func (*TestJig) CreateLoadBalancerServiceWaitForClusterIPOnly ¶ added in v1.26.0
func (j *TestJig) CreateLoadBalancerServiceWaitForClusterIPOnly(tweak func(svc *v1.Service)) (*v1.Service, error)
CreateLoadBalancerServiceWaitForClusterIPOnly creates a loadbalancer service and waits for it to acquire a cluster IP
func (*TestJig) CreateOnlyLocalLoadBalancerService ¶
func (j *TestJig) CreateOnlyLocalLoadBalancerService(ctx context.Context, timeout time.Duration, createPod bool, tweak func(svc *v1.Service)) (*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 (*TestJig) CreateOnlyLocalNodePortService ¶
func (j *TestJig) CreateOnlyLocalNodePortService(ctx context.Context, createPod bool) (*v1.Service, 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 (*TestJig) CreatePDB ¶ added in v1.17.0
func (j *TestJig) CreatePDB(ctx context.Context, deployment *appsv1.Deployment) (*policyv1.PodDisruptionBudget, error)
CreatePDB returns a PodDisruptionBudget for the given Deployment, or returns an error if a PodDisruptionBudget isn't ready
func (*TestJig) CreateSCTPServiceWithPort ¶ added in v1.19.0
func (j *TestJig) CreateSCTPServiceWithPort(ctx context.Context, tweak func(svc *v1.Service), port int32) (*v1.Service, 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 (*TestJig) CreateServicePods ¶
CreateServicePods creates a replication controller with the label same as service. Service listens to TCP and UDP.
func (*TestJig) CreateTCPService ¶ added in v1.17.0
func (j *TestJig) CreateTCPService(ctx context.Context, tweak func(svc *v1.Service)) (*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 (*TestJig) CreateTCPServiceWithPort ¶
func (j *TestJig) CreateTCPServiceWithPort(ctx context.Context, tweak func(svc *v1.Service), port int32) (*v1.Service, error)
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 (*TestJig) CreateUDPService ¶ added in v1.17.0
func (j *TestJig) CreateUDPService(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 (*TestJig) GetEndpointNodeNames ¶ added in v1.17.0
GetEndpointNodeNames returns a string set of node names on which the endpoints of the given Service are running.
func (*TestJig) GetEndpointNodes ¶
GetEndpointNodes returns a map of nodenames:external-ip on which the endpoints of the Service are running.
func (*TestJig) GetEndpointNodesWithIP ¶ added in v1.19.0
func (j *TestJig) GetEndpointNodesWithIP(ctx context.Context, addressType v1.NodeAddressType) (map[string][]string, error)
GetEndpointNodesWithIP returns a map of nodenames:<ip of given type> on which the endpoints of the Service are running.
func (*TestJig) ListNodesWithEndpoint ¶ added in v1.19.0
ListNodesWithEndpoint returns a list of nodes on which the endpoints of the given Service are running.
func (*TestJig) Run ¶ added in v1.17.0
func (j *TestJig) Run(ctx context.Context, tweak func(rc *appsv1.Deployment)) (*appsv1.Deployment, error)
Run creates a Deployment and Pod(s) and waits for the Pod(s) to be running. Callers can provide a function to tweak the Deployment object before it is created.
func (*TestJig) UpdateService ¶
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 (*TestJig) WaitForEndpointOnNode ¶
WaitForEndpointOnNode waits for a service endpoint on the given node (which must be the service's only endpoint).
func (*TestJig) WaitForLoadBalancer ¶ added in v1.17.0
func (j *TestJig) WaitForLoadBalancer(ctx context.Context, timeout time.Duration) (*v1.Service, error)
WaitForLoadBalancer waits the given service to have a LoadBalancer, or returns an error after the given timeout
func (*TestJig) WaitForLoadBalancerDestroy ¶ added in v1.17.0
func (j *TestJig) WaitForLoadBalancerDestroy(ctx context.Context, ip string, port int, timeout time.Duration) (*v1.Service, error)
WaitForLoadBalancerDestroy waits the given service to destroy a LoadBalancer, or returns an error after the given timeout