Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
cli/cmd: make applyComponents() accept slice of objects
Browse files Browse the repository at this point in the history
Instead of slice of names. This shifs the error handling of getting
components to earlier stage, so we don't apply one component and then
fail, because other one does not exist.

Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
  • Loading branch information
invidian committed Sep 25, 2020
1 parent 046f602 commit 6efb011
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions cli/cmd/component-apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,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 {
Expand All @@ -81,22 +84,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() {
Expand Down

0 comments on commit 6efb011

Please sign in to comment.