It's state, not config.

This commit is contained in:
2026-07-10 05:21:03 +00:00
parent 4feaa63da0
commit 5c26c7530a
18 changed files with 184 additions and 216 deletions

View File

@@ -3,12 +3,10 @@ package config
import (
"bytes"
"fmt"
"log/slog"
"os/exec"
"path/filepath"
"strings"
"github.com/wild-cloud/wild-central/internal/network"
"github.com/wild-cloud/wild-central/internal/storage"
)
@@ -89,41 +87,6 @@ func NewManager() *Manager {
}
}
// EnsureGlobalConfig ensures a global config file exists with proper structure
func (m *Manager) EnsureGlobalConfig(dataDir string) error {
configPath := filepath.Join(dataDir, "config.yaml")
// Check if config already exists
if storage.FileExists(configPath) {
// Validate existing config
if err := m.yq.Validate(configPath); err != nil {
return fmt.Errorf("invalid config file: %w", err)
}
return nil
}
// Create config structure with detected defaults
initialConfig := &GlobalConfig{}
// Detect network configuration
netInfo, err := network.DetectNetworkInfo()
if err != nil {
slog.Info("network detection failed, using defaults", "component", "config", "error", err)
} else {
// Set detected values
initialConfig.Cloud.Router.IP = netInfo.Gateway
slog.Info("detected network", "component", "config", "gateway", netInfo.Gateway, "interface", netInfo.PrimaryInterface)
}
// Ensure data directory exists
if err := storage.EnsureDir(dataDir, 0755); err != nil {
return err
}
// Save config using the model's save function
return SaveGlobalConfig(initialConfig, configPath)
}
// EnsureInstanceConfig ensures an instance config file exists with proper structure
func (m *Manager) EnsureInstanceConfig(name string, dataDir string) error {
configPath := filepath.Join(dataDir, "instances", name, "config", "instance.yaml")