Documentation
¶
Overview ¶
Package framework provides a test framework to use in e2e testing.
Index ¶
- Constants
- Variables
- func AddLabelsToNamespace(ctx context.Context, input AddLabelsToNamespaceInput)
- func Apply(ctx context.Context, p framework.ClusterProxy, resources []byte, ...) error
- func ApplyFromTemplate(ctx context.Context, input ApplyFromTemplateInput) error
- func Byf(format string, a ...interface{})
- func ClusterctlGenerateFromTemplate(ctx context.Context, input ClusterctlGenerateFromTemplateInput)
- func CreateDockerRegistrySecret(ctx context.Context, input CreateDockerRegistrySecretInput)
- func CreateNamespace(ctx context.Context, p framework.ClusterProxy, namespace string) error
- func CreateSecret(ctx context.Context, input CreateSecretInput)
- func FleetCreateFleetFile(ctx context.Context, input FleetCreateFleetFileInput)
- func FleetCreateGitRepo(ctx context.Context, input FleetCreateGitRepoInput)
- func FleetDeleteGitRepo(ctx context.Context, input FleetDeleteGitRepoInput)
- func GetClusterctl(ctx context.Context, input GetClusterctlInput) string
- func GetIngressHost(ctx context.Context, input GetIngressHostInput) string
- func GetNodeAddress(ctx context.Context, input GetNodeAddressInput) string
- func GitCloneRepo(ctx context.Context, input GitCloneRepoInput) string
- func GitCommitAndPush(ctx context.Context, input GitCommitAndPushInput)
- func GitPush(ctx context.Context, input GitPushInput)
- func GitSetRemote(ctx context.Context, input GitSetRemoteInput)
- func GiteaCreateRepo(ctx context.Context, input GiteaCreateRepoInput) string
- func Intervals(intervals []string) []interface{}
- func KubectlApply(ctx context.Context, kubeconfigPath string, resources []byte, args ...string) error
- func LoadE2EConfig(configPath string) *clusterctl.E2EConfig
- func Parse[T any](dst *T) error
- func RancherGetClusterKubeconfig(ctx context.Context, input RancherGetClusterKubeconfigInput, ...)
- func RancherGetOriginalKubeconfig(ctx context.Context, input RancherGetClusterKubeconfigInput, ...)
- func RancherLookupUser(ctx context.Context, input RancherLookupUserInput, ...)
- func RunCommand(ctx context.Context, input RunCommandInput, result *RunCommandResult)
- func VerifyCluster(ctx context.Context, input VerifyClusterInput)
- func VerifyCustomResourceHasBeenRemoved(ctx context.Context, input VerifyCustomResourceHasBeenRemovedInput)
- func WaitForCAPIProviderRollout(ctx context.Context, input WaitForCAPIProviderRolloutInput, ...)
- func WaitForDeploymentsRemoved(ctx context.Context, input WaitForDeploymentsRemovedInput, ...)
- type AddLabelsToNamespaceInput
- type ApplyFromTemplateInput
- type ClusterctlGenerateFromTemplateInput
- type CreateDockerRegistrySecretInput
- type CreateSecretInput
- type FleetCreateFleetFileInput
- type FleetCreateGitRepoInput
- type FleetDeleteGitRepoInput
- type GetClusterctlInput
- type GetIngressHostInput
- type GetNodeAddressInput
- type GetServicePortByNameInput
- type GetServicePortByNameOutput
- type GitCloneRepoInput
- type GitCommitAndPushInput
- type GitPushInput
- type GitSetRemoteInput
- type GiteaCreateRepoInput
- type RancherGetClusterKubeconfigInput
- type RancherGetClusterKubeconfigResult
- type RancherLookupUserInput
- type RancherLookupUserResult
- type RunCommandInput
- type RunCommandResult
- type VariableCollection
- type VariableLookupFunc
- type VerifyClusterInput
- type VerifyCustomResourceHasBeenRemovedInput
- type WaitForCAPIProviderRolloutInput
- type WaitForDeploymentsRemovedInput
Constants ¶
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 ¶
Functions ¶
func AddLabelsToNamespace ¶
func AddLabelsToNamespace(ctx context.Context, input AddLabelsToNamespaceInput)
AddLabelsToNamespace will add labels to a namespace.
func Apply ¶ added in v0.16.0
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 CreateNamespace ¶ added in v0.18.0
CreateNamespace creates a namespace.
func CreateSecret ¶
func CreateSecret(ctx context.Context, input CreateSecretInput)
CreateSecret will create a new Kubernetes secret.
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 GetClusterctl ¶ added in v0.22.0
func GetClusterctl(ctx context.Context, input GetClusterctlInput) string
GetClusterctlConfig gets clusterctl config
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 GitPush ¶ added in v0.25.1
func GitPush(ctx context.Context, input GitPushInput)
GitPush pushes changes to the remote repository.
func GitSetRemote ¶ added in v0.25.1
func GitSetRemote(ctx context.Context, input GitSetRemoteInput)
GitSetRemote sets or updates the remote URL for a git repository. If credentials are provided, they will be embedded in the URL.
func GiteaCreateRepo ¶
func GiteaCreateRepo(ctx context.Context, input GiteaCreateRepoInput) string
GiteaCreateRepo will create a new repo in the Gitea server.
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 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 VerifyCluster ¶ added in v0.24.0
func VerifyCluster(ctx context.Context, input VerifyClusterInput)
func VerifyCustomResourceHasBeenRemoved ¶ added in v0.23.0
func VerifyCustomResourceHasBeenRemoved(ctx context.Context, input VerifyCustomResourceHasBeenRemovedInput)
func WaitForCAPIProviderRollout ¶ added in v0.12.0
func WaitForCAPIProviderRollout(ctx context.Context, input WaitForCAPIProviderRolloutInput, intervals ...interface{})
func WaitForDeploymentsRemoved ¶ added in v0.22.0
func WaitForDeploymentsRemoved(ctx context.Context, input WaitForDeploymentsRemovedInput, intervals ...interface{})
WaitForDeploymentsRemoved waits until the Deployment is removed.
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 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"`
// TargetNamespace is the namespace in which the Git repository will apply its content.
TargetNamespace string
// TargetClusterNamespace is defining git repo to use cluster namespace as a target namespace by default.
TargetClusterNamespace bool
// SourceRepo is the default source URL of the Git repository to use in a CI setting.
SourceRepo string `env:"SOURCE_REPO"`
// Repo is the URL of the Git repository.
Repo string
// SourceBranch is the default source branch of the Git repository to use in a CI setting.
SourceBranch string `env:"GITHUB_HEAD_REF"`
// Branch is the branch of the Git repository to use.
Branch string `envDefault:"main"`
// Revision is the specific commit in the Git repository to use.
Revision string
// Paths are the paths within the Git repository to sync.
Paths []string
// FleetGeneration is the generation of the Fleet instance.
FleetGeneration int `envDefault:"1"`
// ClientSecretName is the name of the client secret to use for authentication.
ClientSecretName string `envDefault:"basic-auth-secret"`
// ClusterSelectors is a list of optional target selectors. These will override the default target.
ClusterSelectors []*metav1.LabelSelector
// 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 GetClusterctlInput ¶ added in v0.22.0
type GetClusterctlInput struct {
// GetLister is a function that returns a lister for accessing Kubernetes resources.
GetLister framework.GetLister
// ConfigMapName is the name of the Ingress.
ConfigMapName string
// IngressNamespace is the namespace of the Ingress.
ConfigMapNamespace string
}
GetClusterctlInput represents the input parameters for retrieving the clusterctl config.
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 GitPushInput ¶ added in v0.25.1
type GitPushInput struct {
// RepoLocation is the directory where the repository is located.
RepoLocation string
// RemoteName is the name of the remote to push to.
RemoteName string `envDefault:"origin"`
// RefSpec is the refspec to push (e.g., "refs/heads/main:refs/heads/main").
// If empty, the default git push behavior is used (push current branch to upstream).
RefSpec 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"`
// Force indicates whether to force push.
Force bool
}
GitPushInput is the input to GitPush.
type GitSetRemoteInput ¶ added in v0.25.1
type GitSetRemoteInput struct {
// RepoLocation is the directory where the repository is located.
RepoLocation string
// RemoteName is the name of the remote (e.g., "origin").
RemoteName string `envDefault:"origin"`
// RemoteURL is the URL for the remote repository.
RemoteURL 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"`
}
GitSetRemoteInput is the input to GitSetRemote.
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 {
// ClusterProxy is the framework cluster proxy used to retrieve the kubeconfig.
ClusterProxy framework.ClusterProxy
// 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
// WaitInterval is the interval to wait for the secret to be available.
WaitInterval []interface{}
}
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 ¶
VariableCollection represents a collection of variables for tests.
type VariableLookupFunc ¶
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 VerifyClusterInput ¶ added in v0.24.0
type VerifyClusterInput struct {
BootstrapClusterProxy capiframework.ClusterProxy
Name string
DeleteAfterVerification bool
}
type VerifyCustomResourceHasBeenRemovedInput ¶ added in v0.23.0
type VerifyCustomResourceHasBeenRemovedInput struct {
capiframework.Lister
GroupVersionKind schema.GroupVersionKind
}
type WaitForCAPIProviderRolloutInput ¶ added in v0.12.0
type WaitForCAPIProviderRolloutInput struct {
capiframework.Getter
Deployment *appsv1.Deployment
Name, Namespace, Version, Image string
}
type WaitForDeploymentsRemovedInput ¶ added in v0.22.0
type WaitForDeploymentsRemovedInput = capiframework.WaitForDeploymentsAvailableInput
WaitForDeploymentsRemovedInput is the input for WaitForDeploymentsRemoved.