Documentation
¶
Index ¶
- Constants
- Variables
- func CleanupServiceResources(c clientset.Interface, loadBalancerName, region, zone string)
- func CreateServiceSpec(serviceName, externalName string, isHeadless bool, selector map[string]string) *v1.Service
- func DescribeSvc(ns string)
- func EnableAndDisableInternalLB() (enable func(svc *v1.Service), disable func(svc *v1.Service))
- func GetIngressPoint(ing *v1.LoadBalancerIngress) string
- func GetServiceLoadBalancerCreationTimeout(cs clientset.Interface) time.Duration
- func GetServicesProxyRequest(c clientset.Interface, request *restclient.Request) (*restclient.Request, error)
- func StartServeHostnameService(c clientset.Interface, svc *v1.Service, ns string, replicas int) ([]string, string, error)
- func StopServeHostnameService(clientset clientset.Interface, ns, name string) error
- func UpdateService(c clientset.Interface, namespace, serviceName string, update func(*v1.Service)) (*v1.Service, error)
- func VerifyServeHostnameServiceDown(c clientset.Interface, host string, serviceIP string, servicePort int) error
- func VerifyServeHostnameServiceUp(c clientset.Interface, ns, host string, expectedPods []string, ...) error
- func WaitForServiceResponding(c clientset.Interface, ns, name string) error
- type TestFixture
- func (t *TestFixture) BuildServiceSpec() *v1.Service
- func (t *TestFixture) Cleanup() []error
- func (t *TestFixture) CreateRC(rc *v1.ReplicationController) (*v1.ReplicationController, error)
- func (t *TestFixture) CreateService(service *v1.Service) (*v1.Service, error)
- func (t *TestFixture) DeleteService(serviceName string) error
- type TestJig
- func (j *TestJig) AddRCAntiAffinity(rc *v1.ReplicationController)
- func (j *TestJig) ChangeServiceNodePortOrFail(namespace, name string, initial int) *v1.Service
- func (j *TestJig) ChangeServiceType(namespace, name string, newType v1.ServiceType, timeout time.Duration)
- func (j *TestJig) CheckAffinity(execPod *v1.Pod, targetIP string, targetPort int, shouldHold bool) bool
- func (j *TestJig) CheckServiceReachability(namespace string, svc *v1.Service, pod *v1.Pod)
- func (j *TestJig) CreateExternalNameServiceOrFail(namespace string, tweak func(svc *v1.Service)) *v1.Service
- func (j *TestJig) CreateLoadBalancerService(namespace, serviceName string, timeout time.Duration, ...) *v1.Service
- func (j *TestJig) CreateOnlyLocalLoadBalancerService(namespace, serviceName string, timeout time.Duration, createPod bool, ...) *v1.Service
- func (j *TestJig) CreateOnlyLocalNodePortService(namespace, serviceName string, createPod bool) *v1.Service
- func (j *TestJig) CreatePDBOrFail(namespace string, rc *v1.ReplicationController) *policyv1beta1.PodDisruptionBudget
- func (j *TestJig) CreatePausePodDeployment(name, ns string, replica int32) *appsv1.Deployment
- func (j *TestJig) CreateServicePods(c clientset.Interface, ns string, replica int)
- func (j *TestJig) CreateServiceWithServicePort(labels map[string]string, namespace string, ports []v1.ServicePort) (*v1.Service, error)
- func (j *TestJig) CreateTCPServiceOrFail(namespace string, tweak func(svc *v1.Service)) *v1.Service
- func (j *TestJig) CreateTCPServiceWithPort(namespace string, tweak func(svc *v1.Service), port int32) *v1.Service
- func (j *TestJig) CreateUDPServiceOrFail(namespace string, tweak func(svc *v1.Service)) *v1.Service
- func (j *TestJig) GetEndpointNodes(svc *v1.Service) map[string][]string
- func (j *TestJig) GetHTTPContent(host string, port int, timeout time.Duration, url string) bytes.Buffer
- func (j *TestJig) GetNodes(maxNodesForTest int) (nodes *v1.NodeList)
- func (j *TestJig) GetNodesNames(maxNodesForTest int) []string
- func (j *TestJig) RunOrFail(namespace string, tweak func(rc *v1.ReplicationController)) *v1.ReplicationController
- func (j *TestJig) SanityCheckService(svc *v1.Service, svcType v1.ServiceType)
- func (j *TestJig) Scale(namespace string, replicas int)
- func (j *TestJig) TestHTTPHealthCheckNodePort(host string, port int, request string, timeout time.Duration, ...) error
- func (j *TestJig) TestNotReachableHTTP(host string, port int, timeout time.Duration)
- func (j *TestJig) TestNotReachableUDP(host string, port int, timeout time.Duration)
- func (j *TestJig) TestReachableHTTP(host string, port int, timeout time.Duration)
- func (j *TestJig) TestReachableHTTPWithRetriableErrorCodes(host string, port int, retriableErrCodes []int, timeout time.Duration)
- func (j *TestJig) TestReachableUDP(host string, port int, timeout time.Duration)
- func (j *TestJig) TestRejectedHTTP(host string, port int, timeout time.Duration)
- func (j *TestJig) TestRejectedUDP(host string, port int, timeout time.Duration)
- func (j *TestJig) UpdateService(namespace, name string, update func(*v1.Service)) (*v1.Service, error)
- func (j *TestJig) UpdateServiceOrFail(namespace, name string, update func(*v1.Service)) *v1.Service
- func (j *TestJig) WaitForAvailableEndpoint(namespace, serviceName string, timeout time.Duration)
- func (j *TestJig) WaitForEndpointOnNode(namespace, serviceName, nodeName string)
- func (j *TestJig) WaitForLoadBalancerDestroyOrFail(namespace, name string, ip string, port int, timeout time.Duration) *v1.Service
- func (j *TestJig) WaitForLoadBalancerOrFail(namespace, name string, timeout time.Duration) *v1.Service
- func (j *TestJig) WaitForNewIngressIPOrFail(namespace, name, existingIP string, timeout time.Duration) *v1.Service
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 )
const ( // 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), 5m is very // liberal. Fix tracked in #20567. KubeProxyLagTimeout = 5 * 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 // LoadBalancerCreateTimeoutDefault is the default time to wait for a load balancer to be created/modified. // TODO: once support ticket 21807001 is resolved, reduce this timeout back to something reasonable LoadBalancerCreateTimeoutDefault = 20 * time.Minute // LoadBalancerCreateTimeoutLarge is the maximum time to wait for a load balancer to be created/modified. LoadBalancerCreateTimeoutLarge = 2 * time.Hour // 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 // LoadBalancerPollTimeout is the time required by the loadbalancer to poll. // On average it takes ~6 minutes for a single backend to come online in GCE. LoadBalancerPollTimeout = 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 // AffinityConfirmCount is the number of needed continuous requests to confirm that // affinity is enabled. AffinityConfirmCount = 15 // ServiceEndpointsTimeout is the maximum time in which endpoints for the service should be created. ServiceEndpointsTimeout = 2 * time.Minute )
Variables ¶
var NodePortRange = utilnet.PortRange{Base: 30000, Size: 2768}
NodePortRange should match whatever the default/configured range is
var PauseDeploymentLabels = map[string]string{"deployment": "agnhost-pause"}
PauseDeploymentLabels are unique deployment selector labels for pause pod
Functions ¶
func CleanupServiceResources ¶
CleanupServiceResources cleans up service Type=LoadBalancer resources.
func CreateServiceSpec ¶
func CreateServiceSpec(serviceName, externalName string, isHeadless bool, selector map[string]string) *v1.Service
CreateServiceSpec returns a Service object for testing.
func DescribeSvc ¶
func DescribeSvc(ns string)
DescribeSvc logs the output of kubectl describe svc for the given namespace
func EnableAndDisableInternalLB ¶
EnableAndDisableInternalLB returns two functions for enabling and disabling the internal load balancer setting for the supported cloud providers (currently GCE/GKE and Azure) and empty functions for others.
func GetIngressPoint ¶
func GetIngressPoint(ing *v1.LoadBalancerIngress) string
GetIngressPoint returns a host on which ingress serves.
func GetServiceLoadBalancerCreationTimeout ¶
GetServiceLoadBalancerCreationTimeout returns a timeout value for creating 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 StartServeHostnameService ¶
func StartServeHostnameService(c clientset.Interface, svc *v1.Service, ns string, replicas int) ([]string, string, error)
StartServeHostnameService creates a replication controller that serves its hostname and a service on top of it.
func StopServeHostnameService ¶
StopServeHostnameService stops the given service.
func UpdateService ¶
func UpdateService(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.
func VerifyServeHostnameServiceDown ¶
func VerifyServeHostnameServiceDown(c clientset.Interface, host string, serviceIP string, servicePort int) error
VerifyServeHostnameServiceDown verifies that the given service isn't served.
func VerifyServeHostnameServiceUp ¶
func VerifyServeHostnameServiceUp(c clientset.Interface, ns, host string, expectedPods []string, serviceIP string, servicePort int) error
VerifyServeHostnameServiceUp wgets the given serviceIP:servicePort from the given host and from within a pod. The host is expected to be an SSH-able node in the cluster. Each pod in the service is expected to echo its name. These names are compared with the given expectedPods list after a sort | uniq.
Types ¶
type TestFixture ¶
type TestFixture struct { ServiceName string Namespace string Client clientset.Interface TestID string Labels map[string]string Name string Image string // contains filtered or unexported fields }
TestFixture is a simple helper class to avoid too much boilerplate in tests
func NewServerTest ¶
func NewServerTest(client clientset.Interface, namespace string, serviceName string) *TestFixture
NewServerTest creates a new TestFixture for the tests.
func (*TestFixture) BuildServiceSpec ¶
func (t *TestFixture) BuildServiceSpec() *v1.Service
BuildServiceSpec builds default config for a service (which can then be changed)
func (*TestFixture) Cleanup ¶
func (t *TestFixture) Cleanup() []error
Cleanup cleans all ReplicationControllers and Services which this object holds.
func (*TestFixture) CreateRC ¶
func (t *TestFixture) CreateRC(rc *v1.ReplicationController) (*v1.ReplicationController, error)
CreateRC creates a replication controller and records it for cleanup.
func (*TestFixture) CreateService ¶
CreateService creates a service, and record it for cleanup
func (*TestFixture) DeleteService ¶
func (t *TestFixture) DeleteService(serviceName string) error
DeleteService deletes a service, and remove it from the cleanup list
type TestJig ¶
TestJig is a test jig to help service testing.
func NewTestJig ¶
NewTestJig allocates and inits a new TestJig.
func (*TestJig) AddRCAntiAffinity ¶
func (j *TestJig) AddRCAntiAffinity(rc *v1.ReplicationController)
AddRCAntiAffinity adds AntiAffinity to the given ReplicationController.
func (*TestJig) ChangeServiceNodePortOrFail ¶
ChangeServiceNodePortOrFail changes node ports of the given service.
func (*TestJig) ChangeServiceType ¶
func (j *TestJig) ChangeServiceType(namespace, name string, newType v1.ServiceType, timeout time.Duration)
ChangeServiceType updates the given service's ServiceType to the given newType.
func (*TestJig) CheckAffinity ¶
func (j *TestJig) CheckAffinity(execPod *v1.Pod, targetIP string, targetPort int, shouldHold bool) bool
CheckAffinity function tests whether the service affinity works as expected. If affinity is expected, the test will return true once affinityConfirmCount number of same response observed in a row. If affinity is not expected, the test will keep observe until different responses observed. The function will return false only in case of unexpected errors.
func (*TestJig) CheckServiceReachability ¶
CheckServiceReachability ensures that request are served by the services. Only supports Services with type ClusterIP, NodePort and ExternalName.
func (*TestJig) CreateExternalNameServiceOrFail ¶
func (j *TestJig) CreateExternalNameServiceOrFail(namespace string, tweak func(svc *v1.Service)) *v1.Service
CreateExternalNameServiceOrFail 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(namespace, serviceName string, timeout time.Duration, tweak func(svc *v1.Service)) *v1.Service
CreateLoadBalancerService creates a loadbalancer service and waits for it to acquire an ingress IP.
func (*TestJig) CreateOnlyLocalLoadBalancerService ¶
func (j *TestJig) CreateOnlyLocalLoadBalancerService(namespace, serviceName string, timeout time.Duration, createPod bool, tweak func(svc *v1.Service)) *v1.Service
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(namespace, serviceName string, createPod bool) *v1.Service
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) CreatePDBOrFail ¶
func (j *TestJig) CreatePDBOrFail(namespace string, rc *v1.ReplicationController) *policyv1beta1.PodDisruptionBudget
CreatePDBOrFail returns a PodDisruptionBudget for the given ReplicationController, or fails if a PodDisruptionBudget isn't ready
func (*TestJig) CreatePausePodDeployment ¶
func (j *TestJig) CreatePausePodDeployment(name, ns string, replica int32) *appsv1.Deployment
CreatePausePodDeployment creates a deployment for agnhost-pause pod running in different nodes
func (*TestJig) CreateServicePods ¶
CreateServicePods creates a replication controller with the label same as service
func (*TestJig) CreateServiceWithServicePort ¶
func (j *TestJig) CreateServiceWithServicePort(labels map[string]string, namespace string, ports []v1.ServicePort) (*v1.Service, error)
CreateServiceWithServicePort creates a new Service with ServicePort.
func (*TestJig) CreateTCPServiceOrFail ¶
CreateTCPServiceOrFail 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(namespace string, tweak func(svc *v1.Service), 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 (*TestJig) CreateUDPServiceOrFail ¶
CreateUDPServiceOrFail 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) GetEndpointNodes ¶
GetEndpointNodes returns a map of nodenames:external-ip on which the endpoints of the given Service are running.
func (*TestJig) GetHTTPContent ¶
func (j *TestJig) GetHTTPContent(host string, port int, timeout time.Duration, url string) bytes.Buffer
GetHTTPContent returns the content of the given url by HTTP.
func (*TestJig) GetNodes ¶
GetNodes returns the first maxNodesForTest nodes. Useful in large clusters where we don't eg: want to create an endpoint per node.
func (*TestJig) GetNodesNames ¶
GetNodesNames returns a list of names of the first maxNodesForTest nodes
func (*TestJig) RunOrFail ¶
func (j *TestJig) RunOrFail(namespace string, tweak func(rc *v1.ReplicationController)) *v1.ReplicationController
RunOrFail 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 (*TestJig) SanityCheckService ¶
func (j *TestJig) SanityCheckService(svc *v1.Service, svcType v1.ServiceType)
SanityCheckService performs sanity checks on the given service
func (*TestJig) TestHTTPHealthCheckNodePort ¶
func (j *TestJig) TestHTTPHealthCheckNodePort(host string, port int, request string, timeout time.Duration, expectSucceed bool, threshold int) error
TestHTTPHealthCheckNodePort tests a HTTP connection by the given request to the given host and port.
func (*TestJig) TestNotReachableHTTP ¶
TestNotReachableHTTP tests that a HTTP request doesn't connect to the given host and port.
func (*TestJig) TestNotReachableUDP ¶
TestNotReachableUDP tests that the given host doesn't serve UDP on the given port.
func (*TestJig) TestReachableHTTP ¶
TestReachableHTTP tests that the given host serves HTTP on the given port.
func (*TestJig) TestReachableHTTPWithRetriableErrorCodes ¶
func (j *TestJig) TestReachableHTTPWithRetriableErrorCodes(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 (*TestJig) TestReachableUDP ¶
TestReachableUDP tests that the given host serves UDP on the given port.
func (*TestJig) TestRejectedHTTP ¶
TestRejectedHTTP tests that the given host rejects a HTTP request on the given port.
func (*TestJig) TestRejectedUDP ¶
TestRejectedUDP tests that the given host rejects a UDP request on the given port.
func (*TestJig) UpdateService ¶
func (j *TestJig) UpdateService(namespace, name 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 tries up to 3 times in the face of timeouts and conflicts.
func (*TestJig) UpdateServiceOrFail ¶
UpdateServiceOrFail 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) WaitForAvailableEndpoint ¶
WaitForAvailableEndpoint waits for at least 1 endpoint to be available till timeout
func (*TestJig) WaitForEndpointOnNode ¶
WaitForEndpointOnNode waits for a service endpoint on the given node.
func (*TestJig) WaitForLoadBalancerDestroyOrFail ¶
func (j *TestJig) WaitForLoadBalancerDestroyOrFail(namespace, name string, ip string, port int, timeout time.Duration) *v1.Service
WaitForLoadBalancerDestroyOrFail waits the given service to destroy a LoadBalancer, or fails after the given timeout