Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mikhail Kopylov <mih.kopylov@yandex.ru>
- Loading branch information
1 parent
37cc2fa
commit 0b5e9d3
Showing
15 changed files
with
286 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
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 ( | ||
"fmt" | ||
"io" | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"helm.sh/helm/v3/cmd/helm/require" | ||
"helm.sh/helm/v3/pkg/action" | ||
"helm.sh/helm/v3/pkg/cli/output" | ||
) | ||
|
||
type metadataWriter struct { | ||
metadata *action.Metadata | ||
} | ||
|
||
func newGetMetadataCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { | ||
var outfmt output.Format | ||
client := action.NewGetMetadata(cfg) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "metadata RELEASE_NAME", | ||
Short: "This command fetches metadata for a given release", | ||
Args: require.ExactArgs(1), | ||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
if len(args) != 0 { | ||
return nil, cobra.ShellCompDirectiveNoFileComp | ||
} | ||
return compListReleases(toComplete, args, cfg) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
releaseMetadata, err := client.Run(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
return outfmt.Write(out, &metadataWriter{releaseMetadata}) | ||
}, | ||
} | ||
|
||
f := cmd.Flags() | ||
f.IntVar(&client.Version, "revision", 0, "specify release revision") | ||
err := cmd.RegisterFlagCompletionFunc("revision", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
if len(args) == 1 { | ||
return compListRevisions(toComplete, cfg, args[0]) | ||
} | ||
return nil, cobra.ShellCompDirectiveNoFileComp | ||
}) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
bindOutputFlag(cmd, &outfmt) | ||
|
||
return cmd | ||
} | ||
|
||
func (w metadataWriter) WriteTable(out io.Writer) error { | ||
_, _ = fmt.Fprintf(out, "NAME: %v\n", w.metadata.Name) | ||
_, _ = fmt.Fprintf(out, "CHART: %v\n", w.metadata.Chart) | ||
_, _ = fmt.Fprintf(out, "VERSION: %v\n", w.metadata.Version) | ||
_, _ = fmt.Fprintf(out, "APP_VERSION: %v\n", w.metadata.AppVersion) | ||
_, _ = fmt.Fprintf(out, "NAMESPACE: %v\n", w.metadata.Namespace) | ||
_, _ = fmt.Fprintf(out, "REVISION: %v\n", w.metadata.Revision) | ||
_, _ = fmt.Fprintf(out, "STATUS: %v\n", w.metadata.Status) | ||
_, _ = fmt.Fprintf(out, "DEPLOYED_AT: %v\n", w.metadata.DeployedAt) | ||
return nil | ||
} | ||
|
||
func (w metadataWriter) WriteJSON(out io.Writer) error { | ||
return output.EncodeJSON(out, w.metadata) | ||
} | ||
|
||
func (w metadataWriter) WriteYAML(out io.Writer) error { | ||
return output.EncodeYAML(out, w.metadata) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
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 ( | ||
"testing" | ||
|
||
"helm.sh/helm/v3/pkg/release" | ||
) | ||
|
||
func TestGetMetadataCmd(t *testing.T) { | ||
tests := []cmdTestCase{{ | ||
name: "get metadata with a release", | ||
cmd: "get metadata thomas-guide", | ||
golden: "output/get-metadata.txt", | ||
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "thomas-guide"})}, | ||
}, { | ||
name: "get metadata requires release name arg", | ||
cmd: "get metadata", | ||
golden: "output/get-metadata-args.txt", | ||
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "thomas-guide"})}, | ||
wantError: true, | ||
}, { | ||
name: "get metadata to json", | ||
cmd: "get metadata thomas-guide --output json", | ||
golden: "output/get-metadata.json", | ||
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "thomas-guide"})}, | ||
}, { | ||
name: "get metadata to yaml", | ||
cmd: "get metadata thomas-guide --output yaml", | ||
golden: "output/get-metadata.yaml", | ||
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "thomas-guide"})}, | ||
}} | ||
runTestCmd(t, tests) | ||
} | ||
|
||
func TestGetMetadataCompletion(t *testing.T) { | ||
checkReleaseCompletion(t, "get metadata", false) | ||
} | ||
|
||
func TestGetMetadataRevisionCompletion(t *testing.T) { | ||
revisionFlagCompletionTest(t, "get metadata") | ||
} | ||
|
||
func TestGetMetadataOutputCompletion(t *testing.T) { | ||
outputFlagCompletionTest(t, "get metadata") | ||
} | ||
|
||
func TestGetMetadataFileCompletion(t *testing.T) { | ||
checkFileCompletion(t, "get metadata", false) | ||
checkFileCompletion(t, "get metadata myrelease", false) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Error: "helm get metadata" requires 1 argument | ||
|
||
Usage: helm get metadata RELEASE_NAME [flags] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name":"thomas-guide","chart":"foo","version":"0.1.0-beta.1","appVersion":"1.0","namespace":"default","revision":1,"status":"deployed","deployedAt":"1977-09-02T22:04:05Z"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
NAME: thomas-guide | ||
CHART: foo | ||
VERSION: 0.1.0-beta.1 | ||
APP_VERSION: 1.0 | ||
NAMESPACE: default | ||
REVISION: 1 | ||
STATUS: deployed | ||
DEPLOYED_AT: 1977-09-02T22:04:05Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
appVersion: "1.0" | ||
chart: foo | ||
deployedAt: "1977-09-02T22:04:05Z" | ||
name: thomas-guide | ||
namespace: default | ||
revision: 1 | ||
status: deployed | ||
version: 0.1.0-beta.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.