chore: fix staticcheck SA warnings
- Fix SA4006 unused value issues in ssh.go, validation.go, generator.go - Replace deprecated ioutil with io/os in config.go - Replace deprecated tar.TypeRegA with tar.TypeReg - Remove deprecated rand.Seed calls (auto-seeded in Go 1.20+) - Fix always-true nil check in main.go - Fix impossible nil comparison in tempproxy/client.go - Add nil check for config in monitor.New()
This commit is contained in:
parent
4fd3bdbc04
commit
e25e1af8cb
9 changed files with 23 additions and 27 deletions
|
|
@ -1023,8 +1023,7 @@ func (p *Proxy) getTemperatureLocal(ctx context.Context) (string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Try without -j flag as fallback
|
// Try without -j flag as fallback
|
||||||
cmd = exec.CommandContext(ctx, "sensors")
|
cmd = exec.CommandContext(ctx, "sensors")
|
||||||
output, err = cmd.Output()
|
if _, err = cmd.Output(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("failed to run sensors: %w", err)
|
return "", fmt.Errorf("failed to run sensors: %w", err)
|
||||||
}
|
}
|
||||||
// Return empty JSON object for non-JSON output
|
// Return empty JSON object for non-JSON output
|
||||||
|
|
|
||||||
|
|
@ -412,12 +412,9 @@ func (v *nodeValidator) Validate(ctx context.Context, node string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *nodeValidator) validateAsLocalhost(ctx context.Context, node string) error {
|
func (v *nodeValidator) validateAsLocalhost(_ context.Context, node string) error {
|
||||||
// When cluster validation is unavailable, only allow access to localhost
|
// When cluster validation is unavailable, only allow access to localhost
|
||||||
// This maintains security while allowing self-monitoring
|
// This maintains security while allowing self-monitoring
|
||||||
if ctx == nil {
|
|
||||||
ctx = context.Background()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to discover local host addresses
|
// Try to discover local host addresses
|
||||||
localAddrs, err := discoverLocalHostAddresses()
|
localAddrs, err := discoverLocalHostAddresses()
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -86,7 +86,7 @@ var configExportCmd = &cobra.Command{
|
||||||
|
|
||||||
// Write to file or stdout
|
// Write to file or stdout
|
||||||
if exportFile != "" {
|
if exportFile != "" {
|
||||||
if err := ioutil.WriteFile(exportFile, []byte(exportedData), 0600); err != nil {
|
if err := os.WriteFile(exportFile, []byte(exportedData), 0600); err != nil {
|
||||||
return fmt.Errorf("failed to write export file: %w", err)
|
return fmt.Errorf("failed to write export file: %w", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Configuration exported to %s\n", exportFile)
|
fmt.Printf("Configuration exported to %s\n", exportFile)
|
||||||
|
|
@ -117,7 +117,7 @@ var configImportCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read import file
|
// Read import file
|
||||||
data, err := ioutil.ReadFile(importFile)
|
data, err := os.ReadFile(importFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to read import file: %w", err)
|
return fmt.Errorf("failed to read import file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -245,7 +245,7 @@ var configAutoImportCmd = &cobra.Command{
|
||||||
return fmt.Errorf("failed to fetch configuration from URL: %s", resp.Status)
|
return fmt.Errorf("failed to fetch configuration from URL: %s", resp.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to read configuration response: %w", err)
|
return fmt.Errorf("failed to read configuration response: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -253,12 +253,10 @@ func runServer() {
|
||||||
configWatcher.ReloadConfig()
|
configWatcher.ReloadConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
if reloadFunc != nil {
|
if err := reloadFunc(); err != nil {
|
||||||
if err := reloadFunc(); err != nil {
|
log.Error().Err(err).Msg("Failed to reload monitor after SIGHUP")
|
||||||
log.Error().Err(err).Msg("Failed to reload monitor after SIGHUP")
|
} else {
|
||||||
} else {
|
log.Info().Msg("Runtime configuration reloaded")
|
||||||
log.Info().Msg("Runtime configuration reloaded")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-sigChan:
|
case <-sigChan:
|
||||||
|
|
|
||||||
|
|
@ -236,7 +236,7 @@ func extractHostAgentBinaries(archivePath, targetDir string) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if header.Typeflag != tar.TypeReg && header.Typeflag != tar.TypeRegA && header.Typeflag != tar.TypeSymlink {
|
if header.Typeflag != tar.TypeReg && header.Typeflag != tar.TypeSymlink {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -252,7 +252,7 @@ func extractHostAgentBinaries(archivePath, targetDir string) error {
|
||||||
destPath := filepath.Join(targetDir, base)
|
destPath := filepath.Join(targetDir, base)
|
||||||
|
|
||||||
switch header.Typeflag {
|
switch header.Typeflag {
|
||||||
case tar.TypeReg, tar.TypeRegA:
|
case tar.TypeReg:
|
||||||
if err := writeHostAgentFile(destPath, tr, header.FileInfo().Mode()); err != nil {
|
if err := writeHostAgentFile(destPath, tr, header.FileInfo().Mode()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ func generateVirtualDisks() ([]models.Disk, models.Disk) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateMockData(config MockConfig) models.StateSnapshot {
|
func GenerateMockData(config MockConfig) models.StateSnapshot {
|
||||||
rand.Seed(time.Now().UnixNano())
|
// rand is automatically seeded in Go 1.20+
|
||||||
|
|
||||||
data := models.StateSnapshot{
|
data := models.StateSnapshot{
|
||||||
Nodes: generateNodes(config),
|
Nodes: generateNodes(config),
|
||||||
|
|
@ -273,8 +273,7 @@ func GenerateMockData(config MockConfig) models.StateSnapshot {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate VM count based on node role
|
// Calculate VM count based on node role
|
||||||
vmCount := config.VMsPerNode
|
var vmCount, lxcCount int
|
||||||
lxcCount := config.LXCsPerNode
|
|
||||||
|
|
||||||
switch nodeRole {
|
switch nodeRole {
|
||||||
case "vm-heavy":
|
case "vm-heavy":
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,4 @@ func TestMetricsHistoryConcurrentAccess(t *testing.T) {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
// rand is automatically seeded in Go 1.20+
|
||||||
rand.Seed(time.Now().UnixNano())
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -3700,6 +3700,10 @@ func checkContainerizedTempMonitoring() {
|
||||||
|
|
||||||
// New creates a new Monitor instance
|
// New creates a new Monitor instance
|
||||||
func New(cfg *config.Config) (*Monitor, error) {
|
func New(cfg *config.Config) (*Monitor, error) {
|
||||||
|
if cfg == nil {
|
||||||
|
return nil, fmt.Errorf("config cannot be nil")
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize temperature collector with sensors SSH key
|
// Initialize temperature collector with sensors SSH key
|
||||||
// Will use root user for now - can be made configurable later
|
// Will use root user for now - can be made configurable later
|
||||||
homeDir := os.Getenv("HOME")
|
homeDir := os.Getenv("HOME")
|
||||||
|
|
@ -3712,7 +3716,7 @@ func New(cfg *config.Config) (*Monitor, error) {
|
||||||
// Security warning if running in container with SSH temperature monitoring
|
// Security warning if running in container with SSH temperature monitoring
|
||||||
checkContainerizedTempMonitoring()
|
checkContainerizedTempMonitoring()
|
||||||
|
|
||||||
if cfg != nil && cfg.TemperatureMonitoringEnabled {
|
if cfg.TemperatureMonitoringEnabled {
|
||||||
isContainer := os.Getenv("PULSE_DOCKER") == "true" || system.InContainer()
|
isContainer := os.Getenv("PULSE_DOCKER") == "true" || system.InContainer()
|
||||||
if isContainer && tempCollector != nil && !tempCollector.SocketProxyAvailable() {
|
if isContainer && tempCollector != nil && !tempCollector.SocketProxyAvailable() {
|
||||||
log.Warn().Msg("Temperature monitoring is enabled but the container does not have access to pulse-sensor-proxy. Install the proxy on the host or disable temperatures until it is available.")
|
log.Warn().Msg("Temperature monitoring is enabled but the container does not have access to pulse-sensor-proxy. Install the proxy on the host or disable temperatures until it is available.")
|
||||||
|
|
|
||||||
|
|
@ -278,8 +278,9 @@ func (c *Client) callWithContext(ctx context.Context, method string, params map[
|
||||||
return resp, proxyErr
|
return resp, proxyErr
|
||||||
}
|
}
|
||||||
|
|
||||||
lastErr = proxyErr
|
if proxyErr != nil {
|
||||||
if lastErr == nil {
|
lastErr = proxyErr
|
||||||
|
} else {
|
||||||
lastErr = err
|
lastErr = err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue