Skip to content

Commit

Permalink
Merge pull request #25 from mittwald/add/extend_interface_functions
Browse files Browse the repository at this point in the history
add interface functions to list & get releases
  • Loading branch information
hensur authored Apr 28, 2021
2 parents 45291a9 + 7a48556 commit d504b9f
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
set -x
apt-get -y update && apt-get -y install git
cd /
go get -u github.com/golang/mock/mockgen@v1.4.4
go get -u github.com/golang/mock/mockgen@v1.5.0
cd -
go env
go generate ./...
Expand Down
39 changes: 39 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/downloader"
"helm.sh/helm/v3/pkg/getter"
"helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/repo"
"helm.sh/helm/v3/pkg/storage/driver"
apiextensionsV1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand Down Expand Up @@ -211,6 +212,22 @@ func (c *HelmClient) InstallOrUpgradeChart(ctx context.Context, spec *ChartSpec)
return c.install(spec)
}

// ListDeployedReleases lists all deployed releases.
// Namespace and other context is provided via the Options struct when instantiating a client.
func (c *HelmClient) ListDeployedReleases() ([]*release.Release, error) {
return c.listDeployedReleases()
}

// GetReleaseValues returns the (optionally, all computed) values for the specified release.
func (c *HelmClient) GetReleaseValues(name string, allValues bool) (map[string]interface{}, error) {
return c.getReleaseValues(name, allValues)
}

// GetRelease returns a release specified by name.
func (c *HelmClient) GetRelease(name string) (*release.Release, error) {
return c.getRelease(name)
}

// DeleteChartFromCache deletes the provided chart from the client's cache
func (c *HelmClient) DeleteChartFromCache(spec *ChartSpec) error {
return c.deleteChartFromCache(spec)
Expand Down Expand Up @@ -577,6 +594,28 @@ func (c *HelmClient) chartIsInstalled(release string) (bool, error) {
return true, nil
}

func (c *HelmClient) listDeployedReleases() ([]*release.Release, error) {
listClient := action.NewList(c.ActionConfig)

listClient.StateMask = action.ListDeployed

return listClient.Run()
}

func (c *HelmClient) getReleaseValues(name string, allValues bool) (map[string]interface{}, error) {
getReleaseValuesClient := action.NewGetValues(c.ActionConfig)

getReleaseValuesClient.AllValues = allValues

return getReleaseValuesClient.Run(name)
}

func (c *HelmClient) getRelease(name string) (*release.Release, error) {
getReleaseClient := action.NewGet(c.ActionConfig)

return getReleaseClient.Run(name)
}

// mergeInstallOptions merges values of the provided chart to helm install options used by the client
func mergeInstallOptions(chartSpec *ChartSpec, installOptions *action.Install) {
installOptions.DisableHooks = chartSpec.DisableHooks
Expand Down
18 changes: 18 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,21 @@ func ExampleHelmClient_UninstallRelease() {
panic(err)
}
}

func ExampleHelmClient_ListDeployedReleases() {
if _, err := helmClient.ListDeployedReleases(); err != nil {
panic(err)
}
}

func ExampleHelmClient_GetReleaseValues() {
if _, err := helmClient.GetReleaseValues("etcd-operator", true); err != nil {
panic(err)
}
}

func ExampleHelmClient_GetRelease() {
if _, err := helmClient.GetRelease("etcd-operator"); err != nil {
panic(err)
}
}
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,6 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -830,8 +828,6 @@ golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201112073958-5cba982894dd h1:5CtCZbICpIOFdgO940moixOPjc0178IU44m4EjOO5IY=
golang.org/x/sys v0.0.0-20201112073958-5cba982894dd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
4 changes: 4 additions & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package helmclient
import (
"context"

"helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/repo"
)

Expand All @@ -12,6 +13,9 @@ type Client interface {
AddOrUpdateChartRepo(entry repo.Entry) error
UpdateChartRepos() error
InstallOrUpgradeChart(ctx context.Context, spec *ChartSpec) error
ListDeployedReleases() ([]*release.Release, error)
GetRelease(name string) (*release.Release, error)
GetReleaseValues(name string, allValues bool) (map[string]interface{}, error)
DeleteChartFromCache(spec *ChartSpec) error
UninstallRelease(spec *ChartSpec) error
TemplateChart(spec *ChartSpec) ([]byte, error)
Expand Down
121 changes: 84 additions & 37 deletions mock/interface.go

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

Loading

0 comments on commit d504b9f

Please sign in to comment.