Skip to content

Commit

Permalink
Expose --create-namespace on spray
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe VILA committed Jun 25, 2021
1 parent 0caafe7 commit 12a3f8c
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Release Notes

## Version 4.0.8 - 06/24/2021
* 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

## Version 4.0.7 - 02/03/2021
* Fixed [`#71`](https://github.com/ThalesGroup/helm-spray/issues/71) (Elassyo)

Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func NewRootCmd() *cobra.Command {
f.StringSliceVarP(&s.Excludes, "exclude", "x", []string{}, "specify the subchart to exclude (can specify multiple): process all subcharts except the ones specified in '--exclude'")
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 -")
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>\"")
f.BoolVar(&s.CreateNamespace, "create-namespace", false, "automatically create the namespace if necessary")
f.BoolVar(&s.ResetValues, "reset-values", false, "when upgrading, reset the values to the ones built into the chart")
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")
f.StringSliceVarP(&s.ValuesOpts.ValueFiles, "values", "f", []string{}, "specify values in a YAML file or a URL (can specify multiple)")
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ module github.com/gemalto/helm-spray/v4

go 1.15

require github.com/spf13/cobra v1.0.0
require github.com/spf13/cobra v1.1.3

require helm.sh/helm/v3 v3.4.2
require helm.sh/helm/v3 v3.6.1
279 changes: 279 additions & 0 deletions go.sum

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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 helm

import (
Expand Down Expand Up @@ -95,9 +96,9 @@ func List(namespace string) (map[string]Release, error) {
}

// UpgradeWithValues ...
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) {
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) {
// Prepare parameters...
var myargs = []string{"upgrade", "--install", releaseName, chartPath, "--create-namespace", "--namespace", namespace, "--timeout", strconv.Itoa(timeout) + "s"}
var myargs = []string{"upgrade", "--install", releaseName, chartPath, "--namespace", namespace, "--timeout", strconv.Itoa(timeout) + "s"}

for _, v := range valuesSet {
myargs = append(myargs, "--set")
Expand Down Expand Up @@ -127,6 +128,9 @@ func UpgradeWithValues(namespace string, releaseName string, chartPath string, r
if dryRun {
myargs = append(myargs, "--dry-run")
}
if createNamespace {
myargs = append(myargs, "--create-namespace")
}
if debug {
myargs = append(myargs, "--debug")
log.Info(1, "running helm command for \"%s\": %v\n", releaseName, myargs)
Expand Down
4 changes: 3 additions & 1 deletion pkg/helmspray/helmspray.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Spray struct {
Targets []string
Excludes []string
Namespace string
CreateNamespace bool
PrefixReleases string
PrefixReleasesWithNamespace bool
ResetValues bool
Expand All @@ -39,7 +40,7 @@ type Spray struct {
jobs map[string]struct{}
}

// Running Spray command
// Spray ...
func (s *Spray) Spray() error {

if s.Debug {
Expand Down Expand Up @@ -199,6 +200,7 @@ func (s *Spray) upgrade(releases map[string]helm.Release, deps []dependencies.De
// Upgrade the Deployment
helmstatus, err := helm.UpgradeWithValues(
s.Namespace,
s.CreateNamespace,
dependency.CorrespondingReleaseName,
s.ChartName,
s.ResetValues,
Expand Down
2 changes: 1 addition & 1 deletion plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "spray"
version: 4.0.7
version: 4.0.8
usage: "upgrade sub-charts from an umbrella chart with dependency orders"
description: "Helm plugin for upgrading sub-charts from umbrella chart with dependency orders"
command: "$HELM_PLUGIN_DIR/bin/helm-spray"
Expand Down

0 comments on commit 12a3f8c

Please sign in to comment.