util

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package util provides utility functions for Node Doctor.

Package util provides utility functions for node-doctor.

Index

Constants

This section is empty.

Variables

View Source
var ErrServiceNotFound = errors.New("service not found")

ErrServiceNotFound indicates the requested service was not found.

View Source
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

func CheckProcessRunning(processName string) (bool, error)

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

func CheckProcessRunningByPattern(pattern string) (bool, error)

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

func CheckSystemdServiceStatus(ctx context.Context, serviceName string) (bool, error)

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

func GetContainerRuntime() (runtime string, socket string)

GetContainerRuntime returns information about detected container runtime. Returns the runtime name and socket path if detected.

func GetOSRelease added in v1.4.1

func GetOSRelease() (map[string]string, error)

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

func ParseKubernetesVersion(version string) (major, minor, patch int, ok bool)

ParseKubernetesVersion parses a Kubernetes version string.

func ReadHostFile added in v1.4.1

func ReadHostFile(path string, hostMountPath string) ([]byte, error)

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

func ValidateConfigFile(path string) error

ValidateConfigFile validates a configuration file without loading it into memory.

Types

This section is empty.

Jump to

Keyboard shortcuts

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