diff --git a/cli/cmd/component-apply.go b/cli/cmd/component-apply.go index 8a40b0987..61a852ddd 100644 --- a/cli/cmd/component-apply.go +++ b/cli/cmd/component-apply.go @@ -61,12 +61,18 @@ func runApply(cmd *cobra.Command, args []string) { log.SetLevel(log.DebugLevel) } + if err := componentApply(contextLogger, args); err != nil { + contextLogger.Fatalf("Applying components failed: %v", err) + } +} + +func componentApply(contextLogger *log.Entry, componentsList []string) error { lokoConfig, diags := getLokoConfig() if diags.HasErrors() { - contextLogger.Fatal(diags) + return diags } - componentsToApply := args + componentsToApply := componentsList if len(componentsToApply) == 0 { for _, component := range lokoConfig.RootConfig.Components { componentsToApply = append(componentsToApply, component.Name) @@ -76,12 +82,15 @@ func runApply(cmd *cobra.Command, args []string) { kubeconfig, err := getKubeconfig(contextLogger, lokoConfig, false) if err != nil { contextLogger.Debugf("Error in finding kubeconfig file: %s", err) - contextLogger.Fatal("Suitable kubeconfig file not found. Did you run 'lokoctl cluster apply' ?") + + return fmt.Errorf("suitable kubeconfig file not found. Did you run 'lokoctl cluster apply' ?") } if err := applyComponents(lokoConfig, kubeconfig, componentsToApply...); err != nil { - contextLogger.Fatal(err) + return fmt.Errorf("applying components: %w", err) } + + return nil } func applyComponents(lokoConfig *config.Config, kubeconfig []byte, componentNames ...string) error {