Merge pull request #7356 from EItanya/helm-7351

--registry-config flag is not honored
pull/8270/head
Matthew Fisher 5 years ago committed by GitHub
commit 65ee1e0bc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -68,7 +68,11 @@ func main() {
initKubeLogs() initKubeLogs()
actionConfig := new(action.Configuration) actionConfig := new(action.Configuration)
cmd := newRootCmd(actionConfig, os.Stdout, os.Args[1:]) cmd, err := newRootCmd(actionConfig, os.Stdout, os.Args[1:])
if err != nil {
debug("%+v", err)
os.Exit(1)
}
// run when each command's execute method is called // run when each command's execute method is called
cobra.OnInitialize(func() { cobra.OnInitialize(func() {

@ -115,7 +115,11 @@ func executeActionCommandStdinC(store *storage.Storage, in *os.File, cmd string)
Log: func(format string, v ...interface{}) {}, Log: func(format string, v ...interface{}) {},
} }
root := newRootCmd(actionConfig, buf, args) root, err := newRootCmd(actionConfig, buf, args)
if err != nil {
return nil, "", err
}
root.SetOut(buf) root.SetOut(buf)
root.SetErr(buf) root.SetErr(buf)
root.SetArgs(args) root.SetArgs(args)

@ -68,7 +68,7 @@ By default, the default directories depend on the Operating System. The defaults
| Windows | %TEMP%\helm | %APPDATA%\helm | %APPDATA%\helm | | Windows | %TEMP%\helm | %APPDATA%\helm | %APPDATA%\helm |
` `
func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string) *cobra.Command { func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string) (*cobra.Command, error) {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "helm", Use: "helm",
Short: "The Helm package manager for Kubernetes.", Short: "The Helm package manager for Kubernetes.",
@ -175,10 +175,10 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string
registryClient, err := registry.NewClient( registryClient, err := registry.NewClient(
registry.ClientOptDebug(settings.Debug), registry.ClientOptDebug(settings.Debug),
registry.ClientOptWriter(out), registry.ClientOptWriter(out),
registry.ClientOptCredentialsFile(settings.RegistryConfig),
) )
if err != nil { if err != nil {
// TODO: don't panic here, refactor newRootCmd to return error return nil, err
panic(err)
} }
actionConfig.RegistryClient = registryClient actionConfig.RegistryClient = registryClient
cmd.AddCommand( cmd.AddCommand(
@ -189,5 +189,5 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string
// Find and add plugins // Find and add plugins
loadPlugins(cmd, out) loadPlugins(cmd, out)
return cmd return cmd, nil
} }

@ -42,11 +42,13 @@ const (
type ( type (
// Client works with OCI-compliant registries and local Helm chart cache // Client works with OCI-compliant registries and local Helm chart cache
Client struct { Client struct {
debug bool debug bool
out io.Writer // path to repository config file e.g. ~/.docker/config.json
authorizer *Authorizer credentialsFile string
resolver *Resolver out io.Writer
cache *Cache authorizer *Authorizer
resolver *Resolver
cache *Cache
} }
) )
@ -59,9 +61,11 @@ func NewClient(opts ...ClientOption) (*Client, error) {
opt(client) opt(client)
} }
// set defaults if fields are missing // set defaults if fields are missing
if client.credentialsFile == "" {
client.credentialsFile = helmpath.CachePath("registry", CredentialsFileBasename)
}
if client.authorizer == nil { if client.authorizer == nil {
credentialsFile := helmpath.CachePath("registry", CredentialsFileBasename) authClient, err := auth.NewClient(client.credentialsFile)
authClient, err := auth.NewClient(credentialsFile)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -60,3 +60,10 @@ func ClientOptCache(cache *Cache) ClientOption {
client.cache = cache client.cache = cache
} }
} }
// ClientOptCache returns a function that sets the cache setting on a client options set
func ClientOptCredentialsFile(credentialsFile string) ClientOption {
return func(client *Client) {
client.credentialsFile = credentialsFile
}
}

Loading…
Cancel
Save