Skip to content
Merged
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
4 changes: 2 additions & 2 deletions cmd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var getContextCmd = &cobra.Command{

if err := runtime.NewRuntime(deps).
LoadShell().
LoadConfigHandler().
LoadConfig().
PrintContext(outputFunc).
Do(); err != nil {
return fmt.Errorf("Error getting context: %w", err)
Expand All @@ -47,7 +47,7 @@ var setContextCmd = &cobra.Command{
}
if err := runtime.NewRuntime(deps).
LoadShell().
LoadConfigHandler().
LoadConfig().
WriteResetToken().
SetContext(args[0]).
Do(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (r *Runtime) SetContext(context string) *Runtime {
return r
}
if r.ConfigHandler == nil {
r.err = fmt.Errorf("config handler not loaded - call LoadConfigHandler() first")
r.err = fmt.Errorf("config handler not loaded - call LoadConfig() first")
return r
}
r.err = r.ConfigHandler.SetContext(context)
Expand All @@ -137,7 +137,7 @@ func (r *Runtime) PrintContext(outputFunc func(string)) *Runtime {
return r
}
if r.ConfigHandler == nil {
r.err = fmt.Errorf("config handler not loaded - call LoadConfigHandler() first")
r.err = fmt.Errorf("config handler not loaded - call LoadConfig() first")
return r
}
context := r.ConfigHandler.GetContext()
Expand Down
21 changes: 15 additions & 6 deletions pkg/runtime/runtime_loaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ func (r *Runtime) LoadShell() *Runtime {
return r
}

// LoadConfigHandler loads and initializes the configuration handler dependency.
func (r *Runtime) LoadConfigHandler() *Runtime {
// LoadConfig loads and initializes the configuration handler dependency and fully loads
// all configuration data into memory. It creates a new ConfigHandler if none exists, initializes
// it with required dependencies, and then loads all configuration sources (schema defaults,
// root windsor.yaml context section, context-specific windsor.yaml/yml files, and values.yaml)
// into the internal data map. This method replaces the previous LoadConfigHandler method
// by combining handler creation/initialization with actual configuration loading.
func (r *Runtime) LoadConfig() *Runtime {
if r.err != nil {
return r
}
Expand All @@ -50,6 +55,10 @@ func (r *Runtime) LoadConfigHandler() *Runtime {
r.err = fmt.Errorf("failed to initialize config handler: %w", err)
return r
}
if err := r.ConfigHandler.LoadConfig(); err != nil {
r.err = fmt.Errorf("failed to load configuration: %w", err)
return r
}
return r
}

Expand All @@ -59,7 +68,7 @@ func (r *Runtime) LoadEnvPrinters() *Runtime {
return r
}
if r.ConfigHandler == nil {
r.err = fmt.Errorf("config handler not loaded - call LoadConfigHandler() first")
r.err = fmt.Errorf("config handler not loaded - call LoadConfig() first")
return r
}
if r.EnvPrinters.AwsEnv == nil && r.ConfigHandler.GetBool("aws.enabled", false) {
Expand Down Expand Up @@ -102,7 +111,7 @@ func (r *Runtime) LoadSecretsProviders() *Runtime {
return r
}
if r.ConfigHandler == nil {
r.err = fmt.Errorf("config handler not loaded - call LoadConfigHandler() first")
r.err = fmt.Errorf("config handler not loaded - call LoadConfig() first")
return r
}

Expand Down Expand Up @@ -152,7 +161,7 @@ func (r *Runtime) LoadKubernetes() *Runtime {
return r
}
if r.ConfigHandler == nil {
r.err = fmt.Errorf("config handler not loaded - call LoadConfigHandler() first")
r.err = fmt.Errorf("config handler not loaded - call LoadConfig() first")
return r
}
if r.Injector.Resolve("kubernetesClient") == nil {
Expand Down Expand Up @@ -196,7 +205,7 @@ func (r *Runtime) LoadBlueprint() *Runtime {
return r
}
if r.ConfigHandler == nil {
r.err = fmt.Errorf("config handler not loaded - call LoadConfigHandler() first")
r.err = fmt.Errorf("config handler not loaded - call LoadConfig() first")
return r
}
if r.BlueprintHandler == nil {
Expand Down
68 changes: 34 additions & 34 deletions pkg/runtime/runtime_loaders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@ func TestRuntime_LoadShell(t *testing.T) {
})
}

func TestRuntime_LoadConfigHandler(t *testing.T) {
t.Run("LoadsConfigHandlerSuccessfully", func(t *testing.T) {
func TestRuntime_LoadConfig(t *testing.T) {
t.Run("LoadsConfigSuccessfully", func(t *testing.T) {
// Given a runtime with loaded shell
mocks := setupMocks(t)
runtime := NewRuntime(mocks).LoadShell()

// When loading config handler
result := runtime.LoadConfigHandler()
// When loading config
result := runtime.LoadConfig()

// Then should return the same runtime instance
if result != runtime {
t.Error("Expected LoadConfigHandler to return the same runtime instance")
}

// And config handler should be loaded
// And config should be loaded
if runtime.ConfigHandler == nil {
t.Error("Expected config handler to be loaded")
t.Error("Expected config to be loaded")
}

// And no error should be set
Expand All @@ -147,8 +147,8 @@ func TestRuntime_LoadConfigHandler(t *testing.T) {
// Given a runtime without loaded shell (no pre-loaded dependencies)
runtime := NewRuntime()

// When loading config handler
result := runtime.LoadConfigHandler()
// When loading config
result := runtime.LoadConfig()

// Then should return the same runtime instance
if result != runtime {
Expand All @@ -171,8 +171,8 @@ func TestRuntime_LoadConfigHandler(t *testing.T) {
runtime := NewRuntime()
runtime.err = errors.New("existing error")

// When loading config handler
result := runtime.LoadConfigHandler()
// When loading config
result := runtime.LoadConfig()

// Then should return the same runtime instance
if result != runtime {
Expand All @@ -196,8 +196,8 @@ func TestRuntime_LoadConfigHandler(t *testing.T) {
runtime.Shell = shell.NewMockShell()
// Don't register the shell in the injector - this will cause initialization to fail

// When loading config handler
result := runtime.LoadConfigHandler()
// When loading config
result := runtime.LoadConfig()

// Then should return the same runtime instance
if result != runtime {
Expand All @@ -220,7 +220,7 @@ func TestRuntime_LoadEnvPrinters(t *testing.T) {
t.Run("LoadsEnvPrintersSuccessfully", func(t *testing.T) {
// Given a runtime with loaded shell and config handler
mocks := setupMocks(t)
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// When loading env printers
result := runtime.LoadEnvPrinters()
Expand Down Expand Up @@ -264,7 +264,7 @@ func TestRuntime_LoadEnvPrinters(t *testing.T) {
t.Error("Expected error when config handler not loaded")
}

expectedError := "config handler not loaded - call LoadConfigHandler() first"
expectedError := "config handler not loaded - call LoadConfig() first"
if runtime.err.Error() != expectedError {
t.Errorf("Expected error %q, got %q", expectedError, runtime.err.Error())
}
Expand Down Expand Up @@ -325,7 +325,7 @@ func TestRuntime_LoadEnvPrinters(t *testing.T) {
}
return ""
}
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// When loading env printers
result := runtime.LoadEnvPrinters()
Expand Down Expand Up @@ -371,7 +371,7 @@ func TestRuntime_LoadEnvPrinters(t *testing.T) {
t.Run("LoadsWindsorEnvPrinterAlways", func(t *testing.T) {
// Given a runtime with loaded shell and config handler
mocks := setupMocks(t)
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// When loading env printers
result := runtime.LoadEnvPrinters()
Expand Down Expand Up @@ -405,7 +405,7 @@ func TestRuntime_LoadEnvPrinters(t *testing.T) {
}
return ""
}
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// When loading env printers
result := runtime.LoadEnvPrinters()
Expand Down Expand Up @@ -439,7 +439,7 @@ func TestRuntime_LoadEnvPrinters(t *testing.T) {
}
return ""
}
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// When loading env printers
result := runtime.LoadEnvPrinters()
Expand Down Expand Up @@ -473,7 +473,7 @@ func TestRuntime_LoadEnvPrinters(t *testing.T) {
}
return false
}
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// When loading env printers
result := runtime.LoadEnvPrinters()
Expand Down Expand Up @@ -517,7 +517,7 @@ func TestRuntime_LoadEnvPrinters(t *testing.T) {
}
return false
}
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// When loading env printers
result := runtime.LoadEnvPrinters()
Expand Down Expand Up @@ -557,7 +557,7 @@ func TestRuntime_LoadSecretsProviders(t *testing.T) {
mocks.ConfigHandler.(*config.MockConfigHandler).GetConfigRootFunc = func() (string, error) {
return "/test/config/root", nil
}
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// When loading secrets providers
result := runtime.LoadSecretsProviders()
Expand Down Expand Up @@ -590,7 +590,7 @@ func TestRuntime_LoadSecretsProviders(t *testing.T) {
t.Error("Expected error when config handler not loaded")
}

expectedError := "config handler not loaded - call LoadConfigHandler() first"
expectedError := "config handler not loaded - call LoadConfig() first"
if runtime.err.Error() != expectedError {
t.Errorf("Expected error %q, got %q", expectedError, runtime.err.Error())
}
Expand Down Expand Up @@ -629,7 +629,7 @@ func TestRuntime_LoadSecretsProviders(t *testing.T) {
mocks.ConfigHandler.(*config.MockConfigHandler).GetConfigRootFunc = func() (string, error) {
return "", errors.New("config root error")
}
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// When loading secrets providers
result := runtime.LoadSecretsProviders()
Expand All @@ -656,7 +656,7 @@ func TestRuntime_LoadSecretsProviders(t *testing.T) {
mocks.ConfigHandler.(*config.MockConfigHandler).GetConfigRootFunc = func() (string, error) {
return "/test/config/root", nil
}
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// Mock Stat to return success for secrets.enc.yaml
runtime.Shims.Stat = func(name string) (os.FileInfo, error) {
Expand Down Expand Up @@ -705,7 +705,7 @@ func TestRuntime_LoadSecretsProviders(t *testing.T) {
}
return nil
}
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// Mock Getenv to return SDK token
runtime.Shims.Getenv = func(key string) string {
Expand Down Expand Up @@ -754,7 +754,7 @@ func TestRuntime_LoadSecretsProviders(t *testing.T) {
}
return nil
}
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// Mock Getenv to return no SDK token
runtime.Shims.Getenv = func(key string) string {
Expand Down Expand Up @@ -795,7 +795,7 @@ func TestRuntime_LoadSecretsProviders(t *testing.T) {
mocks.ConfigHandler.(*config.MockConfigHandler).GetFunc = func(key string) any {
return nil // No secrets configuration
}
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// Mock Stat to return file not found for secrets files
runtime.Shims.Stat = func(name string) (os.FileInfo, error) {
Expand Down Expand Up @@ -834,7 +834,7 @@ func TestRuntime_LoadKubernetes(t *testing.T) {
t.Run("LoadsKubernetesSuccessfully", func(t *testing.T) {
// Given a runtime with loaded config handler
mocks := setupMocks(t)
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// And mock config handler returns "talos" for cluster driver
mockConfigHandler := runtime.ConfigHandler.(*config.MockConfigHandler)
Expand Down Expand Up @@ -904,7 +904,7 @@ func TestRuntime_LoadKubernetes(t *testing.T) {
t.Error("Expected error when config handler not loaded")
}

expectedError := "config handler not loaded - call LoadConfigHandler() first"
expectedError := "config handler not loaded - call LoadConfig() first"
if runtime.err.Error() != expectedError {
t.Errorf("Expected error %q, got %q", expectedError, runtime.err.Error())
}
Expand All @@ -921,7 +921,7 @@ func TestRuntime_LoadKubernetes(t *testing.T) {
t.Run("ReturnsErrorWhenUnsupportedClusterDriver", func(t *testing.T) {
// Given a runtime with loaded config handler
mocks := setupMocks(t)
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// And mock config handler returns unsupported cluster driver
mockConfigHandler := runtime.ConfigHandler.(*config.MockConfigHandler)
Expand Down Expand Up @@ -989,7 +989,7 @@ func TestRuntime_LoadKubernetes(t *testing.T) {
t.Run("ReusesExistingKubernetesClient", func(t *testing.T) {
// Given a runtime with loaded config handler
mocks := setupMocks(t)
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// And mock config handler returns "talos" for cluster driver
mockConfigHandler := runtime.ConfigHandler.(*config.MockConfigHandler)
Expand Down Expand Up @@ -1027,7 +1027,7 @@ func TestRuntime_LoadKubernetes(t *testing.T) {
t.Run("ReusesExistingClusterClient", func(t *testing.T) {
// Given a runtime with loaded config handler
mocks := setupMocks(t)
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// And mock config handler returns "talos" for cluster driver
mockConfigHandler := runtime.ConfigHandler.(*config.MockConfigHandler)
Expand Down Expand Up @@ -1064,7 +1064,7 @@ func TestRuntime_LoadKubernetes(t *testing.T) {
t.Run("ReusesExistingKubernetesManager", func(t *testing.T) {
// Given a runtime with loaded config handler
mocks := setupMocks(t)
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// And mock config handler returns "talos" for cluster driver
mockConfigHandler := runtime.ConfigHandler.(*config.MockConfigHandler)
Expand Down Expand Up @@ -1101,7 +1101,7 @@ func TestRuntime_LoadKubernetes(t *testing.T) {
t.Run("PropagatesKubernetesManagerInitializationError", func(t *testing.T) {
// Given a runtime with loaded config handler
mocks := setupMocks(t)
runtime := NewRuntime(mocks).LoadShell().LoadConfigHandler()
runtime := NewRuntime(mocks).LoadShell().LoadConfig()

// And mock config handler returns "talos" for cluster driver
mockConfigHandler := runtime.ConfigHandler.(*config.MockConfigHandler)
Expand Down
Loading
Loading