Skip to content

Commit

Permalink
Merge pull request #3 from hickeyma/feat/add-v2-support
Browse files Browse the repository at this point in the history
feat(*): Add Helm v2 support
  • Loading branch information
hickeyma authored Apr 17, 2020
2 parents 9a92197 + 81615f3 commit e9d0d7d
Show file tree
Hide file tree
Showing 11 changed files with 531 additions and 68 deletions.
20 changes: 12 additions & 8 deletions cmd/mapkubeapis/environment.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright The Helm Authors.
Copyright
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -22,11 +22,13 @@ import (

// EnvSettings defined settings
type EnvSettings struct {
DryRun bool
KubeConfigFile string
KubeContext string
Namespace string
//RunV2 bool
DryRun bool
KubeConfigFile string
KubeContext string
Namespace string
RunV2 bool
StorageType string
TillerOutCluster bool
}

// New returns default env settings
Expand All @@ -45,6 +47,8 @@ func (s *EnvSettings) AddFlags(fs *pflag.FlagSet) {
s.AddBaseFlags(fs)
fs.StringVar(&s.KubeConfigFile, "kubeconfig", "", "path to the kubeconfig file")
fs.StringVar(&s.KubeContext, "kube-context", s.KubeContext, "name of the kubeconfig context to use")
fs.StringVar(&s.Namespace, "namespace", s.Namespace, "namespace scope of the release")
//fs.BoolVar(&s.RunV2, "v2", false, "run for Helm v2 release. The default is Helm v3.")
fs.StringVar(&s.Namespace, "namespace", s.Namespace, "namespace scope of the release. For Helm v2, this is the Tiller namespace e.g. kube-system")
fs.BoolVar(&s.RunV2, "v2", false, "run for Helm v2 release. The default is Helm v3.")
fs.BoolVar(&s.TillerOutCluster, "tiller-out-cluster", false, "for Helm v2 only - when Tiller is not running in the cluster e.g. Tillerless")
fs.StringVarP(&s.StorageType, "release-storage", "s", "secrets", "for Helm v2 only - release storage type/object. It can be 'secrets' or 'configmaps'. This is only used with the 'tiller-out-cluster' flag")
}
27 changes: 23 additions & 4 deletions cmd/mapkubeapis/map.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright The Helm Authors.
Copyright
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@ import (
"github.com/spf13/cobra"

"github.com/hickeyma/helm-mapkubeapis/pkg/common"
v2 "github.com/hickeyma/helm-mapkubeapis/pkg/v2"
v3 "github.com/hickeyma/helm-mapkubeapis/pkg/v3"
)

Expand All @@ -33,6 +34,9 @@ type MapOptions struct {
DryRun bool
ReleaseName string
ReleaseNamespace string
RunV2 bool
StorageType string
TillerOutCluster bool
}

var (
Expand Down Expand Up @@ -82,6 +86,9 @@ func runMap(cmd *cobra.Command, args []string) error {
DryRun: settings.DryRun,
ReleaseName: releaseName,
ReleaseNamespace: settings.Namespace,
RunV2: settings.RunV2,
StorageType: settings.StorageType,
TillerOutCluster: settings.TillerOutCluster,
}
kubeConfig := common.KubeConfig{
Context: settings.KubeContext,
Expand All @@ -103,15 +110,27 @@ func Map(mapOptions MapOptions, kubeConfig common.KubeConfig) error {

log.Printf("Release '%s' will be checked for deprecated Kubernetes APIs and will be updated if necessary to supported API versions.\n", mapOptions.ReleaseName)

v3MapOptions := v3.MapOptions{
options := common.MapOptions{
DryRun: mapOptions.DryRun,
KubeConfig: kubeConfig,
ReleaseName: mapOptions.ReleaseName,
ReleaseNamespace: mapOptions.ReleaseNamespace,
StorageType: mapOptions.StorageType,
TillerOutCluster: mapOptions.TillerOutCluster,
}

if err := v3.MapReleaseWithDeprecatedAPIs(v3MapOptions); err != nil {
return err
if mapOptions.RunV2 {
// default namespace to the Tiller default namespace
if options.ReleaseNamespace == "" {
options.ReleaseNamespace = "kube-system"
}
if err := v2.MapReleaseWithDeprecatedAPIs(options); err != nil {
return err
}
} else {
if err := v3.MapReleaseWithDeprecatedAPIs(options); err != nil {
return err
}
}

log.Printf("Map of release '%s' deprecated APIs to supported APIs, completed successfully.\n", mapOptions.ReleaseName)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mapkubeapis/map_kube_apis.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright The Helm Authors.
Copyright
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ module github.com/hickeyma/helm-mapkubeapis
go 1.13

require (
github.com/DATA-DOG/go-sqlmock v1.4.1 // indirect
github.com/golang/protobuf v1.4.0 // indirect
github.com/jmoiron/sqlx v1.2.0 // indirect
github.com/lib/pq v1.3.0 // indirect
github.com/maorfr/helm-plugin-utils v0.0.0-20200216074820-36d2fcf6ae86
github.com/rubenv/sql-migrate v0.0.0-20200402132117-435005d389bc // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
helm.sh/helm/v3 v3.1.2
k8s.io/helm v2.16.6+incompatible
)

replace (
Expand Down
Loading

0 comments on commit e9d0d7d

Please sign in to comment.