utils

package
v2.21.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2022 License: Apache-2.0 Imports: 58 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LoginEnvironmentVariable         = "KUBERMATIC_OIDC_LOGIN"
	PasswordEnvironmentVariable      = "KUBERMATIC_OIDC_PASSWORD"
	LDAPLoginEnvironmentVariable     = "KUBERMATIC_LDAP_LOGIN"
	LDAPPasswordEnvironmentVariable  = "KUBERMATIC_LDAP_PASSWORD"
	DexValuesFileEnvironmentVariable = "KUBERMATIC_DEX_VALUES_FILE"
)

Variables

View Source
var DefaultLogOptions = log.Options{
	Debug:  false,
	Format: log.FormatConsole,
}

Functions

func APIEndpoint

func APIEndpoint() (string, error)

func CheckPodsRunningReady added in v2.17.0

func CheckPodsRunningReady(ctx context.Context, c ctrlruntimeclient.Client, log *zap.SugaredLogger, ns string, podNames []string, timeout time.Duration) bool

CheckPodsRunningReady returns whether all pods whose names are listed in podNames in namespace ns are running and ready, using c and waiting at most timeout.

func CreateGinkgoLogger added in v2.21.0

func CreateGinkgoLogger(debug bool) *zap.SugaredLogger

CreateGinkgoLogger creates a new Logger that dumps its output to GinkgoWriter.

func GetClients added in v2.17.0

GetClients returns the clients used for testing or an error if something goes wrong during the clients creation.

func GetClientsOrDie added in v2.17.0

func GetClientsOrDie() (ctrlruntimeclient.Client, rest.Interface, *rest.Config)

GetClientsOrDie returns the clients used for testing or panics if something goes wrong during the clients creation.

func IsHealthyCluster

func IsHealthyCluster(healthStatus *apiv1.ClusterHealth) bool

IsHealthyCluster check if all cluster components are up.

func KubernetesVersion

func KubernetesVersion() string

func LDAPCredentials added in v2.21.0

func LDAPCredentials() (string, string, error)

LDAPCredentials takes the login name and password from environment variables and returns them.

func Logout

func Logout()

Logout resets the runtime cache for the master/admin tokens and forces a new login to Dex.

func NewKubermaticClient

func NewKubermaticClient(endpointURL string) (*client.KubermaticKubernetesPlatformAPI, error)

func NewRoundTripperWithRetries

func NewRoundTripperWithRetries(t *testing.T, requestTimeout time.Duration, backoff Backoff, ignoredStatusCodes ...int) http.RoundTripper

func OIDCAdminCredentials

func OIDCAdminCredentials() (string, string, error)

OIDCAdminCredentials takes the admin login name and password from environment variables and returns them.

func OIDCCredentials

func OIDCCredentials() (string, string, error)

OIDCCredentials takes the login name and password from environment variables and returns them.

func PodRunningReady added in v2.17.0

func PodRunningReady(p *corev1.Pod) error

PodRunningReady checks whether pod p's phase is running and it has a ready condition of status true.

func RetrieveAdminMasterToken

func RetrieveAdminMasterToken(ctx context.Context) (string, error)

func RetrieveLDAPToken added in v2.21.0

func RetrieveLDAPToken(ctx context.Context) (string, error)

func RetrieveMasterToken

func RetrieveMasterToken(ctx context.Context) (string, error)

func SetupParams

func SetupParams(t *testing.T, p requestParameterHolder, interval time.Duration, timeout time.Duration, ignoredStatusCodes ...int)

SetupParams configures retries for HTTP calls for a total period defined by 'timeout' parameter and for an 'interval' duration. Deprecated: Use SetupRetryParams instead.

func SetupRetryParams

func SetupRetryParams(t *testing.T, p requestParameterHolder, backoff Backoff, ignoredStatusCodes ...int)

SetupRetryParams configure retries for HTTP calls based on backoff parameters.

func WaitFor

func WaitFor(interval time.Duration, timeout time.Duration, callback func() bool) bool

WaitFor is a convenience wrapper that makes simple, "brute force" waiting loops easier to write.

func WaitForDeploymentReady added in v2.21.0

func WaitForDeploymentReady(ctx context.Context, c ctrlruntimeclient.Client, log *zap.SugaredLogger, ns, name string, timeout time.Duration) error

WaitForDeploymentReady waits until the Deployment is fully ready.

func WaitForPodCondition added in v2.17.0

func WaitForPodCondition(ctx context.Context, c ctrlruntimeclient.Client, log *zap.SugaredLogger, ns, podName, desc string, timeout time.Duration, condition podCondition) error

WaitForPodCondition waits a pods to be matched to the given condition.

func WaitForPodsCreated added in v2.17.0

func WaitForPodsCreated(ctx context.Context, c ctrlruntimeclient.Client, log *zap.SugaredLogger, replicas int, namespace string, matchLabels map[string]string) ([]string, error)

WaitForPodsCreated waits for the given replicas number of pods matching the given set of labels to be created, and returns the names of the matched pods.

Types

type Backoff

type Backoff wait.Backoff

type PatchCluster

type PatchCluster struct {
	Name   string            `json:"name"`
	Labels map[string]string `json:"labels,omitempty"`
}

type TestClient

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

TestClient wraps the Swagger-generated API client with some more convenient functions, tailor-made for writing tests.

func NewTestClient

func NewTestClient(token string, t *testing.T) *TestClient

func (*TestClient) AddProjectUser

func (r *TestClient) AddProjectUser(projectID, email, name, group string) (*apiv1.User, error)

func (*TestClient) AddTokenToServiceAccount

func (r *TestClient) AddTokenToServiceAccount(name, saID, projectID string) (*apiv1.ServiceAccountToken, error)

AddTokenToServiceAccount creates a new token for service account.

func (*TestClient) AssignSSHKeyToCluster

func (r *TestClient) AssignSSHKeyToCluster(projectID, clusterID, dc, keyID string) error

AssignSSHKeyToCluster adds user SSH key to the cluster.

func (*TestClient) BindUserToClusterRole

func (r *TestClient) BindUserToClusterRole(projectID, dc, clusterID, roleName, user string) (*apiv1.ClusterRoleBinding, error)

BindUserToClusterRole.

func (*TestClient) BindUserToRole

func (r *TestClient) BindUserToRole(projectID, dc, clusterID, roleName, namespace, user string) (*apiv1.RoleBinding, error)

func (*TestClient) CleanupCluster

func (r *TestClient) CleanupCluster(t *testing.T, projectID, dc, clusterID string)

func (*TestClient) CleanupProject

func (r *TestClient) CleanupProject(t *testing.T, id string)

func (*TestClient) ConnectClusterTerminal added in v2.21.0

func (r *TestClient) ConnectClusterTerminal(token, clusterID, projectID string) (*websocket.Conn, error)

func (*TestClient) CreateAWSCluster

func (r *TestClient) CreateAWSCluster(projectID, dc, name, secretAccessKey, accessKeyID, version, location, availabilityZone, proxyMode string, replicas int32, konnectivityEnabled bool, cniSettings *models.CNIPluginSettings) (*apiv1.Cluster, error)

CreateAWSCluster creates cluster for AWS provider.

func (*TestClient) CreateClusterTemplate added in v2.18.0

func (r *TestClient) CreateClusterTemplate(projectID, name, scope, credential, version, location string) (*apiv2.ClusterTemplate, error)

CreateClusterTemplate method creates cluster template object.

func (*TestClient) CreateClusterTemplateInstance added in v2.18.0

func (r *TestClient) CreateClusterTemplateInstance(projectID, templateID string, replicas int64) (*apiv2.ClusterTemplateInstance, error)

CreateClusterTemplate method creates cluster template instance object.

func (*TestClient) CreateDC

func (r *TestClient) CreateDC(seed string, dc *models.Datacenter) (*models.Datacenter, error)

func (*TestClient) CreateGroupProjectBinding added in v2.21.0

func (r *TestClient) CreateGroupProjectBinding(group, role, projectID string) (*apiv2.GroupProjectBinding, error)

func (*TestClient) CreateHetznerCluster added in v2.21.0

func (r *TestClient) CreateHetznerCluster(projectID, dc, name, credential, version, location string, replicas int32) (*apiv1.Cluster, error)

CreateHetznerCluster creates cluster for Hetzner provider.

func (*TestClient) CreateKubevirtCluster added in v2.19.0

func (r *TestClient) CreateKubevirtCluster(projectID, dc, name, credential, version, location string, replicas int32) (*apiv1.Cluster, error)

CreateKubevirtCluster creates cluster for Kubevirt provider.

func (*TestClient) CreateProject

func (r *TestClient) CreateProject(name string, ignoredStatusCodes ...int) (*apiv1.Project, error)

CreateProject creates a new project and waits for it to become active (ready).

func (*TestClient) CreateProjectBySA added in v2.18.0

func (r *TestClient) CreateProjectBySA(name string, users []string) (*apiv1.Project, error)

CreateProjectBySA creates a new project and waits for it to become active (ready).

func (*TestClient) CreateServiceAccount

func (r *TestClient) CreateServiceAccount(name, group, projectID string) (*apiv1.ServiceAccount, error)

CreateServiceAccount method creates a new service account and waits a certain amount of time for it to become active.

func (*TestClient) CreateUserSSHKey

func (r *TestClient) CreateUserSSHKey(projectID, keyName, publicKey string) (*apiv1.SSHKey, error)

CreateUserSSHKey creates a new user SSH key.

func (*TestClient) DeleteCluster

func (r *TestClient) DeleteCluster(projectID, dc, clusterID string) error

DeleteCluster delete cluster method.

func (*TestClient) DeleteDC

func (r *TestClient) DeleteDC(seed, dc string) error

func (*TestClient) DeleteGroupProjectBinding added in v2.21.0

func (r *TestClient) DeleteGroupProjectBinding(name, projectId string) error

func (*TestClient) DeleteProject

func (r *TestClient) DeleteProject(id string) error

DeleteProject deletes given project.

func (*TestClient) DeleteServiceAccount

func (r *TestClient) DeleteServiceAccount(saID, projectID string) error

DeleteServiceAccount deletes service account for given ID and project.

func (*TestClient) DeleteTokenForServiceAccount

func (r *TestClient) DeleteTokenForServiceAccount(tokenID, saID, projectID string) error

DeleteTokenForServiceAccount deletes a token for service account.

func (*TestClient) DeleteUserFromProject

func (r *TestClient) DeleteUserFromProject(projectID, userID string) error

func (*TestClient) DeleteUserSSHKey

func (r *TestClient) DeleteUserSSHKey(projectID, keyID string) error

DeleteUserSSHKey deletes user SSH keys.

func (*TestClient) DetachSSHKeyFromClusterParams

func (r *TestClient) DetachSSHKeyFromClusterParams(projectID, clusterID, dc, keyID string) error

DetachSSHKeyFromClusterParams detaches user SSH key from the cluster.

func (*TestClient) GetBearerToken added in v2.21.0

func (r *TestClient) GetBearerToken() runtime.ClientAuthInfoWriter

func (*TestClient) GetCluster

func (r *TestClient) GetCluster(projectID, dc, clusterID string) (*apiv1.Cluster, error)

GetCluster cluster getter.

func (*TestClient) GetClusterBindings

func (r *TestClient) GetClusterBindings(projectID, dc, clusterID string) ([]apiv1.ClusterRoleBinding, error)

func (*TestClient) GetClusterEvents

func (r *TestClient) GetClusterEvents(projectID, dc, clusterID string) ([]*models.Event, error)

GetClusterEvents returns the cluster events.

func (*TestClient) GetClusterHealthStatus

func (r *TestClient) GetClusterHealthStatus(projectID, dc, clusterID string) (*apiv1.ClusterHealth, error)

GetClusterHealthStatus gets the cluster status.

func (*TestClient) GetClusterNodeDeployments

func (r *TestClient) GetClusterNodeDeployments(projectID, dc, clusterID string) ([]apiv1.NodeDeployment, error)

GetClusterNodeDeployments returns the cluster node deployments.

func (*TestClient) GetClusterRoles

func (r *TestClient) GetClusterRoles(projectID, dc, clusterID string) ([]apiv1.ClusterRoleName, error)

func (*TestClient) GetDC

func (r *TestClient) GetDC(dc string) (*models.Datacenter, error)

func (*TestClient) GetDCForProvider

func (r *TestClient) GetDCForProvider(provider, dc string) (*models.Datacenter, error)

func (*TestClient) GetDCForSeed

func (r *TestClient) GetDCForSeed(seed, dc string) (*models.Datacenter, error)

func (*TestClient) GetGlobalSettings

func (r *TestClient) GetGlobalSettings() (*apiv1.GlobalSettings, error)

func (*TestClient) GetKKPAPIClient added in v2.21.0

func (*TestClient) GetKubeconfig

func (r *TestClient) GetKubeconfig(dc, projectID, clusterID string) (string, error)

func (*TestClient) GetProject

func (r *TestClient) GetProject(id string) (*apiv1.Project, error)

GetProject gets the project with the given ID; it does not perform any retries if the API returns errors.

func (*TestClient) GetProjectUsers

func (r *TestClient) GetProjectUsers(projectID string) ([]apiv1.User, error)

func (*TestClient) GetRoleBindings added in v2.18.0

func (r *TestClient) GetRoleBindings(projectID, dc, clusterID string) ([]apiv1.RoleBinding, error)

func (*TestClient) GetRoles

func (r *TestClient) GetRoles(projectID, dc, clusterID string) ([]apiv1.RoleName, error)

func (*TestClient) GetServiceAccount

func (r *TestClient) GetServiceAccount(saID, projectID string) (*apiv1.ServiceAccount, error)

GetServiceAccount returns service account for given ID and project.

func (*TestClient) GetUserClusterClient added in v2.17.0

func (r *TestClient) GetUserClusterClient(dc, projectID, clusterID string) (ctrlruntimeclient.Client, error)

func (*TestClient) ListAzureSizes added in v2.19.0

func (r *TestClient) ListAzureSizes(credential, location string) (models.AzureSizeList, error)

ListAzureSizes returns list Azure sizes.

func (*TestClient) ListClusters added in v2.18.0

func (r *TestClient) ListClusters(projectID string, showDeploymentMachineCount bool) ([]*apiv1.Cluster, error)

ListClusters method lists user clusters.

func (*TestClient) ListCredentials

func (r *TestClient) ListCredentials(providerName, datacenter string) ([]string, error)

ListCredentials returns list of credential names for the provider.

func (*TestClient) ListDC

func (r *TestClient) ListDC() ([]*models.Datacenter, error)

func (*TestClient) ListDCForProvider

func (r *TestClient) ListDCForProvider(provider string) ([]*models.Datacenter, error)

func (*TestClient) ListDCForSeed

func (r *TestClient) ListDCForSeed(seed string) ([]*models.Datacenter, error)

func (*TestClient) ListDOSizes added in v2.19.0

func (r *TestClient) ListDOSizes(credential string) (*models.DigitaloceanSizeList, error)

ListDOSizes returns list DO sizes.

func (*TestClient) ListGCPDiskTypes

func (r *TestClient) ListGCPDiskTypes(credential, zone string) ([]string, error)

ListGCPDiskTypes returns list of GCP disk types.

func (*TestClient) ListGCPSizes

func (r *TestClient) ListGCPSizes(credential, zone string) ([]apiv1.GCPMachineSize, error)

ListGCPSizes returns list of GCP sizes.

func (*TestClient) ListGCPZones

func (r *TestClient) ListGCPZones(credential, dc string) ([]string, error)

ListGCPZones returns list of GCP zones.

func (*TestClient) ListProjects

func (r *TestClient) ListProjects(displayAll bool) ([]*apiv1.Project, error)

ListProjects gets projects.

func (*TestClient) ListUserSSHKey

func (r *TestClient) ListUserSSHKey(projectID string) ([]*apiv1.SSHKey, error)

ListUserSSHKey list user SSH keys.

func (*TestClient) Logout

func (r *TestClient) Logout() error

func (*TestClient) PatchDC

func (r *TestClient) PatchDC(seed, dcToPatch, patch string) (*models.Datacenter, error)

func (*TestClient) PrintClusterEvents

func (r *TestClient) PrintClusterEvents(projectID, dc, clusterID string) error

PrintClusterEvents prints all cluster events using its test.Logf.

func (*TestClient) SetAdmin

func (r *TestClient) SetAdmin(email string, isAdmin bool) error

func (*TestClient) UpdateCluster

func (r *TestClient) UpdateCluster(projectID, dc, clusterID string, patch PatchCluster) (*apiv1.Cluster, error)

func (*TestClient) UpdateDC

func (r *TestClient) UpdateDC(seed, dcToUpdate string, dc *models.Datacenter) (*models.Datacenter, error)

func (*TestClient) UpdateGlobalSettings

func (r *TestClient) UpdateGlobalSettings(patch json.RawMessage) (*apiv1.GlobalSettings, error)

func (*TestClient) UpdateProject

func (r *TestClient) UpdateProject(projectToUpdate *apiv1.Project) (*apiv1.Project, error)

UpdateProject updates the given project.

func (*TestClient) WaitForClusterHealthy

func (r *TestClient) WaitForClusterHealthy(projectID, dc, clusterID string) error

func (*TestClient) WaitForClusterNodeDeploymentsToByReady

func (r *TestClient) WaitForClusterNodeDeploymentsToByReady(projectID, dc, clusterID string, replicas int32) error

func (*TestClient) WaitForClusterNodeDeploymentsToExist

func (r *TestClient) WaitForClusterNodeDeploymentsToExist(projectID, dc, clusterID string) error

func (*TestClient) WaitForOPAEnabledClusterHealthy added in v2.17.0

func (r *TestClient) WaitForOPAEnabledClusterHealthy(projectID, dc, clusterID string) error

type TestPodConfig added in v2.17.0

type TestPodConfig struct {
	Log           *zap.SugaredLogger
	Namespace     string
	Client        ctrlruntimeclient.Client
	PodRestClient rest.Interface
	Config        *rest.Config
	// CreatePodFunc returns the manifest of the pod to be used for running the
	// test. As we need to exec the pod should not terminate (e.g. run an
	// infinite sleep).
	CreatePodFunc       func(ns string) *corev1.Pod
	PodReadinessTimeout time.Duration
	// contains filtered or unexported fields
}

func (*TestPodConfig) CleanUp added in v2.17.0

func (t *TestPodConfig) CleanUp(ctx context.Context) error

CleanUp deletes the resources.

func (*TestPodConfig) DeployTestPod added in v2.17.0

func (t *TestPodConfig) DeployTestPod(ctx context.Context, log *zap.SugaredLogger) error

DeployTestPod deploys the pod to be used to run the test command.

func (*TestPodConfig) Exec added in v2.17.0

func (t *TestPodConfig) Exec(container string, command ...string) (string, string, error)

Exec executes the given command in the chosen container of the test pod.

Jump to

Keyboard shortcuts

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