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(get deployed): Add subcommand "get deployed" #2

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion cmd/helm/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func checkFileCompletion(t *testing.T, cmdName string, shouldBePerformed bool) {
})

testcmd := fmt.Sprintf("__complete %s ''", cmdName)
_, out, err := executeActionCommandC(storage, testcmd)
_, out, err := executeActionCommandC(storage, testcmd, nil, nil)
if err != nil {
t.Errorf("unexpected error, %s", err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/helm/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestCreateCmd(t *testing.T) {
defer testChdir(t, dir)()

// Run a create
if _, _, err := executeActionCommand("create " + cname); err != nil {
if _, _, err := executeActionCommand("create "+cname, nil, nil); err != nil {
t.Fatalf("Failed to run create: %s", err)
}

Expand Down Expand Up @@ -81,7 +81,7 @@ func TestCreateStarterCmd(t *testing.T) {
}

// Run a create
if _, _, err := executeActionCommand(fmt.Sprintf("create --starter=starterchart %s", cname)); err != nil {
if _, _, err := executeActionCommand(fmt.Sprintf("create --starter=starterchart %s", cname), nil, nil); err != nil {
t.Errorf("Failed to run create: %s", err)
return
}
Expand Down Expand Up @@ -149,7 +149,8 @@ func TestCreateStarterAbsoluteCmd(t *testing.T) {
starterChartPath := filepath.Join(starterchart, "starterchart")

// Run a create
if _, _, err := executeActionCommand(fmt.Sprintf("create --starter=%s %s", starterChartPath, cname)); err != nil {
_, _, err := executeActionCommand(fmt.Sprintf("create --starter=%s %s", starterChartPath, cname), nil, nil)
if err != nil {
t.Errorf("Failed to run create: %s", err)
return
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/helm/dependency_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestDependencyBuildCmd(t *testing.T) {
repoFile := filepath.Join(rootDir, "repositories.yaml")

cmd := fmt.Sprintf("dependency build '%s' --repository-config %s --repository-cache %s", filepath.Join(rootDir, chartname), repoFile, rootDir)
_, out, err := executeActionCommand(cmd)
_, out, err := executeActionCommand(cmd, nil, nil)

// In the first pass, we basically want the same results as an update.
if err != nil {
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestDependencyBuildCmd(t *testing.T) {
t.Fatal(err)
}

_, out, err = executeActionCommand(cmd)
_, out, err = executeActionCommand(cmd, nil, nil)
if err != nil {
t.Logf("Output: %s", out)
t.Fatal(err)
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestDependencyBuildCmd(t *testing.T) {
}

skipRefreshCmd := fmt.Sprintf("dependency build '%s' --skip-refresh --repository-config %s --repository-cache %s", filepath.Join(rootDir, chartname), repoFile, rootDir)
_, out, err = executeActionCommand(skipRefreshCmd)
_, out, err = executeActionCommand(skipRefreshCmd, nil, nil)

// In this pass, we check --skip-refresh option becomes effective.
if err != nil {
Expand All @@ -139,7 +139,7 @@ func TestDependencyBuildCmd(t *testing.T) {
dir("repositories.yaml"),
dir(),
dir())
_, out, err = executeActionCommand(cmd)
_, out, err = executeActionCommand(cmd, nil, nil)
if err != nil {
t.Logf("Output: %s", out)
t.Fatal(err)
Expand All @@ -154,7 +154,7 @@ func TestDependencyBuildCmdWithHelmV2Hash(t *testing.T) {
chartName := "testdata/testcharts/issue-7233"

cmd := fmt.Sprintf("dependency build '%s'", chartName)
_, out, err := executeActionCommand(cmd)
_, out, err := executeActionCommand(cmd, nil, nil)

// Want to make sure the build can verify Helm v2 hash
if err != nil {
Expand Down
18 changes: 12 additions & 6 deletions cmd/helm/dependency_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestDependencyUpdateCmd(t *testing.T) {

_, out, err := executeActionCommand(
fmt.Sprintf("dependency update '%s' --repository-config %s --repository-cache %s", dir(chartname), dir("repositories.yaml"), dir()),
)
nil, nil)
if err != nil {
t.Logf("Output: %s", out)
t.Fatal(err)
Expand Down Expand Up @@ -110,7 +110,9 @@ func TestDependencyUpdateCmd(t *testing.T) {
t.Fatal(err)
}

_, out, err = executeActionCommand(fmt.Sprintf("dependency update '%s' --repository-config %s --repository-cache %s", dir(chartname), dir("repositories.yaml"), dir()))
_, out, err = executeActionCommand(
fmt.Sprintf("dependency update '%s' --repository-config %s --repository-cache %s", dir(chartname), dir("repositories.yaml"), dir()),
nil, nil)
if err != nil {
t.Logf("Output: %s", out)
t.Fatal(err)
Expand All @@ -136,7 +138,7 @@ func TestDependencyUpdateCmd(t *testing.T) {
dir("repositories.yaml"),
dir(),
dir())
_, out, err = executeActionCommand(cmd)
_, out, err = executeActionCommand(cmd, nil, nil)
if err != nil {
t.Logf("Output: %s", out)
t.Fatal(err)
Expand Down Expand Up @@ -169,7 +171,9 @@ func TestDependencyUpdateCmd_DoNotDeleteOldChartsOnError(t *testing.T) {
}
createTestingChart(t, dir(), chartname, srv.URL())

_, output, err := executeActionCommand(fmt.Sprintf("dependency update %s --repository-config %s --repository-cache %s", dir(chartname), dir("repositories.yaml"), dir()))
_, output, err := executeActionCommand(
fmt.Sprintf("dependency update %s --repository-config %s --repository-cache %s", dir(chartname), dir("repositories.yaml"), dir()),
nil, nil)
if err != nil {
t.Logf("Output: %s", output)
t.Fatal(err)
Expand All @@ -178,7 +182,9 @@ func TestDependencyUpdateCmd_DoNotDeleteOldChartsOnError(t *testing.T) {
// Chart repo is down
srv.Stop()

_, output, err = executeActionCommand(fmt.Sprintf("dependency update %s --repository-config %s --repository-cache %s", dir(chartname), dir("repositories.yaml"), dir()))
_, output, err = executeActionCommand(
fmt.Sprintf("dependency update %s --repository-config %s --repository-cache %s", dir(chartname), dir("repositories.yaml"), dir()),
nil, nil)
if err == nil {
t.Logf("Output: %s", output)
t.Fatal("Expected error, got nil")
Expand Down Expand Up @@ -233,7 +239,7 @@ func TestDependencyUpdateCmd_WithRepoThatWasNotAdded(t *testing.T) {
_, out, err := executeActionCommand(
fmt.Sprintf("dependency update '%s' --repository-config %s --repository-cache %s", dir(chartname),
dir("repositories.yaml"), dir()),
)
nil, nil)

if err != nil {
t.Logf("Output: %s", out)
Expand Down
1 change: 1 addition & 0 deletions cmd/helm/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func newGetCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
}

cmd.AddCommand(newGetAllCmd(cfg, out))
cmd.AddCommand(newGetDeployedCmd(cfg, out))
cmd.AddCommand(newGetValuesCmd(cfg, out))
cmd.AddCommand(newGetManifestCmd(cfg, out))
cmd.AddCommand(newGetHooksCmd(cfg, out))
Expand Down
80 changes: 80 additions & 0 deletions cmd/helm/get_deployed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright The Helm Authors.

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.
*/

package main

import (
"io"

"github.com/spf13/cobra"

"helm.sh/helm/v3/cmd/helm/require"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli/output"
)

var getDeployedHelp = `
This command prints list of resources deployed under a release.

Example output:

NAMESPACE NAME API_VERSION AGE
thousand-sunny services/zoro v1 2m
namespaces/thousand-sunny v1 2m
thousand-sunny configmaps/nami v1 2m
thousand-sunny deployments/luffy apps/v1 2m
`

// newGetDeployedCmd creates a command for listing the resources deployed under a named release
func newGetDeployedCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
// Output format for the command output. This will be set by input flag -o (or --output).
var outfmt output.Format

// Create get-deployed action's client
client := action.NewGetDeployed(cfg)

cmd := &cobra.Command{
Use: "deployed RELEASE_NAME",
Short: "list resources deployed under a named release",
Long: getDeployedHelp,
Args: require.ExactArgs(1),
ValidArgsFunction: func(_ *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}

return compListReleases(toComplete, args, cfg)
},
RunE: func(_ *cobra.Command, args []string) error {
// Run the client to list resources under the release
resourceList, err := client.Run(args[0])
if err != nil {
return err
}

// Create an output writer with resources listed
writer := action.NewResourceListWriter(resourceList, false)

// Write the resources list with output format provided with input flag
return outfmt.Write(out, writer)
},
}

// Add flag for specifying the output format
bindOutputFlag(cmd, &outfmt)

return cmd
}
Loading