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
29 changes: 15 additions & 14 deletions pkg/runtime/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ import (
"github.com/windsorcli/cli/pkg/constants"
)

// DefaultConfig returns the default configuration for non-dev contexts
// Uses minimal config since non-dev contexts default to provider "none"
var DefaultConfig = v1alpha1.Context{
Provider: ptrString("none"),
Terraform: commonTerraformConfig.Copy(),
}

// DefaultConfig_None returns a minimal default configuration for provider "none"
// with terraform enabled but no cluster or DNS settings
var DefaultConfig_None = v1alpha1.Context{
Provider: ptrString("none"),
Terraform: commonTerraformConfig.Copy(),
}

var commonDockerConfig = docker.DockerConfig{
Enabled: ptrBool(true),
Registries: map[string]docker.RegistryConfig{
Expand Down Expand Up @@ -76,6 +62,12 @@ var commonTerraformConfig = terraform.TerraformConfig{
},
}

// commonClusterConfig_Minimal is a minimal cluster configuration with only enabled set to true.
// Used for provider-specific configurations where the driver will be set by ApplyProviderDefaults.
var commonClusterConfig_Minimal = cluster.ClusterConfig{
Enabled: ptrBool(true),
}

// commonClusterConfig_NoHostPorts is the base cluster configuration without hostports,
// used for VM drivers that use native networking (colima, docker)
var commonClusterConfig_NoHostPorts = cluster.ClusterConfig{
Expand Down Expand Up @@ -120,6 +112,15 @@ var commonClusterConfig_WithHostPorts = cluster.ClusterConfig{
},
}

// DefaultConfig returns the default configuration for non-dev contexts
// Uses minimal config since non-dev contexts default to provider "none"
// Includes cluster.enabled=true for provider-specific contexts (aws, azure)
var DefaultConfig = v1alpha1.Context{
Provider: ptrString("none"),
Terraform: commonTerraformConfig.Copy(),
Cluster: commonClusterConfig_Minimal.Copy(),
}

var DefaultConfig_Localhost = v1alpha1.Context{
Provider: ptrString("generic"),
Environment: map[string]string{},
Expand Down
2 changes: 1 addition & 1 deletion pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ func (rt *Runtime) ApplyConfigDefaults(flagOverrides ...map[string]any) error {

provider := rt.ConfigHandler.GetString("provider")
if provider == "none" {
if err := rt.ConfigHandler.SetDefault(config.DefaultConfig_None); err != nil {
if err := rt.ConfigHandler.SetDefault(config.DefaultConfig); err != nil {
return fmt.Errorf("failed to set default config: %w", err)
}
} else if vmDriver == "docker-desktop" {
Expand Down
10 changes: 5 additions & 5 deletions pkg/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1558,16 +1558,16 @@ func TestRuntime_ApplyConfigDefaults(t *testing.T) {
}

if setDefaultConfig.Provider == nil || *setDefaultConfig.Provider != "none" {
t.Error("Expected DefaultConfig_None to be set with provider 'none'")
t.Error("Expected DefaultConfig to be set with provider 'none'")
}
if setDefaultConfig.Cluster != nil {
t.Error("Expected DefaultConfig_None to have no cluster config")
if setDefaultConfig.Cluster == nil || setDefaultConfig.Cluster.Enabled == nil || !*setDefaultConfig.Cluster.Enabled {
t.Error("Expected DefaultConfig to have cluster.enabled=true")
}
if setDefaultConfig.DNS != nil {
t.Error("Expected DefaultConfig_None to have no DNS config")
t.Error("Expected DefaultConfig to have no DNS config")
}
if setDefaultConfig.Terraform == nil || setDefaultConfig.Terraform.Enabled == nil || !*setDefaultConfig.Terraform.Enabled {
t.Error("Expected DefaultConfig_None to have terraform enabled")
t.Error("Expected DefaultConfig to have terraform enabled")
}
})

Expand Down
Loading