diff --git a/cmd/deploy.go b/cmd/deploy.go index a0a9a5e..9a324a8 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -236,6 +236,34 @@ this flag can be used to tell roxie how to pre-load images for the current clust return cmd } +// canSkipMainImageTagLookup reports whether no requested deployment behavior needs the main tag. +func canSkipMainImageTagLookup(components component.Component, config deployer.Config) bool { + if !config.Operator.SkipDeploymentEnabled() { + return false + } + if components.IncludesCentral() && !config.Central.EarlyReadinessEnabled() && config.CentralVersion() == "" { + return false + } + if components.IncludesSensor() && !config.SecuredCluster.EarlyReadinessEnabled() && config.SecuredClusterVersion() == "" { + return false + } + if config.Roxie.ClusterType.IsLocal() && !config.Roxie.KonfluxImagesEnabled() && + (config.CentralVersion() == "" || config.SecuredClusterVersion() == "") { + return false + } + return true +} + +func ensureClusterType(config *deployer.Config, detect func() types.ClusterType) { + if config.Roxie.ClusterType != "" { + return + } + + clusterType := detect() + log.Dimf("Detected cluster type: %v", clusterType) + config.Roxie.ClusterType = clusterType +} + func runDeploy(cmd *cobra.Command, args []string) error { if !dryRun { if err := env.Initialize(); err != nil { @@ -265,12 +293,15 @@ func runDeploy(cmd *cobra.Command, args []string) error { if err != nil { return err } + ensureClusterType(&deploySettings, env.GetAutoDetectedClusterType) ctx, cancel := context.WithTimeout(context.Background(), computeDeployContextTimeout(components, deploySettings)) defer cancel() if deploySettings.Roxie.Version != "" { log.Dimf("Using main image tag %s", deploySettings.Roxie.Version) + } else if canSkipMainImageTagLookup(components, deploySettings) { + log.Dim("Skipping main image tag lookup because operator deployment is disabled") } else { mainImageTag, err := helpers.LookupMainImageTag(ctx, deploySettings.Roxie.ImageRegistry) if err != nil { @@ -465,11 +496,7 @@ func retrieveClusterConfigForComponents( } func configureConfig(components component.Component, deploySettings *deployer.Config) error { - if deploySettings.Roxie.ClusterType == "" { - clusterType := env.GetAutoDetectedClusterType() - log.Dimf("Detected cluster type: %v", clusterType) - deploySettings.Roxie.ClusterType = clusterType - } + ensureClusterType(deploySettings, env.GetAutoDetectedClusterType) clusterType := deploySettings.Roxie.ClusterType centralDeployLocally := components.IncludesCentral() && clusterType.IsLocal() sensorDeployLocally := components.IncludesSensor() && clusterType.IsLocal() diff --git a/cmd/deploy_test.go b/cmd/deploy_test.go index afc6cda..6dc97e5 100644 --- a/cmd/deploy_test.go +++ b/cmd/deploy_test.go @@ -352,6 +352,86 @@ roxie: } } +func TestCanSkipMainImageTagLookup(t *testing.T) { + tests := []struct { + name string + components component.Component + configure func(*deployer.Config) + want bool + }{ + { + name: "skip when operator is disabled and no other consumer needs the tag", + components: component.Central, + configure: func(config *deployer.Config) { + config.Operator.SkipDeployment = new(true) + }, + want: true, + }, + { + name: "do not skip when operator deployment is enabled", + components: component.Central, + want: false, + }, + { + name: "keep tag for central early-readiness validation", + components: component.Central, + configure: func(config *deployer.Config) { + config.Operator.SkipDeployment = new(true) + config.Central.EarlyReadiness = new(false) + }, + want: false, + }, + { + name: "keep tag for secured-cluster early-readiness validation", + components: component.SecuredCluster, + configure: func(config *deployer.Config) { + config.Operator.SkipDeployment = new(true) + config.SecuredCluster.EarlyReadiness = new(false) + }, + want: false, + }, + { + name: "keep tag for local image preloading", + components: component.Central, + configure: func(config *deployer.Config) { + config.Operator.SkipDeployment = new(true) + config.Roxie.ClusterType = types.ClusterTypeKind + }, + want: false, + }, + { + name: "skip local image preload when all operator versions are configured", + components: component.Central, + configure: func(config *deployer.Config) { + config.Operator.SkipDeployment = new(true) + config.Operator.Version = imagetag.MainTag("4.10.0") + config.Roxie.ClusterType = types.ClusterTypeKind + }, + want: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + config := deployer.DefaultConfig() + if tt.configure != nil { + tt.configure(&config) + } + assert.Equal(t, tt.want, canSkipMainImageTagLookup(tt.components, config)) + }) + } +} + +func TestCanSkipMainImageTagLookupWithAutoDetectedLocalCluster(t *testing.T) { + config := deployer.DefaultConfig() + config.Operator.SkipDeployment = new(true) + ensureClusterType(&config, func() types.ClusterType { + return types.ClusterTypeKind + }) + + assert.False(t, canSkipMainImageTagLookup(component.Central, config)) +} + // TestNewDeployCmd_ConfigMergePreservesEnvVars verifies that spec.customize.envVars // from multiple --config files and --set expressions are merged by name rather // than silently replaced. Overlapping names should use the last-specified value;