Documentation
¶
Overview ¶
Package services provides etcd utilities: error classification, retry detection, and learner state handling.
Package services provides hypervisor utilities: configuration validation, SSH connectivity checks, and virsh availability verification.
Package services provides virsh/libvirt utilities: VM lifecycle, inspection, network config, and recreation via SSH.
Package services provides Pacemaker utilities: cluster status, etcd resource management, STONITH control, and job handling via SSH.
Package services provides taint/untaint utilities for TNF (Two Node with Fencing) fencing alert validation.
Index ¶
- Constants
- Variables
- func CrmDeleteAttributeViaDebug(oc *exutil.CLI, nodeName string, attrName string)
- func CrmDeleteTransientAttributeViaDebug(oc *exutil.CLI, execNodeName string, targetNodeName string, attrName string)
- func CrmQueryAttributeViaDebug(oc *exutil.CLI, nodeName string, attrName string) (string, error)
- func CycleRemovedNode(failedNodeName, failedNodeIP, runningNodeIP string, sshConfig *core.SSHConfig, ...) error
- func DeleteAfterSetupJob(afterSetupJobName string, oc *exutil.CLI) error
- func DeleteAuthJob(authJobName string, oc *exutil.CLI) error
- func DeleteJob(jobName, namespace string, oc *exutil.CLI) error
- func DumpJobPodLogs(jobName, namespace string, oc *exutil.CLI)
- func ExtractDiskSourcePaths(xmlContent string) ([]string, error)
- func ExtractMACAddressFromXML(xmlContent string, networkBridge string) (string, error)
- func ExtractPcsFailedActions(pcsOutput string) string
- func FetchNodeObject(oc *exutil.CLI, nodeName string) (*corev1.Node, error)
- func FindVMByNodeName(nodeName string, sshConfig *core.SSHConfig, knownHostsPath string) (string, error)
- func GetTimestampViaDebug(oc *exutil.CLI, nodeName string) (string, error)
- func GetVMNameByMACMatch(nodeName, nodeMAC string, networkBridge string, sshConfig *core.SSHConfig, ...) (string, error)
- func GetVMNetworkInfo(vmName string, networkBridge string, sshConfig *core.SSHConfig, ...) (string, string, error)
- func HasOutOfServiceAnnotation(node *corev1.Node) bool
- func HasOutOfServiceTaint(node *corev1.Node) bool
- func IsEtcdLearnerError(err error) bool
- func IsRetryableEtcdError(err error) bool
- func JournalGrepViaDebug(oc *exutil.CLI, nodeName, tag, pattern, sinceTimestamp string) (string, error)
- func PcsAlertConfigViaDebug(oc *exutil.CLI, nodeName string) (string, error)
- func PcsDebugRestart(remoteNodeIP string, fullOutput bool, sshConfig *core.SSHConfig, ...) (string, string, error)
- func PcsDebugStart(remoteNodeIP string, fullOutput bool, sshConfig *core.SSHConfig, ...) (string, string, error)
- func PcsDebugStop(remoteNodeIP string, fullOutput bool, sshConfig *core.SSHConfig, ...) (string, string, error)
- func PcsEnableResourceViaDebug(oc *exutil.CLI, nodeName string, resourceName string) error
- func PcsJournal(pcsJournalTailLines int, remoteNodeIP string, sshConfig *core.SSHConfig, ...) (string, string, error)
- func PcsLogBaselinesViaDebug(oc *exutil.CLI, nodes []corev1.Node) map[string]string
- func PcsLogGrepViaDebug(oc *exutil.CLI, nodeName, pattern, baselineLineCount string) (string, error)
- func PcsProperty(remoteNodeIP string, sshConfig *core.SSHConfig, ...) (string, string, error)
- func PcsResourceCleanup(remoteNodeIP string, sshConfig *core.SSHConfig, ...) (string, string, error)
- func PcsResourceCleanupViaDebug(ctx context.Context, oc *exutil.CLI, nodeName string) (string, error)
- func PcsResourceStatus(nodeName, remoteNodeIP string, sshConfig *core.SSHConfig, ...) (string, string, error)
- func PcsStatus(remoteNodeIP string, sshConfig *core.SSHConfig, ...) (string, string, error)
- func PcsStatusFull(remoteNodeIP string, sshConfig *core.SSHConfig, ...) (string, string, error)
- func PcsStatusFullViaDebug(ctx context.Context, oc *exutil.CLI, nodeName string) (string, error)
- func PcsStatusViaDebug(ctx context.Context, oc *exutil.CLI, nodeName string) (string, error)
- func PcsStonithCleanup(remoteNodeIP string, sshConfig *core.SSHConfig, ...) (string, string, error)
- func PcsStonithCleanupViaDebug(ctx context.Context, oc *exutil.CLI, nodeName string) (string, error)
- func PcsStonithConfirm(targetNodeName, remoteNodeIP string, sshConfig *core.SSHConfig, ...) (string, string, error)
- func PcsStonithDisable(remoteNodeIP string, sshConfig *core.SSHConfig, ...) (string, string, error)
- func PcsStonithEnable(remoteNodeIP string, sshConfig *core.SSHConfig, ...) (string, string, error)
- func PrintHypervisorConfigUsage()
- func RemoveTaintAndAnnotation(oc *exutil.CLI, nodeName string)
- func VerifyHypervisorAvailability(sshConfig *core.SSHConfig, knownHostsPath string) error
- func VerifyVirsh(sshConfig *core.SSHConfig, knownHostsPath string) (string, error)
- func VirshAutostartVM(vmName string, sshConfig *core.SSHConfig, knownHostsPath string) error
- func VirshCommand(command string, sshConfig *core.SSHConfig, knownHostsPath string) (string, error)
- func VirshDefineVM(xmlFilePath string, sshConfig *core.SSHConfig, knownHostsPath string) error
- func VirshDestroyVM(vmName string, sshConfig *core.SSHConfig, knownHostsPath string) error
- func VirshDumpXML(vmName string, sshConfig *core.SSHConfig, knownHostsPath string) (string, error)
- func VirshGetVMUUID(vmName string, sshConfig *core.SSHConfig, knownHostsPath string) (string, error)
- func VirshList(sshConfig *core.SSHConfig, knownHostsPath string, flags ...VirshListFlag) (string, error)
- func VirshShutdownVM(vmName string, sshConfig *core.SSHConfig, knownHostsPath string) error
- func VirshStartVM(vmName string, sshConfig *core.SSHConfig, knownHostsPath string) error
- func VirshUndefineVM(vmName string, sshConfig *core.SSHConfig, knownHostsPath string) error
- func VirshVMExists(vmName string, sshConfig *core.SSHConfig, knownHostsPath string) (string, error)
- func WaitForEtcdRevisionCreation(targetNodeIP string, timeout, pollInterval time.Duration, ...) error
- func WaitForJobCompletion(jobName, namespace string, timeout, pollInterval time.Duration, oc *exutil.CLI) error
- func WaitForNodesOnline(nodeNames []string, remoteNodeIP string, timeout, pollInterval time.Duration, ...) error
- func WaitForSurvivorUpdateSetupJobCompletionByNode(oc *exutil.CLI, namespace, nodeName string, minPodCreationTime time.Time, ...) error
- func WaitForUpdateSetupJobCompletionByNode(oc *exutil.CLI, namespace, nodeName string, minJobCreationTime time.Time, ...) error
- func WaitForVMState(vmName string, vmState VMState, timeout time.Duration, ...) error
- type Devices
- type Disk
- type DiskSource
- type DiskSourceRef
- type Domain
- type EtcdErrorType
- type Interface
- type MAC
- type Source
- type VMState
- type VirshListFlag
Constants ¶
const ( // OutOfServiceTaintKey is the Kubernetes taint key applied to fenced nodes. OutOfServiceTaintKey = "node.kubernetes.io/out-of-service" // OutOfServiceTaintValue is the taint value indicating the node was shut down. OutOfServiceTaintValue = "nodeshutdown" // OutOfServiceAnnotationKey tracks which component applied the out-of-service taint. OutOfServiceAnnotationKey = "node.kubernetes.io/out-of-service-applied-by" // OutOfServiceAnnotationValue identifies pacemaker as the taint originator. OutOfServiceAnnotationValue = "pacemaker" // TaintScriptLogTag is the syslog tag used by /usr/local/bin/taint-fenced-node.sh. TaintScriptLogTag = "taint-fenced-node" // UntaintScriptLogTag is the syslog tag used by /usr/local/bin/untaint-fenced-node.sh. UntaintScriptLogTag = "untaint-fenced-node" // TaintAlertLogTag is the syslog tag used by /var/lib/pacemaker/alerts/tnf-taint-alert.sh. TaintAlertLogTag = "tnf-taint-alert" // UntaintAlertLogTag is the syslog tag used by /var/lib/pacemaker/alerts/tnf-untaint-alert.sh. UntaintAlertLogTag = "tnf-untaint-alert" // TaintSuccessLog is the message logged after the taint and annotation are applied. TaintSuccessLog = "Successfully tainted and annotated" // UntaintSuccessLog is the message logged after the taint and annotation are removed. UntaintSuccessLog = "Successfully untainted and removed annotation" // TaintAlertFencingLog is the message logged when the taint alert fires on a successful fence. TaintAlertFencingLog = "Fencing succeeded" // UntaintAlertRejoinLog is the message logged when the untaint alert fires on node rejoin. UntaintAlertRejoinLog = "rejoined cluster (membership)" // TaintAlertID is the pacemaker alert ID for the taint agent. TaintAlertID = "tnf-taint-alert" // UntaintAlertID is the pacemaker alert ID for the untaint agent. UntaintAlertID = "tnf-untaint-alert" // TaintAlertScriptPath is the path to the taint alert script on the node. TaintAlertScriptPath = "/var/lib/pacemaker/alerts/tnf-taint-alert.sh" // UntaintAlertScriptPath is the path to the untaint alert script on the node. UntaintAlertScriptPath = "/var/lib/pacemaker/alerts/tnf-untaint-alert.sh" )
const (
// EtcdNamespace is the OpenShift namespace for etcd static pods and related Secrets/Jobs.
EtcdNamespace = "openshift-etcd"
)
Variables ¶
var VMStateList = []VMState{ VMStateUnknown, VMStateRunning, VMStateShutOff, }
Functions ¶
func CrmDeleteAttributeViaDebug ¶
CrmDeleteAttributeViaDebug deletes a CRM cluster attribute via debug container (best-effort).
CrmDeleteAttributeViaDebug(oc, "master-0", "learner_node")
func CrmDeleteTransientAttributeViaDebug ¶
func CrmDeleteTransientAttributeViaDebug(oc *exutil.CLI, execNodeName string, targetNodeName string, attrName string)
CrmDeleteTransientAttributeViaDebug deletes a per-node transient CRM attribute (set with --lifetime reboot) via debug container (best-effort).
CrmDeleteTransientAttributeViaDebug(oc, "master-0", "master-1", "force_new_cluster")
func CrmQueryAttributeViaDebug ¶
CrmQueryAttributeViaDebug queries a CRM cluster attribute via debug container.
output, err := CrmQueryAttributeViaDebug(oc, "master-0", "learner_node")
func CycleRemovedNode ¶
func CycleRemovedNode(failedNodeName, failedNodeIP, runningNodeIP string, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) error
CycleRemovedNode removes and re-adds a node in the pacemaker cluster configuration.
err := CycleRemovedNode("master-0", "192.168.111.20", runningNodeIP, sshConfig, localKH, remoteKH)
func DeleteAfterSetupJob ¶
DeleteAfterSetupJob deletes the TNF after-setup job for a node from openshift-etcd namespace.
err := DeleteAfterSetupJob("tnf-after-setup-job-master-0", oc)
func DeleteAuthJob ¶
DeleteAuthJob deletes the TNF authentication job for a node from openshift-etcd namespace.
err := DeleteAuthJob("tnf-auth-job-master-0", oc)
func DeleteJob ¶
DeleteJob deletes a Kubernetes job from a specified namespace.
err := DeleteJob("tnf-auth-job-master-0", "openshift-etcd", oc)
func DumpJobPodLogs ¶
DumpJobPodLogs lists pods for the given job (label job-name=jobName), then dumps each pod's container logs into the test output. Call this when a job completes so logs are captured even if the node is later unavailable (e.g. must-gather cannot collect from a dead node).
func ExtractDiskSourcePaths ¶
ExtractDiskSourcePaths returns file paths for file-backed disk devices. Kept for compatibility with older callers.
func ExtractMACAddressFromXML ¶
ExtractMACAddressFromXML extracts the MAC address for a network bridge from VM XML.
mac, err := ExtractMACAddressFromXML(xmlContent, "ostestpr")
func ExtractPcsFailedActions ¶
ExtractPcsFailedActions extracts the "Failed Resource Actions" section from pcs status output.
section := ExtractPcsFailedActions(pcsOutput)
func FetchNodeObject ¶
FetchNodeObject retrieves a fresh node object from the Kubernetes API. Use this instead of a cached node when checking mutable state like taints or annotations.
node, err := FetchNodeObject(oc, "master-0")
func FindVMByNodeName ¶
func FindVMByNodeName(nodeName string, sshConfig *core.SSHConfig, knownHostsPath string) (string, error)
FindVMByNodeName finds a VM that corresponds to an OpenShift node. Handles both simple names (master-0) and FQDNs (master-0.ostest.test.metalkube.org). Matches VM names like "ostest_master_0" by extracting the short name and converting dashes to underscores. Best-effort: substring matching can collide if multiple VMs share a token; prefer MAC-based GetVMNameByMACMatch when the node's MAC is known.
func GetTimestampViaDebug ¶
GetTimestampViaDebug captures a UTC timestamp from a node, used to scope journal log searches to entries emitted after this point.
ts, err := GetTimestampViaDebug(oc, "master-0")
func GetVMNameByMACMatch ¶
func GetVMNameByMACMatch(nodeName, nodeMAC string, networkBridge string, sshConfig *core.SSHConfig, knownHostsPath string) (string, error)
GetVMNameByMACMatch finds the VM name with a specific MAC address by searching all VMs.
vmName, err := GetVMNameByMACMatch("master-0", "52:54:00:12:34:56", "ostestpr", sshConfig, knownHostsPath)
func GetVMNetworkInfo ¶
func GetVMNetworkInfo(vmName string, networkBridge string, sshConfig *core.SSHConfig, knownHostsPath string) (string, string, error)
GetVMNetworkInfo retrieves the UUID and MAC address for a VM's network interface.
uuid, mac, err := GetVMNetworkInfo("master-0", "ostestpr", sshConfig, knownHostsPath)
func HasOutOfServiceAnnotation ¶
HasOutOfServiceAnnotation returns true if the node has the pacemaker out-of-service annotation.
func HasOutOfServiceTaint ¶
HasOutOfServiceTaint returns true if the node has the out-of-service taint with the expected key, value, and NoExecute effect.
func IsEtcdLearnerError ¶
IsEtcdLearnerError checks if an error is related to transient etcd learner state issues.
err := RetryWithOptions(func() error { return createEtcdSecret(oc, secretFile) }, RetryOptions{ShouldRetry: IsEtcdLearnerError}, "create etcd secret")
func IsRetryableEtcdError ¶
IsRetryableEtcdError checks if an etcd error should be retried (learner, network, timeout, rate limit).
err := RetryWithOptions(func() error { return etcdOp() }, RetryOptions{ShouldRetry: IsRetryableEtcdError}, "etcd operation")
func JournalGrepViaDebug ¶
func JournalGrepViaDebug(oc *exutil.CLI, nodeName, tag, pattern, sinceTimestamp string) (string, error)
JournalGrepViaDebug searches the systemd journal on a node for log entries matching the given syslog tag and pattern, scoped to entries after sinceTimestamp. Returns matching lines or an error if the debug command fails.
output, err := JournalGrepViaDebug(oc, "master-0", "taint-fenced-node", "Successfully tainted", "2024-01-01 00:00:00")
func PcsAlertConfigViaDebug ¶
PcsAlertConfigViaDebug runs "pcs alert config" on a node via a debug container and returns the output showing all registered pacemaker alert agents.
output, err := PcsAlertConfigViaDebug(oc, "master-0")
func PcsDebugRestart ¶
func PcsDebugRestart(remoteNodeIP string, fullOutput bool, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) (string, string, error)
PcsDebugRestart restores etcd quorum by performing debug-stop then debug-start.
stdout, stderr, err := PcsDebugRestart(nodeIP, false, sshConfig, localKH, remoteKH)
func PcsDebugStart ¶
func PcsDebugStart(remoteNodeIP string, fullOutput bool, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) (string, string, error)
PcsDebugStart restores etcd quorum by performing debug-start (bypasses cluster checks for two-node scenarios).
stdout, stderr, err := PcsDebugStart(nodeIP, false, sshConfig, localKH, remoteKH)
func PcsDebugStop ¶
func PcsDebugStop(remoteNodeIP string, fullOutput bool, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) (string, string, error)
PcsDebugStop stops the etcd resource using debug-stop (controlled shutdown without triggering recovery).
stdout, stderr, err := PcsDebugStop(nodeIP, false, sshConfig, localKH, remoteKH)
func PcsEnableResourceViaDebug ¶
PcsEnableResourceViaDebug enables a pacemaker resource via debug container.
err := PcsEnableResourceViaDebug(oc, "master-0", "etcd-clone")
func PcsJournal ¶
func PcsJournal(pcsJournalTailLines int, remoteNodeIP string, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) (string, string, error)
PcsJournal retrieves the last N lines of pacemaker journal logs filtered for podman-etcd.
stdout, stderr, err := PcsJournal(100, nodeIP, sshConfig, localKH, remoteKH)
func PcsLogBaselinesViaDebug ¶
PcsLogBaselinesViaDebug captures the current line count of the pacemaker log on each node. Returns a map of nodeName to lineCount string, used to scope log assertions to lines emitted after the baseline.
baselines := PcsLogBaselinesViaDebug(oc, nodes)
func PcsLogGrepViaDebug ¶
func PcsLogGrepViaDebug(oc *exutil.CLI, nodeName, pattern, baselineLineCount string) (string, error)
PcsLogGrepViaDebug searches /var/log/pacemaker/pacemaker.log on a node for lines matching a pattern. If baselineLineCount is non-empty, only lines after that line number are searched.
output, err := PcsLogGrepViaDebug(oc, "master-0", "active etcd resources", "1234")
func PcsProperty ¶
func PcsProperty(remoteNodeIP string, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) (string, string, error)
PcsProperty gets cluster properties from pacemaker.
stdout, stderr, err := PcsProperty(nodeIP, sshConfig, localKH, remoteKH)
func PcsResourceCleanup ¶
func PcsResourceCleanup(remoteNodeIP string, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) (string, string, error)
PcsResourceCleanup cleans up resource failures in the pacemaker cluster.
stdout, stderr, err := PcsResourceCleanup(nodeIP, sshConfig, localKH, remoteKH)
func PcsResourceCleanupViaDebug ¶
func PcsResourceCleanupViaDebug(ctx context.Context, oc *exutil.CLI, nodeName string) (string, error)
PcsResourceCleanupViaDebug clears any failed actions in the cluster's resource manager. This is the debug container equivalent of PcsResourceCleanup for use when SSH is unavailable.
output, err := PcsResourceCleanupViaDebug(ctx, oc, "master-0")
func PcsResourceStatus ¶
func PcsResourceStatus(nodeName, remoteNodeIP string, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) (string, string, error)
PcsResourceStatus retrieves the status of a specific pacemaker resource (etcd) on a node. This is more targeted than PcsStatus and shows whether the etcd resource is started/stopped.
func PcsStatus ¶
func PcsStatus(remoteNodeIP string, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) (string, string, error)
PcsStatus retrieves the overall pacemaker cluster status. This shows the state of all cluster resources, nodes, and any failures.
func PcsStatusFull ¶
func PcsStatusFull(remoteNodeIP string, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) (string, string, error)
PcsStatusFull retrieves the full pacemaker cluster status with additional details. This includes all nodes, resources, fence status, and any pending operations.
func PcsStatusFullViaDebug ¶
PcsStatusFullViaDebug retrieves the full pacemaker cluster status via debug container. Use for logging; the --full output is human-readable (unlike "pcs status xml").
output, err := PcsStatusFullViaDebug(ctx, oc, "master-0")
func PcsStatusViaDebug ¶
PcsStatusViaDebug retrieves the overall pacemaker cluster status via debug container. This shows the state of all cluster resources, nodes, and any failures. Use instead of PcsStatus when SSH to the hypervisor is unavailable.
output, err := PcsStatusViaDebug(ctx, oc, "master-0")
func PcsStonithCleanup ¶
func PcsStonithCleanup(remoteNodeIP string, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) (string, string, error)
PcsStonithCleanup cleans up STONITH failures in the pacemaker cluster.
stdout, stderr, err := PcsStonithCleanup(nodeIP, sshConfig, localKH, remoteKH)
func PcsStonithCleanupViaDebug ¶
func PcsStonithCleanupViaDebug(ctx context.Context, oc *exutil.CLI, nodeName string) (string, error)
PcsStonithCleanupViaDebug clears any failed STONITH (fencing) actions in the cluster. This is the debug container equivalent of PcsStonithCleanup for use when SSH is unavailable.
output, err := PcsStonithCleanupViaDebug(ctx, oc, "master-0")
func PcsStonithConfirm ¶
func PcsStonithConfirm(targetNodeName, remoteNodeIP string, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) (string, string, error)
PcsStonithConfirm manually confirms to the pacemaker cluster that a node has been fenced. This is used when the fencing device cannot fence the node (e.g., when the node has been destroyed and the BMC is unreachable). The --force flag bypasses interactive confirmation.
WARNING: Only use this when you have manually verified the node is powered off and has no access to shared resources. Using this incorrectly can cause data corruption.
stdout, stderr, err := PcsStonithConfirm("master-1", nodeIP, sshConfig, localKH, remoteKH)
func PcsStonithDisable ¶
func PcsStonithDisable(remoteNodeIP string, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) (string, string, error)
PcsStonithDisable disables STONITH in the pacemaker cluster.
stdout, stderr, err := PcsStonithDisable(nodeIP, sshConfig, localKH, remoteKH)
func PcsStonithEnable ¶
func PcsStonithEnable(remoteNodeIP string, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) (string, string, error)
PcsStonithEnable enables STONITH in the pacemaker cluster.
stdout, stderr, err := PcsStonithEnable(nodeIP, sshConfig, localKH, remoteKH)
func PrintHypervisorConfigUsage ¶
func PrintHypervisorConfigUsage()
PrintHypervisorConfigUsage prints usage instructions for configuring hypervisor SSH access. Call this when HasHypervisorConfig() returns false to provide configuration guidance.
func RemoveTaintAndAnnotation ¶
RemoveTaintAndAnnotation removes the out-of-service taint and pacemaker annotation from a node. Retries on conflict up to 3 times. Errors are logged but not returned (best-effort cleanup).
func VerifyHypervisorAvailability ¶
VerifyHypervisorAvailability verifies SSH connectivity and checks virsh/libvirt availability.
err := VerifyHypervisorAvailability(sshConfig, knownHostsPath)
func VerifyVirsh ¶
VerifyVirsh checks if virsh is available by executing 'virsh version'.
output, err := VerifyVirsh(sshConfig, knownHostsPath)
func VirshAutostartVM ¶
VirshAutostartVM enables autostart for a VM (starts on hypervisor boot).
err := VirshAutostartVM("master-0", sshConfig, knownHostsPath)
func VirshCommand ¶
VirshCommand executes a virsh command on the remote hypervisor via SSH.
output, err := VirshCommand("list --all", sshConfig, knownHostsPath)
func VirshDefineVM ¶
VirshDefineVM defines a new VM from an XML configuration file.
err := VirshDefineVM("/tmp/master-0.xml", sshConfig, knownHostsPath)
func VirshDestroyVM ¶
VirshDestroyVM forcefully stops a running VM (equivalent to power-off).
err := VirshDestroyVM("master-0", sshConfig, knownHostsPath)
func VirshDumpXML ¶
VirshDumpXML retrieves the XML configuration of a VM.
xml, err := VirshDumpXML("master-0", sshConfig, knownHostsPath)
func VirshGetVMUUID ¶
func VirshGetVMUUID(vmName string, sshConfig *core.SSHConfig, knownHostsPath string) (string, error)
VirshGetVMUUID retrieves the UUID of a VM.
uuid, err := VirshGetVMUUID("master-0", sshConfig, knownHostsPath)
func VirshList ¶
func VirshList(sshConfig *core.SSHConfig, knownHostsPath string, flags ...VirshListFlag) (string, error)
VirshList lists VMs on the hypervisor with configurable output format. Pass VirshListFlagAll to include inactive domains, VirshListFlagName to output only names.
Examples:
vmList, err := VirshList(sshConfig, knownHostsPath, VirshListFlagAll, VirshListFlagName) // names only vmList, err := VirshList(sshConfig, knownHostsPath, VirshListFlagAll) // table with state
func VirshShutdownVM ¶
VirshShutdownVM gracefully shuts down a running VM (allows guest OS to shutdown cleanly).
err := VirshShutdownVM("master-0", sshConfig, knownHostsPath)
func VirshStartVM ¶
VirshStartVM starts a defined VM.
err := VirshStartVM("master-0", sshConfig, knownHostsPath)
func VirshUndefineVM ¶
VirshUndefineVM undefines a VM (removes libvirt config, not disk images).
err := VirshUndefineVM("master-0", sshConfig, knownHostsPath)
func VirshVMExists ¶
VirshVMExists checks if a VM with the given name exists on the hypervisor.
output, err := VirshVMExists("master-0", sshConfig, knownHostsPath)
func WaitForEtcdRevisionCreation ¶
func WaitForEtcdRevisionCreation(targetNodeIP string, timeout, pollInterval time.Duration, hypervisorConfig *core.SSHConfig, hypervisorKnownHostsPath, targetNodeKnownHostsPath string, oc *exutil.CLI) error
WaitForEtcdRevisionCreation polls until the /var/lib/etcd/revision.json file exists on the target node. This file is created by the Cluster Etcd Operator (CEO) after the node joins the cluster.
err := WaitForEtcdRevisionCreation(targetNodeIP, tenMinuteTimeout, thirtySecondPollInterval, &hypervisorConfig, hypervisorKnownHosts, targetNodeKnownHosts, oc)
func WaitForJobCompletion ¶
func WaitForJobCompletion(jobName, namespace string, timeout, pollInterval time.Duration, oc *exutil.CLI) error
WaitForJobCompletion waits for a Kubernetes job to complete by polling status until Complete or Failed. When the job finishes (success or failure), container logs of the job's pods are dumped into the test output so they are available even if the node is later unavailable.
err := WaitForJobCompletion("tnf-auth-job-master-0", "openshift-etcd", 5*time.Minute, 10*time.Second, oc)
func WaitForNodesOnline ¶
func WaitForNodesOnline(nodeNames []string, remoteNodeIP string, timeout, pollInterval time.Duration, sshConfig *core.SSHConfig, localKnownHostsPath, remoteKnownHostsPath string) error
WaitForNodesOnline waits for all specified nodes to be online in the pacemaker cluster by polling XML status.
err := WaitForNodesOnline([]string{"master-0", "master-1"}, nodeIP, 5*time.Minute, 10*time.Second, sshConfig, localKH, remoteKH)
func WaitForSurvivorUpdateSetupJobCompletionByNode ¶
func WaitForSurvivorUpdateSetupJobCompletionByNode(oc *exutil.CLI, namespace, nodeName string, minPodCreationTime time.Time, timeout, pollInterval time.Duration) error
WaitForSurvivorUpdateSetupJobCompletionByNode waits for the survivor's TNF update-setup job to complete in a run that started after minPodCreationTime. It discovers the job by label and node name (see WaitForUpdateSetupJobCompletionByNode).
func WaitForUpdateSetupJobCompletionByNode ¶
func WaitForUpdateSetupJobCompletionByNode(oc *exutil.CLI, namespace, nodeName string, minJobCreationTime time.Time, timeout, pollInterval time.Duration) error
WaitForUpdateSetupJobCompletionByNode waits for the TNF update-setup job targeting the given node to complete. It discovers the job by label and node name so it works regardless of CEO's job naming (e.g. hash suffix). If minJobCreationTime is non-zero, only a job created after that time is considered (ensures we wait for the job created after the node was recreated, not a stale pre-replacement job).
Types ¶
type Disk ¶
type Disk struct {
Type string `xml:"type,attr"`
Device string `xml:"device,attr"`
Source DiskSource `xml:"source"`
}
Disk represents a disk device in libvirt domain XML.
type DiskSource ¶
type DiskSource struct {
File string `xml:"file,attr"`
Pool string `xml:"pool,attr"`
Volume string `xml:"volume,attr"`
}
DiskSource is the source element for a disk.
type DiskSourceRef ¶
DiskSourceRef describes where a VM disk is sourced from. For Type=file, FilePath is populated. For Type=volume, Pool and Volume are populated and callers can resolve FilePath via virsh vol-path.
func ExtractDiskSourceRefs ¶
func ExtractDiskSourceRefs(xmlContent string) ([]DiskSourceRef, error)
ExtractDiskSourceRefs returns source refs for disk devices from libvirt domain XML. Supported:
- type="file" device="disk" source file=...
- type="volume" device="disk" source pool=... volume=...
Other disk source types are ignored by design.
type Domain ¶
type Domain struct {
XMLName xml.Name `xml:"domain"`
Name string `xml:"name"`
UUID string `xml:"uuid"`
Devices Devices `xml:"devices"`
}
Domain represents a libvirt domain (virtual machine) configuration.
type EtcdErrorType ¶
type EtcdErrorType int
EtcdErrorType categorizes etcd errors for granular error handling.
const ( // EtcdErrorUnknown represents an unclassified error EtcdErrorUnknown EtcdErrorType = iota // EtcdErrorLearner represents errors related to etcd learner state transitions // These are typically transient and should be retried EtcdErrorLearner // EtcdErrorQuorum represents errors related to etcd cluster quorum issues // These may require operator intervention but can sometimes be retried EtcdErrorQuorum // EtcdErrorNetwork represents network connectivity errors // These are typically transient and should be retried EtcdErrorNetwork // EtcdErrorTimeout represents timeout errors // These are typically transient and should be retried EtcdErrorTimeout // EtcdErrorRateLimit represents rate limiting or overload errors // These should be retried with backoff EtcdErrorRateLimit )
func ClassifyEtcdError ¶
func ClassifyEtcdError(err error) EtcdErrorType
ClassifyEtcdError categorizes an etcd error into a specific error type for intelligent retry strategies.
errorType := ClassifyEtcdError(err)
func (EtcdErrorType) String ¶
func (e EtcdErrorType) String() string
String returns a human-readable name for the error type
type Interface ¶
type Interface struct {
Type string `xml:"type,attr"`
MAC MAC `xml:"mac"`
Source Source `xml:"source"`
}
Interface represents a network interface configuration in libvirt XML
type MAC ¶
type MAC struct {
Address string `xml:"address,attr"`
}
MAC contains the MAC address of a network interface
type Source ¶
type Source struct {
Bridge string `xml:"bridge,attr"`
}
Source specifies the network source (bridge, network, etc) for an interface
type VirshListFlag ¶
type VirshListFlag string
VirshListFlag represents optional flags for the virsh list command.
const ( // VirshListFlagAll includes inactive domains in the output (--all) VirshListFlagAll VirshListFlag = "--all" // VirshListFlagName outputs only domain names, one per line (--name) VirshListFlagName VirshListFlag = "--name" )