Skip to content

Commit

Permalink
Merge pull request #68 from guitarlum/master
Browse files Browse the repository at this point in the history
nil pointer fix - also addressed in issue #64
  • Loading branch information
elenz97 authored Apr 11, 2022
2 parents f8612de + 4e805eb commit 84603c8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func newClient(options *Options, clientGetter genericclioptions.RESTClientGetter
}
}

if options.Output == nil {
options.Output = os.Stdout
}

actionConfig := new(action.Configuration)
err = actionConfig.Init(
clientGetter,
Expand All @@ -104,6 +108,7 @@ func newClient(options *Options, clientGetter genericclioptions.RESTClientGetter
ActionConfig: actionConfig,
linting: options.Linting,
DebugLog: debugLog,
output: options.Output,
}, nil
}

Expand Down Expand Up @@ -301,6 +306,7 @@ func (c *HelmClient) install(ctx context.Context, spec *ChartSpec) (*release.Rel
Getters: c.Providers,
RepositoryConfig: c.Settings.RepositoryConfig,
RepositoryCache: c.Settings.RepositoryCache,
Out: c.output,
}
if err := man.Update(); err != nil {
return nil, err
Expand Down
5 changes: 4 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package helmclient

import (
"bytes"
"context"

"helm.sh/helm/v3/pkg/repo"
"k8s.io/client-go/rest"
)

func ExampleNew() {
var outputBuffer bytes.Buffer

opt := &Options{
Namespace: "default", // Change this to the namespace you wish the client to operate in.
RepositoryCache: "/tmp/.helmcache",
RepositoryConfig: "/tmp/.helmrepo",
Debug: true,
Linting: true,
DebugLog: func(format string, v ...interface{}) {},
Output: &outputBuffer, // Not mandatory, leave open for default os.Stdout
}

helmClient, err := New(opt)
Expand Down
5 changes: 4 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package helmclient

import (
"io"
"time"

"helm.sh/helm/v3/pkg/getter"
Expand Down Expand Up @@ -28,14 +29,15 @@ type RestConfClientOptions struct {
RestConfig *rest.Config
}

// Options defines the options of a client.
// Options defines the options of a client. If Output is not set, os.Stdout will be used.
type Options struct {
Namespace string
RepositoryConfig string
RepositoryCache string
Debug bool
Linting bool
DebugLog action.DebugLog
Output io.Writer
}

// RESTClientGetter defines the values of a helm REST client.
Expand All @@ -54,6 +56,7 @@ type HelmClient struct {
// ActionConfig is the helm action configuration.
ActionConfig *action.Configuration
linting bool
output io.Writer
DebugLog action.DebugLog
}

Expand Down

0 comments on commit 84603c8

Please sign in to comment.