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
8 changes: 4 additions & 4 deletions api/v1alpha1/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Config struct {
// Context represents the context configuration
type Context struct {
ID *string `yaml:"id,omitempty"`
Platform *string `yaml:"platform,omitempty"`
Provider *string `yaml:"provider,omitempty"`
Environment map[string]string `yaml:"environment,omitempty"`
Secrets *secrets.SecretsConfig `yaml:"secrets,omitempty"`
AWS *aws.AWSConfig `yaml:"aws,omitempty"`
Expand All @@ -45,8 +45,8 @@ func (base *Context) Merge(overlay *Context) {
if overlay.ID != nil {
base.ID = overlay.ID
}
if overlay.Platform != nil {
base.Platform = overlay.Platform
if overlay.Provider != nil {
base.Provider = overlay.Provider
}
if overlay.Environment != nil {
if base.Environment == nil {
Expand Down Expand Up @@ -132,7 +132,7 @@ func (c *Context) DeepCopy() *Context {
}
return &Context{
ID: c.ID,
Platform: c.Platform,
Provider: c.Provider,
Environment: environmentCopy,
Secrets: c.Secrets.Copy(),
AWS: c.AWS.Copy(),
Expand Down
26 changes: 13 additions & 13 deletions api/v1alpha1/config_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestConfig_Merge(t *testing.T) {
Network: &network.NetworkConfig{
CIDRBlock: ptrString("192.168.0.0/16"),
},
Platform: ptrString("aws"),
Provider: ptrString("aws"),
}

overlay := &Context{
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestConfig_Merge(t *testing.T) {
Network: &network.NetworkConfig{
CIDRBlock: ptrString("10.0.0.0/8"),
},
Platform: ptrString("azure"),
Provider: ptrString("azure"),
}

base.Merge(overlay)
Expand Down Expand Up @@ -154,8 +154,8 @@ func TestConfig_Merge(t *testing.T) {
if base.Network.CIDRBlock == nil || *base.Network.CIDRBlock != "10.0.0.0/8" {
t.Errorf("Network CIDRBlock mismatch: expected '10.0.0.0/8', got '%s'", *base.Network.CIDRBlock)
}
if base.Platform == nil || *base.Platform != "azure" {
t.Errorf("Platform mismatch: expected 'azure', got '%s'", *base.Platform)
if base.Provider == nil || *base.Provider != "azure" {
t.Errorf("Provider mismatch: expected 'azure', got '%s'", *base.Provider)
}
})

Expand Down Expand Up @@ -204,7 +204,7 @@ func TestConfig_Merge(t *testing.T) {
Network: &network.NetworkConfig{
CIDRBlock: ptrString("192.168.0.0/16"),
},
Platform: ptrString("aws"),
Provider: ptrString("aws"),
}

var overlay *Context = nil
Expand Down Expand Up @@ -252,8 +252,8 @@ func TestConfig_Merge(t *testing.T) {
if base.Network.CIDRBlock == nil || *base.Network.CIDRBlock != "192.168.0.0/16" {
t.Errorf("Network CIDRBlock mismatch: expected '192.168.0.0/16', got '%s'", *base.Network.CIDRBlock)
}
if base.Platform == nil || *base.Platform != "aws" {
t.Errorf("Platform mismatch: expected 'aws', got '%s'", *base.Platform)
if base.Provider == nil || *base.Provider != "aws" {
t.Errorf("Provider mismatch: expected 'aws', got '%s'", *base.Provider)
}
})

Expand Down Expand Up @@ -303,7 +303,7 @@ func TestConfig_Merge(t *testing.T) {
Network: &network.NetworkConfig{
CIDRBlock: ptrString("10.0.0.0/8"),
},
Platform: ptrString("azure"),
Provider: ptrString("azure"),
}

base.Merge(overlay)
Expand Down Expand Up @@ -350,8 +350,8 @@ func TestConfig_Merge(t *testing.T) {
if base.Network.CIDRBlock == nil || *base.Network.CIDRBlock != "10.0.0.0/8" {
t.Errorf("Network CIDRBlock mismatch: expected '10.0.0.0/8', got '%s'", *base.Network.CIDRBlock)
}
if base.Platform == nil || *base.Platform != "azure" {
t.Errorf("Platform mismatch: expected 'azure', got '%s'", *base.Platform)
if base.Provider == nil || *base.Provider != "azure" {
t.Errorf("Provider mismatch: expected 'azure', got '%s'", *base.Provider)
}
})

Expand Down Expand Up @@ -418,7 +418,7 @@ func TestConfig_Copy(t *testing.T) {
End: ptrString("192.168.0.255"),
},
},
Platform: ptrString("local"),
Provider: ptrString("local"),
}

copy := original.DeepCopy()
Expand Down Expand Up @@ -463,8 +463,8 @@ func TestConfig_Copy(t *testing.T) {
if original.Network.CIDRBlock == nil || copy.Network.CIDRBlock == nil || *original.Network.CIDRBlock != *copy.Network.CIDRBlock {
t.Errorf("Network CIDRBlock mismatch: expected %v, got %v", *original.Network.CIDRBlock, *copy.Network.CIDRBlock)
}
if original.Platform == nil || copy.Platform == nil || *original.Platform != *copy.Platform {
t.Errorf("Platform mismatch: expected %v, got %v", *original.Platform, *copy.Platform)
if original.Provider == nil || copy.Provider == nil || *original.Provider != *copy.Provider {
t.Errorf("Provider mismatch: expected %v, got %v", *original.Provider, *copy.Provider)
}
})

Expand Down
25 changes: 21 additions & 4 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"context"
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
Expand All @@ -23,7 +24,8 @@ var (
initArch string
initDocker bool
initGitLivereload bool
initPlatform string
initProvider string
initPlatform string // Deprecated: use initProvider instead
initBlueprint string
initEndpoint string
initSetFlags []string
Expand Down Expand Up @@ -108,9 +110,20 @@ var initCmd = &cobra.Command{
return fmt.Errorf("failed to set git.livereload.enabled: %w", err)
}
}
if initProvider != "" {
if err := configHandler.SetContextValue("provider", initProvider); err != nil {
return fmt.Errorf("failed to set provider: %w", err)
}
}

// Handle deprecated --platform flag
if initPlatform != "" {
if err := configHandler.SetContextValue("platform", initPlatform); err != nil {
return fmt.Errorf("failed to set platform: %w", err)
fmt.Fprintf(os.Stderr, "\033[33mWarning: The --platform flag is deprecated and will be removed in a future version. Please use --provider instead.\033[0m\n")
if initProvider != "" {
return fmt.Errorf("cannot specify both --provider and --platform flags. Please use --provider only")
}
if err := configHandler.SetContextValue("provider", initPlatform); err != nil {
return fmt.Errorf("failed to set provider: %w", err)
}
}

Expand Down Expand Up @@ -146,10 +159,14 @@ func init() {
initCmd.Flags().StringVar(&initArch, "vm-arch", "", "Specify the architecture for Colima")
initCmd.Flags().BoolVar(&initDocker, "docker", false, "Enable Docker")
initCmd.Flags().BoolVar(&initGitLivereload, "git-livereload", false, "Enable Git Livereload")
initCmd.Flags().StringVar(&initPlatform, "platform", "", "Specify the platform to use [local|metal]")
initCmd.Flags().StringVar(&initProvider, "provider", "", "Specify the provider to use [local|metal|aws|azure]")
initCmd.Flags().StringVar(&initPlatform, "platform", "", "Deprecated: use --provider instead")
initCmd.Flags().StringVar(&initBlueprint, "blueprint", "", "Specify the blueprint to use")
initCmd.Flags().StringVar(&initEndpoint, "endpoint", "", "Specify the kubernetes API endpoint")
initCmd.Flags().StringSliceVar(&initSetFlags, "set", []string{}, "Override configuration values. Example: --set dns.enabled=false --set cluster.endpoint=https://localhost:6443")

// Mark the platform flag as deprecated
_ = initCmd.Flags().MarkDeprecated("platform", "use --provider instead")

rootCmd.AddCommand(initCmd)
}
2 changes: 1 addition & 1 deletion cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func TestInitCmd(t *testing.T) {
// When executing the init command with platform flag
cmd := createTestInitCmd()
ctx := context.WithValue(context.Background(), injectorKey, mocks.Injector)
cmd.SetArgs([]string{"--platform", "local"})
cmd.SetArgs([]string{"--provider", "local"})
cmd.SetContext(ctx)
err := cmd.Execute()

Expand Down
12 changes: 6 additions & 6 deletions pkg/blueprint/blueprint_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,16 +365,16 @@ func (b *BaseBlueprintHandler) GetTerraformComponents() []blueprintv1alpha1.Terr
return resolvedBlueprint.TerraformComponents
}

// GetDefaultTemplateData generates default template data based on the platform configuration.
// It uses the embedded platform templates to create a map of template files that can be
// GetDefaultTemplateData generates default template data based on the provider configuration.
// It uses the embedded provider templates to create a map of template files that can be
// used by the init pipeline for generating context-specific configurations.
func (b *BaseBlueprintHandler) GetDefaultTemplateData(contextName string) (map[string][]byte, error) {
platform := b.configHandler.GetString("platform")
if platform == "" {
platform = b.configHandler.GetString("cluster.platform")
provider := b.configHandler.GetString("provider")
if provider == "" {
provider = b.configHandler.GetString("cluster.platform")
}

templateData, err := b.loadPlatformTemplate(platform)
templateData, err := b.loadPlatformTemplate(provider)
if err != nil || len(templateData) == 0 {
templateData, err = b.loadPlatformTemplate("default")
if err != nil {
Expand Down
30 changes: 15 additions & 15 deletions pkg/blueprint/blueprint_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2478,13 +2478,13 @@ func TestBlueprintHandler_GetDefaultTemplateData(t *testing.T) {
}

t.Run("ReturnsDefaultTemplate", func(t *testing.T) {
// Given a blueprint handler with default platform
// Given a blueprint handler with default provider
handler, mocks := setup(t)

// Set platform to default
// Set provider to default
if mockConfigHandler, ok := mocks.ConfigHandler.(*config.MockConfigHandler); ok {
mockConfigHandler.GetStringFunc = func(key string, defaultValue ...string) string {
if key == "platform" {
if key == "provider" {
return "default"
}
return ""
Expand Down Expand Up @@ -2514,13 +2514,13 @@ func TestBlueprintHandler_GetDefaultTemplateData(t *testing.T) {
})

t.Run("ReturnsLocalTemplate", func(t *testing.T) {
// Given a blueprint handler with local platform
// Given a blueprint handler with local provider
handler, mocks := setup(t)

// Set platform to local
// Set provider to local
if mockConfigHandler, ok := mocks.ConfigHandler.(*config.MockConfigHandler); ok {
mockConfigHandler.GetStringFunc = func(key string, defaultValue ...string) string {
if key == "platform" {
if key == "provider" {
return "local"
}
return ""
Expand Down Expand Up @@ -2549,10 +2549,10 @@ func TestBlueprintHandler_GetDefaultTemplateData(t *testing.T) {
// Given a blueprint handler with AWS platform
handler, mocks := setup(t)

// Set platform to aws
// Set provider to aws
if mockConfigHandler, ok := mocks.ConfigHandler.(*config.MockConfigHandler); ok {
mockConfigHandler.GetStringFunc = func(key string, defaultValue ...string) string {
if key == "platform" {
if key == "provider" {
return "aws"
}
return ""
Expand All @@ -2577,11 +2577,11 @@ func TestBlueprintHandler_GetDefaultTemplateData(t *testing.T) {
}
})

t.Run("FallsBackToDefaultWhenPlatformEmpty", func(t *testing.T) {
// Given a blueprint handler with empty platform
t.Run("FallsBackToDefaultWhenProviderEmpty", func(t *testing.T) {
// Given a blueprint handler with empty provider
handler, mocks := setup(t)

// Set platform to empty
// Set provider to empty
if mockConfigHandler, ok := mocks.ConfigHandler.(*config.MockConfigHandler); ok {
mockConfigHandler.GetStringFunc = func(key string, defaultValue ...string) string {
return ""
Expand All @@ -2606,14 +2606,14 @@ func TestBlueprintHandler_GetDefaultTemplateData(t *testing.T) {
}
})

t.Run("FallsBackToDefaultWhenUnknownPlatform", func(t *testing.T) {
// Given a blueprint handler with unknown platform
t.Run("FallsBackToDefaultWhenUnknownProvider", func(t *testing.T) {
// Given a blueprint handler with unknown provider
handler, mocks := setup(t)

// Set platform to unknown
// Set provider to unknown
if mockConfigHandler, ok := mocks.ConfigHandler.(*config.MockConfigHandler); ok {
mockConfigHandler.GetStringFunc = func(key string, defaultValue ...string) string {
if key == "platform" {
if key == "provider" {
return "unknown"
}
return ""
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

// DefaultConfig returns the default configuration
var DefaultConfig = v1alpha1.Context{
Provider: ptrString("local"),
Terraform: &terraform.TerraformConfig{
Enabled: ptrBool(true),
Backend: &terraform.BackendConfig{
Expand Down Expand Up @@ -145,6 +146,7 @@ var commonDNSConfig = dns.DNSConfig{
}

var DefaultConfig_Localhost = v1alpha1.Context{
Provider: ptrString("local"),
Environment: map[string]string{},
Docker: commonDockerConfig.Copy(),
Git: commonGitConfig.Copy(),
Expand All @@ -163,6 +165,7 @@ var DefaultConfig_Localhost = v1alpha1.Context{
}

var DefaultConfig_Full = v1alpha1.Context{
Provider: ptrString("local"),
Environment: map[string]string{},
Docker: commonDockerConfig.Copy(),
Git: commonGitConfig.Copy(),
Expand Down
8 changes: 4 additions & 4 deletions pkg/config/yaml_config_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3307,7 +3307,7 @@ contexts:
Environment: map[string]string{
"DEFAULT_VAR": "default_value",
},
Platform: ptrString("local"),
Provider: ptrString("local"),
}

err = handler.SetDefault(defaultConfig)
Expand All @@ -3322,9 +3322,9 @@ contexts:
}

// And the default values should be added
platform := handler.GetString("platform")
if platform != "local" {
t.Errorf("Expected platform to be added as 'local', got '%s'", platform)
provider := handler.GetString("provider")
if provider != "local" {
t.Errorf("Expected provider to be added as 'local', got '%s'", provider)
}
})
}
8 changes: 4 additions & 4 deletions pkg/pipelines/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,18 @@ func (p *InitPipeline) setDefaultConfiguration(_ context.Context, contextName st
return nil
}

// processPlatformConfiguration applies platform-specific configuration settings based on the "platform" value in the configuration handler.
// processPlatformConfiguration applies provider-specific configuration settings based on the "provider" value in the configuration handler.
// For "aws", it enables AWS and sets the cluster driver to "eks".
// For "azure", it enables Azure and sets the cluster driver to "aks".
// For "metal" and "local", it sets the cluster driver to "talos".
// Returns an error if any configuration operation fails.
func (p *InitPipeline) processPlatformConfiguration(_ context.Context) error {
platform := p.configHandler.GetString("platform")
if platform == "" {
provider := p.configHandler.GetString("provider")
if provider == "" {
return nil
}

switch platform {
switch provider {
case "aws":
if err := p.configHandler.SetContextValue("aws.enabled", true); err != nil {
return fmt.Errorf("Error setting aws.enabled: %w", err)
Expand Down
Loading
Loading