e2e

package
v0.0.0-...-1926a09 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout is the default timeout for client operations
	DefaultClientTimeout = 30 * time.Second
	// DefaultPollInterval is the default interval for polling
	DefaultPollInterval = 5 * time.Second
	// DefaultPollTimeout is the default timeout for polling
	DefaultPollTimeout = 15 * time.Minute
)
View Source
const (
	// OLSNameSpace is the namespace where the operator is deployed
	OLSNameSpace = "openshift-lightspeed"
	// OperatorDeploymentName is the name of the operator deployment
	OperatorDeploymentName = "lightspeed-operator-controller-manager"
	// LLMTokenEnvVar is the environment variable containing the LLM API token
	LLMTokenEnvVar = "LLM_TOKEN"
	// LLMTokenFirstSecretName is the name of the first secret containing the LLM API token
	LLMTokenFirstSecretName = "llm-token-first" // #nosec G101
	// LLMTokenSecondSecretName is the name of the second secret containing the LLM API token
	LLMTokenSecondSecretName = "llm-token-second" // #nosec G101
	// LLMApiTokenFileName
	LLMApiTokenFileName = "apitoken"
	// LLMDefaultProvider
	LLMDefaultProvider = "openai"
	// LLMProviderEnvVar is the environment variable containing the LLM provider
	LLMProviderEnvVar = "LLM_PROVIDER"
	// LLMTypeEnvVar is the environment variable containing the LLM type
	LLMTypeEnvVar = "LLM_TYPE"
	// LLMDefaultType is the default LLM type
	LLMDefaultType = "openai"
	// OpenAIDefaultModel is the default model to use
	OpenAIDefaultModel = "gpt-4o-mini"
	// OpenAIAlternativeModel is the alternative model to test model change
	OpenAIAlternativeModel = "gpt-4-1106-preview"
	// LLMModelEnvVar is the environment variable containing the LLM model
	LLMModelEnvVar = "LLM_MODEL"
	// AzureTenantID is the environment variable containing the tenant id for azure openai authentication
	AzureTenantID = "AZUREOPENAI_ENTRA_ID_TENANT_ID"
	// AzureClientID is the environment variable containing the client id for azure openai authentication
	AzureClientID = "AZUREOPENAI_ENTRA_ID_CLIENT_ID"
	// AzureClientSecret is the environment variable containing the client secret for azure openai authentication
	AzureClientSecret = "AZUREOPENAI_ENTRA_ID_CLIENT_SECRET"
	// AzureOpenaiTenantID
	AzureOpenaiTenantID = "tenant_id"
	// AzureOpenaiClientID
	AzureOpenaiClientID = "client_id"
	// AzureOpenaiClientSecret
	AzureOpenaiClientSecret = "client_secret"
	// AzureURL
	AzureURL = "https://ols-test.openai.azure.com/"
	// OLSCRName is the name of the OLSConfig CR
	OLSCRName = "cluster"
	// AppServerDeploymentName is the name of the OLS application server deployment
	AppServerDeploymentName = "lightspeed-app-server"
	// AppServerServiceName is the name of the OLS application server service
	AppServerServiceName = "lightspeed-app-server"
	// AppServerServiceHTTPSPort is the port number of the OLS application server service
	AppServerServiceHTTPSPort = 8443
	// ConsolePluginServiceName is the name of the OLS console plugin deployment
	ConsolePluginDeploymentName = "lightspeed-console-plugin"
	// ConsolePluginServiceName is the name of the OLS console plugin service
	ConsolePluginServiceName = "lightspeed-console-plugin"
	// ConsoleUIPluginName is the name of the OLS console plugin
	ConsoleUIPluginName = "lightspeed-console-plugin"
	// ConsoleUIConfigMapName is the name of the console UI nginx configmap
	ConsoleUIConfigMapName = "lightspeed-console-plugin"
	// ArtifactDir is the relative path to where the artifacts will be exported to
	ArtifactDir = "ARTIFACT_DIR"
	// serverContainerName is the name of the app-server container
	ServerContainerName = "lightspeed-service-api"
	// OLSConsolePluginServiceHTTPSPort is the port number of the OLS console plugin service
	OLSConsolePluginServiceHTTPSPort = 9443
	// AppServerConfigMapName is the name of the OLS application server config map
	AppServerConfigMapName = "olsconfig"
	// AppServerConfigMapKey is the key of config file in the OLS application server config map
	AppServerConfigMapKey = "olsconfig.yaml"
	// AppServerTLSSecretName is the name of the OLS application server TLS secret
	AppServerTLSSecretName = "lightspeed-tls" // #nosec G101
	// ConditionTimeoutEnvVar is the environment variable containing the condition check timeout in seconds
	ConditionTimeoutEnvVar = "CONDITION_TIMEOUT"

	// ServiceAnnotationKeyTLSSecret is the annotation key for TLS secret
	ServiceAnnotationKeyTLSSecret = "service.beta.openshift.io/serving-cert-secret-name"
	// TestSAName is the name of the test service account
	TestSAName = "test-sa"
	// TestSAOutsiderName is the name of the test service account for outsider tests
	TestSAOutsiderName = "test-sa-outsider"
	// QueryAccessClusterRole is the cluster role for query access
	QueryAccessClusterRole = "lightspeed-operator-query-access"
	// AppMetricsAccessClusterRole is the cluster role for app metrics access
	AppMetricsAccessClusterRole = "lightspeed-operator-ols-metrics-reader"
	// OLSRouteName is the name of the OLS route
	OLSRouteName = "ols-route"
	// InClusterHost is the in-cluster host for the lightspeed app server
	InClusterHost = "lightspeed-app-server.openshift-lightspeed.svc.cluster.local"

	// TestCACert is for testing additional CA certificate
	TestCACert = `` /* 1513-byte string literal not displayed */

	// OLSAppCertsMountRoot is the directory hosting the cert files in the container
	OLSAppCertsMountRoot = "/etc/certs"
	// AdditionalCAVolumeName is the name of the additional CA volume in the app server container
	AdditionalCAVolumeName = "additional-ca"
	// UserCACertDir is the directory for storing additional CA certificates in the app server container under OLSAppCertsMountRoot
	UserCACertDir = "ols-user-ca"
	// AdditionalCAHashKey is the key of the hash value of the additional CA certificates
	AdditionalCAHashKey = "hash/additionalca"
	// CertBundleVolumeName is the name of the volume for the certificate bundle
	CertBundleVolumeName = "cert-bundle"
	// CertBundleDir is the path of the volume for the certificate bundle
	CertBundleDir = "cert-bundle"

	// PostgresDeploymentName is the name of OLS application Postgres deployment
	PostgresDeploymentName = "lightspeed-postgres-server"
)
View Source
const DefaultPrometheusQueryTimeout = 120 * time.Second

DefaultPollInterval is the default interval for polling Prometheus metrics. Prometheus metrics are typically scraped every 30 seconds. This is enough for 3 scrapes.

View Source
const MaxLength = 1000

MaxLength is the maximum string length returned by ClampMax().

Variables

This section is empty.

Functions

func CheckErrorAndRestartPortForwardingTestEnvironment

func CheckErrorAndRestartPortForwardingTestEnvironment(env *OLSTestEnvironment, err error)

func ClampMax

func ClampMax(b []byte) string

ClampMax converts a slice of bytes to a string truncated to MaxLength.

func CleanupOLSTestEnvironmentWithCRDeletion

func CleanupOLSTestEnvironmentWithCRDeletion(env *OLSTestEnvironment, testName string) error

CleanupOLSTestEnvironmentWithCRDeletion cleans up the test environment including CR deletion

func CleanupTLSTestEnvironment

func CleanupTLSTestEnvironment(env *OLSTestEnvironment, testName string) error

CleanupTLSTestEnvironment cleans up the test environment

func CreateOLSRoute

func CreateOLSRoute(client *Client) error

CreateOLSRoute creates a route for the OLS application

func GetFirstValueFromPromQuery

func GetFirstValueFromPromQuery(body []byte) (float64, error)

GetFirstValueFromPromQuery takes a query api response body and returns the value of the first timeseries. If body contains multiple timeseries GetFirstValueFromPromQuery errors.

func GetResultSizeFromPromQuery

func GetResultSizeFromPromQuery(body []byte) (int, error)

GetResultSizeFromPromQuery takes a query api response body and returns the size of the result vector.

func Ptr

func Ptr[T any](v T) *T

func RestartPortForwardingTestEnvironment

func RestartPortForwardingTestEnvironment(env *OLSTestEnvironment) error

func TestHTTPSQueryEndpoint

func TestHTTPSQueryEndpoint(env *OLSTestEnvironment, secret *corev1.Secret, requestBody []byte) (*http.Response, []byte, error)

TestHTTPSQueryEndpoint tests HTTPS POST on /v1/query endpoint

func TestOLSServiceActivation

func TestOLSServiceActivation(env *OLSTestEnvironment) (*corev1.Secret, error)

TestOLSServiceActivation tests that TLS is properly activated on the service

func UpdateRapidastConfig

func UpdateRapidastConfig(hostURL, token string) error

UpdateRapidastConfig updates the rapidast config file with host and token

func WriteLogsToFile

func WriteLogsToFile(client *Client, clusterDir string) error

func WriteResourceToFile

func WriteResourceToFile(client *Client, clusterDir string, filename string, resource string) error

Types

type Client

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

func GetClient

func GetClient(options *ClientOptions) (*Client, error)

func (*Client) CheckErrorAndRestartPortForwardService

func (c *Client) CheckErrorAndRestartPortForwardService(err error, serviceName, namespace string, port int, forwardHost *string, cleanUpFuncs *[]func())

CheckErrorAndRestartPortForwardService checks if the error is EOF and restarts the port forwarding service Port forwarding should work on next attempt of the test case

func (*Client) Create

func (c *Client) Create(o client.Object) (err error)

func (*Client) CreateClusterRoleBinding

func (c *Client) CreateClusterRoleBinding(namespace, serviceAccount, clusterRole string) (func(), error)

func (*Client) CreateDockerRegistrySecret

func (c *Client) CreateDockerRegistrySecret(namespace, name, server, username, password, email string) (func(), error)

func (*Client) CreatePVC

func (c *Client) CreatePVC(name, storageClassName string, volumeSize resource.Quantity) (func(), error)

func (*Client) CreatePersistentVolume

func (c *Client) CreatePersistentVolume(name, storageClassName string, volumeSize resource.Quantity) (func(), error)

func (*Client) CreateServiceAccount

func (c *Client) CreateServiceAccount(namespace, serviceAccount string) (func(), error)

func (*Client) CreateStorageClass

func (c *Client) CreateStorageClass(name string) (func(), error)

func (*Client) Delete

func (c *Client) Delete(o client.Object) (err error)

func (*Client) DeleteAndWait

func (c *Client) DeleteAndWait(obj client.Object, timeout time.Duration) error

DeleteAndWait deletes an object and waits for it to be fully removed from the cluster. This ensures complete cleanup before tests proceed, preventing resource pollution from resources with owner references that trigger cascade deletion (e.g., OLSConfig CR). Returns nil if the object is already deleted (IsNotFound).

func (*Client) ForwardPort

func (c *Client) ForwardPort(serviceName, namespaceName string, port int) (string, func(), error)

func (*Client) ForwardPortToPod

func (c *Client) ForwardPortToPod(podName, namespaceName string, port int) (string, func(), error)

func (*Client) ForwardPortV1

func (c *Client) ForwardPortV1(serviceName, namespaceName string, port int) (string, func(), error)

ForwardPortV1 is the original implementation using oc command line tool, selecting running pods

func (*Client) ForwardPortV2

func (c *Client) ForwardPortV2(serviceName, namespaceName string, port int) (string, func(), error)

ForwardPortV2 is the new implementation using service and pod selector, select running but not terminating pods

func (*Client) Get

func (c *Client) Get(o client.Object) (err error)

func (*Client) GetDefaultStorageClass

func (c *Client) GetDefaultStorageClass() (*storagev1.StorageClass, error)

func (*Client) GetServiceAccountToken

func (c *Client) GetServiceAccountToken(namespace, name string) (string, error)

func (*Client) GetStorageClass

func (c *Client) GetStorageClass(name string) (*storagev1.StorageClass, error)

func (*Client) List

func (c *Client) List(o client.ObjectList, opts ...client.ListOption) (err error)

func (*Client) ShowUnavailablePodsOfDeployment

func (c *Client) ShowUnavailablePodsOfDeployment(dep *appsv1.Deployment) error

func (*Client) Update

func (c *Client) Update(obj client.Object, modifier func(client.Object) error) error

Update fetches the latest version of an object, applies modifications via the modifier function, and automatically retries on conflicts. This handles the common race condition where the operator reconciles while the test is updating the same resource.

func (*Client) UpgradeOperator

func (c *Client) UpgradeOperator(namespace string) error

func (*Client) WaitForConfigMapContainString

func (c *Client) WaitForConfigMapContainString(cm *corev1.ConfigMap, key, substr string) error

func (*Client) WaitForDeploymentCondition

func (c *Client) WaitForDeploymentCondition(dep *appsv1.Deployment, condition func(*appsv1.Deployment) (bool, error)) error

func (*Client) WaitForDeploymentRollout

func (c *Client) WaitForDeploymentRollout(dep *appsv1.Deployment) error

func (*Client) WaitForObjectCreated

func (c *Client) WaitForObjectCreated(obj client.Object) error

func (*Client) WaitForSecretCreated

func (c *Client) WaitForSecretCreated(secret *corev1.Secret) error

func (*Client) WaitForServiceCreated

func (c *Client) WaitForServiceCreated(service *corev1.Service) error

type ClientOptions

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

type HTTPSClient

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

func NewHTTPSClient

func NewHTTPSClient(host, serverName string, caCertificate, clientCert, clientKey []byte) *HTTPSClient

func (*HTTPSClient) Get

func (c *HTTPSClient) Get(queryUrl string, headers ...map[string]string) (*http.Response, error)

func (*HTTPSClient) PostJson

func (c *HTTPSClient) PostJson(queryUrl string, body []byte, headers ...map[string]string) (*http.Response, error)

type HeaderInjector

type HeaderInjector struct {
	Name  string
	Value string
}

HeaderInjector injects a fixed HTTP header into the inbound request.

func (*HeaderInjector) WrapTransport

func (h *HeaderInjector) WrapTransport(rt http.RoundTripper) http.RoundTripper

WrapTransport implements the WrapTransporter interface.

type OLSTestEnvironment

type OLSTestEnvironment struct {
	Client       *Client
	CR           *olsv1alpha1.OLSConfig
	SAToken      string
	ForwardHost  string
	CleanUpFuncs []func()
}

OLSTestEnvironment contains all the resources needed for TLS testing

func SetupOLSTestEnvironment

func SetupOLSTestEnvironment(crModifier func(*olsv1alpha1.OLSConfig), callback func(*OLSTestEnvironment) error) (*OLSTestEnvironment, error)

SetupOLSTestEnvironment sets up the common test environment for OLS tests

type PrometheusClient

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

PrometheusClient provides access to the Prometheus, Thanos & Alertmanager API.

func NewPrometheusClient

func NewPrometheusClient(host, token string, wts ...WrapTransporter) *PrometheusClient

NewPrometheusClient creates and returns a new PrometheusClient.

func NewPrometheusClientFromRoute

func NewPrometheusClientFromRoute(
	ctx context.Context,
	routeClient routev1.RouteV1Interface,
	namespace, name string,
	token string,
) (*PrometheusClient, error)

NewPrometheusClientFromRoute creates and returns a new PrometheusClient from the given OpenShift route.

func (*PrometheusClient) Do

func (c *PrometheusClient) Do(method string, path string, body []byte) (*http.Response, error)

Do sends an HTTP request to the remote endpoint and returns the response.

func (*PrometheusClient) PrometheusLabel

func (c *PrometheusClient) PrometheusLabel(label string) ([]byte, error)

PrometheusLabel runs an HTTP GET request against the Prometheus label API and returns the response body.

func (*PrometheusClient) PrometheusQuery

func (c *PrometheusClient) PrometheusQuery(query string) ([]byte, error)

PrometheusQuery runs an HTTP GET request against the Prometheus query API and returns the response body.

func (*PrometheusClient) PrometheusQueryWithStatus

func (c *PrometheusClient) PrometheusQueryWithStatus(query string, status int) ([]byte, error)

func (*PrometheusClient) PrometheusTargets

func (c *PrometheusClient) PrometheusTargets() ([]byte, error)

PrometheusTargets runs an HTTP GET request against the Prometheus targets API and returns the response body.

func (*PrometheusClient) WaitForQueryReturn

func (c *PrometheusClient) WaitForQueryReturn(query string, timeout time.Duration, validate func(float64) error) error

WaitForQueryReturn waits for a given PromQL query for a given time interval and validates the **first and only** result with the given validate function.

func (*PrometheusClient) WaitForQueryReturnEmpty

func (c *PrometheusClient) WaitForQueryReturnEmpty(query string, timeout time.Duration) error

WaitForQueryReturnEmpty waits for a given PromQL query return an empty response for a given time interval

func (*PrometheusClient) WaitForQueryReturnGreaterEqualOne

func (c *PrometheusClient) WaitForQueryReturnGreaterEqualOne(query string, timeout time.Duration) error

WaitForQueryReturnGreaterEqualOne see WaitForQueryReturn.

func (*PrometheusClient) WaitForQueryReturnOne

func (c *PrometheusClient) WaitForQueryReturnOne(query string, timeout time.Duration) error

WaitForQueryReturnOne see WaitForQueryReturn.

type QueryParameterInjector

type QueryParameterInjector struct {
	Name  string
	Value string
}

QueryParameterInjector injects a fixed query parameter into the inbound request. It is typically used when querying kube-rbac-proxy.

func (*QueryParameterInjector) WrapTransport

WrapTransport implements the WrapTransporter interface.

type WrapTransporter

type WrapTransporter interface {
	WrapTransport(rt http.RoundTripper) http.RoundTripper
}

WrapTransporter wraps an http.RoundTripper with another.

Jump to

Keyboard shortcuts

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