Skip to content

Commit cd24c3d

Browse files
author
Moritz Clasmeier
committed
Support local images in deploy command
1 parent 69b1928 commit cd24c3d

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

cmd/deploy.go

Lines changed: 33 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,31 @@ 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+
// Best effort, keep running.
347+
log.Warningf("Transferring images to local cluster failed: %v", err)
348+
}
349+
}
350+
}
351+
324352
if components.IncludesCentral() {
325353
d.PrintCentralDeploymentSummary()
326354
}
@@ -380,11 +408,15 @@ func configureConfig(log *logger.Logger, components component.Component, deployS
380408
profile := clusterdefaults.ResolveAutoResourceProfile(clusterType)
381409
log.Dimf("Selecting resource profile %v for Central", profile)
382410
deploySettings.Central.ResourceProfile = profile
411+
} else if components.IncludesCentral() && deploySettings.Roxie.ClusterType.IsLocal() {
412+
log.Warning("You are deploying Central to a local cluster, it is recommended to use --resources=auto.")
383413
}
384414
if deploySettings.SecuredCluster.ResourceProfile == types.ResourceProfileAuto {
385415
profile := clusterdefaults.ResolveAutoResourceProfile(clusterType)
386416
log.Dimf("Selecting resource profile %v for SecuredCluster", profile)
387417
deploySettings.SecuredCluster.ResourceProfile = profile
418+
} else if components.IncludesSensor() && deploySettings.Roxie.ClusterType.IsLocal() {
419+
log.Warning("You are deploying SecuredCluster to a local cluster, it is recommended to use --resources=auto.")
388420
}
389421

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

0 commit comments

Comments
 (0)