Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions pkg/spec/paths.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
17 changes: 7 additions & 10 deletions pkg/status/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"os"
"os/exec"
"os/user"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -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")
}
Loading