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

feat(client): get release status #184

Open
wants to merge 2 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
15 changes: 15 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ func (c *HelmClient) GetRelease(name string) (*release.Release, error) {
return c.getRelease(name)
}

// ReleaseStatus returns a release and it's status matching the provided 'name'.
func (c *HelmClient) ReleaseStatus(name string, showResources bool, version int) (*release.Release, error) {
return c.releaseStatus(name, showResources, version)
}

// RollbackRelease implicitly rolls back a release to the last revision.
func (c *HelmClient) RollbackRelease(spec *ChartSpec) error {
return c.rollbackRelease(spec)
Expand Down Expand Up @@ -816,6 +821,16 @@ func (c *HelmClient) getRelease(name string) (*release.Release, error) {
return getReleaseClient.Run(name)
}

// releaseStatus returns a release and it's status matching the provided 'name'.
// showResources displays the resources of the named release.
// version displays the status of the named release with revision.
func (c *HelmClient) releaseStatus(name string, showResources bool, version int) (*release.Release, error) {
releaseStatusClient := action.NewStatus(c.ActionConfig)
releaseStatusClient.ShowResources = showResources
releaseStatusClient.Version = version
return releaseStatusClient.Run(name)
}

// rollbackRelease implicitly rolls back a release to the last revision.
func (c *HelmClient) rollbackRelease(spec *ChartSpec) error {
client := action.NewRollback(c.ActionConfig)
Expand Down
8 changes: 8 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package helmclient
import (
"bytes"
"context"

"helm.sh/helm/v3/pkg/chartutil"

"helm.sh/helm/v3/pkg/action"
Expand Down Expand Up @@ -328,6 +329,13 @@ func ExampleHelmClient_GetRelease() {
}
}

func ExampleHelmClient_ReleaseStatus() {
// Get specific details of a deployed release.
if _, err := helmClient.releaseStatus("etcd-operator", true, 0); err != nil {
panic(err)
}
}

func ExampleHelmClient_RollbackRelease() {
// Define the released chart to be installed
chartSpec := ChartSpec{
Expand Down
1 change: 1 addition & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Client interface {
ListDeployedReleases() ([]*release.Release, error)
ListReleasesByStateMask(action.ListStates) ([]*release.Release, error)
GetRelease(name string) (*release.Release, error)
ReleaseStatus(name string, showResources bool, version int) (*release.Release, error)
// RollBack is an interface to abstract a rollback action.
RollBack
GetReleaseValues(name string, allValues bool) (map[string]interface{}, error)
Expand Down
15 changes: 15 additions & 0 deletions mock/interface.go

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

12 changes: 12 additions & 0 deletions mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,16 @@ func TestHelmClientInterfaces(t *testing.T) {
panic(err)
}
})

t.Run("ReleaseStatus", func(t *testing.T) {
mockClient.EXPECT().ReleaseStatus(mockedRelease.Name, true, 0).
Return(&release.Release{Name: mockedRelease.Name}, nil)
r, err := mockClient.ReleaseStatus(mockedRelease.Name, true, 0)
if err != nil {
panic(err)
}
if r == nil {
panic(err)
}
})
}