diff --git a/pkg/spec/paths.go b/pkg/spec/paths.go index f8cbddc..bf6af93 100644 --- a/pkg/spec/paths.go +++ b/pkg/spec/paths.go @@ -1,20 +1,21 @@ package spec import ( - "os/user" + "os" "path/filepath" ) // GetSpecDir returns the appropriate directory for spec artifacts. -// Uses /run/aks-flex-node when running as aks-flex-node user (systemd service) +// Uses /run/aks-flex-node when running as systemd service (RuntimeDirectory creates this) // Uses /tmp/aks-flex-node for direct user execution (testing/development) func GetSpecDir() string { - specDir := "/tmp/aks-flex-node" - currentUser, err := user.Current() - if err == nil && currentUser.Username == "aks-flex-node" { - specDir = "/run/aks-flex-node" + // Check if /run/aks-flex-node exists (created by systemd RuntimeDirectory directive) + runtimeDir := "/run/aks-flex-node" + if fi, err := os.Stat(runtimeDir); err == nil && fi.IsDir() { + return runtimeDir } - return specDir + // Fallback to temp directory for testing/development + return "/tmp/aks-flex-node" } // GetManagedClusterSpecFilePath returns the path where the managed cluster spec snapshot is stored. diff --git a/pkg/status/collector.go b/pkg/status/collector.go index f8b0c5f..fa6384b 100644 --- a/pkg/status/collector.go +++ b/pkg/status/collector.go @@ -5,7 +5,6 @@ import ( "encoding/json" "os" "os/exec" - "os/user" "path/filepath" "strings" "time" @@ -279,17 +278,15 @@ func (c *Collector) NeedsBootstrap(ctx context.Context) bool { } // GetStatusFilePath returns the appropriate status directory path -// Uses /run/aks-flex-node/status.json when running as aks-flex-node user (systemd service) +// Uses /run/aks-flex-node/status.json when running as systemd service (RuntimeDirectory creates this) // Uses /tmp/aks-flex-node/status.json for direct user execution (testing/development) func GetStatusFilePath() string { - // Running as regular user (testing/development) - use temp directory - statusDir := "/tmp/aks-flex-node" - // Check if we're running as the aks-flex-node service user - currentUser, err := user.Current() - if err == nil && currentUser.Username == "aks-flex-node" { - // Running as systemd service user - use runtime directory for status files - statusDir = "/run/aks-flex-node" + // Check if /run/aks-flex-node exists (created by systemd RuntimeDirectory directive) + runtimeDir := "/run/aks-flex-node" + if fi, err := os.Stat(runtimeDir); err == nil && fi.IsDir() { + return filepath.Join(runtimeDir, "status.json") } - return filepath.Join(statusDir, "status.json") + // Fallback to temp directory for testing/development + return filepath.Join("/tmp/aks-flex-node", "status.json") }