diff --git a/cli/cmd/cluster-apply.go b/cli/cmd/cluster-apply.go index 2b0b9bcaf..e460396f7 100644 --- a/cli/cmd/cluster-apply.go +++ b/cli/cmd/cluster-apply.go @@ -145,17 +145,15 @@ func clusterApply(contextLogger *log.Entry) error { return nil } - componentsToApply := []string{} - for _, component := range c.lokomotiveConfig.RootConfig.Components { - componentsToApply = append(componentsToApply, component.Name) + componentObjects, err := componentNamesToObjects(componentNames(nil, *c.lokomotiveConfig)) + if err != nil { + return fmt.Errorf("getting component objects: %w", err) } contextLogger.Println("Applying component configuration") - if len(componentsToApply) > 0 { - if err := applyComponents(c.lokomotiveConfig, kubeconfig, componentsToApply...); err != nil { - return fmt.Errorf("applying component configuration: %v", err) - } + if err := applyComponents(c.lokomotiveConfig, kubeconfig, componentObjects); err != nil { + return fmt.Errorf("applying component configuration: %v", err) } return nil diff --git a/cli/cmd/component-apply.go b/cli/cmd/component-apply.go index 5b01d5fdc..1b6826947 100644 --- a/cli/cmd/component-apply.go +++ b/cli/cmd/component-apply.go @@ -74,7 +74,10 @@ func componentApply(contextLogger *log.Entry, componentsList []string) error { return diags } - componentsToApply := componentNames(componentsList, *lokoConfig) + componentObjects, err := componentNamesToObjects(componentNames(componentsList, *lokoConfig)) + if err != nil { + return fmt.Errorf("getting component objects: %w", err) + } kubeconfig, err := getKubeconfig(contextLogger, lokoConfig, false) if err != nil { @@ -83,22 +86,18 @@ func componentApply(contextLogger *log.Entry, componentsList []string) error { return fmt.Errorf("suitable kubeconfig file not found. Did you run 'lokoctl cluster apply' ?") } - if err := applyComponents(lokoConfig, kubeconfig, componentsToApply); err != nil { + if err := applyComponents(lokoConfig, kubeconfig, componentObjects); err != nil { return fmt.Errorf("applying components: %w", err) } return nil } -func applyComponents(lokoConfig *config.Config, kubeconfig []byte, componentNames []string) error { - for _, componentName := range componentNames { +func applyComponents(lokoConfig *config.Config, kubeconfig []byte, componentObjects []components.Component) error { + for _, component := range componentObjects { + componentName := component.Metadata().Name fmt.Printf("Applying component '%s'...\n", componentName) - component, err := components.Get(componentName) - if err != nil { - return fmt.Errorf("getting component %q: %w", componentName, err) - } - componentConfigBody := lokoConfig.LoadComponentConfigBody(componentName) if diags := component.LoadConfig(componentConfigBody, lokoConfig.EvalContext); diags.HasErrors() {