Documentation ¶
Overview ¶
Example using an existing Workload Cluster ¶
ctx := context.Background() framework, err := clustertest.New("context_name") if err != nil { panic(err) } // The E2E_WC_NAME and E2E_WC_NAMESPACE env vars must be exported cluster, err := framework.LoadCluster() if err != nil { panic(err) } if cluster == nil { // Handle the case where the env vars aren't provided } // Run tests... // No need to clean up as the user is responsible for the cluster
Example Using Ginkgo ¶
func TestCAPA(t *testing.T) { var err error ctx := context.Background() framework, err = clustertest.New("context_name") if err != nil { panic(err) } logger.LogWriter = GinkgoWriter cluster = application.NewClusterApp(utils.GenerateRandomName("t"), application.ProviderAWS). WithOrg(organization.NewRandomOrg()). WithAppVersions("", ""). // If not set, the latest is fetched WithAppValuesFile(path.Clean("./test_data/cluster_values.yaml"), path.Clean("./test_data/default-apps_values.yaml")) BeforeSuite(func() { client, err := framework.ApplyCluster(ctx, cluster) Expect(err).To(BeNil()) Eventually( wait.AreNumNodesReady(ctx, client, 3, &cr.MatchingLabels{"node-role.kubernetes.io/control-plane": ""}), 20*time.Minute, 30*time.Second, ).Should(BeTrue()) }) AfterSuite(func() { err := framework.DeleteCluster(ctx, cluster) Expect(err).To(BeNil()) }) RegisterFailHandler(Fail) RunSpecs(t, "CAPA Suite") }
Index ¶
- Constants
- type Framework
- func (f *Framework) ApplyCluster(ctx context.Context, cluster *application.Cluster) (*client.Client, error)
- func (f *Framework) CreateOrg(ctx context.Context, org *organization.Org) error
- func (f *Framework) DeleteCluster(ctx context.Context, cluster *application.Cluster) error
- func (f *Framework) DeleteOrg(ctx context.Context, org *organization.Org) error
- func (f *Framework) GetApp(ctx context.Context, name, namespace string) (*applicationv1alpha1.App, error)
- func (f *Framework) GetAppAndValues(ctx context.Context, name, namespace string) (*applicationv1alpha1.App, *corev1.ConfigMap, error)
- func (f *Framework) GetConfigMap(ctx context.Context, name, namespace string) (*corev1.ConfigMap, error)
- func (f *Framework) GetExpectedControlPlaneReplicas(ctx context.Context, clusterName string, clusterNamespace string) (int32, error)
- func (f *Framework) LoadCluster() (*application.Cluster, error)
- func (f *Framework) MC() *client.Client
- func (f *Framework) WC(clusterName string) (*client.Client, error)
- func (f *Framework) WaitForClusterReady(ctx context.Context, clusterName string, namespace string) (*client.Client, error)
- func (f *Framework) WaitForControlPlane(ctx context.Context, c *client.Client, expectedNodes int) error
Constants ¶
const ( EnvKubeconfig = "E2E_KUBECONFIG" EnvWorkloadClusterName = "E2E_WC_NAME" EnvWorkloadClusterNamespace = "E2E_WC_NAMESPACE" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Framework ¶
type Framework struct {
// contains filtered or unexported fields
}
Framework is the overall framework for testing of clusters
func New ¶
New initializes a new Framework instance using the provided context from the kubeconfig found in the env var `E2E_KUBECONFIG`
func (*Framework) ApplyCluster ¶
func (f *Framework) ApplyCluster(ctx context.Context, cluster *application.Cluster) (*client.Client, error)
ApplyCluster takes a Cluster object, applies it to the MC in the correct order and then waits for a valid Kubeconfig to be available
A timeout can be provided via the given `ctx` value by using `context.WithTimeout()`
Example:
timeoutCtx, cancelTimeout := context.WithTimeout(context.Background(), 20*time.Minute) defer cancelTimeout() cluster := application.NewClusterApp(utils.GenerateRandomName("t"), application.ProviderAWS) client, err := framework.ApplyCluster(timeoutCtx, cluster)
func (*Framework) CreateOrg ¶
CreateOrg create a new Organization in the MC (which then triggers the creation of the org namespace)
func (*Framework) DeleteCluster ¶
DeleteCluster removes the Cluster app from the MC
func (*Framework) DeleteOrg ¶
DeleteOrg deletes an Organization from the MC, waiting for all Clusters in the org namespace to be deleted first
func (*Framework) GetApp ¶ added in v0.1.0
func (f *Framework) GetApp(ctx context.Context, name, namespace string) (*applicationv1alpha1.App, error)
GetApp gets the App resource from the cluster
func (*Framework) GetAppAndValues ¶ added in v0.0.8
func (f *Framework) GetAppAndValues(ctx context.Context, name, namespace string) (*applicationv1alpha1.App, *corev1.ConfigMap, error)
GetAppAndValues will return the specified App CR and uservalues ConfigMap from the Management Cluster
func (*Framework) GetConfigMap ¶ added in v0.1.0
func (f *Framework) GetConfigMap(ctx context.Context, name, namespace string) (*corev1.ConfigMap, error)
GetConfigMap gets a ConfigMap from the cluster
func (*Framework) GetExpectedControlPlaneReplicas ¶ added in v0.10.0
func (f *Framework) GetExpectedControlPlaneReplicas(ctx context.Context, clusterName string, clusterNamespace string) (int32, error)
GetExpectedControlPlaneReplicas returns the number of control plane node expected according to the clusters KubeadmControlPlane resource
func (*Framework) LoadCluster ¶ added in v0.0.8
func (f *Framework) LoadCluster() (*application.Cluster, error)
LoadCluster will construct a Cluster struct using a Workload Cluster's cluster and default-apps App CRs on the targeted Management Cluster. The name and namespace where the cluster are installed need to be provided with the E2E_WC_NAME and E2E_WC_NAMESPACE env vars.
If one of the env vars are not set, a nil Cluster and nil error will be returned.
Example:
cluster, err := framework.LoadCluster() if err != nil { // handle error } if cluster == nil { // handle cluster not provided }
func (*Framework) WC ¶
WC returns an initialized client for the Workload Cluster matching the given name. If no Workload Cluster is found matching the given name an error is returned.
func (*Framework) WaitForClusterReady ¶
func (f *Framework) WaitForClusterReady(ctx context.Context, clusterName string, namespace string) (*client.Client, error)
WaitForClusterReady watches for a Kubeconfig secret to be created on the MC and then waits until that cluster's api-server response successfully
A timeout can be provided via the given `ctx` value by using `context.WithTimeout()`
Example:
timeoutCtx, cancelTimeout := context.WithTimeout(context.Background(), 20*time.Minute) defer cancelTimeout() wcClient, err := framework.WaitForClusterReady(timeoutCtx, "test-cluster", "default")
func (*Framework) WaitForControlPlane ¶
func (f *Framework) WaitForControlPlane(ctx context.Context, c *client.Client, expectedNodes int) error
WaitForControlPlane polls the provided cluster and waits until the provided number of Control Plane nodes are reporting as ready
Example:
timeoutCtx, cancelTimeout := context.WithTimeout(context.Background(), 20*time.Minute) defer cancelTimeout() err := framework.WaitForControlPlane(timeoutCtx, wcClient, 3)
Directories ¶
Path | Synopsis |
---|---|
pkg
|
|
application
Package application provides wrapper types around the concept of an App and its associated values ConfigMap.
|
Package application provides wrapper types around the concept of an App and its associated values ConfigMap. |
client
package client provides a thin wrapper around the controller-runtime client.
|
package client provides a thin wrapper around the controller-runtime client. |
logger
package logger inplements a logging function for use within the test framework and can be used within test cases.
|
package logger inplements a logging function for use within the test framework and can be used within test cases. |
organization
package organization implements types to handle creation and deletion of Organization resources.
|
package organization implements types to handle creation and deletion of Organization resources. |
utils
package utils contain miscellaneous utility functions that can be useful when writing tests or working with this test framework.
|
package utils contain miscellaneous utility functions that can be useful when writing tests or working with this test framework. |
wait
package wait provides functions to help with waiting for certain conditions to be true.
|
package wait provides functions to help with waiting for certain conditions to be true. |