framework

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package framework provides utilities for integration testing.

Package framework provides utilities for integration testing.

Package framework provides utilities for integration testing.

Index

Constants

This section is empty.

Variables

View Source
var ValidComponents = map[string]struct{}{

	"compute": {},

	"etcd":                          {},
	"kube-apiserver":                {},
	"kube-controller-manager":       {},
	"kube-scheduler":                {},
	"machine-approver":              {},
	"machine-config":                {},
	"version":                       {},
	"dns":                           {},
	"authentication":                {},
	"cert-manager":                  {},
	"cloud-controller-manager":      {},
	"cloud-credential":              {},
	"cluster-api":                   {},
	"config-operator":               {},
	"kube-storage-version-migrator": {},
	"image-registry":                {},
	"ingress":                       {},
	"console":                       {},
	"insights":                      {},
	"machine-api":                   {},
	"monitoring":                    {},
	"network":                       {},
	"node-tuning":                   {},
	"openshift-apiserver":           {},
	"openshift-controller-manager":  {},
	"openshift-samples":             {},
	"operator-lifecycle-manager":    {},
	"service-ca":                    {},
	"storage":                       {},
	"vertical-pod-autoscaler":       {},
	"marketplace":                   {},

	"openshift-compliance":               {},
	"openshift-file-integrity":           {},
	"openshift-logging":                  {},
	"openshift-user-workload-monitoring": {},
	"openshift-gitops":                   {},
	"openshift-operators":                {},
	"kubevirt":                           {},
	"openshift-local-storage":            {},
	"quay":                               {},
	"Argo":                               {},
}

ValidComponents contains all valid OpenShift component values. IMPORTANT: Keep in sync with pkg/processor/mappings.go (coreMatchers and workloadMatchers).

View Source
var ValidLayers = map[string]struct{}{
	"compute":  {},
	"core":     {},
	"workload": {},
}

ValidLayers contains all valid OpenShift layer values. IMPORTANT: Keep in sync with pkg/processor/alerts.go layer definitions.

Functions

func BeValidIncident

func BeValidIncident() types.GomegaMatcher

BeValidIncident returns a Gomega matcher that verifies an Incident has all required labels. Required labels: src_alertname, src_severity, src_namespace, component, layer, group_id All required labels must have non-empty values. Additionally, component and layer must be valid OpenShift values.

func GetEnvBool

func GetEnvBool(key string, defaultVal bool) bool

GetEnvBool returns the boolean value of an environment variable, or the default value if not set. Accepts "true", "1", "yes" as true values (case-insensitive).

func GetEnvInt

func GetEnvInt(key string, defaultVal int) int

GetEnvInt returns the integer value of an environment variable, or the default value if not set or invalid.

func RenderTemplate

func RenderTemplate(tmplStr string, data any) (string, error)

RenderTemplate executes a Go text/template with the given data and returns the result. The template string should use standard Go template syntax (e.g. {{ .FieldName }}).

Types

type Alert

type Alert struct {
	Labels map[string]string
}

Alert represents a Prometheus alert.

type Cluster

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

Cluster provides an interface for interacting with a Kubernetes/OpenShift cluster.

func NewCluster

func NewCluster(namespace string) *Cluster

NewCluster creates a new Cluster with the given default namespace.

func (*Cluster) AllReplicasUpdated

func (c *Cluster) AllReplicasUpdated(ctx context.Context, name string) (bool, error)

AllReplicasUpdated checks whether all replicas have been updated to the latest pod template.

func (*Cluster) Apply

func (c *Cluster) Apply(ctx context.Context, yamlContent string) error

Apply applies YAML content to the cluster via stdin.

func (*Cluster) AreContainersReady

func (c *Cluster) AreContainersReady(ctx context.Context, selector string) (bool, error)

AreContainersReady checks if all containers in pods matching the selector are ready.

func (*Cluster) ArePodsRunning

func (c *Cluster) ArePodsRunning(ctx context.Context, selector string) (bool, error)

ArePodsRunning checks if all pods matching the selector are running.

func (*Cluster) Delete

func (c *Cluster) Delete(ctx context.Context, resourceType, name string) error

Delete removes a specific resource by type and name.

func (*Cluster) DeleteByLabel

func (c *Cluster) DeleteByLabel(ctx context.Context, resourceType, labelSelector string) error

DeleteByLabel removes all resources of a type matching the label selector.

func (*Cluster) GetDeploymentArgs

func (c *Cluster) GetDeploymentArgs(ctx context.Context, deploymentName string, containerIndex int) ([]string, error)

GetDeploymentArgs returns the args of the container at containerIndex in the deployment.

func (*Cluster) GetLogs

func (c *Cluster) GetLogs(ctx context.Context, resourceRef string, tailLines int) (string, error)

GetLogs retrieves logs from a resource (e.g., "deployment/my-app").

func (*Cluster) GetPodStatus

func (c *Cluster) GetPodStatus(ctx context.Context, selector string) (string, error)

GetPodStatus returns a human-readable status of pods matching the selector.

func (*Cluster) GetSelector

func (c *Cluster) GetSelector(ctx context.Context, resourceType, name string) (string, error)

GetSelector returns the label selector for a resource (deployment, statefulset, etc).

func (*Cluster) HasPods

func (c *Cluster) HasPods(ctx context.Context, selector string) (bool, error)

HasPods checks if any pods exist matching the selector.

func (*Cluster) HasUnavailableReplicas

func (c *Cluster) HasUnavailableReplicas(ctx context.Context, name string) (bool, error)

HasUnavailableReplicas checks if a deployment has any unavailable replicas.

func (*Cluster) InNamespace

func (c *Cluster) InNamespace(namespace string) *Cluster

InNamespace returns a new Cluster with a different default namespace.

func (*Cluster) IsDeploymentAvailable

func (c *Cluster) IsDeploymentAvailable(ctx context.Context, name string) (bool, error)

IsDeploymentAvailable checks if a deployment is available.

func (*Cluster) IsGone

func (c *Cluster) IsGone(ctx context.Context, resourceType, name string) (bool, error)

IsGone checks if a resource no longer exists. Use this with Eventually to wait for deletion to complete.

func (*Cluster) IsGoneByLabel

func (c *Cluster) IsGoneByLabel(ctx context.Context, resourceType, labelSelector string) (bool, error)

IsGoneByLabel checks if all resources matching the label selector have been deleted. Use this with Eventually to wait for label-based deletion to complete.

func (*Cluster) IsPodCrashLooping

func (c *Cluster) IsPodCrashLooping(ctx context.Context, selector string) (bool, error)

IsPodCrashLooping checks if any pod matching the selector is in CrashLoopBackOff.

func (*Cluster) PortForward

func (c *Cluster) PortForward(ctx context.Context, resourceRef string, remotePort int) (localPort int, cancel func(), err error)

PortForward starts a port-forward to the given resource (e.g. "svc/my-service") and remote port. It returns the local port assigned by the OS and a cancel function that stops the port-forward. The caller must call cancel when done.

func (*Cluster) SetDeploymentArgs

func (c *Cluster) SetDeploymentArgs(ctx context.Context, deploymentName string, containerIndex int, args []string) error

SetDeploymentArgs replaces the args of the container at containerIndex in the deployment.

func (*Cluster) WaitForRollout

func (c *Cluster) WaitForRollout(ctx context.Context, deploymentName string) error

WaitForRollout waits for the deployment to finish rolling out. It fails fast if any pod enters CrashLoopBackOff rather than waiting for the full timeout.

type Config

type Config struct {
	// Image is the container image expected to be deployed
	Image string

	// ManifestsPath is the path to the manifest files
	ManifestsPath string

	// DeploymentName is the name of the deployment to verify
	DeploymentName string

	// Namespace is the Kubernetes namespace where the deployment lives
	Namespace string

	// Kubeconfig is the path to the kubeconfig file (optional, uses default if empty)
	Kubeconfig string

	// ThanosURL is the URL for querying Thanos/Prometheus
	ThanosURL string

	// ThanosToken is the bearer token for Thanos authentication (optional)
	ThanosToken string
}

Config holds the configuration for integration tests. Values are loaded from environment variables with sensible defaults.

func LoadConfig

func LoadConfig() *Config

LoadConfig creates a Config from environment variables.

type Incident

type Incident struct {
	Labels map[string]string
}

Incident represents a processed incident from cluster_health_components_map.

type PrometheusClient

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

PrometheusClient wraps the existing prom.Loader for integration testing.

func NewPrometheusClient

func NewPrometheusClient(prometheusURL, token string) (*PrometheusClient, error)

NewPrometheusClient creates a client for querying Thanos/Prometheus. Reuses the existing pkg/prom infrastructure.

func (*PrometheusClient) GetAlerts

func (p *PrometheusClient) GetAlerts(ctx context.Context, alertnamePattern string, queryTime time.Time) ([]*Alert, error)

GetAlerts returns all firing alerts matching the alertname pattern. Pattern can be exact ("MyAlert") or regex ("MyAlert.*"). If queryTime is zero, uses time.Now().

func (*PrometheusClient) GetIncidents

func (p *PrometheusClient) GetIncidents(ctx context.Context, alertnamePattern string, queryTime time.Time) ([]*Incident, error)

GetIncidents returns all incidents matching the alertname pattern. Pattern can be exact ("MyAlert") or regex ("MyAlert.*"). If queryTime is zero, uses time.Now().

Jump to

Keyboard shortcuts

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