Documentation
¶
Overview ¶
Package utils provides utility functions for e2e testing. This package contains helper functions for executing commands, managing Kubernetes resources, and handling common testing operations like installing/uninstalling operators and checking CRDs.
Index ¶
- func GetNonEmptyLines(output string) []string
- func GetProjectDir() (string, error)
- func InstallCertManager() error
- func InstallPrometheusOperator() error
- func IsCertManagerCRDsInstalled() bool
- func IsPrometheusCRDsInstalled() bool
- func LoadImageToKindClusterWithName(name string) error
- func Run(cmd *exec.Cmd) (string, error)
- func RunWithInput(cmd *exec.Cmd, input string) (string, error)
- func UncommentCode(filename, target, prefix string) error
- func UninstallCertManager()
- func UninstallPrometheusOperator()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetNonEmptyLines ¶
GetNonEmptyLines converts given command output string into individual objects according to line breakers, and ignores the empty elements in it. This function is useful for parsing command output that contains multiple lines.
Parameters:
- output: The command output string to parse
Returns:
- []string: A slice of non-empty lines from the output
func GetProjectDir ¶
GetProjectDir will return the directory where the project is located. It handles the case where the current working directory might be in a subdirectory like test/e2e and adjusts the path accordingly.
Returns:
- string: The project root directory path
- error: Any error that occurred while getting the working directory
func InstallCertManager ¶
func InstallCertManager() error
InstallCertManager installs the cert-manager bundle. It downloads and applies the cert-manager bundle, then waits for the webhook to be ready. The webhook readiness check is important because cert-manager may be re-installed after uninstalling on a cluster.
Returns:
- error: Any error that occurred during installation
func InstallPrometheusOperator ¶
func InstallPrometheusOperator() error
InstallPrometheusOperator installs the Prometheus Operator to be used for exporting metrics. It downloads and applies the operator bundle from the official GitHub releases.
Returns:
- error: Any error that occurred during installation
func IsCertManagerCRDsInstalled ¶
func IsCertManagerCRDsInstalled() bool
IsCertManagerCRDsInstalled checks if any Cert Manager CRDs are installed by verifying the existence of key CRDs related to Cert Manager. This function is useful for determining if cert-manager is already installed.
Returns:
- bool: True if any Cert Manager CRDs are found, false otherwise
func IsPrometheusCRDsInstalled ¶
func IsPrometheusCRDsInstalled() bool
IsPrometheusCRDsInstalled checks if any Prometheus CRDs are installed by verifying the existence of key CRDs related to Prometheus. This function is useful for determining if Prometheus Operator is already installed.
Returns:
- bool: True if any Prometheus CRDs are found, false otherwise
func LoadImageToKindClusterWithName ¶
LoadImageToKindClusterWithName loads a local docker image to the kind cluster. This function is useful for testing with custom images that aren't available in public registries. The cluster name can be overridden by setting the KIND_CLUSTER environment variable.
Parameters:
- name: The name of the docker image to load
Returns:
- error: Any error that occurred during image loading
func Run ¶
Run executes the provided command within the project context. It sets up the working directory, environment variables, and captures both stdout and stderr. The function logs the command being executed and returns the combined output.
Parameters:
- cmd: The command to execute
Returns:
- string: The combined stdout and stderr output
- error: Any error that occurred during command execution
func RunWithInput ¶ added in v0.5.0
RunWithInput executes the provided command with input from stdin. This is useful for commands like `kubectl apply -f -` that expect YAML input.
Parameters:
- cmd: The command to execute
- input: The input string to provide via stdin
Returns:
- string: The combined stdout and stderr output
- error: Any error that occurred during command execution
func UncommentCode ¶
UncommentCode searches for target in the file and removes the comment prefix of the target content. The target content may span multiple lines. This function is useful for programmatically enabling features in configuration files.
Parameters:
- filename: The path to the file to modify
- target: The target content to uncomment
- prefix: The comment prefix to remove (e.g., "// " or "# ")
Returns:
- error: Any error that occurred during file modification
func UninstallCertManager ¶
func UninstallCertManager()
UninstallCertManager uninstalls the cert-manager bundle. It removes the cert-manager that was previously installed. Errors during uninstallation are logged as warnings since they're not critical.
func UninstallPrometheusOperator ¶
func UninstallPrometheusOperator()
UninstallPrometheusOperator uninstalls the Prometheus Operator. It removes the operator bundle that was previously installed. Errors during uninstallation are logged as warnings since they're not critical.
Types ¶
This section is empty.