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()
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
cobra.OnInitialize(func() {

@ -115,7 +115,11 @@ func executeActionCommandStdinC(store *storage.Storage, in *os.File, cmd string)
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.SetErr(buf)
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 |
`
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{
Use: "helm",
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(
registry.ClientOptDebug(settings.Debug),
registry.ClientOptWriter(out),
registry.ClientOptCredentialsFile(settings.RegistryConfig),
)
if err != nil {
// TODO: don't panic here, refactor newRootCmd to return error
panic(err)
return nil, err
}
actionConfig.RegistryClient = registryClient
cmd.AddCommand(
@ -189,5 +189,5 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string
// Find and add plugins
loadPlugins(cmd, out)
return cmd
return cmd, nil
}

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

@ -60,3 +60,10 @@ func ClientOptCache(cache *Cache) ClientOption {
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