Documentation
¶
Overview ¶
Package framework provides utilities for integration testing.
Package framework provides utilities for integration testing.
Package framework provides utilities for integration testing.
Index ¶
- Variables
- func BeValidIncident() types.GomegaMatcher
- func GetEnvBool(key string, defaultVal bool) bool
- func GetEnvInt(key string, defaultVal int) int
- func RenderTemplate(tmplStr string, data any) (string, error)
- type Alert
- type Cluster
- func (c *Cluster) AllReplicasUpdated(ctx context.Context, name string) (bool, error)
- func (c *Cluster) Apply(ctx context.Context, yamlContent string) error
- func (c *Cluster) AreContainersReady(ctx context.Context, selector string) (bool, error)
- func (c *Cluster) ArePodsRunning(ctx context.Context, selector string) (bool, error)
- func (c *Cluster) Delete(ctx context.Context, resourceType, name string) error
- func (c *Cluster) DeleteByLabel(ctx context.Context, resourceType, labelSelector string) error
- func (c *Cluster) GetDeploymentArgs(ctx context.Context, deploymentName string, containerIndex int) ([]string, error)
- func (c *Cluster) GetLogs(ctx context.Context, resourceRef string, tailLines int) (string, error)
- func (c *Cluster) GetPodStatus(ctx context.Context, selector string) (string, error)
- func (c *Cluster) GetSelector(ctx context.Context, resourceType, name string) (string, error)
- func (c *Cluster) HasPods(ctx context.Context, selector string) (bool, error)
- func (c *Cluster) HasUnavailableReplicas(ctx context.Context, name string) (bool, error)
- func (c *Cluster) InNamespace(namespace string) *Cluster
- func (c *Cluster) IsDeploymentAvailable(ctx context.Context, name string) (bool, error)
- func (c *Cluster) IsGone(ctx context.Context, resourceType, name string) (bool, error)
- func (c *Cluster) IsGoneByLabel(ctx context.Context, resourceType, labelSelector string) (bool, error)
- func (c *Cluster) IsPodCrashLooping(ctx context.Context, selector string) (bool, error)
- func (c *Cluster) PortForward(ctx context.Context, resourceRef string, remotePort int) (localPort int, cancel func(), err error)
- func (c *Cluster) SetDeploymentArgs(ctx context.Context, deploymentName string, containerIndex int, args []string) error
- func (c *Cluster) WaitForRollout(ctx context.Context, deploymentName string) error
- type Config
- type Incident
- type PrometheusClient
Constants ¶
This section is empty.
Variables ¶
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).
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 ¶
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).
Types ¶
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
Cluster provides an interface for interacting with a Kubernetes/OpenShift cluster.
func NewCluster ¶
NewCluster creates a new Cluster with the given default namespace.
func (*Cluster) AllReplicasUpdated ¶
AllReplicasUpdated checks whether all replicas have been updated to the latest pod template.
func (*Cluster) AreContainersReady ¶
AreContainersReady checks if all containers in pods matching the selector are ready.
func (*Cluster) ArePodsRunning ¶
ArePodsRunning checks if all pods matching the selector are running.
func (*Cluster) DeleteByLabel ¶
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) GetPodStatus ¶
GetPodStatus returns a human-readable status of pods matching the selector.
func (*Cluster) GetSelector ¶
GetSelector returns the label selector for a resource (deployment, statefulset, etc).
func (*Cluster) HasUnavailableReplicas ¶
HasUnavailableReplicas checks if a deployment has any unavailable replicas.
func (*Cluster) InNamespace ¶
InNamespace returns a new Cluster with a different default namespace.
func (*Cluster) IsDeploymentAvailable ¶
IsDeploymentAvailable checks if a deployment is available.
func (*Cluster) IsGone ¶
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 ¶
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.
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.
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().