Skip to content

Commit e9d0d7d

Browse files
authored
Merge pull request #3 from hickeyma/feat/add-v2-support
feat(*): Add Helm v2 support
2 parents 9a92197 + 81615f3 commit e9d0d7d

File tree

11 files changed

+531
-68
lines changed

11 files changed

+531
-68
lines changed

cmd/mapkubeapis/environment.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright The Helm Authors.
2+
Copyright
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -22,11 +22,13 @@ import (
2222

2323
// EnvSettings defined settings
2424
type EnvSettings struct {
25-
DryRun bool
26-
KubeConfigFile string
27-
KubeContext string
28-
Namespace string
29-
//RunV2 bool
25+
DryRun bool
26+
KubeConfigFile string
27+
KubeContext string
28+
Namespace string
29+
RunV2 bool
30+
StorageType string
31+
TillerOutCluster bool
3032
}
3133

3234
// New returns default env settings
@@ -45,6 +47,8 @@ func (s *EnvSettings) AddFlags(fs *pflag.FlagSet) {
4547
s.AddBaseFlags(fs)
4648
fs.StringVar(&s.KubeConfigFile, "kubeconfig", "", "path to the kubeconfig file")
4749
fs.StringVar(&s.KubeContext, "kube-context", s.KubeContext, "name of the kubeconfig context to use")
48-
fs.StringVar(&s.Namespace, "namespace", s.Namespace, "namespace scope of the release")
49-
//fs.BoolVar(&s.RunV2, "v2", false, "run for Helm v2 release. The default is Helm v3.")
50+
fs.StringVar(&s.Namespace, "namespace", s.Namespace, "namespace scope of the release. For Helm v2, this is the Tiller namespace e.g. kube-system")
51+
fs.BoolVar(&s.RunV2, "v2", false, "run for Helm v2 release. The default is Helm v3.")
52+
fs.BoolVar(&s.TillerOutCluster, "tiller-out-cluster", false, "for Helm v2 only - when Tiller is not running in the cluster e.g. Tillerless")
53+
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")
5054
}

cmd/mapkubeapis/map.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright The Helm Authors.
2+
Copyright
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import (
2525
"github.com/spf13/cobra"
2626

2727
"github.com/hickeyma/helm-mapkubeapis/pkg/common"
28+
v2 "github.com/hickeyma/helm-mapkubeapis/pkg/v2"
2829
v3 "github.com/hickeyma/helm-mapkubeapis/pkg/v3"
2930
)
3031

@@ -33,6 +34,9 @@ type MapOptions struct {
3334
DryRun bool
3435
ReleaseName string
3536
ReleaseNamespace string
37+
RunV2 bool
38+
StorageType string
39+
TillerOutCluster bool
3640
}
3741

3842
var (
@@ -82,6 +86,9 @@ func runMap(cmd *cobra.Command, args []string) error {
8286
DryRun: settings.DryRun,
8387
ReleaseName: releaseName,
8488
ReleaseNamespace: settings.Namespace,
89+
RunV2: settings.RunV2,
90+
StorageType: settings.StorageType,
91+
TillerOutCluster: settings.TillerOutCluster,
8592
}
8693
kubeConfig := common.KubeConfig{
8794
Context: settings.KubeContext,
@@ -103,15 +110,27 @@ func Map(mapOptions MapOptions, kubeConfig common.KubeConfig) error {
103110

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

106-
v3MapOptions := v3.MapOptions{
113+
options := common.MapOptions{
107114
DryRun: mapOptions.DryRun,
108115
KubeConfig: kubeConfig,
109116
ReleaseName: mapOptions.ReleaseName,
110117
ReleaseNamespace: mapOptions.ReleaseNamespace,
118+
StorageType: mapOptions.StorageType,
119+
TillerOutCluster: mapOptions.TillerOutCluster,
111120
}
112121

113-
if err := v3.MapReleaseWithDeprecatedAPIs(v3MapOptions); err != nil {
114-
return err
122+
if mapOptions.RunV2 {
123+
// default namespace to the Tiller default namespace
124+
if options.ReleaseNamespace == "" {
125+
options.ReleaseNamespace = "kube-system"
126+
}
127+
if err := v2.MapReleaseWithDeprecatedAPIs(options); err != nil {
128+
return err
129+
}
130+
} else {
131+
if err := v3.MapReleaseWithDeprecatedAPIs(options); err != nil {
132+
return err
133+
}
115134
}
116135

117136
log.Printf("Map of release '%s' deprecated APIs to supported APIs, completed successfully.\n", mapOptions.ReleaseName)

cmd/mapkubeapis/map_kube_apis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright The Helm Authors.
2+
Copyright
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@ module github.com/hickeyma/helm-mapkubeapis
33
go 1.13
44

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

1118
replace (

0 commit comments

Comments
 (0)