e2e

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2019 License: Apache-2.0 Imports: 50 Imported by: 2

Documentation

Overview

Package e2e contains supporting infrastructure for end-to-end integration testing driven by the tests in cmd/e2e-test.

Test should be written with a Sandbox:

func TestExample(t *testing.T) {
  for _, tc := range []struct{
    ...
  }{
    ...
  }{
    tc := tc // avoid variable capture
    Framework.RunWithSandbox(t, func(t *testing.T, s *e2e.Sandbox) {
      t.Parallel()
      // Test code...
    })
  }
}

The Sandbox will handle resource isolation and reclaimation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDeployment added in v1.7.0

func CheckDeployment(deployment *apps.Deployment) error

CheckDeployment checks if the given deployment is in a stable state.

func CheckDistinctResponseHost added in v1.7.0

func CheckDistinctResponseHost(vip string, expectDistinctHosts int, tolerateTransientError bool) error

CheckDistinctResponseHost issue GET call to the vip for 100 times, parse the reponses and calculate the number of distinct backends.

func CheckEchoServerResponse added in v1.7.0

func CheckEchoServerResponse(vip string) (app.ResponseBody, error)

CheckEchoServerResponse issue a GET call to the vip and return the ResponseBody.

func CheckGCLB added in v1.6.0

func CheckGCLB(gclb *fuzz.GCLB, numForwardingRules int, numBackendServices int) error

CheckGCLB whitebox testing is OK.

func CheckNegStatus added in v1.7.0

func CheckNegStatus(svc *v1.Service, expectSvcPors []string) (annotations.NegStatus, error)

CheckNegStatus checks if the NEG Status annotation is presented and in the expected state

func CheckNegs added in v1.7.0

func CheckNegs(negs map[meta.Key]*fuzz.NetworkEndpoints, expectHealthy bool, expectCount int) error

CheckNegs checks if the network endpoints in the NEGs is in expected state

func CreateEchoService

func CreateEchoService(s *Sandbox, name string, annotations map[string]string) (*v1.Service, error)

CreateEchoService creates the pod and service serving echoheaders Todo: (shance) remove this and replace uses with EnsureEchoService()

func CreateSecret

func CreateSecret(s *Sandbox, name string, data map[string][]byte) (*v1.Secret, error)

CreateSecret creates a secret from the given data.

func DeleteGCPAddress added in v1.6.0

func DeleteGCPAddress(s *Sandbox, name string) error

DeleteGCPAddress deletes a global static IP address with the given name.

func DeleteSecret added in v1.6.0

func DeleteSecret(s *Sandbox, name string) error

DeleteSecret deletes a secret.

func EnsureEchoDeployment added in v1.7.0

func EnsureEchoDeployment(s *Sandbox, name string, numReplicas int32, modify func(deployment *apps.Deployment)) error

Ensures that the Echo deployment with the given description is set up

func EnsureEchoService added in v1.6.0

func EnsureEchoService(s *Sandbox, name string, annotations map[string]string, svcType v1.ServiceType, numReplicas int32) (*v1.Service, error)

EnsureEchoService that the Echo service with the given description is set up

func EnsureIngress added in v1.6.0

func EnsureIngress(s *Sandbox, ing *v1beta1.Ingress) (*v1beta1.Ingress, error)

EnsureIngress creates a new Ingress or updates an existing one.

func IsRfc1918Addr added in v1.7.0

func IsRfc1918Addr(addr string) bool

IsRfc1918Addr returns true if the address supplied is an RFC1918 address

func NewCloud

func NewCloud(project, GceEndpointOverride string) (cloud.Cloud, error)

NewCloud creates a new cloud for the given project.

func NewGCPAddress added in v1.6.0

func NewGCPAddress(s *Sandbox, name string) error

NewGCPAddress reserves a global static IP address with the given name.

func NoopModify added in v1.7.0

func NoopModify(*apps.Deployment)

NoopModify does not modify the input deployment

func SpreadPodAcrossZones added in v1.7.0

func SpreadPodAcrossZones(deployment *apps.Deployment)

SpreadPodAcrossZones sets pod anti affinity rules to try to spread pods across zones

func WaitForDistinctHosts added in v1.7.0

func WaitForDistinctHosts(ctx context.Context, vip string, expectDistinctHosts int, tolerateTransientError bool) error

WaitForDistinctHosts waits util

func WaitForEchoDeploymentStable added in v1.7.0

func WaitForEchoDeploymentStable(s *Sandbox, name string) error

WaitForEchoDeploymentStable waits until the deployment's readyReplicas, availableReplicas and updatedReplicas are equal to replicas.

func WaitForFinalizerDeletion added in v1.7.0

func WaitForFinalizerDeletion(ctx context.Context, g *fuzz.GCLB, s *Sandbox, ingName string, options *fuzz.GCLBDeleteOptions) error

WaitForFinalizerDeletion waits for gclb resources to be deleted and the finalizer attached to the Ingress resource to be removed.

func WaitForGCLBDeletion

func WaitForGCLBDeletion(ctx context.Context, c cloud.Cloud, g *fuzz.GCLB, options *fuzz.GCLBDeleteOptions) error

WaitForGCLBDeletion waits for the resources associated with the GLBC to be deleted.

func WaitForIngress

func WaitForIngress(s *Sandbox, ing *v1beta1.Ingress, options *WaitForIngressOptions) (*v1beta1.Ingress, error)

WaitForIngress to stabilize. We expect the ingress to be unreachable at first as LB is still programming itself (i.e 404's / 502's)

func WaitForIngressDeletion

func WaitForIngressDeletion(ctx context.Context, g *fuzz.GCLB, s *Sandbox, ing *v1beta1.Ingress, options *fuzz.GCLBDeleteOptions) error

WaitForIngressDeletion deletes the given ingress and waits for the resources associated with it to be deleted.

func WaitForNEGDeletion added in v1.6.0

func WaitForNEGDeletion(ctx context.Context, c cloud.Cloud, g *fuzz.GCLB, options *fuzz.GCLBDeleteOptions) error

WaitForNEGDeletion waits for all NEGs associated with a GCLB to be deleted via GC

func WaitForNegStatus added in v1.7.0

func WaitForNegStatus(s *Sandbox, name string, expectSvcPorts []string) (annotations.NegStatus, error)

WaitForNegStatus waits util the neg status on the service got to expected state.

func WaitForNegs added in v1.7.0

func WaitForNegs(ctx context.Context, c cloud.Cloud, negName string, zones []string, expectHealthy bool, expectCount int) error

WaitForNegs waits until the input NEG got into the expect states.

Types

type Cert added in v1.6.0

type Cert struct {
	Host string
	Name string
	Type CertType
	// contains filtered or unexported fields
}

Cert is a convenience type for representing an SSL certificate.

func NewCert added in v1.6.0

func NewCert(name string, host string, typ CertType) (*Cert, error)

NewCert returns a cert initialized with data but not yet created in the appropriate environment.

func (*Cert) Create added in v1.6.0

func (c *Cert) Create(s *Sandbox) error

Create creates a cert in its environment.

func (*Cert) Delete added in v1.6.0

func (c *Cert) Delete(s *Sandbox) error

Delete deletes the cert from its environment.

type CertType added in v1.6.0

type CertType int

CertType indicates the intended environment in which this cert is created.

const (
	// GCPCert will be created as an SslCertificate resource in GCP.
	GCPCert CertType = iota
	// K8sCert will be created as a Secret in K8s.
	K8sCert CertType = iota
)

type Framework

type Framework struct {
	RestConfig          *rest.Config
	Clientset           *kubernetes.Clientset
	BackendConfigClient *backendconfigclient.Clientset
	Project             string
	Cloud               cloud.Cloud
	Rand                *rand.Rand
	// contains filtered or unexported fields
}

Framework is the end-to-end test framework.

func NewFramework

func NewFramework(config *rest.Config, options Options) *Framework

NewFramework returns a new test framework to run.

func (*Framework) CatchSIGINT

func (f *Framework) CatchSIGINT()

CatchSIGINT and cleanup sandboxes when the test is interrupted.

func (*Framework) RunWithSandbox

func (f *Framework) RunWithSandbox(name string, t *testing.T, testFunc func(*testing.T, *Sandbox))

RunWithSandbox runs the testFunc with the Sandbox, taking care of resource cleanup and isolation. This indirectly calls testing.T.Run().

func (*Framework) SanityCheck

func (f *Framework) SanityCheck() error

SanityCheck the test environment before proceeding.

func (*Framework) WithSandbox

func (f *Framework) WithSandbox(testFunc func(*Sandbox) error) error

WithSandbox runs the testFunc with the Sandbox, taking care of resource cleanup and isolation.

type IngressCRUD added in v1.7.0

type IngressCRUD struct {
	C *kubernetes.Clientset
}

IngressCRUD wraps basic CRUD to allow use of old and new APIs.

func (*IngressCRUD) Create added in v1.7.0

func (crud *IngressCRUD) Create(ing *v1beta1.Ingress) (*v1beta1.Ingress, error)

Create Ingress resource.

func (*IngressCRUD) Delete added in v1.7.0

func (crud *IngressCRUD) Delete(ns, name string) error

Delete Ingress resource.

func (*IngressCRUD) Get added in v1.7.0

func (crud *IngressCRUD) Get(ns, name string) (*v1beta1.Ingress, error)

Get Ingress resource.

func (*IngressCRUD) Update added in v1.7.0

func (crud *IngressCRUD) Update(ing *v1beta1.Ingress) (*v1beta1.Ingress, error)

Update Ingress resource.

type IngressStability added in v1.5.0

type IngressStability string

IngressStability denotes the stabilization status of all Ingresses in a sandbox.

var (
	// Stable indicates an Ingress is stable (i.e consistently serving 200's)
	Stable IngressStability = "Stable"
	// Unstable indicates an Ingress is unstable (i.e serving 404/502's).
	Unstable IngressStability = "Unstable"
)

type Options

type Options struct {
	Project             string
	Seed                int64
	DestroySandboxes    bool
	GceEndpointOverride string
}

Options for the test framework.

type Sandbox

type Sandbox struct {
	// Namespace to create resources in. Resources created in this namespace
	// will be deleted with Destroy().
	Namespace string
	// ValidatorEnv for use with the test.
	ValidatorEnv fuzz.ValidatorEnv
	// contains filtered or unexported fields
}

Sandbox represents a sandbox for running tests in a Kubernetes cluster.

func (*Sandbox) Create

func (s *Sandbox) Create() error

Create the sandbox.

func (*Sandbox) Destroy

func (s *Sandbox) Destroy()

Destroy the sandbox and all resources associated with the sandbox.

func (*Sandbox) DumpSandboxInfo added in v1.7.0

func (s *Sandbox) DumpSandboxInfo(t *testing.T)

DumpSandboxInfo dumps information about the sandbox into logs

func (*Sandbox) MasterUpgraded added in v1.5.0

func (s *Sandbox) MasterUpgraded() bool

MasterUpgraded checks the config map for whether or not the k8s master has successfully finished upgrading or not

func (*Sandbox) MasterUpgrading added in v1.5.0

func (s *Sandbox) MasterUpgrading() bool

MasterUpgrading checks the config map for whether or not the k8s master has successfully finished upgrading or not

func (*Sandbox) PutStatus added in v1.5.0

func (s *Sandbox) PutStatus(status IngressStability)

PutStatus into the status manager.

type StatusManager added in v1.5.0

type StatusManager struct {
	// contains filtered or unexported fields
}

StatusManager manages the status of sandboxed Ingresses via a ConfigMap. It interacts with the an external framework test portion as follows: 1. StatusManager initializes and creates the ConfigMap status-cm. It listens on updates via informers. 2. e2e test calls StatusManager.putStatus with the Ingress name as key, and Unstable as the status 3. e2e test watches for when Ingress stabilizes, then uses StatusManager to update the Ingress's status to Stable 4. The external framework test reads from ConfigMap status-cm. When it detects that all Ingresses are stable (i.e., no value in the map is Unstable), it starts the MasterUpgrade. 5. When the k8s master finishes upgrading, the framework test writes the timestamp to the master-upgraded key in the ConfigMap 6. The external framework test writes the exit key in the ConfigMap to indicate that the e2e test can exit. 7. The StatusManager loop reads the exit key, then starts shutdown().

func NewStatusManager added in v1.5.0

func NewStatusManager(f *Framework) *StatusManager

NewStatusManager returns a new status manager.

type WaitForIngressOptions added in v1.5.0

type WaitForIngressOptions struct {
	// ExpectUnreachable is true when we expect the LB to still be
	// programming itself (i.e 404's / 502's)
	ExpectUnreachable bool
}

WaitForIngressOptions holds options dictating how we wait for an ingress to stabilize

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL