utils

package
v0.0.0-...-a715f90 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LocalGatewayAddress           = "http://localhost:8081"
	ConnectGatewayInternalAddress = "https://connect-gateway.kind.internal:443"
	TempKubeconfigPattern         = "kubeconfig-*.yaml"
	LocalKubeconfigPattern        = "kubeconfig-local-*.yaml"
	ConnectGatewayPort            = 8081
	PortForwardStartupDelay       = 2 * time.Second
)

Constants for downstream cluster access

View Source
const (
	DefaultNamespace = "53cd37b9-66b2-4cc8-b080-3722ed7af64a"
	DefaultNodeGUID  = "12345678-1234-1234-1234-123456789012"
	NamespaceEnvVar  = "NAMESPACE"
	NodeGUIDEnvVar   = "NODEGUID"
	ClusterName      = "demo-cluster"

	ClusterOrchFunctionalTest       = "cluster-orch-functional-test"
	ClusterOrchSmokeTest            = "cluster-orch-smoke-test"
	ClusterOrchRobustnessTest       = "cluster-orch-robustness-test"
	ClusterOrchClusterApiAllTest    = "cluster-orch-cluster-api-all-test"
	ClusterOrchClusterApiSmokeTest  = "cluster-orch-cluster-api-smoke-test"
	ClusterOrchTemplateApiSmokeTest = "cluster-orch-template-api-smoke-test"
	ClusterOrchTemplateApiAllTest   = "cluster-orch-template-api-all-test"

	PortForwardAddress           = "0.0.0.0"
	PortForwardService           = "svc/cluster-manager"
	PortForwardGatewayService    = "svc/cluster-connect-gateway"
	PortForwardLocalPort         = "8080"
	PortForwardRemotePort        = "8080"
	PortForwardGatewayLocalPort  = "8081"
	PortForwardGatewayRemotePort = "8080"

	K3sTemplateOnlyName    = "baseline-k3s"
	K3sTemplateOnlyVersion = "v0.0.10"
	K3sTemplateName        = "baseline-k3s-v0.0.10"

	ClusterTemplateURL = "http://127.0.0.1:8080/v2/templates"
	ClusterCreateURL   = "http://127.0.0.1:8080/v2/clusters"

	ClusterConfigTemplatePath      = "../../configs/cluster-config.json"
	BaselineClusterTemplatePathK3s = "../../configs/baseline-cluster-template-k3s.json"
)
View Source
const (
	// EdgeNodeProviderEnvVar selects which kind of edge node the tests operate against.
	// Supported value:
	//   - "ven" (default): external VM reachable via SSH (see VEN_* env vars below)
	EdgeNodeProviderEnvVar = "EDGE_NODE_PROVIDER"

	EdgeNodeProviderVEN = "ven"

	VENSSHHostEnvVar = "VEN_SSH_HOST"
	VENSSHUserEnvVar = "VEN_SSH_USER"
	VENSSHPortEnvVar = "VEN_SSH_PORT"
	VENSSHKeyEnvVar  = "VEN_SSH_KEY" // path to private key file
)
View Source
const (
	DefaultOIDCConfigFile = "oidc-mock-config-dynamic.yaml"
)

Constants for OIDC configuration

View Source
const (
	TemplateTypeK3sBaseline = "k3s-baseline"
)

Variables

View Source
var (
	SkipDeleteCluster = os.Getenv("SKIP_DELETE_CLUSTER") == "true"
)

Functions

func AuthenticatedHTTPClient

func AuthenticatedHTTPClient(authContext *auth.TestAuthContext) *http.Client

AuthenticatedHTTPClient creates an HTTP client with JWT authentication

func CallClusterManagerAPI

func CallClusterManagerAPI(authContext *auth.TestAuthContext, method, endpoint string, body interface{}) (*http.Response, error)

CallClusterManagerAPI makes an authenticated API call to cluster-manager

func CheckAllComponentsReady

func CheckAllComponentsReady(output string) bool

CheckAllComponentsReady verifies if all components in the cluster are ready. Compatible with clusterctl describe output from CAPI ≤v1.10 and v1.11+.

CAPI ≤v1.10: second field per row is "True"/"False" (the READY condition). CAPI v1.11+: STATUS column contains "ConditionName: True" or "ConditionName: False". The top-level Cluster row must show a True value before the cluster is considered ready.

func CheckLostConnection

func CheckLostConnection(output string) bool

CheckLostConnection verifies if ControlPlane reports connection lost.

func CreateCluster

func CreateCluster(namespace, nodeGUID, templateName string) error

CreateCluster creates a cluster using the provided configuration.

func CreateClusterAuthenticated

func CreateClusterAuthenticated(authContext *auth.TestAuthContext, namespace, nodeGUID, templateName string) error

CreateClusterAuthenticated creates a cluster using JWT authentication

func DeleteAllTemplate

func DeleteAllTemplate(namespace string) error

func DeleteCluster

func DeleteCluster(namespace string) error

DeleteCluster deletes a cluster by name.

func DeleteClusterAuthenticated

func DeleteClusterAuthenticated(authContext *auth.TestAuthContext, namespace string) error

DeleteClusterAuthenticated deletes a cluster by name using JWT authentication.

func DeleteTemplate

func DeleteTemplate(namespace, templateName, templateVersion string) error

func EnsureNamespaceExists

func EnsureNamespaceExists(namespace string) error

EnsureNamespaceExists ensures that the specified namespace exists in the cluster.

func EnsureTCPPortAvailable

func EnsureTCPPortAvailable(port, purpose string) error

EnsureTCPPortAvailable fails fast if a local TCP port is already occupied. This guards against stale kubectl port-forward processes hijacking test traffic.

func ExecOnEdgeNode

func ExecOnEdgeNode(shellCommand string) ([]byte, error)

ExecOnEdgeNode runs a shell command on the edge node. vEN: ssh into the VM and run the command.

func FetchMetrics

func FetchMetrics() (io.ReadCloser, error)

FetchMetrics fetches the metrics from the /metrics endpoint.

func GetClusterInfo

func GetClusterInfo(namespace, clusterName string) (*http.Response, error)

func GetClusterInfoWithAuth

func GetClusterInfoWithAuth(authContext *auth.TestAuthContext, namespace, clusterName string) (*http.Response, error)

GetClusterInfoWithAuth retrieves cluster information using authenticated API call

func GetClusterKubeconfigFromAPI

func GetClusterKubeconfigFromAPI(authContext *auth.TestAuthContext, namespace, clusterName string) (*http.Response, error)

GetClusterKubeconfigFromAPI retrieves kubeconfig from cluster-manager API

func GetClusterManagerEndpoint

func GetClusterManagerEndpoint() string

GetClusterManagerEndpoint returns the cluster-manager API endpoint

func GetClusterTemplate

func GetClusterTemplate(namespace, templateName, templateVersion string) (*api.TemplateInfo, error)

func GetClusterTemplatesWithFilter

func GetClusterTemplatesWithFilter(namespace, filter string) (*api.TemplateInfoList, error)

func GetDefaultTemplate

func GetDefaultTemplate(namespace string) (*api.DefaultTemplateInfo, error)

func GetEdgeNodeProvider

func GetEdgeNodeProvider() string

GetEdgeNodeProvider returns the edge node provider selected via environment variable or the default if not set or invalid.

func GetEnv

func GetEnv(key, defaultValue string) string

GetEnv retrieves the value of the environment variable or returns the default value if not set.

func ImportClusterTemplate

func ImportClusterTemplate(namespace string, templateType string) error

ImportClusterTemplate imports a cluster template into the specified namespace.

func ImportClusterTemplateAuthenticated

func ImportClusterTemplateAuthenticated(authContext *auth.TestAuthContext, namespace string, templateType string) error

ImportClusterTemplateAuthenticated imports a cluster template using JWT authentication

func IsClusterTemplateReady

func IsClusterTemplateReady(namespace, templateName string) bool

IsClusterTemplateReady checks if the cluster template is ready.

func LogCommandOutput

func LogCommandOutput(command string, args []string)

func ParseMetrics

func ParseMetrics(metrics io.Reader) (bool, error)

ParseMetrics checks if the metric websocket_connections_total with status="succeeded" is 1.

func SetDefaultTemplate

func SetDefaultTemplate(namespace, name, version string) error

func SetupTestAuthentication

func SetupTestAuthentication(subject string) (*auth.TestAuthContext, error)

SetupTestAuthentication initializes JWT generation and returns auth context

func TestClusterManagerAuthentication

func TestClusterManagerAuthentication(authContext *auth.TestAuthContext) error

TestClusterManagerAuthentication tests if cluster-manager API accepts JWT authentication

func TestDownstreamClusterAccess

func TestDownstreamClusterAccess(kubeconfigContent string) error

TestDownstreamClusterAccess tests accessing the downstream cluster using the provided kubeconfig

func UnpauseCluster

func UnpauseCluster(namespace, clusterName string) error

UnpauseCluster sets spec.paused=false for a CAPI Cluster.

Types

type AuthTransport

type AuthTransport struct {
	Transport http.RoundTripper
	Token     string
}

AuthTransport adds JWT authentication to HTTP requests

func (*AuthTransport) RoundTrip

func (t *AuthTransport) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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