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

[BREAKING] remove PostRenderer interface type from ChartSpec #87

Merged
merged 2 commits into from
May 10, 2022
Merged
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
6 changes: 2 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ jobs:

- uses: actions/checkout@v2

- name: Install and run mockgen
- name: Run go generate
run: |
set -x
apt-get -y update && apt-get -y install git
cd /
go install github.com/golang/mock/[email protected]
cd -
go env
go install sigs.k8s.io/controller-tools/cmd/[email protected]
go generate ./...
git diff | cat
git status --porcelain=v1
Expand Down
30 changes: 17 additions & 13 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,29 +200,29 @@ func (c *HelmClient) UpdateChartRepos() error {

// InstallOrUpgradeChart installs or upgrades the provided chart and returns the corresponding release.
// Namespace and other context is provided via the helmclient.Options struct when instantiating a client.
func (c *HelmClient) InstallOrUpgradeChart(ctx context.Context, spec *ChartSpec) (*release.Release, error) {
func (c *HelmClient) InstallOrUpgradeChart(ctx context.Context, spec *ChartSpec, opts *GenericHelmOptions) (*release.Release, error) {
exists, err := c.chartExists(spec)
if err != nil {
return nil, err
}

if exists {
return c.upgrade(ctx, spec)
return c.upgrade(ctx, spec, opts)
}

return c.install(ctx, spec)
return c.install(ctx, spec, opts)
}

// InstallChart installs the provided chart and returns the corresponding release.
// Namespace and other context is provided via the helmclient.Options struct when instantiating a client.
func (c *HelmClient) InstallChart(ctx context.Context, spec *ChartSpec) (*release.Release, error) {
return c.install(ctx, spec)
func (c *HelmClient) InstallChart(ctx context.Context, spec *ChartSpec, opts *GenericHelmOptions) (*release.Release, error) {
return c.install(ctx, spec, opts)
}

// UpgradeChart upgrades the provided chart and returns the corresponding release.
// Namespace and other context is provided via the helmclient.Options struct when instantiating a client.
func (c *HelmClient) UpgradeChart(ctx context.Context, spec *ChartSpec) (*release.Release, error) {
return c.upgrade(ctx, spec)
func (c *HelmClient) UpgradeChart(ctx context.Context, spec *ChartSpec, opts *GenericHelmOptions) (*release.Release, error) {
return c.upgrade(ctx, spec, opts)
}

// ListDeployedReleases lists all deployed releases.
Expand Down Expand Up @@ -265,7 +265,7 @@ func (c *HelmClient) UninstallReleaseByName(name string) error {

// install installs the provided chart.
// Optionally lints the chart if the linting flag is set.
func (c *HelmClient) install(ctx context.Context, spec *ChartSpec) (*release.Release, error) {
func (c *HelmClient) install(ctx context.Context, spec *ChartSpec, opts *GenericHelmOptions) (*release.Release, error) {
client := action.NewInstall(c.ActionConfig)
mergeInstallOptions(spec, client)

Expand All @@ -281,8 +281,10 @@ func (c *HelmClient) install(ctx context.Context, spec *ChartSpec) (*release.Rel
client.Version = ">0.0.0-0"
}

if spec.PostRenderer != nil {
client.PostRenderer = spec.PostRenderer
if opts != nil {
if opts.PostRenderer != nil {
client.PostRenderer = opts.PostRenderer
}
}

helmChart, chartPath, err := c.getChart(spec.ChartName, &client.ChartPathOptions)
Expand Down Expand Up @@ -327,7 +329,7 @@ func (c *HelmClient) install(ctx context.Context, spec *ChartSpec) (*release.Rel

// upgrade upgrades a chart and CRDs.
// Optionally lints the chart if the linting flag is set.
func (c *HelmClient) upgrade(ctx context.Context, spec *ChartSpec) (*release.Release, error) {
func (c *HelmClient) upgrade(ctx context.Context, spec *ChartSpec, opts *GenericHelmOptions) (*release.Release, error) {
client := action.NewUpgrade(c.ActionConfig)
mergeUpgradeOptions(spec, client)
client.Install = true
Expand All @@ -336,8 +338,10 @@ func (c *HelmClient) upgrade(ctx context.Context, spec *ChartSpec) (*release.Rel
client.Version = ">0.0.0-0"
}

if spec.PostRenderer != nil {
client.PostRenderer = spec.PostRenderer
if opts != nil {
if opts.PostRenderer != nil {
client.PostRenderer = opts.PostRenderer
}
}

helmChart, chartPath, err := c.getChart(spec.ChartName, &client.ChartPathOptions)
Expand Down
8 changes: 4 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func ExampleHelmClient_InstallOrUpgradeChart() {

// Install a chart release.
// Note that helmclient.Options.Namespace should ideally match the namespace in chartSpec.Namespace.
if _, err := helmClient.InstallOrUpgradeChart(context.Background(), &chartSpec); err != nil {
if _, err := helmClient.InstallOrUpgradeChart(context.Background(), &chartSpec, nil); err != nil {
panic(err)
}
}
Expand All @@ -130,7 +130,7 @@ func ExampleHelmClient_InstallOrUpgradeChart_useChartDirectory() {
Wait: true,
}

if _, err := helmClient.InstallOrUpgradeChart(context.Background(), &chartSpec); err != nil {
if _, err := helmClient.InstallOrUpgradeChart(context.Background(), &chartSpec, nil); err != nil {
panic(err)
}
}
Expand All @@ -145,7 +145,7 @@ func ExampleHelmClient_InstallOrUpgradeChart_useLocalChartArchive() {
Wait: true,
}

if _, err := helmClient.InstallOrUpgradeChart(context.Background(), &chartSpec); err != nil {
if _, err := helmClient.InstallOrUpgradeChart(context.Background(), &chartSpec, nil); err != nil {
panic(err)
}
}
Expand All @@ -160,7 +160,7 @@ func ExampleHelmClient_InstallOrUpgradeChart_useURL() {
Wait: true,
}

if _, err := helmClient.InstallOrUpgradeChart(context.Background(), &chartSpec); err != nil {
if _, err := helmClient.InstallOrUpgradeChart(context.Background(), &chartSpec, nil); err != nil {
panic(err)
}
}
Expand Down
15 changes: 15 additions & 0 deletions hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
Copyright 2022.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
6 changes: 3 additions & 3 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
type Client interface {
AddOrUpdateChartRepo(entry repo.Entry) error
UpdateChartRepos() error
InstallOrUpgradeChart(ctx context.Context, spec *ChartSpec) (*release.Release, error)
InstallChart(ctx context.Context, spec *ChartSpec) (*release.Release, error)
UpgradeChart(ctx context.Context, spec *ChartSpec) (*release.Release, error)
InstallOrUpgradeChart(ctx context.Context, spec *ChartSpec, opts *GenericHelmOptions) (*release.Release, error)
InstallChart(ctx context.Context, spec *ChartSpec, opts *GenericHelmOptions) (*release.Release, error)
UpgradeChart(ctx context.Context, spec *ChartSpec, opts *GenericHelmOptions) (*release.Release, error)
ListDeployedReleases() ([]*release.Release, error)
ListReleasesByStateMask(action.ListStates) ([]*release.Release, error)
GetRelease(name string) (*release.Release, error)
Expand Down
24 changes: 12 additions & 12 deletions mock/interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ type HelmClient struct {
DebugLog action.DebugLog
}

type GenericHelmOptions struct {
PostRenderer postrender.PostRenderer
}

//go:generate controller-gen object object:headerFile="./hack/boilerplate.go.txt" paths="./..." output:dir=.

// ChartSpec defines the values of a helm chart
// +kubebuilder:object:generate:=true
type ChartSpec struct {
ReleaseName string `json:"release"`
ChartName string `json:"chart"`
Expand Down Expand Up @@ -139,8 +146,4 @@ type ChartSpec struct {
// DryRun indicates whether to perform a dry run.
// +optional
DryRun bool `json:"dryRun,omitempty"`
// PostRenderer to run on the Helm Chart
// +kubebuilder:validation:Schemaless
// +optional
PostRenderer postrender.PostRenderer `json:"postRenderer,omitempty"`
}
39 changes: 39 additions & 0 deletions zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.