Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add username and password auth to helm repository config #65

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions cmd/create/helmbundle/helm_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

"github.com/mesosphere/dkp-cli-runtime/core/output"
"github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/action"
"k8s.io/utils/pointer"

"github.com/mesosphere/mindthegap/archive"
"github.com/mesosphere/mindthegap/cleanup"
Expand Down Expand Up @@ -115,9 +117,21 @@ func NewCommand(out output.Output) *cobra.Command {
repoConfig.RepoURL,
),
)
if err := helmClient.GetChartFromRepo(tempDir, repoConfig.RepoURL, chartName, chartVersions...); err != nil {
out.EndOperation(false)
return fmt.Errorf("failed to create Helm chart bundle: %v", err)
var opts []action.PullOpt
if repoConfig.Username != "" {
opts = append(
opts,
helm.UsernamePasswordOpt(repoConfig.Username, repoConfig.Password),
)
}
if !pointer.BoolDeref(repoConfig.TLSVerify, true) {
opts = append(opts, helm.InsecureSkipTLSverifyOpt())
}
for _, chartVersion := range chartVersions {
if err := helmClient.GetChartFromRepo(tempDir, repoConfig.RepoURL, chartName, chartVersion, opts...); err != nil {
out.EndOperation(false)
return fmt.Errorf("failed to create Helm chart bundle: %v", err)
}
}
out.EndOperation(true)
}
Expand Down
6 changes: 6 additions & 0 deletions config/helm_charts_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import (
type HelmRepositorySyncConfig struct {
// RepoURL is the URL for the repository.
RepoURL string `yaml:"repoURL"`
// Username holds the username for the repository.
Username string `yaml:"username,omitempty"`
// Password holds the password for the repository.
Password string `yaml:"password,omitempty"`
// TLS verification mode (enabled by default)
TLSVerify *bool `yaml:"tlsVerify,omitempty"`
// Charts map charts name to slices with the chart versions.
Charts map[string][]string `yaml:"charts,omitempty"`
}
Expand Down
139 changes: 139 additions & 0 deletions config/helm_charts_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Copyright 2021 D2iQ, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package config

import (
"path/filepath"
"reflect"
"strings"
"testing"

"k8s.io/utils/pointer"
)

func TestParseHelmChartsFile(t *testing.T) {
t.Parallel()
tests := []struct {
name string
want HelmChartsConfig
wantErr bool
}{{
name: "empty",
want: HelmChartsConfig{},
}, {
name: "single repository with no charts",
want: HelmChartsConfig{
Repositories: map[string]HelmRepositorySyncConfig{
"test.repository.io": {},
},
},
}, {
name: "single repository with chart with no requested versions",
want: HelmChartsConfig{
Repositories: map[string]HelmRepositorySyncConfig{
"test.repository.io": {
Charts: map[string][]string{
"test-chart": nil,
},
},
},
},
}, {
name: "single repository with chart with single version",
want: HelmChartsConfig{
Repositories: map[string]HelmRepositorySyncConfig{
"test.repository.io": {
Charts: map[string][]string{
"test-chart": {"v1.2.3"},
},
},
},
},
}, {
name: "single repository with chart with multiple versions",
want: HelmChartsConfig{
Repositories: map[string]HelmRepositorySyncConfig{
"test.repository.io": {
Charts: map[string][]string{
"test-chart": {"v1.2.3", "v2.4.6", "v3.6.9"},
},
},
},
},
}, {
name: "single repository with multiple charts with multiple versions",
want: HelmChartsConfig{
Repositories: map[string]HelmRepositorySyncConfig{
"test.repository.io": {
Charts: map[string][]string{
"test-chart": {"v1.2.3", "v2.4.6", "v3.6.9"},
"test-chart2": {"v3.6.9", "v4.8.12", "v5.10.15"},
"test-chart3": {"v6.12.18", "v7.14.21", "v8.16.24"},
},
},
},
},
}, {
name: "multiple repositories with multiple charts with multiple versions",
want: HelmChartsConfig{
Repositories: map[string]HelmRepositorySyncConfig{
"test.repository.io": {
Charts: map[string][]string{
"test-chart": {"v1.2.3", "v2.4.6", "v3.6.9"},
"test-chart2": {"v3.6.9", "v4.8.12", "v5.10.15"},
"test-chart3": {"v6.12.18", "v7.14.21", "v8.16.24"},
},
}, "test.repository2.io": {
Charts: map[string][]string{
"test-chart": {"v1.2.31", "v2.4.61", "v3.6.91"},
"test-chart5": {"v3.6.92", "v4.8.122", "v5.10.152"},
"test-chart6": {"v63.126.189", "v73.146.219", "v8.16.243"},
},
},
},
},
}, {
name: "single repository with tls config",
want: HelmChartsConfig{
Repositories: map[string]HelmRepositorySyncConfig{
"test.repository.io": {
TLSVerify: pointer.Bool(false),
},
},
},
}, {
name: "multiple repositories with tls config",
want: HelmChartsConfig{
Repositories: map[string]HelmRepositorySyncConfig{
"test.repository.io": {
TLSVerify: pointer.Bool(false),
},
"test.repository2.io": {
TLSVerify: pointer.Bool(true),
},
},
},
}}
for ti := range tests {
tt := tests[ti]
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ext := "yaml"
got, err := ParseHelmChartsConfigFile(
filepath.Join(
"testdata",
"helmcharts",
strings.ReplaceAll(tt.name, " ", "_")+"."+ext,
),
)
if (err != nil) != tt.wantErr {
t.Errorf("ParseFile() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseFile() = %v, want %v", got, tt.want)
}
})
}
}
2 changes: 1 addition & 1 deletion config/images_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type RegistrySyncConfig struct {
// Images map images name to slices with the images' references (tags, digests)
Images map[string][]string
// TLS verification mode (enabled by default)
TLSVerify *bool `yaml:"tls-verify,omitempty"`
TLSVerify *bool `yaml:"tlsVerify,omitempty"`
// Username and password used to authenticate with the registry
Credentials *types.DockerAuthConfig `yaml:"credentials,omitempty"`
}
Expand Down
4 changes: 4 additions & 0 deletions config/testdata/helmcharts/empty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2021 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

---
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2021 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

---
repositories:
test.repository.io:
charts:
test-chart:
- v1.2.3
- v2.4.6
- v3.6.9
test-chart2:
- v3.6.9
- v4.8.12
- v5.10.15
test-chart3:
- v6.12.18
- v7.14.21
- v8.16.24
test.repository2.io:
charts:
test-chart:
- v1.2.31
- v2.4.61
- v3.6.91
test-chart5:
- v3.6.92
- v4.8.122
- v5.10.152
test-chart6:
- v63.126.189
- v73.146.219
- v8.16.243
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2021 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

---
repositories:
test.repository.io:
tlsVerify: false
test.repository2.io:
tlsVerify: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2021 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

---
repositories:
test.repository.io:
charts:
test-chart:
- v1.2.3
- v2.4.6
- v3.6.9
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright 2021 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

---
repositories:
test.repository.io:
charts:
test-chart:
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2021 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

---
repositories:
test.repository.io:
charts:
test-chart:
- v1.2.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2021 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

---
repositories:
test.repository.io:
charts:
test-chart:
- v1.2.3
- v2.4.6
- v3.6.9
test-chart2:
- v3.6.9
- v4.8.12
- v5.10.15
test-chart3:
- v6.12.18
- v7.14.21
- v8.16.24
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2021 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

---
repositories:
test.repository.io:
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2021 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

---
repositories:
test.repository.io:
tlsVerify: false
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

---
test.registry.io:
tls-verify: false
tlsVerify: false
test.registry2.io:
tls-verify: true
tlsVerify: true
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

---
test.registry.io:
tls-verify: false
tlsVerify: false
Loading