Skip to content

Commit 12a3f8c

Browse files
author
Christophe VILA
committed
Expose --create-namespace on spray
1 parent 0caafe7 commit 12a3f8c

File tree

7 files changed

+295
-6
lines changed

7 files changed

+295
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Release Notes
22

3+
## Version 4.0.8 - 06/24/2021
4+
* Exposed helm install/update --create-namespace flag on spray. Since 4.0.6, --create-namespace is automatically passed to helm install/update commands but because it is trying to create namespace even if it already exists, it can generate errors when user rights on cluster do not include namespace creation
5+
36
## Version 4.0.7 - 02/03/2021
47
* Fixed [`#71`](https://github.com/ThalesGroup/helm-spray/issues/71) (Elassyo)
58

cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func NewRootCmd() *cobra.Command {
145145
f.StringSliceVarP(&s.Excludes, "exclude", "x", []string{}, "specify the subchart to exclude (can specify multiple): process all subcharts except the ones specified in '--exclude'")
146146
f.StringVarP(&s.PrefixReleases, "prefix-releases", "", "", "prefix the releases by the given string, resulting into releases names formats:\n \"<prefix>-<chart name or alias>\"\nAllowed characters are a-z A-Z 0-9 and -")
147147
f.BoolVar(&s.PrefixReleasesWithNamespace, "prefix-releases-with-namespace", false, "prefix the releases by the name of the namespace, resulting into releases names formats:\n \"<namespace>-<chart name or alias>\"")
148+
f.BoolVar(&s.CreateNamespace, "create-namespace", false, "automatically create the namespace if necessary")
148149
f.BoolVar(&s.ResetValues, "reset-values", false, "when upgrading, reset the values to the ones built into the chart")
149150
f.BoolVar(&s.ReuseValues, "reuse-values", false, "when upgrading, reuse the last release's values and merge in any overrides from the command line via '--set' and '-f'.\nIf '--reset-values' is specified, this is ignored")
150151
f.StringSliceVarP(&s.ValuesOpts.ValueFiles, "values", "f", []string{}, "specify values in a YAML file or a URL (can specify multiple)")

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ module github.com/gemalto/helm-spray/v4
22

33
go 1.15
44

5-
require github.com/spf13/cobra v1.0.0
5+
require github.com/spf13/cobra v1.1.3
66

7-
require helm.sh/helm/v3 v3.4.2
7+
require helm.sh/helm/v3 v3.6.1

go.sum

Lines changed: 279 additions & 0 deletions
Large diffs are not rendered by default.

pkg/helm/helm.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010
See the License for the specific language governing permissions and
1111
limitations under the License.
1212
*/
13+
1314
package helm
1415

1516
import (
@@ -95,9 +96,9 @@ func List(namespace string) (map[string]Release, error) {
9596
}
9697

9798
// UpgradeWithValues ...
98-
func UpgradeWithValues(namespace string, releaseName string, chartPath string, resetValues bool, reuseValues bool, valueFiles []string, valuesSet []string, valuesSetString []string, valuesSetFile []string, force bool, timeout int, dryRun bool, debug bool) (Status, error) {
99+
func UpgradeWithValues(namespace string, createNamespace bool, releaseName string, chartPath string, resetValues bool, reuseValues bool, valueFiles []string, valuesSet []string, valuesSetString []string, valuesSetFile []string, force bool, timeout int, dryRun bool, debug bool) (Status, error) {
99100
// Prepare parameters...
100-
var myargs = []string{"upgrade", "--install", releaseName, chartPath, "--create-namespace", "--namespace", namespace, "--timeout", strconv.Itoa(timeout) + "s"}
101+
var myargs = []string{"upgrade", "--install", releaseName, chartPath, "--namespace", namespace, "--timeout", strconv.Itoa(timeout) + "s"}
101102

102103
for _, v := range valuesSet {
103104
myargs = append(myargs, "--set")
@@ -127,6 +128,9 @@ func UpgradeWithValues(namespace string, releaseName string, chartPath string, r
127128
if dryRun {
128129
myargs = append(myargs, "--dry-run")
129130
}
131+
if createNamespace {
132+
myargs = append(myargs, "--create-namespace")
133+
}
130134
if debug {
131135
myargs = append(myargs, "--debug")
132136
log.Info(1, "running helm command for \"%s\": %v\n", releaseName, myargs)

pkg/helmspray/helmspray.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Spray struct {
2424
Targets []string
2525
Excludes []string
2626
Namespace string
27+
CreateNamespace bool
2728
PrefixReleases string
2829
PrefixReleasesWithNamespace bool
2930
ResetValues bool
@@ -39,7 +40,7 @@ type Spray struct {
3940
jobs map[string]struct{}
4041
}
4142

42-
// Running Spray command
43+
// Spray ...
4344
func (s *Spray) Spray() error {
4445

4546
if s.Debug {
@@ -199,6 +200,7 @@ func (s *Spray) upgrade(releases map[string]helm.Release, deps []dependencies.De
199200
// Upgrade the Deployment
200201
helmstatus, err := helm.UpgradeWithValues(
201202
s.Namespace,
203+
s.CreateNamespace,
202204
dependency.CorrespondingReleaseName,
203205
s.ChartName,
204206
s.ResetValues,

plugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "spray"
2-
version: 4.0.7
2+
version: 4.0.8
33
usage: "upgrade sub-charts from an umbrella chart with dependency orders"
44
description: "Helm plugin for upgrading sub-charts from umbrella chart with dependency orders"
55
command: "$HELM_PLUGIN_DIR/bin/helm-spray"

0 commit comments

Comments
 (0)