Skip to content

Commit

Permalink
asset/store: log asset creation
Browse files Browse the repository at this point in the history
This makes it clear when and why a particular asset was created so it
should help with debugging. The output of this looks as follows:

    INFO[0000] Fetching Bootstrap Ignition Config...
    DEBU[0000] Generating dependencies of Bootstrap Ignition Config...
    INFO[0000]   Fetching Install Config...
    DEBU[0000]   Generating dependencies of Install Config...
    INFO[0000]     Fetching Cluster ID...
    DEBU[0000]     Generating Cluster ID...
    INFO[0000]     Fetching Email Address...
    DEBU[0000]     Generating Email Address...
  • Loading branch information
crawford committed Sep 19, 2018
1 parent a23d3e6 commit 5236a96
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/asset/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
],
importpath = "github.com/openshift/installer/pkg/asset",
visibility = ["//visibility:public"],
deps = ["//vendor/github.com/Sirupsen/logrus:go_default_library"],
)

go_test(
Expand Down
24 changes: 20 additions & 4 deletions pkg/asset/store.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package asset

import (
"github.com/Sirupsen/logrus"
)

// Store is a store for the states of assets.
type Store interface {
// Fetch retrieves the state of the given asset, generating it and its
Expand All @@ -15,19 +19,31 @@ type StoreImpl struct {
// Fetch retrieves the state of the given asset, generating it and its
// dependencies if necessary.
func (s *StoreImpl) Fetch(asset Asset) (*State, error) {
return s.fetch(asset, "")
}

func (s *StoreImpl) fetch(asset Asset, indent string) (*State, error) {
logrus.Infof("%sFetching %s...", indent, asset.Name())
state, ok := s.assets[asset]
if ok {
logrus.Debugf("%sFound %s...", indent, asset.Name())
return state, nil
}
dependies := asset.Dependencies()
dependenciesStates := make(map[Asset]*State, len(dependies))
for _, d := range dependies {
ds, err := s.Fetch(d)

dependencies := asset.Dependencies()
dependenciesStates := make(map[Asset]*State, len(dependencies))
if len(dependencies) > 0 {
logrus.Debugf("%sGenerating dependencies of %s...", indent, asset.Name())
}
for _, d := range dependencies {
ds, err := s.fetch(d, indent+" ")
if err != nil {
return nil, err
}
dependenciesStates[d] = ds
}

logrus.Debugf("%sGenerating %s...", indent, asset.Name())
state, err := asset.Generate(dependenciesStates)
if err != nil {
return nil, err
Expand Down

0 comments on commit 5236a96

Please sign in to comment.