fix: init `Storage` by the Log function used by `Configuration`, concrete `Driver`, etc.

1. init `Storage` by the Log function used by `Configuration`, concrete `Driver`, etc.
2. fix some log output format for log style consistency

close #8108

Signed-off-by: Liu Ming <hit_oak_tree@126.com>
pull/8082/head
Liu Ming 5 years ago
parent e2442699fa
commit 389c355962

@ -186,7 +186,7 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options
return nil, err return nil, err
} }
debug("CHART PATH: %s\n", cp) debug("CHART PATH: %s", cp)
p := getter.All(settings) p := getter.All(settings)
vals, err := valueOpts.MergeValues(p) vals, err := valueOpts.MergeValues(p)

@ -375,11 +375,11 @@ func (c *Configuration) Init(getter genericclioptions.RESTClientGetter, namespac
case "secret", "secrets", "": case "secret", "secrets", "":
d := driver.NewSecrets(newSecretClient(lazyClient)) d := driver.NewSecrets(newSecretClient(lazyClient))
d.Log = log d.Log = log
store = storage.Init(d) store = storage.NewStorage(d, log)
case "configmap", "configmaps": case "configmap", "configmaps":
d := driver.NewConfigMaps(newConfigMapClient(lazyClient)) d := driver.NewConfigMaps(newConfigMapClient(lazyClient))
d.Log = log d.Log = log
store = storage.Init(d) store = storage.NewStorage(d, log)
case "memory": case "memory":
var d *driver.Memory var d *driver.Memory
if c.Releases != nil { if c.Releases != nil {
@ -394,7 +394,7 @@ func (c *Configuration) Init(getter genericclioptions.RESTClientGetter, namespac
d = driver.NewMemory() d = driver.NewMemory()
} }
d.SetNamespace(namespace) d.SetNamespace(namespace)
store = storage.Init(d) store = storage.NewStorage(d, log)
case "sql": case "sql":
d, err := driver.NewSQL( d, err := driver.NewSQL(
os.Getenv("HELM_DRIVER_SQL_CONNECTION_STRING"), os.Getenv("HELM_DRIVER_SQL_CONNECTION_STRING"),
@ -404,7 +404,7 @@ func (c *Configuration) Init(getter genericclioptions.RESTClientGetter, namespac
if err != nil { if err != nil {
panic(fmt.Sprintf("Unable to instantiate SQL driver: %v", err)) panic(fmt.Sprintf("Unable to instantiate SQL driver: %v", err))
} }
store = storage.Init(d) store = storage.NewStorage(d, log)
default: default:
// Not sure what to do here. // Not sure what to do here.
panic("Unknown driver in HELM_DRIVER: " + helmDriver) panic("Unknown driver in HELM_DRIVER: " + helmDriver)

@ -192,7 +192,7 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err
} }
kind := info.Mapping.GroupVersionKind.Kind kind := info.Mapping.GroupVersionKind.Kind
c.Log("Created a new %s called %q in %s\n", kind, info.Name, info.Namespace) c.Log("Created a new %s called %q in %s", kind, info.Name, info.Namespace)
return nil return nil
} }

@ -252,12 +252,17 @@ func makeKey(rlsname string, version int) string {
// Init initializes a new storage backend with the driver d. // Init initializes a new storage backend with the driver d.
// If d is nil, the default in-memory driver is used. // If d is nil, the default in-memory driver is used.
func Init(d driver.Driver) *Storage { func Init(d driver.Driver) *Storage {
return NewStorage(d, func(_ string, _ ...interface{}) {})
}
// NewStorage creates a new Storage object with the given Driver and log function.
func NewStorage(d driver.Driver, debug func(format string, args ...interface{})) *Storage {
// default driver is in memory // default driver is in memory
if d == nil { if d == nil {
d = driver.NewMemory() d = driver.NewMemory()
} }
return &Storage{ return &Storage{
Driver: d, Driver: d,
Log: func(_ string, _ ...interface{}) {}, Log: debug,
} }
} }

Loading…
Cancel
Save