From 1fc4fe56958e0edc2398becd5a2da601a89ebc1a Mon Sep 17 00:00:00 2001 From: Ryan VanGundy <85766511+rmvangun@users.noreply.github.com> Date: Sun, 2 Nov 2025 17:22:20 -0500 Subject: [PATCH 1/2] refactor(constants): Make global constants camelcase Follow idiomatic Go by making constants camel case vs. all caps. Signed-off-by: Ryan VanGundy <85766511+rmvangun@users.noreply.github.com> --- .github/renovate.json | 2 +- api/v1alpha1/blueprint_types.go | 10 +- api/v1alpha1/blueprint_types_test.go | 4 +- cmd/check.go | 2 +- cmd/init_test.go | 48 ++-- pkg/composer/blueprint/blueprint_handler.go | 58 ++--- .../blueprint_handler_public_test.go | 22 +- pkg/constants/constants.go | 219 ++++++++++-------- pkg/context/config/defaults.go | 40 ++-- pkg/context/env/kube_env.go | 2 +- pkg/context/tools/tools_manager.go | 32 +-- pkg/context/tools/tools_manager_test.go | 40 ++-- pkg/provisioner/cluster/cluster_client.go | 4 +- .../cluster/cluster_client_test.go | 8 +- .../kubernetes/kubernetes_manager.go | 16 +- pkg/provisioner/provisioner.go | 2 +- pkg/workstation/network/colima_network.go | 2 +- pkg/workstation/network/network.go | 2 +- pkg/workstation/services/dns_service.go | 2 +- .../services/git_livereload_service.go | 14 +- .../services/git_livereload_service_test.go | 2 +- .../services/localstack_service.go | 4 +- pkg/workstation/services/registry_service.go | 6 +- .../services/registry_service_test.go | 10 +- pkg/workstation/services/talos_service.go | 14 +- .../services/talos_service_test.go | 66 +++--- 26 files changed, 324 insertions(+), 307 deletions(-) diff --git a/.github/renovate.json b/.github/renovate.json index 959219834..44d5cc13d 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -83,7 +83,7 @@ "/^pkg/constants/constants.go$/" ], "matchStrings": [ - "// renovate: datasource=(?\\S+) depName=(?\\S+)\n\\s*\\w+\\s*=\\s*\"(?[^\"]+)\"" + "// renovate: datasource=(?\\S+) depName=(?\\S+)\n.*?(?v?\\d+\\.\\d+\\.\\d+[^\"\\s]*)" ], "datasourceTemplate": "{{datasource}}", "versioningTemplate": "semver" diff --git a/api/v1alpha1/blueprint_types.go b/api/v1alpha1/blueprint_types.go index a0e277aac..ce78a40cb 100644 --- a/api/v1alpha1/blueprint_types.go +++ b/api/v1alpha1/blueprint_types.go @@ -626,27 +626,27 @@ func (k *Kustomization) ToFluxKustomization(namespace string, defaultSourceName path = "kustomize/" + strings.ReplaceAll(path, "\\", "/") } - interval := metav1.Duration{Duration: constants.DEFAULT_FLUX_KUSTOMIZATION_INTERVAL} + interval := metav1.Duration{Duration: constants.DefaultFluxKustomizationInterval} if k.Interval != nil && k.Interval.Duration != 0 { interval = *k.Interval } - retryInterval := metav1.Duration{Duration: constants.DEFAULT_FLUX_KUSTOMIZATION_RETRY_INTERVAL} + retryInterval := metav1.Duration{Duration: constants.DefaultFluxKustomizationRetryInterval} if k.RetryInterval != nil && k.RetryInterval.Duration != 0 { retryInterval = *k.RetryInterval } - timeout := metav1.Duration{Duration: constants.DEFAULT_FLUX_KUSTOMIZATION_TIMEOUT} + timeout := metav1.Duration{Duration: constants.DefaultFluxKustomizationTimeout} if k.Timeout != nil && k.Timeout.Duration != 0 { timeout = *k.Timeout } - wait := constants.DEFAULT_FLUX_KUSTOMIZATION_WAIT + wait := constants.DefaultFluxKustomizationWait if k.Wait != nil { wait = *k.Wait } - force := constants.DEFAULT_FLUX_KUSTOMIZATION_FORCE + force := constants.DefaultFluxKustomizationForce if k.Force != nil { force = *k.Force } diff --git a/api/v1alpha1/blueprint_types_test.go b/api/v1alpha1/blueprint_types_test.go index 967eda643..bc736a2f3 100644 --- a/api/v1alpha1/blueprint_types_test.go +++ b/api/v1alpha1/blueprint_types_test.go @@ -825,7 +825,7 @@ func TestKustomization_ToFluxKustomization(t *testing.T) { if result.Spec.Path != "kustomize/test/path" { t.Errorf("Expected path 'kustomize/test/path', got '%s'", result.Spec.Path) } - if result.Spec.Interval.Duration != constants.DEFAULT_FLUX_KUSTOMIZATION_INTERVAL { + if result.Spec.Interval.Duration != constants.DefaultFluxKustomizationInterval { t.Errorf("Expected default interval, got %v", result.Spec.Interval.Duration) } if result.Spec.PostBuild == nil { @@ -1114,7 +1114,7 @@ func TestKustomization_ToFluxKustomization(t *testing.T) { result := kustomization.ToFluxKustomization("test-namespace", "default-source", []Source{}) - if result.Spec.Interval.Duration != constants.DEFAULT_FLUX_KUSTOMIZATION_INTERVAL { + if result.Spec.Interval.Duration != constants.DefaultFluxKustomizationInterval { t.Errorf("Expected default interval, got %v", result.Spec.Interval.Duration) } }) diff --git a/cmd/check.go b/cmd/check.go index 9699be941..16399d4ab 100644 --- a/cmd/check.go +++ b/cmd/check.go @@ -68,7 +68,7 @@ var checkNodeHealthCmd = &cobra.Command{ // If timeout is not set via flag, use default if !cmd.Flags().Changed("timeout") { - nodeHealthTimeout = constants.DEFAULT_NODE_HEALTH_CHECK_TIMEOUT + nodeHealthTimeout = constants.DefaultNodeHealthCheckTimeout } // Create output function diff --git a/cmd/init_test.go b/cmd/init_test.go index d30d2515b..36b6e9a3a 100644 --- a/cmd/init_test.go +++ b/cmd/init_test.go @@ -495,12 +495,12 @@ func TestInitCmd(t *testing.T) { // If context is "local" and neither provider nor blueprint is set, set both if len(args) > 0 && strings.HasPrefix(args[0], "local") && initProvider == "" && initBlueprint == "" { initProvider = "generic" - initBlueprint = constants.DEFAULT_OCI_BLUEPRINT_URL + initBlueprint = constants.DefaultOCIBlueprintURL } // If provider is set and blueprint is not set, set blueprint (covers all providers, including local) if initProvider != "" && initBlueprint == "" { - initBlueprint = constants.DEFAULT_OCI_BLUEPRINT_URL + initBlueprint = constants.DefaultOCIBlueprintURL } // If blueprint is set, use it (overrides all) @@ -517,8 +517,8 @@ func TestInitCmd(t *testing.T) { t.Errorf("Expected blueprint to be set in context for local context") } else if blueprint, ok := blueprintCtx.(string); !ok { t.Errorf("Expected blueprint context value to be a string") - } else if blueprint != constants.DEFAULT_OCI_BLUEPRINT_URL { - t.Errorf("Expected blueprint to be %s, got %s", constants.DEFAULT_OCI_BLUEPRINT_URL, blueprint) + } else if blueprint != constants.DefaultOCIBlueprintURL { + t.Errorf("Expected blueprint to be %s, got %s", constants.DefaultOCIBlueprintURL, blueprint) } }) @@ -536,12 +536,12 @@ func TestInitCmd(t *testing.T) { // If context is "local" and neither provider nor blueprint is set, set both if len(args) > 0 && strings.HasPrefix(args[0], "local") && initProvider == "" && initBlueprint == "" { initProvider = "generic" - initBlueprint = constants.DEFAULT_OCI_BLUEPRINT_URL + initBlueprint = constants.DefaultOCIBlueprintURL } // If provider is set and blueprint is not set, set blueprint (covers all providers, including local) if initProvider != "" && initBlueprint == "" { - initBlueprint = constants.DEFAULT_OCI_BLUEPRINT_URL + initBlueprint = constants.DefaultOCIBlueprintURL } // If blueprint is set, use it (overrides all) @@ -558,8 +558,8 @@ func TestInitCmd(t *testing.T) { t.Errorf("Expected blueprint to be set in context when explicit provider is specified") } else if blueprint, ok := blueprintCtx.(string); !ok { t.Errorf("Expected blueprint context value to be a string") - } else if blueprint != constants.DEFAULT_OCI_BLUEPRINT_URL { - t.Errorf("Expected blueprint to be %s, got %s", constants.DEFAULT_OCI_BLUEPRINT_URL, blueprint) + } else if blueprint != constants.DefaultOCIBlueprintURL { + t.Errorf("Expected blueprint to be %s, got %s", constants.DefaultOCIBlueprintURL, blueprint) } }) @@ -577,12 +577,12 @@ func TestInitCmd(t *testing.T) { // If context is "local" and neither provider nor blueprint is set, set both if len(args) > 0 && strings.HasPrefix(args[0], "local") && initProvider == "" && initBlueprint == "" { initProvider = "generic" - initBlueprint = constants.DEFAULT_OCI_BLUEPRINT_URL + initBlueprint = constants.DefaultOCIBlueprintURL } // If provider is set and blueprint is not set, set blueprint (covers all providers, including local) if initProvider != "" && initBlueprint == "" { - initBlueprint = constants.DEFAULT_OCI_BLUEPRINT_URL + initBlueprint = constants.DefaultOCIBlueprintURL } // If blueprint is set, use it (overrides all) @@ -614,12 +614,12 @@ func TestInitCmd(t *testing.T) { // If context is "local" and neither provider nor blueprint is set, set both if len(args) > 0 && strings.HasPrefix(args[0], "local") && initProvider == "" && initBlueprint == "" { initProvider = "generic" - initBlueprint = constants.DEFAULT_OCI_BLUEPRINT_URL + initBlueprint = constants.DefaultOCIBlueprintURL } // If provider is set and blueprint is not set, set blueprint (covers all providers, including local) if initProvider != "" && initBlueprint == "" { - initBlueprint = constants.DEFAULT_OCI_BLUEPRINT_URL + initBlueprint = constants.DefaultOCIBlueprintURL } // If blueprint is set, use it (overrides all) @@ -649,7 +649,7 @@ func TestInitCmd(t *testing.T) { // If provider is set and blueprint is not set, set blueprint (covers all providers, including local) if initProvider != "" && initBlueprint == "" { - initBlueprint = constants.DEFAULT_OCI_BLUEPRINT_URL + initBlueprint = constants.DefaultOCIBlueprintURL } if initBlueprint != "" { @@ -661,8 +661,8 @@ func TestInitCmd(t *testing.T) { t.Errorf("Expected blueprint to be set in context when provider is specified") } else if blueprint, ok := blueprintCtx.(string); !ok { t.Errorf("Expected blueprint context value to be a string") - } else if blueprint != constants.DEFAULT_OCI_BLUEPRINT_URL { - t.Errorf("Expected blueprint to be %s, got %s", constants.DEFAULT_OCI_BLUEPRINT_URL, blueprint) + } else if blueprint != constants.DefaultOCIBlueprintURL { + t.Errorf("Expected blueprint to be %s, got %s", constants.DefaultOCIBlueprintURL, blueprint) } }) @@ -678,7 +678,7 @@ func TestInitCmd(t *testing.T) { // If provider is set and blueprint is not set, set blueprint (covers all providers, including local) if initProvider != "" && initBlueprint == "" { - initBlueprint = constants.DEFAULT_OCI_BLUEPRINT_URL + initBlueprint = constants.DefaultOCIBlueprintURL } if initBlueprint != "" { @@ -708,7 +708,7 @@ func TestInitCmd(t *testing.T) { // Handle deprecated --platform flag and set blueprint if initPlatform != "" && initProvider == "" && initBlueprint == "" { - initBlueprint = constants.DEFAULT_OCI_BLUEPRINT_URL + initBlueprint = constants.DefaultOCIBlueprintURL } if initBlueprint != "" { @@ -720,8 +720,8 @@ func TestInitCmd(t *testing.T) { t.Errorf("Expected blueprint to be set in context when platform is specified") } else if blueprint, ok := blueprintCtx.(string); !ok { t.Errorf("Expected blueprint context value to be a string") - } else if blueprint != constants.DEFAULT_OCI_BLUEPRINT_URL { - t.Errorf("Expected blueprint to be %s, got %s", constants.DEFAULT_OCI_BLUEPRINT_URL, blueprint) + } else if blueprint != constants.DefaultOCIBlueprintURL { + t.Errorf("Expected blueprint to be %s, got %s", constants.DefaultOCIBlueprintURL, blueprint) } }) @@ -740,7 +740,7 @@ func TestInitCmd(t *testing.T) { provider: "", blueprint: "", expectedProvider: "local", - expectedBlueprint: constants.DEFAULT_OCI_BLUEPRINT_URL, + expectedBlueprint: constants.DefaultOCIBlueprintURL, }, { name: "local-dev context with no flags", @@ -748,7 +748,7 @@ func TestInitCmd(t *testing.T) { provider: "", blueprint: "", expectedProvider: "local", - expectedBlueprint: constants.DEFAULT_OCI_BLUEPRINT_URL, + expectedBlueprint: constants.DefaultOCIBlueprintURL, }, { name: "local context with explicit provider", @@ -756,7 +756,7 @@ func TestInitCmd(t *testing.T) { provider: "aws", blueprint: "", expectedProvider: "aws", - expectedBlueprint: constants.DEFAULT_OCI_BLUEPRINT_URL, + expectedBlueprint: constants.DefaultOCIBlueprintURL, }, { name: "local context with explicit blueprint", @@ -790,12 +790,12 @@ func TestInitCmd(t *testing.T) { // If context is "local" and neither provider nor blueprint is set, set both if len(tc.args) > 0 && strings.HasPrefix(tc.args[0], "local") && initProvider == "" && initBlueprint == "" { initProvider = "local" - initBlueprint = constants.DEFAULT_OCI_BLUEPRINT_URL + initBlueprint = constants.DefaultOCIBlueprintURL } // If provider is set and blueprint is not set, set blueprint (covers all providers, including local) if initProvider != "" && initBlueprint == "" { - initBlueprint = constants.DEFAULT_OCI_BLUEPRINT_URL + initBlueprint = constants.DefaultOCIBlueprintURL } // If blueprint is set, use it (overrides all) diff --git a/pkg/composer/blueprint/blueprint_handler.go b/pkg/composer/blueprint/blueprint_handler.go index 313bd702d..7098af252 100644 --- a/pkg/composer/blueprint/blueprint_handler.go +++ b/pkg/composer/blueprint/blueprint_handler.go @@ -314,7 +314,7 @@ func (b *BaseBlueprintHandler) WaitForKustomizations(message string, names ...st defer spin.Stop() timeout := b.shims.TimeAfter(b.calculateMaxWaitTime()) - ticker := b.shims.NewTicker(constants.DEFAULT_KUSTOMIZATION_WAIT_POLL_INTERVAL) + ticker := b.shims.NewTicker(constants.DefaultKustomizationWaitPollInterval) defer b.shims.TickerStop(ticker) var kustomizationNames []string @@ -351,7 +351,7 @@ func (b *BaseBlueprintHandler) WaitForKustomizations(message string, names ...st ready, err := b.checkKustomizationStatus(kustomizationNames) if err != nil { consecutiveFailures++ - if consecutiveFailures >= constants.DEFAULT_KUSTOMIZATION_WAIT_MAX_FAILURES { + if consecutiveFailures >= constants.DefaultKustomizationWaitMaxFailures { spin.Stop() fmt.Fprintf(os.Stderr, "✗%s - \033[31mFailed\033[0m\n", spin.Suffix) return fmt.Errorf("%s after %d consecutive failures", err.Error(), consecutiveFailures) @@ -382,7 +382,7 @@ func (b *BaseBlueprintHandler) Install() error { spin.Start() defer spin.Stop() - if err := b.kubernetesManager.CreateNamespace(constants.DEFAULT_FLUX_SYSTEM_NAMESPACE); err != nil { + if err := b.kubernetesManager.CreateNamespace(constants.DefaultFluxSystemNamespace); err != nil { spin.Stop() fmt.Fprintf(os.Stderr, "✗%s - \033[31mFailed\033[0m\n", spin.Suffix) return fmt.Errorf("failed to create namespace: %w", err) @@ -395,7 +395,7 @@ func (b *BaseBlueprintHandler) Install() error { Ref: b.blueprint.Repository.Ref, SecretName: b.blueprint.Repository.SecretName, } - if err := b.applySourceRepository(source, constants.DEFAULT_FLUX_SYSTEM_NAMESPACE); err != nil { + if err := b.applySourceRepository(source, constants.DefaultFluxSystemNamespace); err != nil { spin.Stop() fmt.Fprintf(os.Stderr, "✗%s - \033[31mFailed\033[0m\n", spin.Suffix) return fmt.Errorf("failed to apply blueprint repository: %w", err) @@ -403,7 +403,7 @@ func (b *BaseBlueprintHandler) Install() error { } for _, source := range b.blueprint.Sources { - if err := b.applySourceRepository(source, constants.DEFAULT_FLUX_SYSTEM_NAMESPACE); err != nil { + if err := b.applySourceRepository(source, constants.DefaultFluxSystemNamespace); err != nil { spin.Stop() fmt.Fprintf(os.Stderr, "✗%s - \033[31mFailed\033[0m\n", spin.Suffix) return fmt.Errorf("failed to apply source %s: %w", source.Name, err) @@ -419,7 +419,7 @@ func (b *BaseBlueprintHandler) Install() error { kustomizations := b.GetKustomizations() kustomizationNames := make([]string, len(kustomizations)) for i, k := range kustomizations { - if err := b.kubernetesManager.ApplyKustomization(b.toFluxKustomization(k, constants.DEFAULT_FLUX_SYSTEM_NAMESPACE)); err != nil { + if err := b.kubernetesManager.ApplyKustomization(b.toFluxKustomization(k, constants.DefaultFluxSystemNamespace)); err != nil { spin.Stop() fmt.Fprintf(os.Stderr, "✗%s - \033[31mFailed\033[0m\n", spin.Suffix) return fmt.Errorf("failed to apply kustomization %s: %w", k.Name, err) @@ -493,20 +493,20 @@ func (b *BaseBlueprintHandler) GetKustomizations() []blueprintv1alpha1.Kustomiza } if kustomizations[i].Interval == nil || kustomizations[i].Interval.Duration == 0 { - kustomizations[i].Interval = &metav1.Duration{Duration: constants.DEFAULT_FLUX_KUSTOMIZATION_INTERVAL} + kustomizations[i].Interval = &metav1.Duration{Duration: constants.DefaultFluxKustomizationInterval} } if kustomizations[i].RetryInterval == nil || kustomizations[i].RetryInterval.Duration == 0 { - kustomizations[i].RetryInterval = &metav1.Duration{Duration: constants.DEFAULT_FLUX_KUSTOMIZATION_RETRY_INTERVAL} + kustomizations[i].RetryInterval = &metav1.Duration{Duration: constants.DefaultFluxKustomizationRetryInterval} } if kustomizations[i].Timeout == nil || kustomizations[i].Timeout.Duration == 0 { - kustomizations[i].Timeout = &metav1.Duration{Duration: constants.DEFAULT_FLUX_KUSTOMIZATION_TIMEOUT} + kustomizations[i].Timeout = &metav1.Duration{Duration: constants.DefaultFluxKustomizationTimeout} } if kustomizations[i].Wait == nil { - defaultWait := constants.DEFAULT_FLUX_KUSTOMIZATION_WAIT + defaultWait := constants.DefaultFluxKustomizationWait kustomizations[i].Wait = &defaultWait } if kustomizations[i].Force == nil { - defaultForce := constants.DEFAULT_FLUX_KUSTOMIZATION_FORCE + defaultForce := constants.DefaultFluxKustomizationForce kustomizations[i].Force = &defaultForce } if kustomizations[i].Destroy == nil { @@ -538,20 +538,20 @@ func (b *BaseBlueprintHandler) Generate() *blueprintv1alpha1.Blueprint { } if generated.Kustomizations[i].Interval == nil || generated.Kustomizations[i].Interval.Duration == 0 { - generated.Kustomizations[i].Interval = &metav1.Duration{Duration: constants.DEFAULT_FLUX_KUSTOMIZATION_INTERVAL} + generated.Kustomizations[i].Interval = &metav1.Duration{Duration: constants.DefaultFluxKustomizationInterval} } if generated.Kustomizations[i].RetryInterval == nil || generated.Kustomizations[i].RetryInterval.Duration == 0 { - generated.Kustomizations[i].RetryInterval = &metav1.Duration{Duration: constants.DEFAULT_FLUX_KUSTOMIZATION_RETRY_INTERVAL} + generated.Kustomizations[i].RetryInterval = &metav1.Duration{Duration: constants.DefaultFluxKustomizationRetryInterval} } if generated.Kustomizations[i].Timeout == nil || generated.Kustomizations[i].Timeout.Duration == 0 { - generated.Kustomizations[i].Timeout = &metav1.Duration{Duration: constants.DEFAULT_FLUX_KUSTOMIZATION_TIMEOUT} + generated.Kustomizations[i].Timeout = &metav1.Duration{Duration: constants.DefaultFluxKustomizationTimeout} } if generated.Kustomizations[i].Wait == nil { - defaultWait := constants.DEFAULT_FLUX_KUSTOMIZATION_WAIT + defaultWait := constants.DefaultFluxKustomizationWait generated.Kustomizations[i].Wait = &defaultWait } if generated.Kustomizations[i].Force == nil { - defaultForce := constants.DEFAULT_FLUX_KUSTOMIZATION_FORCE + defaultForce := constants.DefaultFluxKustomizationForce generated.Kustomizations[i].Force = &defaultForce } if generated.Kustomizations[i].Destroy == nil { @@ -762,17 +762,17 @@ func (b *BaseBlueprintHandler) destroyKustomizations(ctx context.Context, kustom Source: k.Source, Components: k.Cleanup, Timeout: &metav1.Duration{Duration: 30 * time.Minute}, - Interval: &metav1.Duration{Duration: constants.DEFAULT_FLUX_KUSTOMIZATION_INTERVAL}, - RetryInterval: &metav1.Duration{Duration: constants.DEFAULT_FLUX_KUSTOMIZATION_RETRY_INTERVAL}, + Interval: &metav1.Duration{Duration: constants.DefaultFluxKustomizationInterval}, + RetryInterval: &metav1.Duration{Duration: constants.DefaultFluxKustomizationRetryInterval}, Wait: func() *bool { b := true; return &b }(), Force: func() *bool { b := true; return &b }(), } - if err := b.kubernetesManager.ApplyKustomization(b.toFluxKustomization(*cleanupKustomization, constants.DEFAULT_FLUX_SYSTEM_NAMESPACE)); err != nil { + if err := b.kubernetesManager.ApplyKustomization(b.toFluxKustomization(*cleanupKustomization, constants.DefaultFluxSystemNamespace)); err != nil { return fmt.Errorf("failed to apply cleanup kustomization for %s: %w", k.Name, err) } - timeout := b.shims.TimeAfter(constants.DEFAULT_FLUX_CLEANUP_TIMEOUT) + timeout := b.shims.TimeAfter(constants.DefaultFluxCleanupTimeout) ticker := b.shims.NewTicker(2 * time.Second) defer b.shims.TickerStop(ticker) @@ -799,14 +799,14 @@ func (b *BaseBlueprintHandler) destroyKustomizations(ctx context.Context, kustom cleanupSpin.Stop() if !cleanupReady { - fmt.Fprintf(os.Stderr, "Warning: Cleanup kustomization %s did not become ready within %v, proceeding anyway\n", cleanupKustomization.Name, constants.DEFAULT_FLUX_CLEANUP_TIMEOUT) + fmt.Fprintf(os.Stderr, "Warning: Cleanup kustomization %s did not become ready within %v, proceeding anyway\n", cleanupKustomization.Name, constants.DefaultFluxCleanupTimeout) } fmt.Fprintf(os.Stderr, "\033[32m✔\033[0m 🧹 Applying cleanup kustomization for %s - \033[32mDone\033[0m\n", k.Name) cleanupDeleteSpin := spinner.New(spinner.CharSets[14], 100*time.Millisecond, spinner.WithColor("green")) cleanupDeleteSpin.Suffix = fmt.Sprintf(" 🗑️ Deleting cleanup kustomization %s", cleanupKustomization.Name) cleanupDeleteSpin.Start() - if err := b.kubernetesManager.DeleteKustomization(cleanupKustomization.Name, constants.DEFAULT_FLUX_SYSTEM_NAMESPACE); err != nil { + if err := b.kubernetesManager.DeleteKustomization(cleanupKustomization.Name, constants.DefaultFluxSystemNamespace); err != nil { return fmt.Errorf("failed to delete cleanup kustomization %s: %w", cleanupKustomization.Name, err) } @@ -817,7 +817,7 @@ func (b *BaseBlueprintHandler) destroyKustomizations(ctx context.Context, kustom deleteSpin := spinner.New(spinner.CharSets[14], 100*time.Millisecond, spinner.WithColor("green")) deleteSpin.Suffix = fmt.Sprintf(" 🗑️ Deleting kustomization %s", k.Name) deleteSpin.Start() - if err := b.kubernetesManager.DeleteKustomization(k.Name, constants.DEFAULT_FLUX_SYSTEM_NAMESPACE); err != nil { + if err := b.kubernetesManager.DeleteKustomization(k.Name, constants.DefaultFluxSystemNamespace); err != nil { return fmt.Errorf("failed to delete kustomization %s: %w", k.Name, err) } @@ -1231,10 +1231,10 @@ func (b *BaseBlueprintHandler) applyGitRepository(source blueprintv1alpha1.Sourc Spec: sourcev1.GitRepositorySpec{ URL: sourceUrl, Interval: metav1.Duration{ - Duration: constants.DEFAULT_FLUX_SOURCE_INTERVAL, + Duration: constants.DefaultFluxSourceInterval, }, Timeout: &metav1.Duration{ - Duration: constants.DEFAULT_FLUX_SOURCE_TIMEOUT, + Duration: constants.DefaultFluxSourceTimeout, }, Reference: &sourcev1.GitRepositoryRef{ Branch: source.Ref.Branch, @@ -1296,10 +1296,10 @@ func (b *BaseBlueprintHandler) applyOCIRepository(source blueprintv1alpha1.Sourc Spec: sourcev1.OCIRepositorySpec{ URL: ociURL, Interval: metav1.Duration{ - Duration: constants.DEFAULT_FLUX_SOURCE_INTERVAL, + Duration: constants.DefaultFluxSourceInterval, }, Timeout: &metav1.Duration{ - Duration: constants.DEFAULT_FLUX_SOURCE_TIMEOUT, + Duration: constants.DefaultFluxSourceTimeout, }, Reference: ref, }, @@ -1357,7 +1357,7 @@ func (b *BaseBlueprintHandler) calculateMaxWaitTime() time.Duration { if k.Timeout != nil { timeouts[k.Name] = k.Timeout.Duration } else { - timeouts[k.Name] = constants.DEFAULT_FLUX_KUSTOMIZATION_TIMEOUT + timeouts[k.Name] = constants.DefaultFluxKustomizationTimeout } } @@ -1804,7 +1804,7 @@ func (b *BaseBlueprintHandler) createConfigMap(values map[string]any, configMapN return fmt.Errorf("failed to flatten values for %s: %w", configMapName, err) } - if err := b.kubernetesManager.ApplyConfigMap(configMapName, constants.DEFAULT_FLUX_SYSTEM_NAMESPACE, stringValues); err != nil { + if err := b.kubernetesManager.ApplyConfigMap(configMapName, constants.DefaultFluxSystemNamespace, stringValues); err != nil { return fmt.Errorf("failed to apply ConfigMap %s: %w", configMapName, err) } diff --git a/pkg/composer/blueprint/blueprint_handler_public_test.go b/pkg/composer/blueprint/blueprint_handler_public_test.go index 421559002..453e47064 100644 --- a/pkg/composer/blueprint/blueprint_handler_public_test.go +++ b/pkg/composer/blueprint/blueprint_handler_public_test.go @@ -1115,14 +1115,14 @@ func TestBlueprintHandler_Install(t *testing.T) { } // Verify k5 (default intervals/timeouts) - if appliedKustomizations[4].Spec.Interval.Duration != constants.DEFAULT_FLUX_KUSTOMIZATION_INTERVAL { - t.Errorf("Expected k5 interval to be %v, got %v", constants.DEFAULT_FLUX_KUSTOMIZATION_INTERVAL, appliedKustomizations[4].Spec.Interval.Duration) + if appliedKustomizations[4].Spec.Interval.Duration != constants.DefaultFluxKustomizationInterval { + t.Errorf("Expected k5 interval to be %v, got %v", constants.DefaultFluxKustomizationInterval, appliedKustomizations[4].Spec.Interval.Duration) } - if appliedKustomizations[4].Spec.RetryInterval.Duration != constants.DEFAULT_FLUX_KUSTOMIZATION_RETRY_INTERVAL { - t.Errorf("Expected k5 retry interval to be %v, got %v", constants.DEFAULT_FLUX_KUSTOMIZATION_RETRY_INTERVAL, appliedKustomizations[4].Spec.RetryInterval.Duration) + if appliedKustomizations[4].Spec.RetryInterval.Duration != constants.DefaultFluxKustomizationRetryInterval { + t.Errorf("Expected k5 retry interval to be %v, got %v", constants.DefaultFluxKustomizationRetryInterval, appliedKustomizations[4].Spec.RetryInterval.Duration) } - if appliedKustomizations[4].Spec.Timeout.Duration != constants.DEFAULT_FLUX_KUSTOMIZATION_TIMEOUT { - t.Errorf("Expected k5 timeout to be %v, got %v", constants.DEFAULT_FLUX_KUSTOMIZATION_TIMEOUT, appliedKustomizations[4].Spec.Timeout.Duration) + if appliedKustomizations[4].Spec.Timeout.Duration != constants.DefaultFluxKustomizationTimeout { + t.Errorf("Expected k5 timeout to be %v, got %v", constants.DefaultFluxKustomizationTimeout, appliedKustomizations[4].Spec.Timeout.Duration) } // Verify k6 (custom intervals/timeouts) @@ -4625,19 +4625,19 @@ func TestBaseBlueprintHandler_Generate(t *testing.T) { if kustomization.Path != "kustomize" { t.Errorf("Expected path 'kustomize', got %s", kustomization.Path) } - if kustomization.Interval == nil || kustomization.Interval.Duration != constants.DEFAULT_FLUX_KUSTOMIZATION_INTERVAL { + if kustomization.Interval == nil || kustomization.Interval.Duration != constants.DefaultFluxKustomizationInterval { t.Errorf("Expected default interval, got %v", kustomization.Interval) } - if kustomization.RetryInterval == nil || kustomization.RetryInterval.Duration != constants.DEFAULT_FLUX_KUSTOMIZATION_RETRY_INTERVAL { + if kustomization.RetryInterval == nil || kustomization.RetryInterval.Duration != constants.DefaultFluxKustomizationRetryInterval { t.Errorf("Expected default retry interval, got %v", kustomization.RetryInterval) } - if kustomization.Timeout == nil || kustomization.Timeout.Duration != constants.DEFAULT_FLUX_KUSTOMIZATION_TIMEOUT { + if kustomization.Timeout == nil || kustomization.Timeout.Duration != constants.DefaultFluxKustomizationTimeout { t.Errorf("Expected default timeout, got %v", kustomization.Timeout) } - if kustomization.Wait == nil || *kustomization.Wait != constants.DEFAULT_FLUX_KUSTOMIZATION_WAIT { + if kustomization.Wait == nil || *kustomization.Wait != constants.DefaultFluxKustomizationWait { t.Errorf("Expected default wait, got %v", kustomization.Wait) } - if kustomization.Force == nil || *kustomization.Force != constants.DEFAULT_FLUX_KUSTOMIZATION_FORCE { + if kustomization.Force == nil || *kustomization.Force != constants.DefaultFluxKustomizationForce { t.Errorf("Expected default force, got %v", kustomization.Force) } if kustomization.Destroy == nil || *kustomization.Destroy != true { diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 57146c7e5..a62f1a3ce 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -2,110 +2,127 @@ package constants import "time" -// Default git livereload settings -const ( - // renovate: datasource=docker depName=ghcr.io/windsorcli/git-livereload-server - DEFAULT_GIT_LIVE_RELOAD_IMAGE = "ghcr.io/windsorcli/git-livereload:v0.2.1" - DEFAULT_GIT_LIVE_RELOAD_RSYNC_INCLUDE = "kustomize" - DEFAULT_GIT_LIVE_RELOAD_RSYNC_EXCLUDE = ".windsor,.terraform,.volumes,.venv" - DEFAULT_GIT_LIVE_RELOAD_RSYNC_PROTECT = "flux-system" - DEFAULT_GIT_LIVE_RELOAD_USERNAME = "local" - DEFAULT_GIT_LIVE_RELOAD_PASSWORD = "local" - // Hook URL corresponds to the webhook token "abcdef123456". - // see: https://fluxcd.io/flux/components/notification/receivers/ - DEFAULT_GIT_LIVE_RELOAD_WEBHOOK_URL = "http://worker-1.test:30292/hook/5dc88e45e809fb0872b749c0969067e2c1fd142e17aed07573fad20553cc0c59" -) - -// Default Talos settings -const ( - // renovate: datasource=github-releases depName=siderolabs/talos - DEFAULT_TALOS_IMAGE = "ghcr.io/siderolabs/talos:v1.9.5" - DEFAULT_TALOS_WORKER_CPU = 4 - DEFAULT_TALOS_WORKER_RAM = 4 - DEFAULT_TALOS_CONTROL_PLANE_CPU = 2 - DEFAULT_TALOS_CONTROL_PLANE_RAM = 2 - DEFAULT_TALOS_API_PORT = 50000 - GRPCMaxMessageSize = 32 * 1024 * 1024 // 32MB -) - -const ( - DEFAULT_FLUX_SYSTEM_NAMESPACE = "system-gitops" - DEFAULT_FLUX_KUSTOMIZATION_INTERVAL = 1 * time.Minute - DEFAULT_FLUX_KUSTOMIZATION_PRUNE = true - DEFAULT_FLUX_KUSTOMIZATION_RETRY_INTERVAL = 2 * time.Minute - DEFAULT_FLUX_KUSTOMIZATION_WAIT = true - DEFAULT_FLUX_KUSTOMIZATION_FORCE = false - DEFAULT_FLUX_KUSTOMIZATION_TIMEOUT = 5 * time.Minute - DEFAULT_FLUX_SOURCE_INTERVAL = 1 * time.Minute - DEFAULT_FLUX_SOURCE_TIMEOUT = 2 * time.Minute - DEFAULT_FLUX_CLEANUP_TIMEOUT = 30 * time.Minute - - // Used for aggregate CLI wait (not per-resource) - DEFAULT_KUSTOMIZATION_WAIT_TOTAL_TIMEOUT = 10 * time.Minute - // Poll interval for CLI WaitForKustomizations - DEFAULT_KUSTOMIZATION_WAIT_POLL_INTERVAL = 5 * time.Second - // Maximum number of consecutive failures before giving up - DEFAULT_KUSTOMIZATION_WAIT_MAX_FAILURES = 5 -) - -// Default AWS settings -const ( - // renovate: datasource=docker depName=localstack/localstack - DEFAULT_AWS_LOCALSTACK_IMAGE = "localstack/localstack:3.8.1" - // renovate: datasource=docker depName=localstack/localstack-pro - DEFAULT_AWS_LOCALSTACK_PRO_IMAGE = "localstack/localstack-pro:3.8.1" -) - -// Default DNS settings -const ( - // renovate: datasource=docker depName=coredns/coredns - DEFAULT_DNS_IMAGE = "coredns/coredns:1.11.3" -) - -// Default Registry settings -const ( - // renovate: datasource=docker depName=registry - REGISTRY_DEFAULT_IMAGE = "registry:2.8.3" - REGISTRY_DEFAULT_HOST_PORT = 5001 -) - -// Default network settings -const ( - DEFAULT_NETWORK_CIDR = "10.5.0.0/16" -) - -// Kubernetes settings -const ( - KUBERNETES_SHORT_TIMEOUT = 200 * time.Millisecond -) - -// Minimum versions for tools -const ( - MINIMUM_VERSION_COLIMA = "0.7.0" - MINIMUM_VERSION_DOCKER = "23.0.0" - MINIMUM_VERSION_DOCKER_COMPOSE = "2.20.0" - MINIMUM_VERSION_KUBECTL = "1.27.0" - MINIMUM_VERSION_LIMA = "1.0.0" - MINIMUM_VERSION_TALOSCTL = "1.7.0" - MINIMUM_VERSION_TERRAFORM = "1.7.0" - MINIMUM_VERSION_1PASSWORD = "2.15.0" - MINIMUM_VERSION_AWS_CLI = "2.15.0" -) - -// Default node health check settings -const ( - DEFAULT_NODE_HEALTH_CHECK_TIMEOUT = 5 * time.Minute - DEFAULT_NODE_HEALTH_CHECK_POLL_INTERVAL = 10 * time.Second -) - -// Default OCI blueprint settings -const ( - DEFAULT_OCI_BLUEPRINT_URL = "oci://ghcr.io/windsorcli/core:latest" -) +// The Constants package provides centralized default values and configuration constants +// It provides shared constants for default settings, timeouts, versions, and resource configurations +// The Constants package serves as a single source of truth for default values across the application +// enabling consistent behavior and easy maintenance of configuration defaults + +// ============================================================================= +// Constants +// ============================================================================= + +// renovate: datasource=docker depName=ghcr.io/windsorcli/git-livereload-server +const DefaultGitLiveReloadImage = "ghcr.io/windsorcli/git-livereload:v0.2.1" + +const DefaultGitLiveReloadRsyncInclude = "kustomize" + +const DefaultGitLiveReloadRsyncExclude = ".windsor,.terraform,.volumes,.venv" + +const DefaultGitLiveReloadRsyncProtect = "flux-system" + +const DefaultGitLiveReloadUsername = "local" + +const DefaultGitLiveReloadPassword = "local" + +// Hook URL corresponds to the webhook token "abcdef123456". +// see: https://fluxcd.io/flux/components/notification/receivers/ +const DefaultGitLiveReloadWebhookURL = "http://worker-1.test:30292/hook/5dc88e45e809fb0872b749c0969067e2c1fd142e17aed07573fad20553cc0c59" + +// renovate: datasource=github-releases depName=siderolabs/talos +const DefaultTalosImage = "ghcr.io/siderolabs/talos:v1.9.5" + +const DefaultTalosWorkerCPU = 4 + +const DefaultTalosWorkerRAM = 4 + +const DefaultTalosControlPlaneCPU = 2 + +const DefaultTalosControlPlaneRAM = 2 + +const DefaultTalosAPIPort = 50000 + +const DefaultFluxSystemNamespace = "system-gitops" + +const DefaultFluxKustomizationInterval = 1 * time.Minute + +const DefaultFluxKustomizationPrune = true + +const DefaultFluxKustomizationRetryInterval = 2 * time.Minute + +const DefaultFluxKustomizationWait = true + +const DefaultFluxKustomizationForce = false + +const DefaultFluxKustomizationTimeout = 5 * time.Minute + +const DefaultFluxSourceInterval = 1 * time.Minute + +const DefaultFluxSourceTimeout = 2 * time.Minute + +const DefaultFluxCleanupTimeout = 30 * time.Minute + +// Used for aggregate CLI wait (not per-resource) +const DefaultKustomizationWaitTotalTimeout = 10 * time.Minute + +// Poll interval for CLI WaitForKustomizations +const DefaultKustomizationWaitPollInterval = 5 * time.Second + +// Maximum number of consecutive failures before giving up +const DefaultKustomizationWaitMaxFailures = 5 + +// renovate: datasource=docker depName=localstack/localstack +const DefaultAWSLocalstackImage = "localstack/localstack:3.8.1" + +// renovate: datasource=docker depName=localstack/localstack-pro +const DefaultAWSLocalstackProImage = "localstack/localstack-pro:3.8.1" + +// renovate: datasource=docker depName=coredns/coredns +const DefaultDNSImage = "coredns/coredns:1.11.3" + +// renovate: datasource=docker depName=registry +const RegistryDefaultImage = "registry:2.8.3" + +const RegistryDefaultHostPort = 5001 + +const DefaultNetworkCIDR = "10.5.0.0/16" + +const KubernetesShortTimeout = 200 * time.Millisecond + +const MinimumVersionColima = "0.7.0" + +const MinimumVersionDocker = "23.0.0" + +const MinimumVersionDockerCompose = "2.20.0" + +const MinimumVersionKubectl = "1.27.0" + +const MinimumVersionLima = "1.0.0" + +const MinimumVersionTalosctl = "1.7.0" + +const MinimumVersionTerraform = "1.7.0" + +const MinimumVersion1Password = "2.15.0" + +const MinimumVersionAWSCLI = "2.15.0" + +const DefaultNodeHealthCheckTimeout = 5 * time.Minute + +const DefaultNodeHealthCheckPollInterval = 10 * time.Second + +const DefaultOCIBlueprintURL = "oci://ghcr.io/windsorcli/core:latest" + +// ============================================================================= +// Variables +// ============================================================================= // Build-time variable for pinned blueprint URL (set via ldflags) var PinnedBlueprintURL = "" +// ============================================================================= +// Helpers +// ============================================================================= + // GetEffectiveBlueprintURL returns the pinned blueprint URL if set at build time, // otherwise returns the default blueprint URL. This allows for different behavior // between development builds (using :latest) and release builds (using pinned versions). @@ -113,5 +130,5 @@ func GetEffectiveBlueprintURL() string { if PinnedBlueprintURL != "" { return PinnedBlueprintURL } - return DEFAULT_OCI_BLUEPRINT_URL + return DefaultOCIBlueprintURL } diff --git a/pkg/context/config/defaults.go b/pkg/context/config/defaults.go index 7161b6420..29ab66cfe 100644 --- a/pkg/context/config/defaults.go +++ b/pkg/context/config/defaults.go @@ -53,12 +53,12 @@ var commonDockerConfig = docker.DockerConfig{ var commonGitConfig = git.GitConfig{ Livereload: &git.GitLivereloadConfig{ Enabled: ptrBool(true), - RsyncInclude: ptrString(constants.DEFAULT_GIT_LIVE_RELOAD_RSYNC_INCLUDE), - RsyncProtect: ptrString(constants.DEFAULT_GIT_LIVE_RELOAD_RSYNC_PROTECT), - Username: ptrString(constants.DEFAULT_GIT_LIVE_RELOAD_USERNAME), - Password: ptrString(constants.DEFAULT_GIT_LIVE_RELOAD_PASSWORD), - WebhookUrl: ptrString(constants.DEFAULT_GIT_LIVE_RELOAD_WEBHOOK_URL), - Image: ptrString(constants.DEFAULT_GIT_LIVE_RELOAD_IMAGE), + RsyncInclude: ptrString(constants.DefaultGitLiveReloadRsyncInclude), + RsyncProtect: ptrString(constants.DefaultGitLiveReloadRsyncProtect), + Username: ptrString(constants.DefaultGitLiveReloadUsername), + Password: ptrString(constants.DefaultGitLiveReloadPassword), + WebhookUrl: ptrString(constants.DefaultGitLiveReloadWebhookURL), + Image: ptrString(constants.DefaultGitLiveReloadImage), VerifySsl: ptrBool(false), }, } @@ -77,15 +77,15 @@ var commonClusterConfig_NoHostPorts = cluster.ClusterConfig{ Driver: ptrString("talos"), ControlPlanes: cluster.NodeGroupConfig{ Count: ptrInt(1), - CPU: ptrInt(constants.DEFAULT_TALOS_CONTROL_PLANE_CPU), - Memory: ptrInt(constants.DEFAULT_TALOS_CONTROL_PLANE_RAM), + CPU: ptrInt(constants.DefaultTalosControlPlaneCPU), + Memory: ptrInt(constants.DefaultTalosControlPlaneRAM), Nodes: make(map[string]cluster.NodeConfig), HostPorts: []string{}, }, Workers: cluster.NodeGroupConfig{ Count: ptrInt(1), - CPU: ptrInt(constants.DEFAULT_TALOS_WORKER_CPU), - Memory: ptrInt(constants.DEFAULT_TALOS_WORKER_RAM), + CPU: ptrInt(constants.DefaultTalosWorkerCPU), + Memory: ptrInt(constants.DefaultTalosWorkerRAM), Nodes: make(map[string]cluster.NodeConfig), HostPorts: []string{}, Volumes: []string{"${WINDSOR_PROJECT_ROOT}/.volumes:/var/local"}, @@ -99,15 +99,15 @@ var commonClusterConfig_WithHostPorts = cluster.ClusterConfig{ Driver: ptrString("talos"), ControlPlanes: cluster.NodeGroupConfig{ Count: ptrInt(1), - CPU: ptrInt(constants.DEFAULT_TALOS_CONTROL_PLANE_CPU), - Memory: ptrInt(constants.DEFAULT_TALOS_CONTROL_PLANE_RAM), + CPU: ptrInt(constants.DefaultTalosControlPlaneCPU), + Memory: ptrInt(constants.DefaultTalosControlPlaneRAM), Nodes: make(map[string]cluster.NodeConfig), HostPorts: []string{}, }, Workers: cluster.NodeGroupConfig{ Count: ptrInt(1), - CPU: ptrInt(constants.DEFAULT_TALOS_WORKER_CPU), - Memory: ptrInt(constants.DEFAULT_TALOS_WORKER_RAM), + CPU: ptrInt(constants.DefaultTalosWorkerCPU), + Memory: ptrInt(constants.DefaultTalosWorkerRAM), Nodes: make(map[string]cluster.NodeConfig), HostPorts: []string{"8080:30080/tcp", "8443:30443/tcp", "9292:30292/tcp", "8053:30053/udp"}, Volumes: []string{"${WINDSOR_PROJECT_ROOT}/.volumes:/var/local"}, @@ -120,14 +120,14 @@ var commonClusterConfig = cluster.ClusterConfig{ Driver: ptrString("talos"), ControlPlanes: cluster.NodeGroupConfig{ Count: ptrInt(1), - CPU: ptrInt(constants.DEFAULT_TALOS_CONTROL_PLANE_CPU), - Memory: ptrInt(constants.DEFAULT_TALOS_CONTROL_PLANE_RAM), + CPU: ptrInt(constants.DefaultTalosControlPlaneCPU), + Memory: ptrInt(constants.DefaultTalosControlPlaneRAM), Nodes: make(map[string]cluster.NodeConfig), }, Workers: cluster.NodeGroupConfig{ Count: ptrInt(1), - CPU: ptrInt(constants.DEFAULT_TALOS_WORKER_CPU), - Memory: ptrInt(constants.DEFAULT_TALOS_WORKER_RAM), + CPU: ptrInt(constants.DefaultTalosWorkerCPU), + Memory: ptrInt(constants.DefaultTalosWorkerRAM), Nodes: make(map[string]cluster.NodeConfig), HostPorts: []string{}, Volumes: []string{"${WINDSOR_PROJECT_ROOT}/.volumes:/var/local"}, @@ -147,7 +147,7 @@ var DefaultConfig_Localhost = v1alpha1.Context{ Terraform: commonTerraformConfig.Copy(), Cluster: commonClusterConfig_WithHostPorts.Copy(), Network: &network.NetworkConfig{ - CIDRBlock: ptrString(constants.DEFAULT_NETWORK_CIDR), + CIDRBlock: ptrString(constants.DefaultNetworkCIDR), }, DNS: &dns.DNSConfig{ Enabled: ptrBool(true), @@ -166,7 +166,7 @@ var DefaultConfig_Full = v1alpha1.Context{ Terraform: commonTerraformConfig.Copy(), Cluster: commonClusterConfig_NoHostPorts.Copy(), Network: &network.NetworkConfig{ - CIDRBlock: ptrString(constants.DEFAULT_NETWORK_CIDR), + CIDRBlock: ptrString(constants.DefaultNetworkCIDR), LoadBalancerIPs: &struct { Start *string `yaml:"start,omitempty"` End *string `yaml:"end,omitempty"` diff --git a/pkg/context/env/kube_env.go b/pkg/context/env/kube_env.go index af92840bc..fffcba577 100644 --- a/pkg/context/env/kube_env.go +++ b/pkg/context/env/kube_env.go @@ -161,7 +161,7 @@ var queryPersistentVolumeClaims = func(kubeConfigPath string) (*corev1.Persisten return nil, err } - ctx, cancel := context.WithTimeout(context.Background(), constants.KUBERNETES_SHORT_TIMEOUT) + ctx, cancel := context.WithTimeout(context.Background(), constants.KubernetesShortTimeout) defer cancel() pvcs, err := clientset.CoreV1().PersistentVolumeClaims("").List(ctx, metav1.ListOptions{}) diff --git a/pkg/context/tools/tools_manager.go b/pkg/context/tools/tools_manager.go index 89479484a..3b25aac95 100644 --- a/pkg/context/tools/tools_manager.go +++ b/pkg/context/tools/tools_manager.go @@ -178,8 +178,8 @@ func (t *BaseToolsManager) checkDocker() error { output, _ := t.shell.ExecSilent("docker", "version", "--format", "{{.Client.Version}}") dockerVersion := extractVersion(output) - if dockerVersion != "" && compareVersion(dockerVersion, constants.MINIMUM_VERSION_DOCKER) < 0 { - return fmt.Errorf("docker version %s is below the minimum required version %s", dockerVersion, constants.MINIMUM_VERSION_DOCKER) + if dockerVersion != "" && compareVersion(dockerVersion, constants.MinimumVersionDocker) < 0 { + return fmt.Errorf("docker version %s is below the minimum required version %s", dockerVersion, constants.MinimumVersionDocker) } var dockerComposeVersion string @@ -197,10 +197,10 @@ func (t *BaseToolsManager) checkDocker() error { // Validate the collected docker-compose version if dockerComposeVersion != "" { - if compareVersion(dockerComposeVersion, constants.MINIMUM_VERSION_DOCKER_COMPOSE) >= 0 { + if compareVersion(dockerComposeVersion, constants.MinimumVersionDockerCompose) >= 0 { return nil } - return fmt.Errorf("docker-compose version %s is below the minimum required version %s", dockerComposeVersion, constants.MINIMUM_VERSION_DOCKER_COMPOSE) + return fmt.Errorf("docker-compose version %s is below the minimum required version %s", dockerComposeVersion, constants.MinimumVersionDockerCompose) } if _, err := execLookPath("docker-cli-plugin-docker-compose"); err == nil { @@ -222,8 +222,8 @@ func (t *BaseToolsManager) checkColima() error { if colimaVersion == "" { return fmt.Errorf("failed to extract colima version") } - if compareVersion(colimaVersion, constants.MINIMUM_VERSION_COLIMA) < 0 { - return fmt.Errorf("colima version %s is below the minimum required version %s", colimaVersion, constants.MINIMUM_VERSION_COLIMA) + if compareVersion(colimaVersion, constants.MinimumVersionColima) < 0 { + return fmt.Errorf("colima version %s is below the minimum required version %s", colimaVersion, constants.MinimumVersionColima) } if _, err := execLookPath("limactl"); err != nil { @@ -234,8 +234,8 @@ func (t *BaseToolsManager) checkColima() error { if limactlVersion == "" { return fmt.Errorf("failed to extract limactl version") } - if compareVersion(limactlVersion, constants.MINIMUM_VERSION_LIMA) < 0 { - return fmt.Errorf("limactl version %s is below the minimum required version %s", limactlVersion, constants.MINIMUM_VERSION_LIMA) + if compareVersion(limactlVersion, constants.MinimumVersionLima) < 0 { + return fmt.Errorf("limactl version %s is below the minimum required version %s", limactlVersion, constants.MinimumVersionLima) } return nil @@ -253,8 +253,8 @@ func (t *BaseToolsManager) checkKubectl() error { if kubectlVersion == "" { return fmt.Errorf("failed to extract kubectl version") } - if compareVersion(kubectlVersion, constants.MINIMUM_VERSION_KUBECTL) < 0 { - return fmt.Errorf("kubectl version %s is below the minimum required version %s", kubectlVersion, constants.MINIMUM_VERSION_KUBECTL) + if compareVersion(kubectlVersion, constants.MinimumVersionKubectl) < 0 { + return fmt.Errorf("kubectl version %s is below the minimum required version %s", kubectlVersion, constants.MinimumVersionKubectl) } return nil @@ -272,8 +272,8 @@ func (t *BaseToolsManager) checkTerraform() error { if terraformVersion == "" { return fmt.Errorf("failed to extract terraform version") } - if compareVersion(terraformVersion, constants.MINIMUM_VERSION_TERRAFORM) < 0 { - return fmt.Errorf("terraform version %s is below the minimum required version %s", terraformVersion, constants.MINIMUM_VERSION_TERRAFORM) + if compareVersion(terraformVersion, constants.MinimumVersionTerraform) < 0 { + return fmt.Errorf("terraform version %s is below the minimum required version %s", terraformVersion, constants.MinimumVersionTerraform) } return nil @@ -297,8 +297,8 @@ func (t *BaseToolsManager) checkOnePassword() error { return fmt.Errorf("failed to extract 1Password CLI version") } - if compareVersion(version, constants.MINIMUM_VERSION_1PASSWORD) < 0 { - return fmt.Errorf("1Password CLI version %s is below the minimum required version %s", version, constants.MINIMUM_VERSION_1PASSWORD) + if compareVersion(version, constants.MinimumVersion1Password) < 0 { + return fmt.Errorf("1Password CLI version %s is below the minimum required version %s", version, constants.MinimumVersion1Password) } return nil @@ -323,8 +323,8 @@ func (t *BaseToolsManager) checkAwsCli() error { if awsVersion == "" { return fmt.Errorf("failed to extract aws cli version") } - if compareVersion(awsVersion, constants.MINIMUM_VERSION_AWS_CLI) < 0 { - return fmt.Errorf("aws cli version %s is below the minimum required version %s", awsVersion, constants.MINIMUM_VERSION_AWS_CLI) + if compareVersion(awsVersion, constants.MinimumVersionAWSCLI) < 0 { + return fmt.Errorf("aws cli version %s is below the minimum required version %s", awsVersion, constants.MinimumVersionAWSCLI) } return nil diff --git a/pkg/context/tools/tools_manager_test.go b/pkg/context/tools/tools_manager_test.go index 621c8bacf..b5a1c64c9 100644 --- a/pkg/context/tools/tools_manager_test.go +++ b/pkg/context/tools/tools_manager_test.go @@ -80,27 +80,27 @@ func setupMocks(t *testing.T, opts ...*SetupOptions) *Mocks { shell.ExecSilentFunc = func(name string, args ...string) (string, error) { switch { case name == "docker" && len(args) >= 2 && args[0] == "version" && args[1] == "--format": - return fmt.Sprintf("%s", constants.MINIMUM_VERSION_DOCKER), nil + return fmt.Sprintf("%s", constants.MinimumVersionDocker), nil case name == "docker" && args[0] == "version": - return fmt.Sprintf("Docker version %s", constants.MINIMUM_VERSION_DOCKER), nil + return fmt.Sprintf("Docker version %s", constants.MinimumVersionDocker), nil case name == "docker" && args[0] == "compose" && args[1] == "version": - return fmt.Sprintf("Docker Compose version %s", constants.MINIMUM_VERSION_DOCKER_COMPOSE), nil + return fmt.Sprintf("Docker Compose version %s", constants.MinimumVersionDockerCompose), nil case name == "docker-compose" && args[0] == "version": - return fmt.Sprintf("docker-compose version %s", constants.MINIMUM_VERSION_DOCKER_COMPOSE), nil + return fmt.Sprintf("docker-compose version %s", constants.MinimumVersionDockerCompose), nil case name == "colima" && args[0] == "version": - return fmt.Sprintf("colima version %s", constants.MINIMUM_VERSION_COLIMA), nil + return fmt.Sprintf("colima version %s", constants.MinimumVersionColima), nil case name == "limactl" && args[0] == "--version": - return fmt.Sprintf("limactl version %s", constants.MINIMUM_VERSION_LIMA), nil + return fmt.Sprintf("limactl version %s", constants.MinimumVersionLima), nil case name == "kubectl" && args[0] == "version" && args[1] == "--client": - return fmt.Sprintf("Client Version: v%s", constants.MINIMUM_VERSION_KUBECTL), nil + return fmt.Sprintf("Client Version: v%s", constants.MinimumVersionKubectl), nil case name == "talosctl" && args[0] == "version" && args[1] == "--client" && args[2] == "--short": - return fmt.Sprintf("v%s", constants.MINIMUM_VERSION_TALOSCTL), nil + return fmt.Sprintf("v%s", constants.MinimumVersionTalosctl), nil case name == "terraform" && args[0] == "version": - return fmt.Sprintf("Terraform v%s", constants.MINIMUM_VERSION_TERRAFORM), nil + return fmt.Sprintf("Terraform v%s", constants.MinimumVersionTerraform), nil case name == "op" && args[0] == "--version": - return fmt.Sprintf("1Password CLI %s", constants.MINIMUM_VERSION_1PASSWORD), nil + return fmt.Sprintf("1Password CLI %s", constants.MinimumVersion1Password), nil case name == "aws" && args[0] == "--version": - return fmt.Sprintf("aws-cli/%s Python/3.13.3 Darwin/24.0.0 exe/x86_64", constants.MINIMUM_VERSION_AWS_CLI), nil + return fmt.Sprintf("aws-cli/%s Python/3.13.3 Darwin/24.0.0 exe/x86_64", constants.MinimumVersionAWSCLI), nil } return "", fmt.Errorf("command not found") } @@ -279,15 +279,15 @@ func TestToolsManager_Check(t *testing.T) { t.Errorf("Failed to get %s version: %v", tool, err) continue } - if !strings.Contains(output, constants.MINIMUM_VERSION_DOCKER) && - !strings.Contains(output, constants.MINIMUM_VERSION_DOCKER_COMPOSE) && - !strings.Contains(output, constants.MINIMUM_VERSION_COLIMA) && - !strings.Contains(output, constants.MINIMUM_VERSION_LIMA) && - !strings.Contains(output, constants.MINIMUM_VERSION_KUBECTL) && - !strings.Contains(output, constants.MINIMUM_VERSION_TALOSCTL) && - !strings.Contains(output, constants.MINIMUM_VERSION_TERRAFORM) && - !strings.Contains(output, constants.MINIMUM_VERSION_1PASSWORD) && - !strings.Contains(output, constants.MINIMUM_VERSION_AWS_CLI) { + if !strings.Contains(output, constants.MinimumVersionDocker) && + !strings.Contains(output, constants.MinimumVersionDockerCompose) && + !strings.Contains(output, constants.MinimumVersionColima) && + !strings.Contains(output, constants.MinimumVersionLima) && + !strings.Contains(output, constants.MinimumVersionKubectl) && + !strings.Contains(output, constants.MinimumVersionTalosctl) && + !strings.Contains(output, constants.MinimumVersionTerraform) && + !strings.Contains(output, constants.MinimumVersion1Password) && + !strings.Contains(output, constants.MinimumVersionAWSCLI) { t.Errorf("Expected %s version check to pass, got output: %s", tool, output) } } diff --git a/pkg/provisioner/cluster/cluster_client.go b/pkg/provisioner/cluster/cluster_client.go index 442cb5273..3c70e5385 100644 --- a/pkg/provisioner/cluster/cluster_client.go +++ b/pkg/provisioner/cluster/cluster_client.go @@ -37,8 +37,8 @@ type BaseClusterClient struct { // NewBaseClusterClient creates a new BaseClusterClient with default timeouts. func NewBaseClusterClient() *BaseClusterClient { return &BaseClusterClient{ - healthCheckTimeout: constants.DEFAULT_NODE_HEALTH_CHECK_TIMEOUT, - healthCheckPollInterval: constants.DEFAULT_NODE_HEALTH_CHECK_POLL_INTERVAL, + healthCheckTimeout: constants.DefaultNodeHealthCheckTimeout, + healthCheckPollInterval: constants.DefaultNodeHealthCheckPollInterval, } } diff --git a/pkg/provisioner/cluster/cluster_client_test.go b/pkg/provisioner/cluster/cluster_client_test.go index 99187e8c0..7a181a165 100644 --- a/pkg/provisioner/cluster/cluster_client_test.go +++ b/pkg/provisioner/cluster/cluster_client_test.go @@ -34,12 +34,12 @@ func TestNewBaseClusterClient(t *testing.T) { } // Then it should have default timeout values - if client.healthCheckTimeout != constants.DEFAULT_NODE_HEALTH_CHECK_TIMEOUT { - t.Errorf("Expected healthCheckTimeout %v, got %v", constants.DEFAULT_NODE_HEALTH_CHECK_TIMEOUT, client.healthCheckTimeout) + if client.healthCheckTimeout != constants.DefaultNodeHealthCheckTimeout { + t.Errorf("Expected healthCheckTimeout %v, got %v", constants.DefaultNodeHealthCheckTimeout, client.healthCheckTimeout) } - if client.healthCheckPollInterval != constants.DEFAULT_NODE_HEALTH_CHECK_POLL_INTERVAL { - t.Errorf("Expected healthCheckPollInterval %v, got %v", constants.DEFAULT_NODE_HEALTH_CHECK_POLL_INTERVAL, client.healthCheckPollInterval) + if client.healthCheckPollInterval != constants.DefaultNodeHealthCheckPollInterval { + t.Errorf("Expected healthCheckPollInterval %v, got %v", constants.DefaultNodeHealthCheckPollInterval, client.healthCheckPollInterval) } }) } diff --git a/pkg/provisioner/kubernetes/kubernetes_manager.go b/pkg/provisioner/kubernetes/kubernetes_manager.go index daf0c817b..17e8ea155 100644 --- a/pkg/provisioner/kubernetes/kubernetes_manager.go +++ b/pkg/provisioner/kubernetes/kubernetes_manager.go @@ -183,7 +183,7 @@ func (k *BaseKubernetesManager) WaitForKustomizations(message string, names ...s Version: "v1", Resource: "kustomizations", } - obj, err := k.client.GetResource(gvr, constants.DEFAULT_FLUX_SYSTEM_NAMESPACE, name) + obj, err := k.client.GetResource(gvr, constants.DefaultFluxSystemNamespace, name) if err != nil { allReady = false break @@ -445,7 +445,7 @@ func (k *BaseKubernetesManager) CheckGitRepositoryStatus() error { Resource: "gitrepositories", } - gitObjList, err := k.client.ListResources(gitGvr, constants.DEFAULT_FLUX_SYSTEM_NAMESPACE) + gitObjList, err := k.client.ListResources(gitGvr, constants.DefaultFluxSystemNamespace) if err != nil { return fmt.Errorf("failed to list git repositories: %w", err) } @@ -469,7 +469,7 @@ func (k *BaseKubernetesManager) CheckGitRepositoryStatus() error { Resource: "ocirepositories", } - ociObjList, err := k.client.ListResources(ociGvr, constants.DEFAULT_FLUX_SYSTEM_NAMESPACE) + ociObjList, err := k.client.ListResources(ociGvr, constants.DefaultFluxSystemNamespace) if err != nil { return fmt.Errorf("failed to list oci repositories: %w", err) } @@ -501,7 +501,7 @@ func (k *BaseKubernetesManager) GetKustomizationStatus(names []string) (map[stri Resource: "kustomizations", } - objList, err := k.client.ListResources(gvr, constants.DEFAULT_FLUX_SYSTEM_NAMESPACE) + objList, err := k.client.ListResources(gvr, constants.DefaultFluxSystemNamespace) if err != nil { return nil, fmt.Errorf("failed to list kustomizations: %w", err) } @@ -799,10 +799,10 @@ func (k *BaseKubernetesManager) applyBlueprintGitRepository(source blueprintv1al Spec: sourcev1.GitRepositorySpec{ URL: sourceUrl, Interval: metav1.Duration{ - Duration: constants.DEFAULT_FLUX_SOURCE_INTERVAL, + Duration: constants.DefaultFluxSourceInterval, }, Timeout: &metav1.Duration{ - Duration: constants.DEFAULT_FLUX_SOURCE_TIMEOUT, + Duration: constants.DefaultFluxSourceTimeout, }, Reference: &sourcev1.GitRepositoryRef{ Branch: source.Ref.Branch, @@ -862,10 +862,10 @@ func (k *BaseKubernetesManager) applyBlueprintOCIRepository(source blueprintv1al Spec: sourcev1.OCIRepositorySpec{ URL: ociURL, Interval: metav1.Duration{ - Duration: constants.DEFAULT_FLUX_SOURCE_INTERVAL, + Duration: constants.DefaultFluxSourceInterval, }, Timeout: &metav1.Duration{ - Duration: constants.DEFAULT_FLUX_SOURCE_TIMEOUT, + Duration: constants.DefaultFluxSourceTimeout, }, Reference: ref, }, diff --git a/pkg/provisioner/provisioner.go b/pkg/provisioner/provisioner.go index 40acbf08c..5db2a8304 100644 --- a/pkg/provisioner/provisioner.go +++ b/pkg/provisioner/provisioner.go @@ -143,7 +143,7 @@ func (i *Provisioner) Install(blueprint *blueprintv1alpha1.Blueprint) error { return fmt.Errorf("failed to initialize kubernetes manager: %w", err) } - if err := i.KubernetesManager.ApplyBlueprint(blueprint, constants.DEFAULT_FLUX_SYSTEM_NAMESPACE); err != nil { + if err := i.KubernetesManager.ApplyBlueprint(blueprint, constants.DefaultFluxSystemNamespace); err != nil { return fmt.Errorf("failed to apply blueprint: %w", err) } diff --git a/pkg/workstation/network/colima_network.go b/pkg/workstation/network/colima_network.go index 1b7366088..010a6bd84 100644 --- a/pkg/workstation/network/colima_network.go +++ b/pkg/workstation/network/colima_network.go @@ -72,7 +72,7 @@ func (n *ColimaNetworkManager) Initialize() error { // Set docker.NetworkCIDR to the default value if it's not set if n.configHandler.GetString("network.cidr_block") == "" { - return n.configHandler.Set("network.cidr_block", constants.DEFAULT_NETWORK_CIDR) + return n.configHandler.Set("network.cidr_block", constants.DefaultNetworkCIDR) } return nil diff --git a/pkg/workstation/network/network.go b/pkg/workstation/network/network.go index e51fc62e7..89298a477 100644 --- a/pkg/workstation/network/network.go +++ b/pkg/workstation/network/network.go @@ -91,7 +91,7 @@ func (n *BaseNetworkManager) Initialize() error { networkCIDR := n.configHandler.GetString("network.cidr_block") if networkCIDR == "" { - networkCIDR = constants.DEFAULT_NETWORK_CIDR + networkCIDR = constants.DefaultNetworkCIDR if err := n.configHandler.Set("network.cidr_block", networkCIDR); err != nil { return fmt.Errorf("error setting default network CIDR: %w", err) } diff --git a/pkg/workstation/services/dns_service.go b/pkg/workstation/services/dns_service.go index b7a53f95d..6ded68e09 100644 --- a/pkg/workstation/services/dns_service.go +++ b/pkg/workstation/services/dns_service.go @@ -74,7 +74,7 @@ func (s *DNSService) GetComposeConfig() (*types.Config, error) { corednsConfig := types.ServiceConfig{ Name: serviceName, ContainerName: containerName, - Image: constants.DEFAULT_DNS_IMAGE, + Image: constants.DefaultDNSImage, Restart: "always", Command: []string{"-conf", "/etc/coredns/Corefile"}, Volumes: []types.ServiceVolumeConfig{ diff --git a/pkg/workstation/services/git_livereload_service.go b/pkg/workstation/services/git_livereload_service.go index 99201338a..78bad2f4b 100644 --- a/pkg/workstation/services/git_livereload_service.go +++ b/pkg/workstation/services/git_livereload_service.go @@ -44,14 +44,14 @@ func NewGitLivereloadService(injector di.Injector) *GitLivereloadService { // Returns a types.Config pointer containing the service definition, or an error if the project root cannot be determined. func (s *GitLivereloadService) GetComposeConfig() (*types.Config, error) { contextName := s.configHandler.GetContext() - rsyncInclude := s.configHandler.GetString("git.livereload.rsync_include", constants.DEFAULT_GIT_LIVE_RELOAD_RSYNC_INCLUDE) - rsyncExclude := s.configHandler.GetString("git.livereload.rsync_exclude", constants.DEFAULT_GIT_LIVE_RELOAD_RSYNC_EXCLUDE) - rsyncProtect := s.configHandler.GetString("git.livereload.rsync_protect", constants.DEFAULT_GIT_LIVE_RELOAD_RSYNC_PROTECT) - gitUsername := s.configHandler.GetString("git.livereload.username", constants.DEFAULT_GIT_LIVE_RELOAD_USERNAME) - gitPassword := s.configHandler.GetString("git.livereload.password", constants.DEFAULT_GIT_LIVE_RELOAD_PASSWORD) - webhookUrl := s.configHandler.GetString("git.livereload.webhook_url", constants.DEFAULT_GIT_LIVE_RELOAD_WEBHOOK_URL) + rsyncInclude := s.configHandler.GetString("git.livereload.rsync_include", constants.DefaultGitLiveReloadRsyncInclude) + rsyncExclude := s.configHandler.GetString("git.livereload.rsync_exclude", constants.DefaultGitLiveReloadRsyncExclude) + rsyncProtect := s.configHandler.GetString("git.livereload.rsync_protect", constants.DefaultGitLiveReloadRsyncProtect) + gitUsername := s.configHandler.GetString("git.livereload.username", constants.DefaultGitLiveReloadUsername) + gitPassword := s.configHandler.GetString("git.livereload.password", constants.DefaultGitLiveReloadPassword) + webhookUrl := s.configHandler.GetString("git.livereload.webhook_url", constants.DefaultGitLiveReloadWebhookURL) verifySsl := s.configHandler.GetBool("git.livereload.verify_ssl", false) - image := s.configHandler.GetString("git.livereload.image", constants.DEFAULT_GIT_LIVE_RELOAD_IMAGE) + image := s.configHandler.GetString("git.livereload.image", constants.DefaultGitLiveReloadImage) envVars := map[string]*string{ "RSYNC_INCLUDE": ptrString(rsyncInclude), diff --git a/pkg/workstation/services/git_livereload_service_test.go b/pkg/workstation/services/git_livereload_service_test.go index 87a087e5a..6f6720ca3 100644 --- a/pkg/workstation/services/git_livereload_service_test.go +++ b/pkg/workstation/services/git_livereload_service_test.go @@ -58,7 +58,7 @@ func TestGitLivereloadService_GetComposeConfig(t *testing.T) { // Then verify the configuration contains the expected service expectedName := "git" - expectedImage := constants.DEFAULT_GIT_LIVE_RELOAD_IMAGE + expectedImage := constants.DefaultGitLiveReloadImage serviceFound := false for _, service := range composeConfig.Services { diff --git a/pkg/workstation/services/localstack_service.go b/pkg/workstation/services/localstack_service.go index 42fd2272b..1f2628940 100644 --- a/pkg/workstation/services/localstack_service.go +++ b/pkg/workstation/services/localstack_service.go @@ -47,9 +47,9 @@ func (s *LocalstackService) GetComposeConfig() (*types.Config, error) { localstackAuthToken := os.Getenv("LOCALSTACK_AUTH_TOKEN") // Get the image to use - image := constants.DEFAULT_AWS_LOCALSTACK_IMAGE + image := constants.DefaultAWSLocalstackImage if localstackAuthToken != "" { - image = constants.DEFAULT_AWS_LOCALSTACK_PRO_IMAGE + image = constants.DefaultAWSLocalstackProImage } // Get the localstack services to enable diff --git a/pkg/workstation/services/registry_service.go b/pkg/workstation/services/registry_service.go index e208f33fc..606d90aa2 100644 --- a/pkg/workstation/services/registry_service.go +++ b/pkg/workstation/services/registry_service.go @@ -22,7 +22,7 @@ import ( // ============================================================================= var ( - registryNextPort = constants.REGISTRY_DEFAULT_HOST_PORT + 1 + registryNextPort = constants.RegistryDefaultHostPort + 1 registryMu sync.Mutex localRegistry *RegistryService ) @@ -92,7 +92,7 @@ func (s *RegistryService) SetAddress(address string) error { if localRegistry == nil { localRegistry = s - hostPort = constants.REGISTRY_DEFAULT_HOST_PORT + hostPort = constants.RegistryDefaultHostPort err = s.configHandler.Set("docker.registry_url", hostName) if err != nil { return fmt.Errorf("failed to set registry URL for registry %s: %w", s.name, err) @@ -130,7 +130,7 @@ func (s *RegistryService) generateRegistryService(registry docker.RegistryConfig service := types.ServiceConfig{ Name: serviceName, ContainerName: containerName, - Image: constants.REGISTRY_DEFAULT_IMAGE, + Image: constants.RegistryDefaultImage, Restart: "always", Labels: map[string]string{ "role": "registry", diff --git a/pkg/workstation/services/registry_service_test.go b/pkg/workstation/services/registry_service_test.go index a407de82a..309303124 100644 --- a/pkg/workstation/services/registry_service_test.go +++ b/pkg/workstation/services/registry_service_test.go @@ -231,7 +231,7 @@ contexts: service.Initialize() service.SetName("registry") // Reset package-level variables - registryNextPort = constants.REGISTRY_DEFAULT_HOST_PORT + 1 + registryNextPort = constants.RegistryDefaultHostPort + 1 localRegistry = nil return service, mocks } @@ -274,7 +274,7 @@ contexts: } // And the host port should be set to default - expectedHostPort := constants.REGISTRY_DEFAULT_HOST_PORT + expectedHostPort := constants.RegistryDefaultHostPort actualHostPort := mocks.ConfigHandler.GetInt("docker.registries.registry.hostport", 0) if actualHostPort != expectedHostPort { t.Errorf("expected host port %d, got %d", expectedHostPort, actualHostPort) @@ -384,14 +384,14 @@ contexts: } // Then the first registry should have default port - expectedHostPort1 := constants.REGISTRY_DEFAULT_HOST_PORT + expectedHostPort1 := constants.RegistryDefaultHostPort actualHostPort1 := mocks.ConfigHandler.GetInt("docker.registries.registry1.hostport", 0) if actualHostPort1 != expectedHostPort1 { t.Errorf("expected host port %d for first registry, got %d", expectedHostPort1, actualHostPort1) } // And the second registry should have incremented port - expectedHostPort2 := constants.REGISTRY_DEFAULT_HOST_PORT + 1 + expectedHostPort2 := constants.RegistryDefaultHostPort + 1 actualHostPort2 := mocks.ConfigHandler.GetInt("docker.registries.registry2.hostport", 0) if actualHostPort2 != expectedHostPort2 { t.Errorf("expected host port %d for second registry, got %d", expectedHostPort2, actualHostPort2) @@ -516,7 +516,7 @@ contexts: service.SetName("registry") // Reset package-level variables - registryNextPort = constants.REGISTRY_DEFAULT_HOST_PORT + 1 + registryNextPort = constants.RegistryDefaultHostPort + 1 localRegistry = nil // And mock configuration diff --git a/pkg/workstation/services/talos_service.go b/pkg/workstation/services/talos_service.go index 1c13ac139..39d70973f 100644 --- a/pkg/workstation/services/talos_service.go +++ b/pkg/workstation/services/talos_service.go @@ -24,8 +24,8 @@ import ( // Initialize the global port settings var ( - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 - defaultAPIPort = constants.DEFAULT_TALOS_API_PORT + nextAPIPort = constants.DefaultTalosAPIPort + 1 + defaultAPIPort = constants.DefaultTalosAPIPort portLock sync.Mutex controlPlaneLeader *TalosService usedHostPorts = make(map[uint32]bool) @@ -158,11 +158,11 @@ func (s *TalosService) GetComposeConfig() (*types.Config, error) { nodeType := "workers" if s.mode == "controlplane" { nodeType = "controlplanes" - cpu = s.configHandler.GetInt("cluster.controlplanes.cpu", constants.DEFAULT_TALOS_CONTROL_PLANE_CPU) - ram = s.configHandler.GetInt("cluster.controlplanes.memory", constants.DEFAULT_TALOS_CONTROL_PLANE_RAM) + cpu = s.configHandler.GetInt("cluster.controlplanes.cpu", constants.DefaultTalosControlPlaneCPU) + ram = s.configHandler.GetInt("cluster.controlplanes.memory", constants.DefaultTalosControlPlaneRAM) } else { - cpu = s.configHandler.GetInt("cluster.workers.cpu", constants.DEFAULT_TALOS_WORKER_CPU) - ram = s.configHandler.GetInt("cluster.workers.memory", constants.DEFAULT_TALOS_WORKER_RAM) + cpu = s.configHandler.GetInt("cluster.workers.cpu", constants.DefaultTalosWorkerCPU) + ram = s.configHandler.GetInt("cluster.workers.memory", constants.DefaultTalosWorkerRAM) } nodeName := s.name @@ -193,7 +193,7 @@ func (s *TalosService) GetComposeConfig() (*types.Config, error) { if clusterImage != "" { image = clusterImage } else { - image = constants.DEFAULT_TALOS_IMAGE + image = constants.DefaultTalosImage } } } diff --git a/pkg/workstation/services/talos_service_test.go b/pkg/workstation/services/talos_service_test.go index fe49109b6..6b346fd72 100644 --- a/pkg/workstation/services/talos_service_test.go +++ b/pkg/workstation/services/talos_service_test.go @@ -68,9 +68,9 @@ contexts: local_volume_path: "/var/local" cpu: %d memory: %d -`, constants.DEFAULT_TALOS_API_PORT, - constants.DEFAULT_TALOS_WORKER_CPU, - constants.DEFAULT_TALOS_WORKER_RAM) +`, constants.DefaultTalosAPIPort, + constants.DefaultTalosWorkerCPU, + constants.DefaultTalosWorkerRAM) } if err := mocks.ConfigHandler.LoadConfigString(configToLoad); err != nil { @@ -127,7 +127,7 @@ func TestTalosService_SetAddress(t *testing.T) { t.Helper() // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -153,7 +153,7 @@ func TestTalosService_SetAddress(t *testing.T) { } // And the endpoint should be set correctly - expectedEndpoint := fmt.Sprintf("127.0.0.1:%d", constants.DEFAULT_TALOS_API_PORT) + expectedEndpoint := fmt.Sprintf("127.0.0.1:%d", constants.DefaultTalosAPIPort) actualEndpoint := mocks.ConfigHandler.GetString("cluster.controlplanes.nodes.controlplane1.endpoint", "") if actualEndpoint != expectedEndpoint { t.Errorf("expected endpoint %s, got %s", expectedEndpoint, actualEndpoint) @@ -172,7 +172,7 @@ func TestTalosService_SetAddress(t *testing.T) { mocks := setupTalosServiceMocks(t) // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -202,7 +202,7 @@ func TestTalosService_SetAddress(t *testing.T) { } // And the endpoint should be set correctly with an incremented port - expectedEndpoint := fmt.Sprintf("127.0.0.1:%d", constants.DEFAULT_TALOS_API_PORT+1) + expectedEndpoint := fmt.Sprintf("127.0.0.1:%d", constants.DefaultTalosAPIPort+1) actualEndpoint := mocks.ConfigHandler.GetString("cluster.controlplanes.nodes.controlplane2.endpoint", "") if actualEndpoint != expectedEndpoint { t.Errorf("expected endpoint %s, got %s", expectedEndpoint, actualEndpoint) @@ -221,7 +221,7 @@ func TestTalosService_SetAddress(t *testing.T) { mocks := setupTalosServiceMocks(t) // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -241,7 +241,7 @@ func TestTalosService_SetAddress(t *testing.T) { } // And the endpoint should be set correctly - expectedEndpoint := fmt.Sprintf("127.0.0.1:%d", constants.DEFAULT_TALOS_API_PORT+1) + expectedEndpoint := fmt.Sprintf("127.0.0.1:%d", constants.DefaultTalosAPIPort+1) actualEndpoint := mocks.ConfigHandler.GetString("cluster.workers.nodes.worker1.endpoint", "") if actualEndpoint != expectedEndpoint { t.Errorf("expected endpoint %s, got %s", expectedEndpoint, actualEndpoint) @@ -260,7 +260,7 @@ func TestTalosService_SetAddress(t *testing.T) { mocks := setupTalosServiceMocks(t) // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -317,7 +317,7 @@ func TestTalosService_SetAddress(t *testing.T) { mocks := setupTalosServiceMocks(t) // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -350,7 +350,7 @@ func TestTalosService_SetAddress(t *testing.T) { mocks := setupTalosServiceMocks(t) // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -383,7 +383,7 @@ func TestTalosService_SetAddress(t *testing.T) { mocks := setupTalosServiceMocks(t) // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -437,7 +437,7 @@ func TestTalosService_SetAddress(t *testing.T) { mocks := setupTalosServiceMocks(t) // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -462,7 +462,7 @@ func TestTalosService_SetAddress(t *testing.T) { } // And the endpoint should use the custom TLD - expectedEndpoint := fmt.Sprintf("127.0.0.1:%d", constants.DEFAULT_TALOS_API_PORT+1) + expectedEndpoint := fmt.Sprintf("127.0.0.1:%d", constants.DefaultTalosAPIPort+1) actualEndpoint := mocks.ConfigHandler.GetString("cluster.workers.nodes.worker1.endpoint", "") if actualEndpoint != expectedEndpoint { t.Errorf("expected endpoint %s, got %s", expectedEndpoint, actualEndpoint) @@ -481,7 +481,7 @@ func TestTalosService_SetAddress(t *testing.T) { mocks := setupTalosServiceMocks(t) // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -555,7 +555,7 @@ func TestTalosService_SetAddress(t *testing.T) { mocks := setupTalosServiceMocks(t) // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -678,7 +678,7 @@ func TestTalosService_SetAddress(t *testing.T) { mocks := setupTalosServiceMocks(t) // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -733,7 +733,7 @@ func TestTalosService_SetAddress(t *testing.T) { mocks := setupTalosServiceMocks(t) // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -769,7 +769,7 @@ func TestTalosService_SetAddress(t *testing.T) { mocks := setupTalosServiceMocks(t) // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -805,7 +805,7 @@ func TestTalosService_SetAddress(t *testing.T) { mocks := setupTalosServiceMocks(t) // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -894,7 +894,7 @@ func TestTalosService_GetComposeConfig(t *testing.T) { t.Helper() // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -918,7 +918,7 @@ func TestTalosService_GetComposeConfig(t *testing.T) { t.Helper() // Reset package-level variables - nextAPIPort = constants.DEFAULT_TALOS_API_PORT + 1 + nextAPIPort = constants.DefaultTalosAPIPort + 1 controlPlaneLeader = nil usedHostPorts = make(map[uint32]bool) @@ -963,8 +963,8 @@ func TestTalosService_GetComposeConfig(t *testing.T) { if serviceConfig.Name != "controlplane1" { t.Errorf("expected service name controlplane1, got %s", serviceConfig.Name) } - if serviceConfig.Image != constants.DEFAULT_TALOS_IMAGE { - t.Errorf("expected image %s, got %s", constants.DEFAULT_TALOS_IMAGE, serviceConfig.Image) + if serviceConfig.Image != constants.DefaultTalosImage { + t.Errorf("expected image %s, got %s", constants.DefaultTalosImage, serviceConfig.Image) } if !serviceConfig.Privileged { t.Error("expected service to be privileged") @@ -1035,15 +1035,15 @@ func TestTalosService_GetComposeConfig(t *testing.T) { if serviceConfig.Name != "worker1" { t.Errorf("expected service name worker1, got %s", serviceConfig.Name) } - if serviceConfig.Image != constants.DEFAULT_TALOS_IMAGE { - t.Errorf("expected image %s, got %s", constants.DEFAULT_TALOS_IMAGE, serviceConfig.Image) + if serviceConfig.Image != constants.DefaultTalosImage { + t.Errorf("expected image %s, got %s", constants.DefaultTalosImage, serviceConfig.Image) } // And the service should have worker-specific CPU and RAM settings if serviceConfig.Environment["TALOSSKU"] == nil { t.Error("expected TALOSSKU environment variable") } else { - expectedSKU := fmt.Sprintf("%dCPU-%dRAM", constants.DEFAULT_TALOS_WORKER_CPU, constants.DEFAULT_TALOS_WORKER_RAM*1024) + expectedSKU := fmt.Sprintf("%dCPU-%dRAM", constants.DefaultTalosWorkerCPU, constants.DefaultTalosWorkerRAM*1024) if *serviceConfig.Environment["TALOSSKU"] != expectedSKU { t.Errorf("expected TALOSSKU=%s, got %s", expectedSKU, *serviceConfig.Environment["TALOSSKU"]) } @@ -1372,11 +1372,11 @@ contexts: } // Check default API port - if serviceConfig.Ports[0].Target != uint32(constants.DEFAULT_TALOS_API_PORT) { - t.Errorf("expected target port %d, got %d", constants.DEFAULT_TALOS_API_PORT, serviceConfig.Ports[0].Target) + if serviceConfig.Ports[0].Target != uint32(constants.DefaultTalosAPIPort) { + t.Errorf("expected target port %d, got %d", constants.DefaultTalosAPIPort, serviceConfig.Ports[0].Target) } - if serviceConfig.Ports[0].Published != fmt.Sprintf("%d", constants.DEFAULT_TALOS_API_PORT) { - t.Errorf("expected published port %d, got %s", constants.DEFAULT_TALOS_API_PORT, serviceConfig.Ports[0].Published) + if serviceConfig.Ports[0].Published != fmt.Sprintf("%d", constants.DefaultTalosAPIPort) { + t.Errorf("expected published port %d, got %s", constants.DefaultTalosAPIPort, serviceConfig.Ports[0].Published) } if serviceConfig.Ports[0].Protocol != "tcp" { t.Errorf("expected protocol tcp, got %s", serviceConfig.Ports[0].Protocol) @@ -1469,7 +1469,7 @@ contexts: } // Reset defaultAPIPort - defaultAPIPort = constants.DEFAULT_TALOS_API_PORT + defaultAPIPort = constants.DefaultTalosAPIPort }) t.Run("SuccessWithEnvVarVolumes", func(t *testing.T) { From 0e06c5a3d5adf567c7a3e4d0865b0d63fe8122b1 Mon Sep 17 00:00:00 2001 From: Ryan VanGundy <85766511+rmvangun@users.noreply.github.com> Date: Sun, 2 Nov 2025 17:23:17 -0500 Subject: [PATCH 2/2] rearrange Signed-off-by: Ryan VanGundy <85766511+rmvangun@users.noreply.github.com> --- pkg/context/tools/tools_manager.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/context/tools/tools_manager.go b/pkg/context/tools/tools_manager.go index 3b25aac95..b1498d693 100644 --- a/pkg/context/tools/tools_manager.go +++ b/pkg/context/tools/tools_manager.go @@ -10,11 +10,11 @@ import ( "time" "github.com/briandowns/spinner" - "github.com/windsorcli/cli/pkg/context/config" "github.com/windsorcli/cli/pkg/constants" - "github.com/windsorcli/cli/pkg/di" + "github.com/windsorcli/cli/pkg/context/config" "github.com/windsorcli/cli/pkg/context/shell" sh "github.com/windsorcli/cli/pkg/context/shell" + "github.com/windsorcli/cli/pkg/di" ) // The ToolsManager is a core component that manages development tools and dependencies