Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make chart loader pluggable #216

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func newClient(options *Options, clientGetter genericclioptions.RESTClientGetter
linting: options.Linting,
DebugLog: debugLog,
output: options.Output,
ChartLoader: &DefaultChartLoader{
Settings: settings,
DebugLog: debugLog,
},
}, nil
}

Expand Down Expand Up @@ -323,8 +327,7 @@ func (c *HelmClient) install(ctx context.Context, spec *ChartSpec, opts *Generic
return nil, err
}

p := getter.All(c.Settings)
values, err := spec.GetValuesMap(p)
values, err := spec.GetValuesMap(c.Providers)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -373,8 +376,7 @@ func (c *HelmClient) upgrade(ctx context.Context, spec *ChartSpec, opts *Generic
return nil, err
}

p := getter.All(c.Settings)
values, err := spec.GetValuesMap(p)
values, err := spec.GetValuesMap(c.Providers)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -507,8 +509,7 @@ func (c *HelmClient) TemplateChart(spec *ChartSpec, options *HelmTemplateOptions
return nil, err
}

p := getter.All(c.Settings)
values, err := spec.GetValuesMap(p)
values, err := spec.GetValuesMap(c.Providers)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -544,8 +545,7 @@ func (c *HelmClient) LintChart(spec *ChartSpec) error {
return err
}

p := getter.All(c.Settings)
values, err := spec.GetValuesMap(p)
values, err := spec.GetValuesMap(c.Providers)
if err != nil {
return err
}
Expand Down Expand Up @@ -755,25 +755,6 @@ func (c *HelmClient) upgradeCRDV1(ctx context.Context, cl *clientset.Clientset,
return nil
}

// GetChart returns a chart matching the provided chart name and options.
func (c *HelmClient) GetChart(chartName string, chartPathOptions *action.ChartPathOptions) (*chart.Chart, string, error) {
chartPath, err := chartPathOptions.LocateChart(chartName, c.Settings)
if err != nil {
return nil, "", err
}

helmChart, err := loader.Load(chartPath)
if err != nil {
return nil, "", err
}

if helmChart.Metadata.Deprecated {
c.DebugLog("WARNING: This chart (%q) is deprecated", helmChart.Metadata.Name)
}

return helmChart, chartPath, err
}

// RunTests runs the tests that were deployed with the release provided. It returns true
// if all the tests ran successfully and false in all other cases.
// NOTE: error = nil implies that all tests ran to either success or failure.
Expand Down Expand Up @@ -848,6 +829,25 @@ func (c *HelmClient) rollbackRelease(spec *ChartSpec) error {
return client.Run(spec.ReleaseName)
}

// GetChart returns a chart matching the provided chart name and options.
func (l *DefaultChartLoader) GetChart(chartName string, chartPathOptions *action.ChartPathOptions) (*chart.Chart, string, error) {
chartPath, err := chartPathOptions.LocateChart(chartName, l.Settings)
if err != nil {
return nil, "", err
}

helmChart, err := loader.Load(chartPath)
if err != nil {
return nil, "", err
}

if helmChart.Metadata.Deprecated {
l.DebugLog("WARNING: This chart (%q) is deprecated", helmChart.Metadata.Name)
}

return helmChart, chartPath, err
}

// updateDependencies checks dependencies for given helmChart and updates dependencies with metadata if dependencyUpdate is true. returns updated HelmChart
func updateDependencies(helmChart *chart.Chart, chartPathOptions *action.ChartPathOptions, chartPath string, c *HelmClient, dependencyUpdate bool, spec *ChartSpec) (*chart.Chart, error) {
if req := helmChart.Metadata.Dependencies; req != nil {
Expand Down
7 changes: 6 additions & 1 deletion interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ type Client interface {
LintChart(spec *ChartSpec) error
SetDebugLog(debugLog action.DebugLog)
ListReleaseHistory(name string, max int) ([]*release.Release, error)
GetChart(chartName string, chartPathOptions *action.ChartPathOptions) (*chart.Chart, string, error)
// ChartLoader is an interface to abstract loading charts.
ChartLoader
RunChartTests(releaseName string) (bool, error)
}

type ChartLoader interface {
GetChart(chartName string, chartPathOptions *action.ChartPathOptions) (*chart.Chart, string, error)
}

type RollBack interface {
RollbackRelease(spec *ChartSpec) error
}
8 changes: 8 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ type HelmClient struct {
linting bool
output io.Writer
DebugLog action.DebugLog

ChartLoader
}

// DefaultChartLoader is the default implementation of the ChartLoader interface.
type DefaultChartLoader struct {
Settings *cli.EnvSettings
DebugLog action.DebugLog
}

func (c *HelmClient) GetSettings() *cli.EnvSettings {
Expand Down