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

Add new upgrade command #64

Merged
merged 6 commits into from
Mar 8, 2021
Merged
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
30 changes: 30 additions & 0 deletions cmd/hypper/dependency_build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
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
Itxaka marked this conversation as resolved.
Show resolved Hide resolved

import (
"k8s.io/client-go/util/homedir"
"os"
"path/filepath"
)

// defaultKeyring returns the expanded path to the default keyring.
func defaultKeyring() string {
if v, ok := os.LookupEnv("GNUPGHOME"); ok {
return filepath.Join(v, "pubring.gpg")
}
return filepath.Join(homedir.HomeDir(), ".gnupg", "pubring.gpg")
}
53 changes: 53 additions & 0 deletions cmd/hypper/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ package main

import (
"fmt"
"github.com/spf13/pflag"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli/values"
"helm.sh/helm/v3/pkg/postrender"
"strings"

"github.com/spf13/cobra"
Expand All @@ -28,6 +32,7 @@ import (
)

const outputFlag = "output"
const postRenderFlag = "post-renderer"

// bindOutputFlag will add the output flag to the given command and bind the
// value to the given format pointer
Expand Down Expand Up @@ -76,3 +81,51 @@ func (o *outputValue) Set(s string) error {
*o = outputValue(outfmt)
return nil
}

func addChartPathOptionsFlags(f *pflag.FlagSet, c *action.ChartPathOptions) {
f.StringVar(&c.Version, "version", "", "specify the exact chart version to use. If this is not specified, the latest version is used")
f.BoolVar(&c.Verify, "verify", false, "verify the package before using it")
f.StringVar(&c.Keyring, "keyring", defaultKeyring(), "location of public keys used for verification")
f.StringVar(&c.RepoURL, "repo", "", "chart repository url where to locate the requested chart")
f.StringVar(&c.Username, "username", "", "chart repository username where to locate the requested chart")
f.StringVar(&c.Password, "password", "", "chart repository password where to locate the requested chart")
f.StringVar(&c.CertFile, "cert-file", "", "identify HTTPS client using this SSL certificate file")
f.StringVar(&c.KeyFile, "key-file", "", "identify HTTPS client using this SSL key file")
f.BoolVar(&c.InsecureSkipTLSverify, "insecure-skip-tls-verify", false, "skip tls certificate checks for the chart download")
f.StringVar(&c.CaFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
}

func addValueOptionsFlags(f *pflag.FlagSet, v *values.Options) {
f.StringSliceVarP(&v.ValueFiles, "values", "f", []string{}, "specify values in a YAML file or a URL (can specify multiple)")
f.StringArrayVar(&v.Values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
f.StringArrayVar(&v.StringValues, "set-string", []string{}, "set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
f.StringArrayVar(&v.FileValues, "set-file", []string{}, "set values from respective files specified via the command line (can specify multiple or separate values with commas: key1=path1,key2=path2)")
}

func bindPostRenderFlag(cmd *cobra.Command, varRef *postrender.PostRenderer) {
cmd.Flags().Var(&postRenderer{varRef}, postRenderFlag, "the path to an executable to be used for post rendering. If it exists in $PATH, the binary will be used, otherwise it will try to look for the executable at the given path")
}

type postRenderer struct {
renderer *postrender.PostRenderer
}

func (p postRenderer) String() string {
return "exec"
}

func (p postRenderer) Type() string {
return "postrenderer"
}

func (p postRenderer) Set(s string) error {
if s == "" {
return nil
}
pr, err := postrender.NewExec(s)
if err != nil {
return err
}
*p.renderer = pr
return nil
}
1 change: 1 addition & 0 deletions cmd/hypper/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func newRootCmd(actionConfig *action.Configuration, logger log.Logger, args []st
newListCmd(actionConfig, logger),
newStatusCmd(actionConfig, logger),
newRepoCmd(logger),
newUpgradeCmd(actionConfig, logger),
)

flags.ParseErrorsWhitelist.UnknownFlags = true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: cannot load Chart.yaml: error converting YAML to JSON: yaml: line 6: did not find expected '-' indicator
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: UPGRADE FAILED: "funny-bunny" has no deployed releases
7 changes: 7 additions & 0 deletions cmd/hypper/testdata/output/upgrade-with-install-timeout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Release "funny-bunny" has been upgraded 🥳
NAME: funny-bunny
LAST DEPLOYED: Fri Sep 2 22:04:05 1977
NAMESPACE: default
STATUS: deployed
REVISION: 2
TEST SUITE: None
7 changes: 7 additions & 0 deletions cmd/hypper/testdata/output/upgrade-with-install.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Release "funny-bunny" has been upgraded 🥳
NAME: funny-bunny
LAST DEPLOYED: Fri Sep 2 22:04:05 1977
NAMESPACE: default
STATUS: deployed
REVISION: 2
TEST SUITE: None
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: found in Chart.yaml, but missing in charts/ directory: reqsubchart2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: UPGRADE FAILED: another operation (install/upgrade/rollback) is in progress
7 changes: 7 additions & 0 deletions cmd/hypper/testdata/output/upgrade-with-reset-values.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Release "funny-bunny" has been upgraded 🥳
NAME: funny-bunny
LAST DEPLOYED: Fri Sep 2 22:04:05 1977
NAMESPACE: default
STATUS: deployed
REVISION: 5
TEST SUITE: None
7 changes: 7 additions & 0 deletions cmd/hypper/testdata/output/upgrade-with-reset-values2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Release "funny-bunny" has been upgraded 🥳
NAME: funny-bunny
LAST DEPLOYED: Fri Sep 2 22:04:05 1977
NAMESPACE: default
STATUS: deployed
REVISION: 6
TEST SUITE: None
7 changes: 7 additions & 0 deletions cmd/hypper/testdata/output/upgrade-with-timeout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Release "funny-bunny" has been upgraded 🥳
NAME: funny-bunny
LAST DEPLOYED: Fri Sep 2 22:04:05 1977
NAMESPACE: default
STATUS: deployed
REVISION: 4
TEST SUITE: None
7 changes: 7 additions & 0 deletions cmd/hypper/testdata/output/upgrade-with-wait-for-jobs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Release "funny-bunny" has been upgraded 🥳
NAME: funny-bunny
LAST DEPLOYED: Fri Sep 2 22:04:05 1977
NAMESPACE: default
STATUS: deployed
REVISION: 3
TEST SUITE: None
7 changes: 7 additions & 0 deletions cmd/hypper/testdata/output/upgrade-with-wait.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Release "funny-bunny" has been upgraded 🥳
NAME: funny-bunny
LAST DEPLOYED: Fri Sep 2 22:04:05 1977
NAMESPACE: default
STATUS: deployed
REVISION: 3
TEST SUITE: None
7 changes: 7 additions & 0 deletions cmd/hypper/testdata/output/upgrade.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Release "funny-bunny" has been upgraded 🥳
NAME: funny-bunny
LAST DEPLOYED: Fri Sep 2 22:04:05 1977
NAMESPACE: default
STATUS: deployed
REVISION: 3
TEST SUITE: None
2 changes: 2 additions & 0 deletions cmd/hypper/testdata/output/version-comp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:0
Completion ended with directive: ShellCompDirectiveDefault
2 changes: 2 additions & 0 deletions cmd/hypper/testdata/output/version-invalid-comp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:0
Completion ended with directive: ShellCompDirectiveDefault
21 changes: 21 additions & 0 deletions cmd/hypper/testdata/testcharts/chart-bad-requirements/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
description: A Helm chart for Kubernetes
name: chart-missing-deps
version: 0.1.0
dependencies:
- name: reqsubchart
version: 0.1.0
repository: "https://example.com/charts"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
description: A Helm chart for Kubernetes
name: reqsubchart
version: 0.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Default values for reqsubchart.
# This is a YAML-formatted file.
# Declare name/value pairs to be passed into your templates.
# name: value
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Default values for reqtest.
# This is a YAML-formatted file.
# Declare name/value pairs to be passed into your templates.
# name: value
21 changes: 21 additions & 0 deletions cmd/hypper/testdata/testcharts/chart-missing-deps/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
11 changes: 11 additions & 0 deletions cmd/hypper/testdata/testcharts/chart-missing-deps/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
description: A Helm chart for Kubernetes
name: chart-missing-deps
version: 0.1.0
dependencies:
- name: reqsubchart
version: 0.1.0
repository: "https://example.com/charts"
- name: reqsubchart2
version: 0.2.0
repository: "https://example.com/charts"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
description: A Helm chart for Kubernetes
name: reqsubchart
version: 0.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Default values for reqsubchart.
# This is a YAML-formatted file.
# Declare name/value pairs to be passed into your templates.
# name: value
4 changes: 4 additions & 0 deletions cmd/hypper/testdata/testcharts/chart-missing-deps/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Default values for reqtest.
# This is a YAML-formatted file.
# Declare name/value pairs to be passed into your templates.
# name: value
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v2
description: Chart with subchart notes
name: wacky-bunny-v1
version: 0.0.1
dependencies:
- name: subchart-with-notes
version: 0.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v2
description: Subchart with notes
name: subchart-with-notes
version: 0.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SUBCHART NOTES
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PARENT NOTES
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v2
description: Chart with subchart that needs to be fetched
name: chart-with-subchart-update
version: 0.0.1
dependencies:
- name: subchart-with-notes
version: 0.0.1
repository: file://../chart-with-subchart-notes/charts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v2
description: Subchart with notes
name: subchart-with-notes
version: 0.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SUBCHART NOTES
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PARENT NOTES
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ .Release.Name }}-configmap"
data:
myvalue: "Hello World"
drink: {{ .Values.favoriteDrink }}
1 change: 1 addition & 0 deletions cmd/hypper/testdata/testcharts/upgradetest/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
favoriteDrink: beer
Loading