Documentation
¶
Overview ¶
Package util provides utility functions for Node Doctor.
Package util provides utility functions for node-doctor.
Index ¶
- Variables
- func CheckProcessRunning(processName string) (bool, error)
- func CheckProcessRunningByPattern(pattern string) (bool, error)
- func CheckSystemdServiceStatus(ctx context.Context, serviceName string) (bool, error)
- func DefaultConfig() (*types.NodeDoctorConfig, error)
- func DetectKubernetesDistribution() string
- func GetContainerRuntime() (runtime string, socket string)
- func GetOSRelease() (map[string]string, error)
- func GetServiceStatus(ctx context.Context, serviceName string, processNames []string) (active bool, method string, err error)
- func IsRunningInContainer() bool
- func IsSystemctlAvailable() bool
- func LoadConfig(path string) (*types.NodeDoctorConfig, error)
- func LoadConfigOrDefault(path string) (*types.NodeDoctorConfig, error)
- func ParseKubernetesVersion(version string) (major, minor, patch int, ok bool)
- func ReadHostFile(path string, hostMountPath string) ([]byte, error)
- func SaveConfig(config *types.NodeDoctorConfig, path string) error
- func ValidateConfigFile(path string) error
Constants ¶
This section is empty.
Variables ¶
var ErrServiceNotFound = errors.New("service not found")
ErrServiceNotFound indicates the requested service was not found.
var ErrSystemctlNotAvailable = errors.New("systemctl is not available")
ErrSystemctlNotAvailable indicates systemctl is not available in the environment.
Functions ¶
func CheckProcessRunning ¶ added in v1.4.1
CheckProcessRunning checks if a process with the given name is running. This provides an alternative to systemd checks when running in containers.
func CheckProcessRunningByPattern ¶ added in v1.4.1
CheckProcessRunningByPattern checks if any process matches the given pattern. This is useful for processes with dynamic names or arguments.
func CheckSystemdServiceStatus ¶ added in v1.4.1
CheckSystemdServiceStatus checks the status of a systemd service. Returns (active, error). If systemctl is not available, returns ErrSystemctlNotAvailable.
func DefaultConfig ¶
func DefaultConfig() (*types.NodeDoctorConfig, error)
DefaultConfig returns a default configuration suitable for basic monitoring.
func DetectKubernetesDistribution ¶ added in v1.4.1
func DetectKubernetesDistribution() string
DetectKubernetesDistribution detects the Kubernetes distribution. Returns one of: "rke1", "rke2", "k3s", "standard", "unknown"
func GetContainerRuntime ¶ added in v1.4.1
GetContainerRuntime returns information about detected container runtime. Returns the runtime name and socket path if detected.
func GetOSRelease ¶ added in v1.4.1
GetOSRelease reads and parses /etc/os-release.
func GetServiceStatus ¶ added in v1.4.1
func GetServiceStatus(ctx context.Context, serviceName string, processNames []string) (active bool, method string, err error)
GetServiceStatus returns a unified service status using the best available method. It tries systemd first, then falls back to process detection. processNames is a list of process names to look for if systemd is unavailable.
func IsRunningInContainer ¶ added in v1.4.1
func IsRunningInContainer() bool
IsRunningInContainer detects if the current process is running inside a container. It uses multiple detection methods for reliability.
func IsSystemctlAvailable ¶ added in v1.4.1
func IsSystemctlAvailable() bool
IsSystemctlAvailable checks if systemctl is available in PATH.
func LoadConfig ¶
func LoadConfig(path string) (*types.NodeDoctorConfig, error)
LoadConfig loads configuration from a file (YAML or JSON). The file format is determined by extension (.yaml, .yml, .json). Environment variables are substituted, defaults are applied, and validation is performed.
func LoadConfigOrDefault ¶
func LoadConfigOrDefault(path string) (*types.NodeDoctorConfig, error)
LoadConfigOrDefault loads configuration from a file, or returns default if file doesn't exist.
func ParseKubernetesVersion ¶ added in v1.4.1
ParseKubernetesVersion parses a Kubernetes version string.
func ReadHostFile ¶ added in v1.4.1
ReadHostFile reads a file from the host filesystem when running in a container. If hostPath is mounted (e.g., at /host), it reads from there. Otherwise, it reads from the regular path.
func SaveConfig ¶
func SaveConfig(config *types.NodeDoctorConfig, path string) error
SaveConfig saves configuration to a file (YAML or JSON based on extension).
func ValidateConfigFile ¶
ValidateConfigFile validates a configuration file without loading it into memory.
Types ¶
This section is empty.