Documentation
¶
Overview ¶
Package utils provides debugging utilities for SBD node mapping and device inspection
Usage Examples:
// Print node mapping to stdout
err := testClients.NodeMapSummary("sbd-agent-pod-name", "sbd-system", "")
// Save node mapping to file
err := testClients.NodeMapSummary("sbd-agent-pod-name", "sbd-system", "node-mapping.txt")
// Print SBD device info to stdout
err := testClients.SBDDeviceSummary("sbd-agent-pod-name", "sbd-system", "")
// Save SBD device info to file
err := testClients.SBDDeviceSummary("sbd-agent-pod-name", "sbd-system", "sbd-device.txt")
Index ¶
- Constants
- func CheckClusterConnection() error
- func CleanupSBDConfigs(testNamespace *TestNamespace)
- func DescribeEnvironment(testClients *TestClients, testNamespace *TestNamespace)
- func GetAWSInstanceIDForNode(tc *TestClients, nodeName string) (string, error)
- func GetAgentImage() string
- func GetNonEmptyLines(output string) []string
- func GetProjectDir() (string, error)
- func GetProjectImage() string
- func InstallCertManager() error
- func InstallPrometheusOperator() error
- func IsCRCEnvironment() bool
- func IsCertManagerCRDsInstalled() bool
- func IsPrometheusCRDsInstalled() bool
- func LoadImageToCRCCluster(name string) error
- func LoadImageToCluster(name string) error
- func LoadImageToKindClusterWithName(name string) error
- func NewFakeClient(tb testing.TB) rtclient.Client
- func PrintFenceDevice(slots []SBDNodeSummary)
- func PrintNodeMap(nodeMapTable *sbdprotocol.NodeMapTable)
- func PrintSBDDevice(slots []SBDNodeSummary)
- func RebootAWSInstanceForNode(tc *TestClients, nodeName string) error
- func Run(cmd *exec.Cmd) (string, error)
- func SaveFenceDeviceToFile(slots []SBDNodeSummary, filename string) error
- func SaveNodeMapToFile(nodeMapTable *sbdprotocol.NodeMapTable, filename string) error
- func SaveSBDDeviceToFile(slots []SBDNodeSummary, filename string) error
- func UncommentCode(filename, target, prefix string) error
- func UninstallCertManager()
- func UninstallPrometheusOperator()
- func WaitForNodesReady(testNamespace *TestNamespace, timeout, interval string, attemptReboot bool)
- type DaemonSetChecker
- type DebugCollector
- func (dc *DebugCollector) CollectAgentLogs(namespace string)
- func (dc *DebugCollector) CollectControllerLogs(namespace, podName string)
- func (dc *DebugCollector) CollectKubernetesEvents(namespace string)
- func (dc *DebugCollector) CollectPodDescription(namespace, podName string)
- func (dc *DebugCollector) CollectPodLogs(namespace, podName, containerName string)
- func (dc *DebugCollector) CollectSBDConfigs(namespace string)
- func (dc *DebugCollector) CollectSBDRemediations(namespace string)
- func (dc *DebugCollector) CollectStorageJobs(namespace string)
- type NodeBootInfo
- type NodeStabilityChecker
- type PodStatusChecker
- func (psc *PodStatusChecker) CheckPodRestarts() (bool, []string)
- func (psc *PodStatusChecker) GetFirstPod() (*corev1.Pod, error)
- func (psc *PodStatusChecker) GetPodLogs(podName string, tailLines *int64) (string, error)
- func (psc *PodStatusChecker) WaitForPodsReady(minCount int, timeout time.Duration) error
- func (psc *PodStatusChecker) WaitForPodsRunning(minCount int, timeout time.Duration) error
- type ResourceCleaner
- type SBDAgentValidator
- type SBDNodeSummary
- type ServiceAccountTokenGenerator
- type TestAgentOptions
- type TestClients
- func (tc *TestClients) CreateTestNamespace(namespace string) (*TestNamespace, error)
- func (tc *TestClients) FenceDeviceSummary(podName, namespace, outputFile string) error
- func (tc *TestClients) GetFenceDeviceInfoFromPod(podName, namespace string) ([]SBDNodeSummary, error)
- func (tc *TestClients) GetNodeMapFromPod(podName, namespace string) (*sbdprotocol.NodeMapTable, error)
- func (tc *TestClients) GetSBDDeviceInfoFromPod(podName, namespace string) ([]SBDNodeSummary, error)
- func (tc *TestClients) NewDebugCollector(artifactsDir string) *DebugCollector
- func (tc *TestClients) NewNodeStabilityChecker() *NodeStabilityChecker
- func (tc *TestClients) NewServiceAccountTokenGenerator() *ServiceAccountTokenGenerator
- func (tc *TestClients) NodeMapSummary(podName, namespace, outputFile string) error
- func (tc *TestClients) SBDDeviceSummary(podName, namespace, outputFile string) error
- func (tc *TestClients) ValidateStorageConfiguration(podName, namespace string) error
- type TestFlags
- type TestNamespace
- func (tn *TestNamespace) Cleanup() error
- func (tn *TestNamespace) CleanupSBDConfig(sbdConfig *medik8sv1alpha1.SBDConfig) error
- func (tn *TestNamespace) CreateSBDConfig(name string, options ...func(*medik8sv1alpha1.SBDConfig)) (*medik8sv1alpha1.SBDConfig, error)
- func (tn *TestNamespace) NewDaemonSetChecker() *DaemonSetChecker
- func (tn *TestNamespace) NewPodStatusChecker(labels map[string]string) *PodStatusChecker
- func (tn *TestNamespace) NewSBDAgentValidator() *SBDAgentValidator
- func (tn *TestNamespace) OperatorNamespace() *TestNamespace
- func (tn *TestNamespace) PodLogsContain(expectedLogs []string) (bool, error)
- type ValidateAgentDeploymentOptions
Constants ¶
const (
// Default operator namespace
OperatorNamespaceName = "sbd-operator-system"
)
Variables ¶
This section is empty.
Functions ¶
func CheckClusterConnection ¶
func CheckClusterConnection() error
func CleanupSBDConfigs ¶
func CleanupSBDConfigs(testNamespace *TestNamespace)
func DescribeEnvironment ¶
func DescribeEnvironment(testClients *TestClients, testNamespace *TestNamespace)
func GetAWSInstanceIDForNode ¶
func GetAWSInstanceIDForNode(tc *TestClients, nodeName string) (string, error)
GetAWSInstanceIDForNode finds the AWS EC2 instance ID for a given Kubernetes node name
func GetAgentImage ¶
func GetAgentImage() string
getAgentImage returns the agent image name based on environment variables. It uses the same pattern as the Makefile QUAY_* variables, with sensible defaults for local testing.
func GetNonEmptyLines ¶
GetNonEmptyLines converts given command output string into individual objects according to line breakers, and ignores the empty elements in it.
func GetProjectDir ¶
GetProjectDir will return the directory where the project is
func GetProjectImage ¶
func GetProjectImage() string
getProjectImage returns the project image name based on environment variables. It uses the same pattern as the Makefile QUAY_* variables, with sensible defaults for local testing.
func InstallCertManager ¶
func InstallCertManager() error
InstallCertManager installs the cert manager bundle.
func InstallPrometheusOperator ¶
func InstallPrometheusOperator() error
InstallPrometheusOperator installs the prometheus Operator to be used to export the enabled metrics.
func IsCRCEnvironment ¶
func IsCRCEnvironment() bool
IsCRCEnvironment detects if we're in a CRC environment
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.
func IsPrometheusCRDsInstalled ¶
func IsPrometheusCRDsInstalled() bool
IsPrometheusCRDsInstalled checks if any Prometheus CRDs are installed by verifying the existence of key CRDs related to Prometheus.
func LoadImageToCRCCluster ¶
LoadImageToCRCCluster loads a local docker image to the CRC OpenShift cluster
func LoadImageToCluster ¶
LoadImageToCluster loads an image to the appropriate cluster (Kind or CRC)
func LoadImageToKindClusterWithName ¶
LoadImageToKindClusterWithName loads a local docker image to the kind cluster
func NewFakeClient ¶
NewFakeClient creates a minimal fake controller-runtime client for tests
func PrintFenceDevice ¶
func PrintFenceDevice(slots []SBDNodeSummary)
PrintFenceDevice prints the fence device summary to stdout
func PrintNodeMap ¶
func PrintNodeMap(nodeMapTable *sbdprotocol.NodeMapTable)
PrintNodeMap prints the node mapping summary to stdout
func PrintSBDDevice ¶
func PrintSBDDevice(slots []SBDNodeSummary)
PrintSBDDevice prints the SBD device summary to stdout
func RebootAWSInstanceForNode ¶
func RebootAWSInstanceForNode(tc *TestClients, nodeName string) error
RebootAWSInstanceForNode finds and reboots the AWS EC2 instance for a given Kubernetes node name
func SaveFenceDeviceToFile ¶
func SaveFenceDeviceToFile(slots []SBDNodeSummary, filename string) error
SaveFenceDeviceToFile saves the fence device summary to a file
func SaveNodeMapToFile ¶
func SaveNodeMapToFile(nodeMapTable *sbdprotocol.NodeMapTable, filename string) error
SaveNodeMapToFile saves the node mapping summary to a file
func SaveSBDDeviceToFile ¶
func SaveSBDDeviceToFile(slots []SBDNodeSummary, filename string) error
SaveSBDDeviceToFile saves SBD device slots to a file for debugging
func UncommentCode ¶
UncommentCode searches for target in the file and remove the comment prefix of the target content. The target content may span multiple lines.
func UninstallCertManager ¶
func UninstallCertManager()
UninstallCertManager uninstalls the cert manager
func UninstallPrometheusOperator ¶
func UninstallPrometheusOperator()
UninstallPrometheusOperator uninstalls the prometheus
func WaitForNodesReady ¶
func WaitForNodesReady(testNamespace *TestNamespace, timeout, interval string, attemptReboot bool)
Types ¶
type DaemonSetChecker ¶
type DaemonSetChecker struct {
Clients *TestClients
Namespace string
}
DaemonSetChecker provides utilities for checking DaemonSet status
func (*DaemonSetChecker) CheckDaemonSetArgs ¶
func (dsc *DaemonSetChecker) CheckDaemonSetArgs(ds *appsv1.DaemonSet, expectedArgs []string) error
CheckDaemonSetArgs verifies that a DaemonSet container has expected arguments
func (*DaemonSetChecker) WaitForDaemonSet ¶
func (dsc *DaemonSetChecker) WaitForDaemonSet(labels map[string]string, timeout time.Duration) (*appsv1.DaemonSet, error)
WaitForDaemonSet waits for a DaemonSet to be created and returns it
type DebugCollector ¶
type DebugCollector struct {
Clients *TestClients
ArtifactsDir string
}
DebugCollector provides utilities for collecting debug information
func (*DebugCollector) CollectAgentLogs ¶
func (dc *DebugCollector) CollectAgentLogs(namespace string)
CollectAgentLogs collects logs from all SBD agent pods
func (*DebugCollector) CollectControllerLogs ¶
func (dc *DebugCollector) CollectControllerLogs(namespace, podName string)
CollectControllerLogs collects logs from the controller manager pod
func (*DebugCollector) CollectKubernetesEvents ¶
func (dc *DebugCollector) CollectKubernetesEvents(namespace string)
CollectKubernetesEvents collects Kubernetes events from a namespace
func (*DebugCollector) CollectPodDescription ¶
func (dc *DebugCollector) CollectPodDescription(namespace, podName string)
CollectPodDescription collects and prints pod description
func (*DebugCollector) CollectPodLogs ¶
func (dc *DebugCollector) CollectPodLogs(namespace, podName, containerName string)
CollectPodLogs collects logs from a specific pod container
func (*DebugCollector) CollectSBDConfigs ¶
func (dc *DebugCollector) CollectSBDConfigs(namespace string)
CollectSBDConfigs collects SBDConfig CRs
func (*DebugCollector) CollectSBDRemediations ¶
func (dc *DebugCollector) CollectSBDRemediations(namespace string)
CollectSBDRemediations collects StorageBasedRemediation CRs
func (*DebugCollector) CollectStorageJobs ¶
func (dc *DebugCollector) CollectStorageJobs(namespace string)
CollectStorageJobs collects SBD device initialization jobs for debugging
type NodeBootInfo ¶
type NodeBootInfo struct {
BootID string
KernelVersion string
KubeletVersion string
StartTime metav1.Time
}
NodeBootInfo stores information to detect node reboots
type NodeStabilityChecker ¶
type NodeStabilityChecker struct {
Clients *TestClients
// contains filtered or unexported fields
}
NodeStabilityChecker provides utilities for checking node stability and reboot detection
func (*NodeStabilityChecker) CheckForNodeReboots ¶
func (nsc *NodeStabilityChecker) CheckForNodeReboots() (bool, []string, error)
CheckForNodeReboots checks if any nodes have rebooted since initial capture
func (*NodeStabilityChecker) WaitForNoReboots ¶
func (nsc *NodeStabilityChecker) WaitForNoReboots(duration time.Duration) error
WaitForNoReboots specifically waits and ensures no node reboots occur
func (*NodeStabilityChecker) WaitForNodesStable ¶
func (nsc *NodeStabilityChecker) WaitForNodesStable(duration time.Duration) error
WaitForNodesStable waits for all nodes to remain stable (Ready) and ensures no reboots occur
type PodStatusChecker ¶
type PodStatusChecker struct {
Clients *TestClients
Namespace string
Labels map[string]string
}
PodStatusChecker provides utilities for checking pod status
func (*PodStatusChecker) CheckPodRestarts ¶
func (psc *PodStatusChecker) CheckPodRestarts() (bool, []string)
CheckPodRestarts checks if any pods have been restarted and returns details
func (*PodStatusChecker) GetFirstPod ¶
func (psc *PodStatusChecker) GetFirstPod() (*corev1.Pod, error)
GetFirstPod returns the first pod matching the labels
func (*PodStatusChecker) GetPodLogs ¶
func (psc *PodStatusChecker) GetPodLogs(podName string, tailLines *int64) (string, error)
GetPodLogs retrieves logs from a pod
func (*PodStatusChecker) WaitForPodsReady ¶
func (psc *PodStatusChecker) WaitForPodsReady(minCount int, timeout time.Duration) error
WaitForPodsReady waits for pods matching the labels to become ready
func (*PodStatusChecker) WaitForPodsRunning ¶
func (psc *PodStatusChecker) WaitForPodsRunning(minCount int, timeout time.Duration) error
WaitForPodsRunning waits for pods to be in Running state (not necessarily ready)
type ResourceCleaner ¶
type ResourceCleaner struct {
Clients *TestClients
}
ResourceCleaner provides utilities for cleaning up test resources
type SBDAgentValidator ¶
type SBDAgentValidator struct {
TestNS *TestNamespace
Clients *TestClients
}
SBDAgentValidator provides comprehensive validation for SBD agent deployments
func (*SBDAgentValidator) ValidateAgentDeployment ¶
func (sav *SBDAgentValidator) ValidateAgentDeployment(opts ValidateAgentDeploymentOptions) error
ValidateAgentDeployment performs comprehensive validation of SBD agent deployment
func (*SBDAgentValidator) ValidateNoNodeReboots ¶
func (sav *SBDAgentValidator) ValidateNoNodeReboots(opts ValidateAgentDeploymentOptions) error
ValidateNoNodeReboots performs focused validation to ensure SBD agents don't cause node reboots
type SBDNodeSummary ¶
type SBDNodeSummary struct {
NodeID uint16
Timestamp time.Time
Sequence uint64
Type string
HasData bool
}
SBDNodeSummary represents a summary of SBD node information for display purposes
type ServiceAccountTokenGenerator ¶
type ServiceAccountTokenGenerator struct {
Clients *TestClients
}
ServiceAccountTokenGenerator provides utilities for generating service account tokens
func (*ServiceAccountTokenGenerator) GenerateToken ¶
func (satg *ServiceAccountTokenGenerator) GenerateToken(namespace, serviceAccountName string) (string, error)
GenerateToken generates a token for the specified service account
type TestAgentOptions ¶
type TestAgentOptions struct {
NodeName string
MetricsPort int
FileLockingEnabled bool
PetInterval time.Duration
HeartbeatInterval time.Duration
PeerCheckInterval time.Duration
WatchdogTimeout time.Duration
SBDTimeoutSeconds int
RebootMethod string
SyncInterval time.Duration
K8sClient rtclient.Client
Logger logr.Logger
}
TestAgentOptions contains options for creating test SBD agents
func DefaultTestAgentOptions ¶
func DefaultTestAgentOptions() TestAgentOptions
DefaultTestAgentOptions returns default options for test SBD agents
type TestClients ¶
type TestClients struct {
Client client.Client
Clientset *kubernetes.Clientset
Config *rest.Config
Context context.Context
Ec2Client *ec2.EC2
AWSInitialized bool
}
TestClients holds the Kubernetes clients used for testing
func SetupKubernetesClients ¶
func SetupKubernetesClients() (*TestClients, error)
SetupKubernetesClients initializes Kubernetes clients for testing
func (*TestClients) CreateTestNamespace ¶
func (tc *TestClients) CreateTestNamespace(namespace string) (*TestNamespace, error)
CreateTestNamespace creates a test namespace and returns a cleanup function
func (*TestClients) FenceDeviceSummary ¶
func (tc *TestClients) FenceDeviceSummary(podName, namespace, outputFile string) error
FenceDeviceSummary gets fence device info from a pod and either prints or saves it
func (*TestClients) GetFenceDeviceInfoFromPod ¶
func (tc *TestClients) GetFenceDeviceInfoFromPod(podName, namespace string) ([]SBDNodeSummary, error)
GetFenceDeviceInfoFromPod extracts fence device information from an SBD agent pod
func (*TestClients) GetNodeMapFromPod ¶
func (tc *TestClients) GetNodeMapFromPod(podName, namespace string) (*sbdprotocol.NodeMapTable, error)
GetNodeMapFromPod extracts the current node mapping from an SBD agent pod
func (*TestClients) GetSBDDeviceInfoFromPod ¶
func (tc *TestClients) GetSBDDeviceInfoFromPod(podName, namespace string) ([]SBDNodeSummary, error)
GetSBDDeviceInfoFromPod extracts SBD device information from an SBD agent pod
func (*TestClients) NewDebugCollector ¶
func (tc *TestClients) NewDebugCollector(artifactsDir string) *DebugCollector
NewDebugCollector creates a new DebugCollector
func (*TestClients) NewNodeStabilityChecker ¶
func (tc *TestClients) NewNodeStabilityChecker() *NodeStabilityChecker
NewNodeStabilityChecker creates a new node stability checker
func (*TestClients) NewServiceAccountTokenGenerator ¶
func (tc *TestClients) NewServiceAccountTokenGenerator() *ServiceAccountTokenGenerator
NewServiceAccountTokenGenerator creates a new token generator
func (*TestClients) NodeMapSummary ¶
func (tc *TestClients) NodeMapSummary(podName, namespace, outputFile string) error
NodeMapSummary gets node mapping from a pod and either prints or saves it
func (*TestClients) SBDDeviceSummary ¶
func (tc *TestClients) SBDDeviceSummary(podName, namespace, outputFile string) error
SBDDeviceSummary gets SBD device info from a pod and either prints or saves it
func (*TestClients) ValidateStorageConfiguration ¶
func (tc *TestClients) ValidateStorageConfiguration(podName, namespace string) error
ValidateStorageConfiguration validates that storage is properly configured for SBD
type TestFlags ¶
type TestFlags struct {
DebugMode bool
NodeSelector string
KeepResources bool
ArtifactsDir string
TestID string
AWSRegion string
}
TestFlags provides access to parsed command line flags
type TestNamespace ¶
type TestNamespace struct {
Name string
ArtifactsDir string
Clients *TestClients
}
TestNamespace represents a test namespace with cleanup functionality
func SuiteSetup ¶
func SuiteSetup(prefix string) (*TestNamespace, error)
func (*TestNamespace) Cleanup ¶
func (tn *TestNamespace) Cleanup() error
Cleanup removes the test namespace and all its resources
func (*TestNamespace) CleanupSBDConfig ¶
func (tn *TestNamespace) CleanupSBDConfig(sbdConfig *medik8sv1alpha1.SBDConfig) error
CleanupSBDConfig deletes an SBDConfig and waits for cleanup to complete
func (*TestNamespace) CreateSBDConfig ¶
func (tn *TestNamespace) CreateSBDConfig(name string, options ...func(*medik8sv1alpha1.SBDConfig)) (*medik8sv1alpha1.SBDConfig, error)
CreateSBDConfig creates a test SBDConfig with common defaults
func (*TestNamespace) NewDaemonSetChecker ¶
func (tn *TestNamespace) NewDaemonSetChecker() *DaemonSetChecker
NewDaemonSetChecker creates a new DaemonSet checker
func (*TestNamespace) NewPodStatusChecker ¶
func (tn *TestNamespace) NewPodStatusChecker(labels map[string]string) *PodStatusChecker
NewPodStatusChecker creates a new PodStatusChecker for monitoring pods
func (*TestNamespace) NewSBDAgentValidator ¶
func (tn *TestNamespace) NewSBDAgentValidator() *SBDAgentValidator
NewSBDAgentValidator creates a new SBD agent validator
func (*TestNamespace) OperatorNamespace ¶
func (tn *TestNamespace) OperatorNamespace() *TestNamespace
func (*TestNamespace) PodLogsContain ¶
func (tn *TestNamespace) PodLogsContain(expectedLogs []string) (bool, error)
type ValidateAgentDeploymentOptions ¶
type ValidateAgentDeploymentOptions struct {
SBDConfigName string
ExpectedArgs []string
MinReadyPods int
DaemonSetTimeout time.Duration
PodReadyTimeout time.Duration
NodeStableTime time.Duration
LogCheckTimeout time.Duration
}
ValidateAgentDeploymentOptions configures the validation behavior
func DefaultValidateAgentDeploymentOptions ¶
func DefaultValidateAgentDeploymentOptions(sbdConfigName string) ValidateAgentDeploymentOptions
DefaultValidateAgentDeploymentOptions returns sensible defaults for validation