From 2a682deadf2035c1e6643cf986ca4afbeb26ff78 Mon Sep 17 00:00:00 2001 From: cleverhu Date: Mon, 12 Sep 2022 03:50:19 +0800 Subject: [PATCH 1/3] add create time for helm search repo Signed-off-by: cleverhu --- cmd/helm/search_repo.go | 5 +++-- cmd/helm/testdata/output/search-constraint-single.txt | 4 ++-- cmd/helm/testdata/output/search-constraint.txt | 4 ++-- cmd/helm/testdata/output/search-multiple-devel-release.txt | 4 ++-- cmd/helm/testdata/output/search-multiple-stable-release.txt | 4 ++-- .../output/search-multiple-versions-constraints.txt | 6 +++--- cmd/helm/testdata/output/search-multiple-versions.txt | 6 +++--- cmd/helm/testdata/output/search-regex.txt | 4 ++-- cmd/helm/testdata/output/search-versions-constraint.txt | 4 ++-- 9 files changed, 21 insertions(+), 20 deletions(-) diff --git a/cmd/helm/search_repo.go b/cmd/helm/search_repo.go index 3acd9ab4b..7664ccd89 100644 --- a/cmd/helm/search_repo.go +++ b/cmd/helm/search_repo.go @@ -24,6 +24,7 @@ import ( "os" "path/filepath" "strings" + "time" "github.com/Masterminds/semver/v3" "github.com/gosuri/uitable" @@ -227,9 +228,9 @@ func (r *repoSearchWriter) WriteTable(out io.Writer) error { } table := uitable.New() table.MaxColWidth = r.columnWidth - table.AddRow("NAME", "CHART VERSION", "APP VERSION", "DESCRIPTION") + table.AddRow("NAME", "CHART VERSION", "APP VERSION", "DESCRIPTION", "CREATED") for _, r := range r.results { - table.AddRow(r.Name, r.Chart.Version, r.Chart.AppVersion, r.Chart.Description) + table.AddRow(r.Name, r.Chart.Version, r.Chart.AppVersion, r.Chart.Description, r.Chart.Created.Format(time.RFC3339)) } return output.EncodeTable(out, table) } diff --git a/cmd/helm/testdata/output/search-constraint-single.txt b/cmd/helm/testdata/output/search-constraint-single.txt index a1f75099f..17e310872 100644 --- a/cmd/helm/testdata/output/search-constraint-single.txt +++ b/cmd/helm/testdata/output/search-constraint-single.txt @@ -1,2 +1,2 @@ -NAME CHART VERSION APP VERSION DESCRIPTION -testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod +NAME CHART VERSION APP VERSION DESCRIPTION CREATED +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod 2018-07-09T11:34:37Z diff --git a/cmd/helm/testdata/output/search-constraint.txt b/cmd/helm/testdata/output/search-constraint.txt index 9fb22fe76..b289af9ee 100644 --- a/cmd/helm/testdata/output/search-constraint.txt +++ b/cmd/helm/testdata/output/search-constraint.txt @@ -1,2 +1,2 @@ -NAME CHART VERSION APP VERSION DESCRIPTION -testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod +NAME CHART VERSION APP VERSION DESCRIPTION CREATED +testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod 2018-06-27T10:00:18Z diff --git a/cmd/helm/testdata/output/search-multiple-devel-release.txt b/cmd/helm/testdata/output/search-multiple-devel-release.txt index 7e29a8f7e..e12bcba57 100644 --- a/cmd/helm/testdata/output/search-multiple-devel-release.txt +++ b/cmd/helm/testdata/output/search-multiple-devel-release.txt @@ -1,2 +1,2 @@ -NAME CHART VERSION APP VERSION DESCRIPTION -testing/alpine 0.3.0-rc.1 3.0.0 Deploy a basic Alpine Linux pod +NAME CHART VERSION APP VERSION DESCRIPTION CREATED +testing/alpine 0.3.0-rc.1 3.0.0 Deploy a basic Alpine Linux pod 2020-11-12T08:44:58Z diff --git a/cmd/helm/testdata/output/search-multiple-stable-release.txt b/cmd/helm/testdata/output/search-multiple-stable-release.txt index a1f75099f..17e310872 100644 --- a/cmd/helm/testdata/output/search-multiple-stable-release.txt +++ b/cmd/helm/testdata/output/search-multiple-stable-release.txt @@ -1,2 +1,2 @@ -NAME CHART VERSION APP VERSION DESCRIPTION -testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod +NAME CHART VERSION APP VERSION DESCRIPTION CREATED +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod 2018-07-09T11:34:37Z diff --git a/cmd/helm/testdata/output/search-multiple-versions-constraints.txt b/cmd/helm/testdata/output/search-multiple-versions-constraints.txt index a6a388858..51362c358 100644 --- a/cmd/helm/testdata/output/search-multiple-versions-constraints.txt +++ b/cmd/helm/testdata/output/search-multiple-versions-constraints.txt @@ -1,3 +1,3 @@ -NAME CHART VERSION APP VERSION DESCRIPTION -testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod -testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod +NAME CHART VERSION APP VERSION DESCRIPTION CREATED +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod 2018-07-09T11:34:37Z +testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod 2018-06-27T10:00:18Z diff --git a/cmd/helm/testdata/output/search-multiple-versions.txt b/cmd/helm/testdata/output/search-multiple-versions.txt index a6a388858..51362c358 100644 --- a/cmd/helm/testdata/output/search-multiple-versions.txt +++ b/cmd/helm/testdata/output/search-multiple-versions.txt @@ -1,3 +1,3 @@ -NAME CHART VERSION APP VERSION DESCRIPTION -testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod -testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod +NAME CHART VERSION APP VERSION DESCRIPTION CREATED +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod 2018-07-09T11:34:37Z +testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod 2018-06-27T10:00:18Z diff --git a/cmd/helm/testdata/output/search-regex.txt b/cmd/helm/testdata/output/search-regex.txt index a1f75099f..17e310872 100644 --- a/cmd/helm/testdata/output/search-regex.txt +++ b/cmd/helm/testdata/output/search-regex.txt @@ -1,2 +1,2 @@ -NAME CHART VERSION APP VERSION DESCRIPTION -testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod +NAME CHART VERSION APP VERSION DESCRIPTION CREATED +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod 2018-07-09T11:34:37Z diff --git a/cmd/helm/testdata/output/search-versions-constraint.txt b/cmd/helm/testdata/output/search-versions-constraint.txt index 9fb22fe76..b289af9ee 100644 --- a/cmd/helm/testdata/output/search-versions-constraint.txt +++ b/cmd/helm/testdata/output/search-versions-constraint.txt @@ -1,2 +1,2 @@ -NAME CHART VERSION APP VERSION DESCRIPTION -testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod +NAME CHART VERSION APP VERSION DESCRIPTION CREATED +testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod 2018-06-27T10:00:18Z From 769d083913f467e73dd48d9b7d1e53f16f42901d Mon Sep 17 00:00:00 2001 From: Kazuhiro Suzuki Date: Tue, 5 Nov 2024 23:07:32 +0900 Subject: [PATCH 2/3] revert testdata to make created field optional Signed-off-by: Kazuhiro Suzuki --- cmd/helm/testdata/output/search-constraint-single.txt | 4 ++-- cmd/helm/testdata/output/search-constraint.txt | 4 ++-- cmd/helm/testdata/output/search-multiple-devel-release.txt | 4 ++-- cmd/helm/testdata/output/search-multiple-stable-release.txt | 4 ++-- .../output/search-multiple-versions-constraints.txt | 6 +++--- cmd/helm/testdata/output/search-multiple-versions.txt | 6 +++--- cmd/helm/testdata/output/search-regex.txt | 4 ++-- cmd/helm/testdata/output/search-versions-constraint.txt | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cmd/helm/testdata/output/search-constraint-single.txt b/cmd/helm/testdata/output/search-constraint-single.txt index 17e310872..a1f75099f 100644 --- a/cmd/helm/testdata/output/search-constraint-single.txt +++ b/cmd/helm/testdata/output/search-constraint-single.txt @@ -1,2 +1,2 @@ -NAME CHART VERSION APP VERSION DESCRIPTION CREATED -testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod 2018-07-09T11:34:37Z +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod diff --git a/cmd/helm/testdata/output/search-constraint.txt b/cmd/helm/testdata/output/search-constraint.txt index b289af9ee..9fb22fe76 100644 --- a/cmd/helm/testdata/output/search-constraint.txt +++ b/cmd/helm/testdata/output/search-constraint.txt @@ -1,2 +1,2 @@ -NAME CHART VERSION APP VERSION DESCRIPTION CREATED -testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod 2018-06-27T10:00:18Z +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod diff --git a/cmd/helm/testdata/output/search-multiple-devel-release.txt b/cmd/helm/testdata/output/search-multiple-devel-release.txt index e12bcba57..7e29a8f7e 100644 --- a/cmd/helm/testdata/output/search-multiple-devel-release.txt +++ b/cmd/helm/testdata/output/search-multiple-devel-release.txt @@ -1,2 +1,2 @@ -NAME CHART VERSION APP VERSION DESCRIPTION CREATED -testing/alpine 0.3.0-rc.1 3.0.0 Deploy a basic Alpine Linux pod 2020-11-12T08:44:58Z +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.3.0-rc.1 3.0.0 Deploy a basic Alpine Linux pod diff --git a/cmd/helm/testdata/output/search-multiple-stable-release.txt b/cmd/helm/testdata/output/search-multiple-stable-release.txt index 17e310872..a1f75099f 100644 --- a/cmd/helm/testdata/output/search-multiple-stable-release.txt +++ b/cmd/helm/testdata/output/search-multiple-stable-release.txt @@ -1,2 +1,2 @@ -NAME CHART VERSION APP VERSION DESCRIPTION CREATED -testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod 2018-07-09T11:34:37Z +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod diff --git a/cmd/helm/testdata/output/search-multiple-versions-constraints.txt b/cmd/helm/testdata/output/search-multiple-versions-constraints.txt index 51362c358..a6a388858 100644 --- a/cmd/helm/testdata/output/search-multiple-versions-constraints.txt +++ b/cmd/helm/testdata/output/search-multiple-versions-constraints.txt @@ -1,3 +1,3 @@ -NAME CHART VERSION APP VERSION DESCRIPTION CREATED -testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod 2018-07-09T11:34:37Z -testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod 2018-06-27T10:00:18Z +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod +testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod diff --git a/cmd/helm/testdata/output/search-multiple-versions.txt b/cmd/helm/testdata/output/search-multiple-versions.txt index 51362c358..a6a388858 100644 --- a/cmd/helm/testdata/output/search-multiple-versions.txt +++ b/cmd/helm/testdata/output/search-multiple-versions.txt @@ -1,3 +1,3 @@ -NAME CHART VERSION APP VERSION DESCRIPTION CREATED -testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod 2018-07-09T11:34:37Z -testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod 2018-06-27T10:00:18Z +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod +testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod diff --git a/cmd/helm/testdata/output/search-regex.txt b/cmd/helm/testdata/output/search-regex.txt index 17e310872..a1f75099f 100644 --- a/cmd/helm/testdata/output/search-regex.txt +++ b/cmd/helm/testdata/output/search-regex.txt @@ -1,2 +1,2 @@ -NAME CHART VERSION APP VERSION DESCRIPTION CREATED -testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod 2018-07-09T11:34:37Z +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod diff --git a/cmd/helm/testdata/output/search-versions-constraint.txt b/cmd/helm/testdata/output/search-versions-constraint.txt index b289af9ee..9fb22fe76 100644 --- a/cmd/helm/testdata/output/search-versions-constraint.txt +++ b/cmd/helm/testdata/output/search-versions-constraint.txt @@ -1,2 +1,2 @@ -NAME CHART VERSION APP VERSION DESCRIPTION CREATED -testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod 2018-06-27T10:00:18Z +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod From ef94826e76ce269a78ccef68eccbf7b961ed7885 Mon Sep 17 00:00:00 2001 From: Kazuhiro Suzuki Date: Tue, 5 Nov 2024 23:41:37 +0900 Subject: [PATCH 3/3] add --with-timestamps option to search repo cmd Signed-off-by: Kazuhiro Suzuki --- cmd/helm/search_repo.go | 22 ++++++++++++++----- cmd/helm/search_repo_test.go | 4 ++++ .../testdata/output/search-output-json.txt | 2 +- .../output/search-output-timestamps.txt | 2 ++ .../testdata/output/search-output-yaml.txt | 1 + 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 cmd/helm/testdata/output/search-output-timestamps.txt diff --git a/cmd/helm/search_repo.go b/cmd/helm/search_repo.go index 7664ccd89..88c497fa4 100644 --- a/cmd/helm/search_repo.go +++ b/cmd/helm/search_repo.go @@ -73,6 +73,7 @@ type searchRepoOptions struct { repoCacheDir string outputFormat output.Format failOnNoResult bool + withTimeStamps bool } func newSearchRepoCmd(out io.Writer) *cobra.Command { @@ -96,6 +97,7 @@ func newSearchRepoCmd(out io.Writer) *cobra.Command { f.StringVar(&o.version, "version", "", "search using semantic versioning constraints on repositories you have added") f.UintVar(&o.maxColWidth, "max-col-width", 50, "maximum column width for output table") f.BoolVar(&o.failOnNoResult, "fail-on-no-result", false, "search fails if no results are found") + f.BoolVar(&o.withTimeStamps, "with-timestamps", false, "print created timestamps on output table") bindOutputFlag(cmd, &o.outputFormat) @@ -127,7 +129,7 @@ func (o *searchRepoOptions) run(out io.Writer, args []string) error { return err } - return o.outputFormat.Write(out, &repoSearchWriter{data, o.maxColWidth, o.failOnNoResult}) + return o.outputFormat.Write(out, &repoSearchWriter{data, o.maxColWidth, o.failOnNoResult, o.withTimeStamps}) } func (o *searchRepoOptions) setupSearchedVersion() { @@ -205,12 +207,14 @@ type repoChartElement struct { Version string `json:"version"` AppVersion string `json:"app_version"` Description string `json:"description"` + Created string `json:"created"` } type repoSearchWriter struct { results []*search.Result columnWidth uint failOnNoResult bool + withTimestamps bool } func (r *repoSearchWriter) WriteTable(out io.Writer) error { @@ -228,9 +232,17 @@ func (r *repoSearchWriter) WriteTable(out io.Writer) error { } table := uitable.New() table.MaxColWidth = r.columnWidth - table.AddRow("NAME", "CHART VERSION", "APP VERSION", "DESCRIPTION", "CREATED") - for _, r := range r.results { - table.AddRow(r.Name, r.Chart.Version, r.Chart.AppVersion, r.Chart.Description, r.Chart.Created.Format(time.RFC3339)) + if r.withTimestamps { + table.AddRow("NAME", "CHART VERSION", "APP VERSION", "DESCRIPTION", "CREATED") + } else { + table.AddRow("NAME", "CHART VERSION", "APP VERSION", "DESCRIPTION") + } + for _, ret := range r.results { + if r.withTimestamps { + table.AddRow(ret.Name, ret.Chart.Version, ret.Chart.AppVersion, ret.Chart.Description, ret.Chart.Created.Format(time.RFC3339)) + } else { + table.AddRow(ret.Name, ret.Chart.Version, ret.Chart.AppVersion, ret.Chart.Description) + } } return output.EncodeTable(out, table) } @@ -253,7 +265,7 @@ func (r *repoSearchWriter) encodeByFormat(out io.Writer, format output.Format) e chartList := make([]repoChartElement, 0, len(r.results)) for _, r := range r.results { - chartList = append(chartList, repoChartElement{r.Name, r.Chart.Version, r.Chart.AppVersion, r.Chart.Description}) + chartList = append(chartList, repoChartElement{r.Name, r.Chart.Version, r.Chart.AppVersion, r.Chart.Description, r.Chart.Created.Format(time.RFC3339)}) } switch format { diff --git a/cmd/helm/search_repo_test.go b/cmd/helm/search_repo_test.go index 9039842f0..344f41bf9 100644 --- a/cmd/helm/search_repo_test.go +++ b/cmd/helm/search_repo_test.go @@ -86,6 +86,10 @@ func TestSearchRepositoriesCmd(t *testing.T) { name: "search for 'alpine', expect valid yaml output", cmd: "search repo alpine --output yaml", golden: "output/search-output-yaml.txt", + }, { + name: "search for 'alpine' with timestamps, expect valid table output with timestamps", + cmd: "search repo alpine --with-timestamps", + golden: "output/search-output-timestamps.txt", }} settings.Debug = true diff --git a/cmd/helm/testdata/output/search-output-json.txt b/cmd/helm/testdata/output/search-output-json.txt index 9b211e1b5..7e64d9ebc 100644 --- a/cmd/helm/testdata/output/search-output-json.txt +++ b/cmd/helm/testdata/output/search-output-json.txt @@ -1 +1 @@ -[{"name":"testing/mariadb","version":"0.3.0","app_version":"","description":"Chart for MariaDB"}] +[{"name":"testing/mariadb","version":"0.3.0","app_version":"","description":"Chart for MariaDB","created":"2018-04-23T08:20:27Z"}] diff --git a/cmd/helm/testdata/output/search-output-timestamps.txt b/cmd/helm/testdata/output/search-output-timestamps.txt new file mode 100644 index 000000000..17e310872 --- /dev/null +++ b/cmd/helm/testdata/output/search-output-timestamps.txt @@ -0,0 +1,2 @@ +NAME CHART VERSION APP VERSION DESCRIPTION CREATED +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod 2018-07-09T11:34:37Z diff --git a/cmd/helm/testdata/output/search-output-yaml.txt b/cmd/helm/testdata/output/search-output-yaml.txt index 122b7f345..1f925a5b3 100644 --- a/cmd/helm/testdata/output/search-output-yaml.txt +++ b/cmd/helm/testdata/output/search-output-yaml.txt @@ -1,4 +1,5 @@ - app_version: 2.3.4 + created: "2018-07-09T11:34:37Z" description: Deploy a basic Alpine Linux pod name: testing/alpine version: 0.2.0