Documentation
¶
Overview ¶
Package tftestenv contains helpers to create and work with cloud infrastructure using terraform. It is similar to testenv, which helps create new test kubernetes environment and cleanup at the end of the tests. For ease of use, it also contains some helper utilities for interacting with the various cloud providers for generating kubeconfig of the created cluster, registry login and pushing images to the registries, etc.
Index ¶
- func CreateAndPushImages(repos map[string]string, tags []string) error
- func CreateKubeconfigAKS(ctx context.Context, kubeconfigYaml string, kcPath string) error
- func CreateKubeconfigEKS(ctx context.Context, clusterName, eksHost, eksClusterArn, eksCa, kcPath string) error
- func CreateKubeconfigGKE(ctx context.Context, kubeconfigYaml string, kcPath string) error
- func GetGoogleArtifactRegistryAndRepository(project, region, repositoryID string) (string, string)
- func PushTestAppImagesACR(ctx context.Context, localImgs map[string]string, registryURL string) (map[string]string, error)
- func PushTestAppImagesECR(ctx context.Context, localImgs map[string]string, remoteImage string) (map[string]string, error)
- func PushTestAppImagesGCR(ctx context.Context, localImgs map[string]string, ...) (map[string]string, error)
- func RegistryLoginACR(ctx context.Context, registryURL string) error
- func RegistryLoginECR(ctx context.Context, region, repoURL string) error
- func RegistryLoginGCR(ctx context.Context, repoURL string) error
- func RunCommand(ctx context.Context, dir, command string, opts RunCommandOptions) error
- type CreateKubeconfig
- type Environment
- type EnvironmentOption
- type RunCommandOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateAndPushImages ¶
CreateAndPushImages randomly generates test images with the given tags and pushes them to the given test repositories.
func CreateKubeconfigAKS ¶
CreateKubeconfigAKS constructs kubeconfig for an AKS cluster from the terraform state output at the given kubeconfig path.
func CreateKubeconfigEKS ¶
func CreateKubeconfigEKS(ctx context.Context, clusterName, eksHost, eksClusterArn, eksCa, kcPath string) error
CreateKubeconfigEKS constructs kubeconfig from the terraform state output at the given kubeconfig path. func createKubeconfigEKS(ctx context.Context, state map[string]*tfjson.StateOutput, kcPath string) error {
func CreateKubeconfigGKE ¶
CreateKubeconfigGKE constructs kubeconfig from the terraform state output at the given kubeconfig path.
func GetGoogleArtifactRegistryAndRepository ¶
GetGoogleArtifactRegistryAndRepository returns artifact registry and artifact repository URL from the given repository ID.
func PushTestAppImagesACR ¶
func PushTestAppImagesACR(ctx context.Context, localImgs map[string]string, registryURL string) (map[string]string, error)
PushTestAppImagesACR pushes app images that are being tested. It must be called after RegistryLoginACR to ensure the local docker client is already logged in and is capable of pushing the test images.
func PushTestAppImagesECR ¶
func PushTestAppImagesECR(ctx context.Context, localImgs map[string]string, remoteImage string) (map[string]string, error)
PushTestAppImagesECR pushes app image that is being tested. It must be called after RegistryLoginECR to ensure the local docker client is already logged in and is capable of pushing the test images.
func PushTestAppImagesGCR ¶
func PushTestAppImagesGCR(ctx context.Context, localImgs map[string]string, project, region, artifactRepoID string) (map[string]string, error)
PushTestAppImagesGCR pushes app images that are being tested. It must be called after RegistryLoginGCR to ensure the local docker client is already logged in and is capable of pushing the test images.
func RegistryLoginACR ¶
RegistryLoginACR logs into the container/artifact registries using the provider's CLI tools and returns a list of test repositories.
func RegistryLoginECR ¶
RegistryLoginECR logs into the container/artifact registries using the provider's CLI tools and returns a list of test repositories.
func RegistryLoginGCR ¶
RegistryLoginGCR logs into the container/artifact registries using the provider's CLI tools and returns a list of test repositories. func registryLoginGCR(ctx context.Context, output map[string]*tfjson.StateOutput) (map[string]string, error) {
func RunCommand ¶
func RunCommand(ctx context.Context, dir, command string, opts RunCommandOptions) error
RunCommand executes given command in a given directory.
Types ¶
type CreateKubeconfig ¶
type CreateKubeconfig func(ctx context.Context, state map[string]*tfjson.StateOutput, kcPath string) error
createKubeconfig create a kubeconfig for the target cluster and writes to the given path using the contextual values from the infrastructure state.
type Environment ¶
type Environment struct { client.Client Config *rest.Config // CreateKubeconfig provides the terraform state output which is used to // construct kubeconfig. CreateKubeconfig CreateKubeconfig // contains filtered or unexported fields }
Environment encapsulates a Kubernetes test environment.
func New ¶
func New(ctx context.Context, scheme *runtime.Scheme, terraformPath string, kubeconfigPath string, opts ...EnvironmentOption) (*Environment, error)
New finds or downloads terraform binary, uses it to run terraform in the given terraformPath to create a kubernetes cluster. A kubeconfig of the created is constructed at the given kubeconfigPath which is then used to construct a kubernetes client that can be used in the tests.
func (*Environment) StateOutput ¶
func (env *Environment) StateOutput(ctx context.Context) (map[string]*tfjson.StateOutput, error)
State queries and returns the current state output of terraform.
type EnvironmentOption ¶
type EnvironmentOption func(*Environment)
EnvironmentOption is used to configure the Environment.
func WithBuildDir ¶
func WithBuildDir(dir string) EnvironmentOption
WithBuildDir sets the build directory for the environment. Defaults to "build".
func WithCreateKubeconfig ¶
func WithCreateKubeconfig(create CreateKubeconfig) EnvironmentOption
WithCreateKubeconfig configures how kubeconfig is constructured using the output state of the terraform infrastructure.
func WithExisting ¶
func WithExisting(existing bool) EnvironmentOption
WithExisting configures the Environment to use the existing infrastructure. By default, the environment set up would fail if the terraform state is not clean.
func WithRetain ¶
func WithRetain(retain bool) EnvironmentOption
WithRetain configures the Environment to retain the created or existing infrastructure.
func WithVerbose ¶
func WithVerbose(verbose bool) EnvironmentOption
WithVerbose configures the terraform executor to run in verbose mode.
type RunCommandOptions ¶
RunCommandOptions is used to configure the RunCommand execution.