imageImport: exit with non-zero exit code on failure
... if at least one step in the importing process fails, e.g. failed import for at least one cluster or one image Fixes #393
This commit is contained in:
parent
b5eeda74d6
commit
8612b76577
@ -22,6 +22,8 @@ THE SOFTWARE.
|
||||
package image
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/rancher/k3d/v3/cmd/util"
|
||||
@ -46,15 +48,20 @@ func NewCmdImageImport() *cobra.Command {
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
images, clusters := parseLoadImageCmd(cmd, args)
|
||||
log.Debugf("Load images [%+v] from runtime [%s] into clusters [%+v]", images, runtimes.SelectedRuntime, clusters)
|
||||
log.Debugf("Importing image(s) [%+v] from runtime [%s] into cluster(s) [%+v]...", images, runtimes.SelectedRuntime, clusters)
|
||||
errOccured := false
|
||||
for _, cluster := range clusters {
|
||||
log.Infof("Loading images into '%s'", cluster.Name)
|
||||
log.Infof("Importing image(s) into cluster '%s'", cluster.Name)
|
||||
if err := tools.ImageImportIntoClusterMulti(cmd.Context(), runtimes.SelectedRuntime, images, &cluster, loadImageOpts); err != nil {
|
||||
log.Errorf("Failed to load images into cluster '%s'", cluster.Name)
|
||||
log.Errorln(err)
|
||||
log.Errorf("Failed to import image(s) into cluster '%s': %+v", cluster.Name, err)
|
||||
errOccured = true
|
||||
}
|
||||
}
|
||||
log.Info("DONE")
|
||||
if errOccured {
|
||||
log.Warnln("At least one error occured while trying to import the image(s) into the selected cluster(s)")
|
||||
os.Exit(1)
|
||||
}
|
||||
log.Infof("Successfully imported %d image(s) into %d cluster(s)", len(images), len(clusters))
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user