Skip to content

Commit b51a356

Browse files
committed
Upgrade helm-operator to Helm v3
1 parent 76b9041 commit b51a356

File tree

33 files changed

+956
-562
lines changed

33 files changed

+956
-562
lines changed

cmd/operator-sdk/new/cmd.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/operator-framework/operator-sdk/internal/scaffold/input"
2929
"github.com/operator-framework/operator-sdk/internal/util/projutil"
3030

31+
"github.com/ghodss/yaml"
3132
"github.com/pkg/errors"
3233
log "github.com/sirupsen/logrus"
3334
"github.com/spf13/cobra"
@@ -314,8 +315,13 @@ func doHelmScaffold() error {
314315
return fmt.Errorf("failed to create helm chart: %s", err)
315316
}
316317

317-
valuesPath := filepath.Join("<project_dir>", helm.HelmChartsDir, chart.GetMetadata().GetName(), "values.yaml")
318-
crSpec := fmt.Sprintf("# Default values copied from %s\n\n%s", valuesPath, chart.GetValues().GetRaw())
318+
valuesPath := filepath.Join("<project_dir>", helm.HelmChartsDir, chart.Name(), "values.yaml")
319+
320+
rawValues, err := yaml.Marshal(chart.Values)
321+
if err != nil {
322+
return fmt.Errorf("failed to get raw chart values: %s", err)
323+
}
324+
crSpec := fmt.Sprintf("# Default values copied from %s\n\n%s", valuesPath, rawValues)
319325

320326
roleScaffold := helm.DefaultRoleScaffold
321327
if k8sCfg, err := config.GetConfig(); err != nil {
@@ -331,7 +337,7 @@ func doHelmScaffold() error {
331337
&helm.Dockerfile{},
332338
&helm.WatchesYAML{
333339
Resource: resource,
334-
ChartName: chart.GetMetadata().GetName(),
340+
ChartName: chart.Name(),
335341
},
336342
&scaffold.ServiceAccount{},
337343
&roleScaffold,

go.mod

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ go 1.13
44

55
require (
66
github.com/DATA-DOG/go-sqlmock v1.3.3 // indirect
7-
github.com/Masterminds/goutils v1.1.0 // indirect
8-
github.com/Masterminds/semver v1.5.0 // indirect
9-
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
107
github.com/blang/semver v3.5.1+incompatible
118
github.com/coreos/go-semver v0.3.0
129
github.com/coreos/prometheus-operator v0.34.0
@@ -15,24 +12,22 @@ require (
1512
github.com/go-logr/logr v0.1.0
1613
github.com/go-logr/zapr v0.1.1
1714
github.com/gobuffalo/packr v1.30.1 // indirect
18-
github.com/gobwas/glob v0.2.3 // indirect
1915
github.com/gregjones/httpcache v0.0.0-20190203031600-7a902570cb17 // indirect
20-
github.com/huandu/xstrings v1.2.0 // indirect
16+
github.com/helm/helm-2to3 v0.2.0
2117
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365
2218
github.com/jmoiron/sqlx v1.2.0 // indirect
2319
github.com/lib/pq v1.2.0 // indirect
2420
github.com/markbates/inflect v1.0.4
2521
github.com/martinlindhe/base36 v1.0.0
2622
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a
2723
github.com/mattn/go-isatty v0.0.8
28-
github.com/mitchellh/copystructure v1.0.0 // indirect
2924
github.com/mitchellh/go-homedir v1.1.0
3025
github.com/mitchellh/mapstructure v1.1.2
3126
github.com/operator-framework/operator-lifecycle-manager v0.0.0-20191115003340-16619cd27fa5
3227
github.com/operator-framework/operator-registry v1.5.1
3328
github.com/pborman/uuid v1.2.0
3429
github.com/pkg/errors v0.8.1
35-
github.com/prometheus/client_golang v1.1.0
30+
github.com/prometheus/client_golang v1.2.1
3631
github.com/rogpeppe/go-internal v1.5.0
3732
github.com/rubenv/sql-migrate v0.0.0-20191025130928-9355dd04f4b3 // indirect
3833
github.com/sergi/go-diff v1.0.0
@@ -42,12 +37,12 @@ require (
4237
github.com/spf13/pflag v1.0.5
4338
github.com/spf13/viper v1.4.0
4439
github.com/stretchr/testify v1.4.0
45-
github.com/technosophos/moniker v0.0.0-20180509230615-a5dbd03a2245 // indirect
4640
github.com/ziutek/mymysql v1.5.4 // indirect
4741
go.uber.org/zap v1.10.0
4842
golang.org/x/tools v0.0.0-20191018212557-ed542cd5b28a
4943
gopkg.in/gorp.v1 v1.7.2 // indirect
5044
gopkg.in/yaml.v2 v2.2.4
45+
helm.sh/helm/v3 v3.0.0
5146
k8s.io/api v0.0.0
5247
k8s.io/apiextensions-apiserver v0.0.0
5348
k8s.io/apimachinery v0.0.0
@@ -60,7 +55,7 @@ require (
6055
k8s.io/kube-openapi v0.0.0-20190918143330-0270cf2f1c1d
6156
k8s.io/kube-state-metrics v1.7.2
6257
k8s.io/kubectl v0.0.0
63-
k8s.io/kubernetes v1.16.2
58+
k8s.io/kubernetes v1.16.2 // indirect
6459
sigs.k8s.io/controller-runtime v0.4.0
6560
sigs.k8s.io/controller-tools v0.2.2
6661
)
@@ -89,3 +84,5 @@ replace (
8984
k8s.io/metrics => k8s.io/metrics v0.0.0-20191016113814-3b1a734dba6e
9085
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.0.0-20191016112829-06bb3c9d77c9
9186
)
87+
88+
replace github.com/docker/docker => github.com/moby/moby v0.7.3-0.20190826074503-38ab9da00309 // Required by Helm

go.sum

Lines changed: 158 additions & 69 deletions
Large diffs are not rendered by default.

internal/olm/client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
"k8s.io/apimachinery/pkg/util/wait"
4040
"k8s.io/client-go/kubernetes/scheme"
4141
"k8s.io/client-go/rest"
42-
deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
42+
deploymentutil "k8s.io/kubectl/pkg/util/deployment"
4343
"sigs.k8s.io/controller-runtime/pkg/client"
4444
)
4545

internal/scaffold/ansible/go_mod.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ replace (
6969
k8s.io/metrics => k8s.io/metrics v0.0.0-20191016113814-3b1a734dba6e
7070
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.0.0-20191016112829-06bb3c9d77c9
7171
)
72+
73+
replace github.com/docker/docker => github.com/moby/moby v0.7.3-0.20190826074503-38ab9da00309 // Required by Helm
7274
`
7375

7476
func PrintGoMod() error {

internal/scaffold/go_mod.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ replace (
6868
k8s.io/metrics => k8s.io/metrics v0.0.0-20191016113814-3b1a734dba6e
6969
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.0.0-20191016112829-06bb3c9d77c9
7070
)
71+
72+
replace github.com/docker/docker => github.com/moby/moby v0.7.3-0.20190826074503-38ab9da00309 // Required by Helm
7173
`
7274

7375
func PrintGoMod() error {

internal/scaffold/helm/chart.go

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@ import (
2020
"io/ioutil"
2121
"os"
2222
"path/filepath"
23-
"strings"
2423

2524
"github.com/operator-framework/operator-sdk/internal/scaffold"
2625

2726
"github.com/iancoleman/strcase"
2827
log "github.com/sirupsen/logrus"
29-
"k8s.io/helm/pkg/chartutil"
30-
"k8s.io/helm/pkg/downloader"
31-
"k8s.io/helm/pkg/getter"
32-
"k8s.io/helm/pkg/helm/environment"
33-
"k8s.io/helm/pkg/helm/helmpath"
34-
"k8s.io/helm/pkg/proto/hapi/chart"
35-
"k8s.io/helm/pkg/repo"
28+
"helm.sh/helm/v3/pkg/chart"
29+
"helm.sh/helm/v3/pkg/chart/loader"
30+
"helm.sh/helm/v3/pkg/chartutil"
31+
"helm.sh/helm/v3/pkg/cli"
32+
"helm.sh/helm/v3/pkg/downloader"
33+
"helm.sh/helm/v3/pkg/getter"
34+
"helm.sh/helm/v3/pkg/repo"
3635
)
3736

3837
const (
@@ -139,14 +138,14 @@ func CreateChart(projectDir string, opts CreateChartOptions) (*scaffold.Resource
139138
}
140139
}
141140

142-
relChartPath := filepath.Join(HelmChartsDir, c.GetMetadata().GetName())
141+
relChartPath := filepath.Join(HelmChartsDir, c.Name())
143142
absChartPath := filepath.Join(projectDir, relChartPath)
144143
if err := fetchChartDependencies(absChartPath); err != nil {
145144
return nil, nil, fmt.Errorf("failed to fetch chart dependencies: %s", err)
146145
}
147146

148147
// Reload chart in case dependencies changed
149-
c, err = chartutil.Load(absChartPath)
148+
c, err = loader.Load(absChartPath)
150149
if err != nil {
151150
return nil, nil, fmt.Errorf("failed to load chart: %s", err)
152151
}
@@ -161,22 +160,12 @@ func scaffoldChart(destDir, apiVersion, kind string) (*scaffold.Resource, *chart
161160
return nil, nil, err
162161
}
163162

164-
chartfile := &chart.Metadata{
165-
// Many helm charts use hyphenated names, but we chose not to because
166-
// of the issues related to how hyphens are interpreted in templates.
167-
// See https://github.com/helm/helm/issues/2192
168-
Name: r.LowerKind,
169-
Description: "A Helm chart for Kubernetes",
170-
Version: "0.1.0",
171-
AppVersion: "1.0",
172-
ApiVersion: chartutil.ApiVersionV1,
173-
}
174-
chartPath, err := chartutil.Create(chartfile, destDir)
163+
chartPath, err := chartutil.Create(r.LowerKind, destDir)
175164
if err != nil {
176165
return nil, nil, err
177166
}
178167

179-
chart, err := chartutil.Load(chartPath)
168+
chart, err := loader.Load(chartPath)
180169
if err != nil {
181170
return nil, nil, err
182171
}
@@ -198,7 +187,7 @@ func fetchChart(destDir string, opts CreateChartOptions) (*scaffold.Resource, *c
198187
return nil, nil, err
199188
}
200189

201-
chartName := chart.GetMetadata().GetName()
190+
chartName := chart.Name()
202191
if len(opts.ResourceAPIVersion) == 0 {
203192
opts.ResourceAPIVersion = DefaultAPIVersion
204193
}
@@ -214,7 +203,7 @@ func fetchChart(destDir string, opts CreateChartOptions) (*scaffold.Resource, *c
214203
}
215204

216205
func createChartFromDisk(destDir, source string) (*chart.Chart, error) {
217-
chart, err := chartutil.Load(source)
206+
chart, err := loader.Load(source)
218207
if err != nil {
219208
return nil, err
220209
}
@@ -227,15 +216,13 @@ func createChartFromDisk(destDir, source string) (*chart.Chart, error) {
227216
}
228217

229218
func createChartFromRemote(destDir string, opts CreateChartOptions) (*chart.Chart, error) {
230-
helmHome, ok := os.LookupEnv(environment.HomeEnvVar)
231-
if !ok {
232-
helmHome = environment.DefaultHelmHome
233-
}
234-
getters := getter.All(environment.EnvSettings{})
219+
settings := cli.New()
220+
getters := getter.All(settings)
235221
c := downloader.ChartDownloader{
236-
HelmHome: helmpath.Home(helmHome),
237-
Out: os.Stderr,
238-
Getters: getters,
222+
Out: os.Stderr,
223+
Getters: getters,
224+
RepositoryConfig: settings.RepositoryConfig,
225+
RepositoryCache: settings.RepositoryCache,
239226
}
240227

241228
if opts.Repo != "" {
@@ -261,30 +248,25 @@ func createChartFromRemote(destDir string, opts CreateChartOptions) (*chart.Char
261248
// One of Helm's error messages directs users to run `helm init`, which
262249
// installs tiller in a remote cluster. Since that's unnecessary and
263250
// unhelpful, modify the error message to be relevant for operator-sdk.
264-
if strings.Contains(err.Error(), "Couldn't load repositories file") {
265-
return nil, fmt.Errorf("failed to load repositories file %s "+
266-
"(you might need to run `helm init --client-only` "+
267-
"to create and initialize it)", c.HelmHome.RepositoryFile())
268-
}
251+
252+
// TODO(joelanford): Is there anything to initialize in helm v3
269253
return nil, err
270254
}
271255

272256
return createChartFromDisk(destDir, chartArchive)
273257
}
274258

275259
func fetchChartDependencies(chartPath string) error {
276-
helmHome, ok := os.LookupEnv(environment.HomeEnvVar)
277-
if !ok {
278-
helmHome = environment.DefaultHelmHome
279-
}
280-
getters := getter.All(environment.EnvSettings{})
260+
settings := cli.New()
261+
getters := getter.All(settings)
281262

282263
out := &bytes.Buffer{}
283264
man := &downloader.Manager{
284-
Out: out,
285-
ChartPath: chartPath,
286-
HelmHome: helmpath.Home(helmHome),
287-
Getters: getters,
265+
Out: out,
266+
ChartPath: chartPath,
267+
Getters: getters,
268+
RepositoryConfig: settings.RepositoryConfig,
269+
RepositoryCache: settings.RepositoryCache,
288270
}
289271
if err := man.Build(); err != nil {
290272
fmt.Println(out.String())

0 commit comments

Comments
 (0)