Skip to content

Commit fbfbc09

Browse files
committed
WIP: initial transition to Helm v3 and K8s 1.16
1 parent 04629a2 commit fbfbc09

31 files changed

+853
-554
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"
@@ -308,8 +309,13 @@ func doHelmScaffold() error {
308309
return fmt.Errorf("failed to create helm chart: %s", err)
309310
}
310311

311-
valuesPath := filepath.Join("<project_dir>", helm.HelmChartsDir, chart.GetMetadata().GetName(), "values.yaml")
312-
crSpec := fmt.Sprintf("# Default values copied from %s\n\n%s", valuesPath, chart.GetValues().GetRaw())
312+
valuesPath := filepath.Join("<project_dir>", helm.HelmChartsDir, chart.Name(), "values.yaml")
313+
314+
rawValues, err := yaml.Marshal(chart.Values)
315+
if err != nil {
316+
return fmt.Errorf("failed to get raw chart values: %s", err)
317+
}
318+
crSpec := fmt.Sprintf("# Default values copied from %s\n\n%s", valuesPath, rawValues)
313319

314320
roleScaffold := helm.DefaultRoleScaffold
315321
if k8sCfg, err := config.GetConfig(); err != nil {
@@ -325,7 +331,7 @@ func doHelmScaffold() error {
325331
&helm.Dockerfile{},
326332
&helm.WatchesYAML{
327333
Resource: resource,
328-
ChartName: chart.GetMetadata().GetName(),
334+
ChartName: chart.Name(),
329335
},
330336
&scaffold.ServiceAccount{},
331337
&roleScaffold,

go.mod

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,29 @@ 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
1310
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
1411
github.com/go-logr/logr v0.1.0
1512
github.com/go-logr/zapr v0.1.1
1613
github.com/gobuffalo/packr v1.30.1 // indirect
17-
github.com/gobwas/glob v0.2.3 // indirect
1814
github.com/gregjones/httpcache v0.0.0-20190203031600-7a902570cb17 // indirect
19-
github.com/huandu/xstrings v1.2.0 // indirect
15+
github.com/helm/helm-2to3 v0.2.0
2016
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365
2117
github.com/jmoiron/sqlx v1.2.0 // indirect
2218
github.com/lib/pq v1.2.0 // indirect
2319
github.com/markbates/inflect v1.0.4
2420
github.com/martinlindhe/base36 v1.0.0
2521
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a
2622
github.com/mattn/go-isatty v0.0.8
27-
github.com/mitchellh/copystructure v1.0.0 // indirect
2823
github.com/mitchellh/go-homedir v1.1.0
2924
github.com/mitchellh/mapstructure v1.1.2
3025
github.com/operator-framework/operator-lifecycle-manager v0.0.0-20191115003340-16619cd27fa5
3126
github.com/operator-framework/operator-registry v1.5.1
3227
github.com/pborman/uuid v1.2.0
3328
github.com/pkg/errors v0.8.1
34-
github.com/prometheus/client_golang v1.1.0
29+
github.com/prometheus/client_golang v1.2.1
3530
github.com/rogpeppe/go-internal v1.5.0
3631
github.com/rubenv/sql-migrate v0.0.0-20191025130928-9355dd04f4b3 // indirect
3732
github.com/sergi/go-diff v1.0.0
@@ -41,12 +36,12 @@ require (
4136
github.com/spf13/pflag v1.0.5
4237
github.com/spf13/viper v1.4.0
4338
github.com/stretchr/testify v1.4.0
44-
github.com/technosophos/moniker v0.0.0-20180509230615-a5dbd03a2245 // indirect
4539
github.com/ziutek/mymysql v1.5.4 // indirect
4640
go.uber.org/zap v1.10.0
4741
golang.org/x/tools v0.0.0-20191018212557-ed542cd5b28a
4842
gopkg.in/gorp.v1 v1.7.2 // indirect
4943
gopkg.in/yaml.v2 v2.2.4
44+
helm.sh/helm/v3 v3.0.0
5045
k8s.io/api v0.0.0
5146
k8s.io/apiextensions-apiserver v0.0.0
5247
k8s.io/apimachinery v0.0.0
@@ -59,7 +54,7 @@ require (
5954
k8s.io/kube-openapi v0.0.0-20190918143330-0270cf2f1c1d
6055
k8s.io/kube-state-metrics v1.7.2
6156
k8s.io/kubectl v0.0.0
62-
k8s.io/kubernetes v1.16.2
57+
k8s.io/kubernetes v1.16.2 // indirect
6358
sigs.k8s.io/controller-runtime v0.4.0
6459
sigs.k8s.io/controller-tools v0.2.2
6560
)
@@ -88,3 +83,5 @@ replace (
8883
k8s.io/metrics => k8s.io/metrics v0.0.0-20191016113814-3b1a734dba6e
8984
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.0.0-20191016112829-06bb3c9d77c9
9085
)
86+
87+
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ 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 (
74+
github.com/docker/docker => github.com/moby/moby v0.7.3-0.20190826074503-38ab9da00309 // Required by Helm
75+
)
7276
`
7377

7478
func PrintGoMod() error {

internal/scaffold/go_mod.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ 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 (
73+
github.com/docker/docker => github.com/moby/moby v0.7.3-0.20190826074503-38ab9da00309 // Required by Helm
74+
)
7175
`
7276

7377
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
}
@@ -199,7 +188,7 @@ func fetchChart(destDir string, opts CreateChartOptions) (*scaffold.Resource, *c
199188
return nil, nil, err
200189
}
201190

202-
chartName := chart.GetMetadata().GetName()
191+
chartName := chart.Name()
203192
if len(opts.ResourceAPIVersion) == 0 {
204193
opts.ResourceAPIVersion = DefaultAPIVersion
205194
}
@@ -215,7 +204,7 @@ func fetchChart(destDir string, opts CreateChartOptions) (*scaffold.Resource, *c
215204
}
216205

217206
func createChartFromDisk(destDir, source string, isDir bool) (*chart.Chart, error) {
218-
chart, err := chartutil.Load(source)
207+
chart, err := loader.Load(source)
219208
if err != nil {
220209
return nil, err
221210
}
@@ -228,15 +217,13 @@ func createChartFromDisk(destDir, source string, isDir bool) (*chart.Chart, erro
228217
}
229218

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

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

273257
return createChartFromDisk(destDir, chartArchive, false)
274258
}
275259

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

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

0 commit comments

Comments
 (0)