Skip to content
Open
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
37 changes: 32 additions & 5 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() &&
Comment thread
AlexVulaj marked this conversation as resolved.
Resolved
(config.CentralVersion() == "" || config.SecuredClusterVersion() == "") {
return false
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We perform a bunch of handcrafted checks here which are based on how the code elsewhere works at this moment. I am afraid that as the code evolves, this part will get out of date and bugs will emerge. I wonder if we could use this opportunity to try a different approach. Namely, change deploySettings.Roxie.Version (which seems to be the thing populated by the tag lookup) into a method that will fetch the tag as needed lazily on the fly and cache it.

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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clusterType := deploySettings.Roxie.ClusterType
centralDeployLocally := components.IncludesCentral() && clusterType.IsLocal()
sensorDeployLocally := components.IncludesSensor() && clusterType.IsLocal()
Expand Down
80 changes: 80 additions & 0 deletions cmd/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading