framework

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Overview

Package framework provides a test framework to use in e2e testing.

Index

Constants

View Source
const (
	// DefaultNamespace is the name of the default Kubernetes namespace.
	DefaultNamespace = "default"
	// DefaultBranchName is the name of the default git branch.
	DefaultBranchName = "main"
	// FleetLocalNamespace is the name of the namespace used for local cluster by Fleet.
	FleetLocalNamespace = "fleet-local"
	// MagicDNS is the dns name to use in isolated mode
	MagicDNS = "sslip.io"
	// DefaulRancherTurtlesNamespace is the name of the default namespace for Rancher Turtles.
	DefaultRancherTurtlesNamespace = "rancher-turtles-system"
)

Variables

View Source
var EnvOptions = env.Options{FuncMap: map[reflect.Type]env.ParserFunc{
	reflect.TypeOf(in): func(v string) (interface{}, error) {
		return Intervals(strings.Split(v, ",")), nil
	},
}}

Functions

func AddLabelsToNamespace

func AddLabelsToNamespace(ctx context.Context, input AddLabelsToNamespaceInput)

AddLabelsToNamespace will add labels to a namespace.

func Apply added in v0.16.0

func Apply(ctx context.Context, p framework.ClusterProxy, resources []byte, args ...string) error

Apply wraps `kubectl apply ...` and prints the output so we can see what gets applied to the cluster.

func ApplyFromTemplate

func ApplyFromTemplate(ctx context.Context, input ApplyFromTemplateInput) error

ApplyFromTemplate will generate a yaml definition from a given template and apply it in the cluster.

func Byf

func Byf(format string, a ...interface{})

Byf is used to provider better output for a test using a formatted string.

func ClusterctlGenerateFromTemplate

func ClusterctlGenerateFromTemplate(ctx context.Context, input ClusterctlGenerateFromTemplateInput)

ClusterctlGenerateFromTemplate will generate a cluster definition from a given template.

func CreateDockerRegistrySecret

func CreateDockerRegistrySecret(ctx context.Context, input CreateDockerRegistrySecretInput)

func CreateSecret

func CreateSecret(ctx context.Context, input CreateSecretInput)

CreateSecret will create a new Kubernetes secret.

func DeployChartMuseum

func DeployChartMuseum(ctx context.Context, input ChartMuseumInput) string

DeployChartMuseum will create a new repo in the Gitea server.

func FleetCreateFleetFile

func FleetCreateFleetFile(ctx context.Context, input FleetCreateFleetFileInput)

FleetCreateFleetFile will create a fleet.yaml file in the given location. See the Fleet docs for further information: https://fleet.rancher.io/ref-fleet-yaml

func FleetCreateGitRepo

func FleetCreateGitRepo(ctx context.Context, input FleetCreateGitRepoInput)

FleetCreateGitRepo will create and apply a GitRepo resource to the cluster. See the Fleet docs for further information: https://fleet.rancher.io/gitrepo-add

func FleetDeleteGitRepo

func FleetDeleteGitRepo(ctx context.Context, input FleetDeleteGitRepoInput)

FleetDeleteGitRepo will delete a GitRepo resource from a cluster.

func GetIngressHost

func GetIngressHost(ctx context.Context, input GetIngressHostInput) string

GetIngressHost gets the host from an ingress object.

func GetNodeAddress

func GetNodeAddress(ctx context.Context, input GetNodeAddressInput) string

GetNodeAddress gets the address for a node based on index.

func GitCloneRepo

func GitCloneRepo(ctx context.Context, input GitCloneRepoInput) string

GitCloneRepo will clone a repo to a given location.

func GitCommitAndPush

func GitCommitAndPush(ctx context.Context, input GitCommitAndPushInput)

GitCommitAndPush will commit the files for a repo and push the changes to the origin.

func GiteaCreateRepo

func GiteaCreateRepo(ctx context.Context, input GiteaCreateRepoInput) string

GiteaCreateRepo will create a new repo in the Gitea server.

func Intervals added in v0.16.0

func Intervals(intervals []string) []interface{}

func KubectlApply added in v0.16.0

func KubectlApply(ctx context.Context, kubeconfigPath string, resources []byte, args ...string) error

KubectlApply shells out to kubectl apply.

TODO: Remove this usage of kubectl and replace with a function from apply.go using the controller-runtime client.

func LoadE2EConfig added in v0.16.0

func LoadE2EConfig(configPath string) *clusterctl.E2EConfig

func Parse added in v0.16.0

func Parse[T any](dst *T) error

func RancherGetClusterKubeconfig

func RancherGetClusterKubeconfig(ctx context.Context, input RancherGetClusterKubeconfigInput, result *RancherGetClusterKubeconfigResult)

RancherGetClusterKubeconfig will get the Kubeconfig for a cluster from Rancher.

func RancherGetOriginalKubeconfig

func RancherGetOriginalKubeconfig(ctx context.Context, input RancherGetClusterKubeconfigInput, result *RancherGetClusterKubeconfigResult)

RancherGetOriginalKubeconfig will get the unmodified Kubeconfig for a cluster from Rancher.

func RancherLookupUser

func RancherLookupUser(ctx context.Context, input RancherLookupUserInput, result *RancherLookupUserResult)

func RunCommand

func RunCommand(ctx context.Context, input RunCommandInput, result *RunCommandResult)

RunCommand will run a command with the given args and environment variables.

func WaitForCAPIProviderRollout added in v0.12.0

func WaitForCAPIProviderRollout(ctx context.Context, input WaitForCAPIProviderRolloutInput, intervals ...interface{})

Types

type AddLabelsToNamespaceInput

type AddLabelsToNamespaceInput struct {
	// ClusterProxy is the cluster proxy object used for interacting with the Kubernetes cluster.
	ClusterProxy framework.ClusterProxy

	// Name is the name of the namespace to which labels will be added.
	Name string

	// Labels is a map of key-value pairs representing the labels to be added to the namespace.
	Labels map[string]string
}

AddLabelsToNamespaceInput represents the input parameters for adding labels to a namespace.

type ApplyFromTemplateInput

type ApplyFromTemplateInput struct {
	// Template is the content of the template to be applied.
	Template []byte

	// AddtionalEnvironmentVariables is a map of additional environment variables to be set during template application.
	AddtionalEnvironmentVariables map[string]string

	// Proxy is the cluster proxy used for applying the template.
	Proxy framework.ClusterProxy

	// OutputFilePath is the path where the output of the template application will be stored.
	OutputFilePath string
}

ApplyFromTemplateInput represents the input parameters for applying a template.

type ChartMuseumInput

type ChartMuseumInput struct {
	// HelmBinaryPath is the path to the Helm binary.
	HelmBinaryPath string

	// ChartsPath is the path to the charts.
	ChartsPath string

	// ChartVersion is the version of the chart.
	ChartVersion string

	// ChartMuseumManifests are the ChartMuseum manifests.
	ChartMuseumManifests []byte

	// DeploymentName is the name of the deployment.
	DeploymentName string

	// ServiceName is the name of the service.
	ServiceName string

	// PortName is the name of the port.
	PortName string

	// Proxy is the cluster proxy.
	Proxy framework.ClusterProxy

	// WaitInterval is the wait interval.
	WaitInterval []interface{}

	// CustomIngressConfig is the custom ingress configuration.
	CustomIngressConfig []byte
}

ChartMuseumInput represents the input parameters for interacting with ChartMuseum.

type ClusterctlGenerateFromTemplateInput

type ClusterctlGenerateFromTemplateInput struct {
	// ClusterName is the name of the cluster.
	ClusterName string

	// TemplatePath is the path to the template.
	TemplatePath string

	// OutputFilePath is the path to the output file.
	OutputFilePath string

	// ClusterCtlBinaryPath is the path to the ClusterCtl binary.
	ClusterCtlBinaryPath string

	// EnvironmentVariables are the environment variables to be set.
	EnvironmentVariables map[string]string
}

ClusterctlGenerateFromTemplateInput represents the input parameters for generating from a template.

type CreateDockerRegistrySecretInput

type CreateDockerRegistrySecretInput struct {
	// BootstrapClusterProxy is the bootstrap cluster proxy.
	BootstrapClusterProxy framework.ClusterProxy

	// Name is the name of the secret.
	Name string `envDefault:"regcred"`

	// Namespace is the namespace where the secret will be created.
	Namespace string `envDefault:"rancher-turtles-system"`

	// DockerServer is the Docker server URL.
	DockerServer string `envDefault:"https://ghcr.io/"`

	// DockerUsername is the username for authenticating with the Docker registry.
	DockerUsername string `env:"GITHUB_USERNAME"`

	// DockerPassword is the password for authenticating with the Docker registry.
	DockerPassword string `env:"GITHUB_TOKEN"`
}

CreateDockerRegistrySecretInput represents the input parameters for creating a Docker registry secret.

type CreateSecretInput

type CreateSecretInput struct {
	// Creator is the framework.Creator responsible for creating the secret.
	Creator framework.Creator

	// Name is the name of the secret.
	Name string

	// Namespace is the namespace in which the secret will be created.
	Namespace string

	// Type is the type of the secret.
	Type corev1.SecretType

	// Data is a map of key-value pairs representing the secret data.
	Data map[string]string

	// Labels is a map of key-value pairs representing the labels associated with the secret.
	Labels map[string]string

	// Annotations is a map of key-value pairs representing the annotations associated with the secret.
	Annotations map[string]string
}

CreateSecretInput represents the input parameters for creating a secret.

type FleetCreateFleetFileInput

type FleetCreateFleetFileInput struct {
	// Namespace is the namespace in which the fleet file will be created.
	Namespace string

	// FilePath is the file path of the fleet file.
	FilePath string
}

FleetCreateFleetFileInput represents the input parameters for creating a fleet file.

type FleetCreateGitRepoInput

type FleetCreateGitRepoInput struct {
	// Name is the name of the Git repository.
	Name string

	// Namespace is the namespace in which the Git repository will be created.
	Namespace string `envDefault:"fleet-local"`

	// Repo is the URL of the Git repository.
	Repo string

	// Branch is the branch of the Git repository to use.
	Branch string `envDefault:"main"`

	// Paths are the paths within the Git repository to sync.
	Paths []string

	// FleetGeneration is the generation of the Fleet instance.
	FleetGeneration int

	// ClientSecretName is the name of the client secret to use for authentication.
	ClientSecretName string `envDefault:"basic-auth-secret"`

	// ClusterProxy is the ClusterProxy instance for interacting with the cluster.
	ClusterProxy framework.ClusterProxy
}

FleetCreateGitRepoInput represents the input parameters for creating a Git repository in Fleet.

type FleetDeleteGitRepoInput

type FleetDeleteGitRepoInput struct {
	// Name is the name of the Git repository to be deleted.
	Name string

	// Namespace is the namespace of the Git repository to be deleted.
	Namespace string `envDefault:"fleet-local"`

	// ClusterProxy is the cluster proxy used for interacting with the cluster.
	ClusterProxy framework.ClusterProxy
}

FleetDeleteGitRepoInput represents the input parameters for deleting a Git repository in the fleet.

type GetIngressHostInput

type GetIngressHostInput struct {
	// GetLister is a function that returns a lister for accessing Kubernetes resources.
	GetLister framework.GetLister

	// IngressName is the name of the Ingress.
	IngressName string

	// IngressNamespace is the namespace of the Ingress.
	IngressNamespace string

	// IngressRuleIndex is the index of the Ingress rule.
	IngressRuleIndex int
}

GetIngressHostInput represents the input parameters for retrieving the host of an Ingress.

type GetNodeAddressInput

type GetNodeAddressInput struct {
	// Lister is an interface used for listing resources.
	Lister framework.Lister

	// NodeIndex is the index of the node to retrieve the address from.
	NodeIndex int

	// AddressIndex is the index of the address to retrieve from the node.
	AddressIndex int
}

GetNodeAddressInput represents the input parameters for retrieving a specific node's address.

type GetServicePortByNameInput

type GetServicePortByNameInput struct {
	// GetLister is the function used to retrieve a lister.
	GetLister framework.GetLister

	// ServiceName is the name of the service.
	ServiceName string

	// ServiceNamespace is the namespace of the service.
	ServiceNamespace string

	// PortName is the name of the port.
	PortName string
}

GetServicePortByNameInput represents the input parameters for retrieving a service port by name.

type GetServicePortByNameOutput

type GetServicePortByNameOutput struct {
	// Port is the port number of the service.
	Port int32

	// NodePort is the node port number of the service.
	NodePort int32
}

GetServicePortByNameOutput represents the output of the GetServicePortByName function.

func GetServicePortByName

func GetServicePortByName(ctx context.Context, input GetServicePortByNameInput, intervals ...interface{}) GetServicePortByNameOutput

GetServicePortByName will get the ports for a service by port name.

type GitCloneRepoInput

type GitCloneRepoInput struct {
	// Address is the URL of the repository to clone.
	Address string

	// CloneLocation is the directory where the repository will be cloned.
	CloneLocation string

	// Username is the username for authentication (optional).
	Username string `env:"GITEA_USER_NAME"`

	// Password is the password for authentication (optional).
	Password string `env:"GITEA_USER_PWD"`
}

GitCloneRepoInput is the input to GitCloneRepo.

type GitCommitAndPushInput

type GitCommitAndPushInput struct {
	// CloneLocation is the directory where the repository is cloned.
	CloneLocation string

	// Username is the username for authentication (optional).
	Username string `env:"GITEA_USER_NAME"`

	// Password is the password for authentication (optional).
	Password string `env:"GITEA_USER_PWD"`

	// CommitMessage is the message for the commit.
	CommitMessage string

	// GitPushWait is the wait time for the git push operation.
	GitPushWait []interface{} `envDefault:"3m,10s"`
}

GitCommitAndPushInput is the input to GitCommitAndPush.

type GiteaCreateRepoInput

type GiteaCreateRepoInput struct {
	// ServerAddr is the address of the Gitea server.
	ServerAddr string

	// RepoName is the name of the repository to be created.
	RepoName string

	// Username is the username of the user creating the repository.
	Username string `env:"GITEA_USER_NAME"`

	// Password is the password of the user creating the repository.
	Password string `env:"GITEA_USER_PWD"`
}

GiteaCreateRepoInput represents the input parameters for creating a repository in Gitea.

type RancherGetClusterKubeconfigInput

type RancherGetClusterKubeconfigInput struct {
	// Getter is the framework getter used to retrieve the kubeconfig.
	Getter framework.Getter

	// SecretName is the name of the secret containing the kubeconfig.
	SecretName string

	// Namespace is the namespace of the secret containing the kubeconfig.
	Namespace string

	// ClusterName is the name of the cluster.
	ClusterName string

	// RancherServerURL is the URL of the Rancher server.
	RancherServerURL string

	// WriteToTempFile indicates whether to write the kubeconfig to a temporary file.
	WriteToTempFile bool
}

RancherGetClusterKubeconfigInput represents the input parameters for getting the kubeconfig of a cluster in Rancher.

type RancherGetClusterKubeconfigResult

type RancherGetClusterKubeconfigResult struct {
	// KubeconfigData contains the kubeconfig data as a byte array.
	KubeconfigData []byte

	// TempFilePath is the temporary file path where the kubeconfig is stored.
	TempFilePath string
}

RancherGetClusterKubeconfigResult represents the result of getting the kubeconfig for a Rancher cluster.

type RancherLookupUserInput

type RancherLookupUserInput struct {
	// ClusterProxy is the cluster proxy used for communication with Rancher.
	ClusterProxy framework.ClusterProxy

	// Username is the username of the user to look up.
	Username string
}

RancherLookupUserInput represents the input for looking up a user in Rancher.

type RancherLookupUserResult

type RancherLookupUserResult struct {
	// User is the username of the user found in Rancher.
	User string
}

RancherLookupUserResult represents the result of a user lookup in Rancher.

type RunCommandInput

type RunCommandInput struct {
	// Command is the command to be executed.
	Command string

	// Args are the arguments to be passed to the command.
	Args []string

	// EnvironmentVariables are the environment variables to be set for the command.
	EnvironmentVariables map[string]string
}

RunCommandInput represents the input parameters for running a command.

type RunCommandResult

type RunCommandResult struct {
	// ExitCode is the exit code of the command.
	ExitCode int

	// Stdout is the standard output of the command.
	Stdout []byte

	// Stderr is the standard error of the command.
	Stderr []byte

	// Error is the error that occurred while running the command.
	Error error
}

RunCommandResult represents the result of running a command.

type VariableCollection

type VariableCollection map[string]string

VariableCollection represents a collection of variables for tests.

type VariableLookupFunc

type VariableLookupFunc func(key string) string

VariableLookupFunc is a function type used for looking up variable values.

func GetVariable

func GetVariable(vars VariableCollection) VariableLookupFunc

GetVariable is used to get the value for a variable. The expectation is that the variable exists in one of the sources. Assertion will fail if its not found. The order of precedence when checking for variables is: 1. Environment variables 2. Base variables This is a re-implementation of the CAPI function to add additional logging.

type WaitForCAPIProviderRolloutInput added in v0.12.0

type WaitForCAPIProviderRolloutInput struct {
	capiframework.Getter
	Deployment                      *appsv1.Deployment
	Name, Namespace, Version, Image string
}

Jump to

Keyboard shortcuts

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