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 component render-manifest use errors instead of Fatalf
Browse files Browse the repository at this point in the history
To remove a dependency on log.Entry to make moving this code around
easier and to avoid hiding function complexity from logger.

Part of #630

Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
  • Loading branch information
invidian committed Sep 25, 2020
1 parent bc28e30 commit bdecc4b
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions cli/cmd/component-render-manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,35 @@ func runComponentRender(cmd *cobra.Command, args []string) {
"args": args,
})

if err := componentRenderManifest(contextLogger, args); err != nil {
contextLogger.Fatalf("Rendering component manifests failed: %v", err)
}
}

func componentRenderManifest(contextLogger *log.Entry, componentsList []string) error {
lokoConfig, diags := getLokoConfig()
if diags.HasErrors() {
for _, diagnostic := range diags {
contextLogger.Error(diagnostic.Error())
}
contextLogger.Fatal("Errors found while loading configuration")

return diags
}

componentsToRender := componentNames(args, *lokoConfig)
var componentsToRender []string
if len(componentsList) > 0 {
componentsToRender = append(componentsToRender, componentsList...)
} else {
for _, component := range lokoConfig.RootConfig.Components {
componentsToRender = append(componentsToRender, component.Name)
}
}

if err := renderComponentManifests(lokoConfig, componentsToRender); err != nil {
contextLogger.Fatal(err)
return fmt.Errorf("rendering component manifests: %w", err)
}

return nil
}

func renderComponentManifests(lokoConfig *config.Config, componentNames []string) error {
Expand Down

0 comments on commit bdecc4b

Please sign in to comment.