mirror of
https://github.com/helm/helm.git
synced 2026-06-30 19:57:48 +00:00
Provide a helper to set the registryClient in cmd
If enabled the registryClient is set using a helper that accepts the TLS flags. This keeps the client creation consistent accross the different commands. Signed-off-by: Soule BA <bah.soule@gmail.com>
This commit is contained in:
@@ -20,7 +20,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -137,6 +136,11 @@ func NewInstall(cfg *Configuration) *Install {
|
||||
return in
|
||||
}
|
||||
|
||||
// SetRegistryClient sets the registry client for the install action
|
||||
func (i *Install) SetRegistryClient(registryClient *registry.Client) {
|
||||
i.ChartPathOptions.registryClient = registryClient
|
||||
}
|
||||
|
||||
func (i *Install) installCRDs(crds []chart.CRD) error {
|
||||
// We do these one file at a time in the order they were read.
|
||||
totalItems := []*resource.Info{}
|
||||
@@ -676,22 +680,11 @@ OUTER:
|
||||
// - URL
|
||||
//
|
||||
// If 'verify' was set on ChartPathOptions, this will attempt to also verify the chart.
|
||||
func (c *ChartPathOptions) LocateChart(name string, out io.Writer, settings *cli.EnvSettings) (string, error) {
|
||||
// If there is no registry client and the name is in an OCI registry return
|
||||
// an error and a lookup will not occur.
|
||||
if registry.IsOCI(name) {
|
||||
if (c.CertFile != "" && c.KeyFile != "") || c.CaFile != "" || c.InsecureSkipTLSverify {
|
||||
registryClient, err := registry.NewRegistryClientWithTLS(out, c.CertFile, c.KeyFile, c.CaFile,
|
||||
c.InsecureSkipTLSverify, settings.RegistryConfig, settings.Debug)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
c.registryClient = registryClient
|
||||
}
|
||||
if c.registryClient == nil {
|
||||
return "", fmt.Errorf("unable to lookup chart %q, missing registry client", name)
|
||||
}
|
||||
func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (string, error) {
|
||||
if registry.IsOCI(name) && c.registryClient == nil {
|
||||
return "", fmt.Errorf("unable to lookup chart %q, missing registry client", name)
|
||||
}
|
||||
|
||||
name = strings.TrimSpace(name)
|
||||
version := strings.TrimSpace(c.Version)
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package action
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -48,7 +47,6 @@ type Pull struct {
|
||||
UntarDir string
|
||||
DestDir string
|
||||
cfg *Configuration
|
||||
out io.Writer
|
||||
}
|
||||
|
||||
type PullOpt func(*Pull)
|
||||
@@ -59,13 +57,6 @@ func WithConfig(cfg *Configuration) PullOpt {
|
||||
}
|
||||
}
|
||||
|
||||
// WithOptWriter sets the registryOut field on the push configuration object.
|
||||
func WithPullOptWriter(out io.Writer) PullOpt {
|
||||
return func(p *Pull) {
|
||||
p.out = out
|
||||
}
|
||||
}
|
||||
|
||||
// NewPull creates a new Pull object.
|
||||
func NewPull() *Pull {
|
||||
return NewPullWithOpts()
|
||||
@@ -81,6 +72,11 @@ func NewPullWithOpts(opts ...PullOpt) *Pull {
|
||||
return p
|
||||
}
|
||||
|
||||
// SetRegistryClient sets the registry client on the pull configuration object.
|
||||
func (p *Pull) SetRegistryClient(client *registry.Client) {
|
||||
p.cfg.RegistryClient = client
|
||||
}
|
||||
|
||||
// Run executes 'helm pull' against the given release.
|
||||
func (p *Pull) Run(chartRef string) (string, error) {
|
||||
var out strings.Builder
|
||||
@@ -102,16 +98,6 @@ func (p *Pull) Run(chartRef string) (string, error) {
|
||||
}
|
||||
|
||||
if registry.IsOCI(chartRef) {
|
||||
// Provide a tls enabled client for the pull command if the user has
|
||||
// specified the cert file or key file or ca file.
|
||||
if (p.ChartPathOptions.CertFile != "" && p.ChartPathOptions.KeyFile != "") || p.ChartPathOptions.CaFile != "" || p.ChartPathOptions.InsecureSkipTLSverify {
|
||||
registryClient, err := registry.NewRegistryClientWithTLS(p.out, p.ChartPathOptions.CertFile, p.ChartPathOptions.KeyFile, p.ChartPathOptions.CaFile,
|
||||
p.ChartPathOptions.InsecureSkipTLSverify, p.Settings.RegistryConfig, p.Settings.Debug)
|
||||
if err != nil {
|
||||
return out.String(), err
|
||||
}
|
||||
p.cfg.RegistryClient = registryClient
|
||||
}
|
||||
c.Options = append(c.Options,
|
||||
getter.WithRegistryClient(p.cfg.RegistryClient))
|
||||
c.RegistryClient = p.cfg.RegistryClient
|
||||
|
||||
@@ -90,21 +90,11 @@ func (p *Push) Run(chartRef string, remote string) (string, error) {
|
||||
Pushers: pusher.All(p.Settings),
|
||||
Options: []pusher.Option{
|
||||
pusher.WithTLSClientConfig(p.certFile, p.keyFile, p.caFile),
|
||||
pusher.WithInsecureSkipTLSVerify(p.insecureSkipTLSverify),
|
||||
},
|
||||
}
|
||||
|
||||
if registry.IsOCI(remote) {
|
||||
// Provide a tls enabled client for the pull command if the user has
|
||||
// specified the cert file or key file or ca file.
|
||||
if (p.certFile != "" && p.keyFile != "") || p.caFile != "" || p.insecureSkipTLSverify {
|
||||
registryClient, err := registry.NewRegistryClientWithTLS(p.out, p.certFile, p.keyFile, p.caFile,
|
||||
p.insecureSkipTLSverify, p.Settings.RegistryConfig, p.Settings.Debug)
|
||||
if err != nil {
|
||||
return out.String(), err
|
||||
}
|
||||
p.cfg.RegistryClient = registryClient
|
||||
}
|
||||
|
||||
// Don't use the default registry client if tls options are set.
|
||||
c.Options = append(c.Options, pusher.WithRegistryClient(p.cfg.RegistryClient))
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"helm.sh/helm/v3/pkg/chart"
|
||||
"helm.sh/helm/v3/pkg/chart/loader"
|
||||
"helm.sh/helm/v3/pkg/chartutil"
|
||||
"helm.sh/helm/v3/pkg/registry"
|
||||
)
|
||||
|
||||
// ShowOutputFormat is the format of the output of `helm show`
|
||||
@@ -82,6 +83,11 @@ func NewShowWithConfig(output ShowOutputFormat, cfg *Configuration) *Show {
|
||||
return sh
|
||||
}
|
||||
|
||||
// SetRegistryClient sets the registry client to use when pulling a chart from a registry.
|
||||
func (s *Show) SetRegistryClient(client *registry.Client) {
|
||||
s.ChartPathOptions.registryClient = client
|
||||
}
|
||||
|
||||
// Run executes 'helm show' against the given release.
|
||||
func (s *Show) Run(chartpath string) (string, error) {
|
||||
if s.chart == nil {
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
"helm.sh/helm/v3/pkg/chartutil"
|
||||
"helm.sh/helm/v3/pkg/kube"
|
||||
"helm.sh/helm/v3/pkg/postrender"
|
||||
"helm.sh/helm/v3/pkg/registry"
|
||||
"helm.sh/helm/v3/pkg/release"
|
||||
"helm.sh/helm/v3/pkg/releaseutil"
|
||||
"helm.sh/helm/v3/pkg/storage/driver"
|
||||
@@ -122,6 +123,11 @@ func NewUpgrade(cfg *Configuration) *Upgrade {
|
||||
return up
|
||||
}
|
||||
|
||||
// SetRegistryClient sets the registry client to use when fetching charts.
|
||||
func (u *Upgrade) SetRegistryClient(client *registry.Client) {
|
||||
u.ChartPathOptions.registryClient = client
|
||||
}
|
||||
|
||||
// Run executes the upgrade on the given release.
|
||||
func (u *Upgrade) Run(name string, chart *chart.Chart, vals map[string]interface{}) (*release.Release, error) {
|
||||
ctx := context.Background()
|
||||
|
||||
Reference in New Issue
Block a user