Skip to content

Commit 33b8be7

Browse files
author
Moritz Clasmeier
committed
Support local images in deploy command
1 parent 9c577ef commit 33b8be7

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

cmd/deploy.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import (
2929
)
3030

3131
var (
32-
sharedNamespace = "stackrox"
32+
sharedNamespace = "stackrox"
33+
imagePreLoadCommand string
3334
)
3435

3536
func newDeployCmd(settings *deployer.Config) *cobra.Command {
@@ -51,6 +52,8 @@ Examples:
5152
cmd.Flags().StringVar(&shell, "shell", "", "Shell to spawn after Central deployment")
5253

5354
cmd.Flags().StringVar(&envrc, "envrc", "", "Write environment to file instead of spawning sub-shell")
55+
cmd.Flags().StringVar(&imagePreLoadCommand, "image-preload-command", "",
56+
"Use custom command for pre-loading images to local cluster. Image can be referenced as $IMAGE.")
5457

5558
registerFlag(cmd, settings, "olm", "Deploy operator via OLM (requires OLM installed)",
5659
withNoOptDefVal("true"),
@@ -321,6 +324,30 @@ func runDeploy(cmd *cobra.Command, args []string) error {
321324
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
322325
defer cancel()
323326

327+
// If we are deploying to a local cluster and the images exist locally, then we transfer them
328+
// to the local cluster.
329+
if deploySettings.Roxie.ClusterType.IsLocal() && !deploySettings.Roxie.KonfluxImages {
330+
var preLoader deployer.ImagePreLoader
331+
if imagePreLoadCommand != "" {
332+
preLoader = deployer.NewCustomImagePreloader(ctx, log, imagePreLoadCommand)
333+
} else {
334+
preLoader, err = d.GetPreLoaderForCluster()
335+
if err != nil && !errors.Is(err, deployer.ErrLocalImagesUnsupported) {
336+
return fmt.Errorf("obtaining image preloader for cluster: %w", err)
337+
}
338+
}
339+
if preLoader == nil {
340+
log.Warningf("Image preloading not supported for cluster %s.", d.GetKubeContext())
341+
log.Warningf("Use --image-preload-command for specifying custom image preloading mechanism.")
342+
} else {
343+
log.Dimf("Using image pre-loader %q", preLoader.Name())
344+
345+
if err := d.TryTransferLocalImages(ctx, preLoader); err != nil {
346+
return fmt.Errorf("transferring images to local cluster failed: %w", err)
347+
}
348+
}
349+
}
350+
324351
if components.IncludesCentral() {
325352
d.PrintCentralDeploymentSummary()
326353
}
@@ -380,11 +407,15 @@ func configureConfig(log *logger.Logger, components component.Component, deployS
380407
profile := clusterdefaults.ResolveAutoResourceProfile(clusterType)
381408
log.Dimf("Selecting resource profile %v for Central", profile)
382409
deploySettings.Central.ResourceProfile = profile
410+
} else if components.IncludesCentral() && deploySettings.Roxie.ClusterType.IsLocal() {
411+
log.Warning("You are deploying Central to a local cluster, it is recommended to use --resources=auto.")
383412
}
384413
if deploySettings.SecuredCluster.ResourceProfile == types.ResourceProfileAuto {
385414
profile := clusterdefaults.ResolveAutoResourceProfile(clusterType)
386415
log.Dimf("Selecting resource profile %v for SecuredCluster", profile)
387416
deploySettings.SecuredCluster.ResourceProfile = profile
417+
} else if components.IncludesSensor() && deploySettings.Roxie.ClusterType.IsLocal() {
418+
log.Warning("You are deploying SecuredCluster to a local cluster, it is recommended to use --resources=auto.")
388419
}
389420

390421
// We need to do this regardless of whether the operator is deployed or not, because

0 commit comments

Comments
 (0)