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
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/windsor/main.go",
"args": ["init", "local"]
"args": ["init", "local"],
},
{
"name": "Windsor Up",
Expand Down
2 changes: 1 addition & 1 deletion cmd/build_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/shell"
"github.com/windsorcli/cli/pkg/context/shell"
)

func TestBuildIDCmd(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"testing"

"github.com/spf13/cobra"
"github.com/windsorcli/cli/pkg/config"
"github.com/windsorcli/cli/pkg/context/config"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/infrastructure/kubernetes"
"github.com/windsorcli/cli/pkg/resources/artifact"
"github.com/windsorcli/cli/pkg/resources/blueprint"
"github.com/windsorcli/cli/pkg/shell"
"github.com/windsorcli/cli/pkg/context/shell"
)

// =============================================================================
Expand Down
4 changes: 2 additions & 2 deletions cmd/down_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/windsorcli/cli/pkg/config"
"github.com/windsorcli/cli/pkg/context/config"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/pipelines"
"github.com/windsorcli/cli/pkg/shell"
"github.com/windsorcli/cli/pkg/context/shell"
)

// =============================================================================
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/windsorcli/cli/pkg/config"
"github.com/windsorcli/cli/pkg/context/config"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/pipelines"
"github.com/windsorcli/cli/pkg/runtime"
Expand Down
4 changes: 2 additions & 2 deletions cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/windsorcli/cli/pkg/config"
"github.com/windsorcli/cli/pkg/context/config"
"github.com/windsorcli/cli/pkg/constants"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/pipelines"
"github.com/windsorcli/cli/pkg/shell"
"github.com/windsorcli/cli/pkg/context/shell"
)

// =============================================================================
Expand Down
4 changes: 2 additions & 2 deletions cmd/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"testing"

"github.com/spf13/cobra"
"github.com/windsorcli/cli/pkg/config"
"github.com/windsorcli/cli/pkg/context/config"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/infrastructure/kubernetes"
"github.com/windsorcli/cli/pkg/resources/artifact"
"github.com/windsorcli/cli/pkg/resources/blueprint"
"github.com/windsorcli/cli/pkg/shell"
"github.com/windsorcli/cli/pkg/context/shell"
)

// =============================================================================
Expand Down
8 changes: 4 additions & 4 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
"testing"

"github.com/spf13/cobra"
"github.com/windsorcli/cli/pkg/config"
"github.com/windsorcli/cli/pkg/context/config"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/environment/envvars"
envvars "github.com/windsorcli/cli/pkg/context/env"
"github.com/windsorcli/cli/pkg/infrastructure/kubernetes"
blueprintpkg "github.com/windsorcli/cli/pkg/resources/blueprint"
"github.com/windsorcli/cli/pkg/secrets"
"github.com/windsorcli/cli/pkg/shell"
"github.com/windsorcli/cli/pkg/context/secrets"
"github.com/windsorcli/cli/pkg/context/shell"
)

// =============================================================================
Expand Down
4 changes: 2 additions & 2 deletions cmd/up_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/windsorcli/cli/pkg/config"
"github.com/windsorcli/cli/pkg/context/config"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/pipelines"
"github.com/windsorcli/cli/pkg/shell"
"github.com/windsorcli/cli/pkg/context/shell"
)

// =============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"strings"

"github.com/windsorcli/cli/api/v1alpha1"
"github.com/windsorcli/cli/pkg/context/shell"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/shell"
)

// The ConfigHandler is a core component that manages configuration state and context across the application.
Expand Down Expand Up @@ -61,6 +61,7 @@ type configHandler struct {
shims *Shims
schemaValidator *SchemaValidator
data map[string]any
defaultConfig *v1alpha1.Context
}

// =============================================================================
Expand Down Expand Up @@ -323,7 +324,30 @@ func (c *configHandler) SaveConfig(overwrite ...bool) error {
}

if !contextExists || shouldOverwrite {
contextStruct := c.mapToContext(staticFields)
var contextStruct *v1alpha1.Context
if !contextExists && c.defaultConfig != nil {
defaultCopy := c.defaultConfig.DeepCopy()
if len(staticFields) > 0 {
overlayStruct := c.mapToContext(staticFields)
if overlayStruct != nil {
defaultCopy.Merge(overlayStruct)
}
}
contextStruct = defaultCopy
} else {
mergedStaticFields := staticFields
if c.schemaValidator != nil && c.schemaValidator.Schema != nil {
defaults, err := c.schemaValidator.GetSchemaDefaults()
if err == nil && defaults != nil {
defaultsStatic, _ := c.separateStaticAndDynamicFields(defaults)
mergedStaticFields = c.deepMerge(defaultsStatic, staticFields)
}
}
contextStruct = c.mapToContext(mergedStaticFields)
}
if contextStruct == nil {
contextStruct = &v1alpha1.Context{}
}
data, err := c.shims.YamlMarshal(contextStruct)
if err != nil {
return fmt.Errorf("error marshalling context config: %w", err)
Expand Down Expand Up @@ -353,6 +377,8 @@ func (c *configHandler) SaveConfig(overwrite ...bool) error {
// SetDefault sets the default context configuration in the config handler's internal data.
// It marshals the given v1alpha1.Context struct to a map and merges it into the handler's data.
// This method is typically used during initialization when context files do not yet exist.
// The original default config is stored so it can be used when saving a new config file to ensure
// all default values are preserved even if they were empty/nil (which would be omitted by omitempty tags).
func (c *configHandler) SetDefault(context v1alpha1.Context) error {
contextData, err := c.shims.YamlMarshal(context)
if err != nil {
Expand All @@ -365,6 +391,10 @@ func (c *configHandler) SetDefault(context v1alpha1.Context) error {
}

c.data = c.deepMerge(c.data, contextMap)

contextCopy := context
c.defaultConfig = &contextCopy

return nil
}

Expand Down Expand Up @@ -735,6 +765,8 @@ func (c *configHandler) LoadSchemaFromBytes(schemaContent []byte) error {
// The result provides all configuration values, with schema defaults filled in for missing keys, ensuring
// downstream consumers (such as blueprint processing) always receive a complete set of config values.
// If the schema validator or schema is unavailable, only the currently loaded data is returned.
// It also ensures that cluster.controlplanes.nodes and cluster.workers.nodes are initialized as empty maps
// even though they are not serialized to YAML, so template expressions can safely evaluate them.
func (c *configHandler) GetContextValues() (map[string]any, error) {
result := make(map[string]any)
if c.schemaValidator != nil && c.schemaValidator.Schema != nil {
Expand All @@ -744,6 +776,43 @@ func (c *configHandler) GetContextValues() (map[string]any, error) {
}
}
result = c.deepMerge(result, c.data)

clusterVal, ok := result["cluster"].(map[string]any)
if !ok {
if _, exists := result["cluster"]; !exists || result["cluster"] == nil {
result["cluster"] = map[string]any{
"controlplanes": map[string]any{
"nodes": make(map[string]any),
},
"workers": map[string]any{
"nodes": make(map[string]any),
},
}
return result, nil
}
return result, nil
}

if controlplanesVal, ok := clusterVal["controlplanes"].(map[string]any); ok {
if _, exists := controlplanesVal["nodes"]; !exists {
controlplanesVal["nodes"] = make(map[string]any)
}
} else {
clusterVal["controlplanes"] = map[string]any{
"nodes": make(map[string]any),
}
}

if workersVal, ok := clusterVal["workers"].(map[string]any); ok {
if _, exists := workersVal["nodes"]; !exists {
workersVal["nodes"] = make(map[string]any)
}
} else {
clusterVal["workers"] = map[string]any{
"nodes": make(map[string]any),
}
}

return result, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/shell"
"github.com/windsorcli/cli/pkg/context/shell"
)

// =============================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/windsorcli/cli/api/v1alpha1"
"github.com/windsorcli/cli/pkg/di"
"github.com/windsorcli/cli/pkg/shell"
"github.com/windsorcli/cli/pkg/context/shell"
)

// =============================================================================
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/goccy/go-yaml"
"github.com/windsorcli/cli/pkg/shell"
"github.com/windsorcli/cli/pkg/context/shell"
)

// The SchemaValidator is a JSON Schema validation component for Windsor blueprints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
"testing"

"github.com/windsorcli/cli/pkg/shell"
"github.com/windsorcli/cli/pkg/context/shell"
)

// The SchemaValidatorTest is a comprehensive test suite for the SchemaValidator component.
Expand Down
File renamed without changes.
Loading
Loading