[Backport release-1.3] Feat: support basic auth private helm repo (#3631)

* support auth

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
(cherry picked from commit 54c05afb1a)

* add test

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

fix check diff

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

fix test

fix

add comments

fix test

(cherry picked from commit a8961ec8cc)

* add tests

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

fix

add more test

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
(cherry picked from commit 4f45a6af8e)

* add more test

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
(cherry picked from commit dee791aa51)

* extract set auth info as a global func

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
(cherry picked from commit f8fb0137e3)

* return bcode

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
(cherry picked from commit 057a67d8b9)

Co-authored-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
This commit is contained in:
github-actions[bot]
2022-04-12 16:10:48 +08:00
committed by GitHub
co-authored by 楚岳
parent e26104adcc
commit a13cab65b2
17 changed files with 363 additions and 31 deletions
+3 -3
View File
@@ -52,7 +52,7 @@ type versionedRegistry struct {
}
func (i *versionedRegistry) ListAddon() ([]*UIData, error) {
chartIndex, err := i.h.GetIndexInfo(i.url, false)
chartIndex, err := i.h.GetIndexInfo(i.url, false, nil)
if err != nil {
return nil, err
}
@@ -107,7 +107,7 @@ func (i *versionedRegistry) resolveAddonListFromIndex(repoName string, index *re
}
func (i versionedRegistry) loadAddon(ctx context.Context, name, version string) (*WholeAddonPackage, error) {
versions, err := i.h.ListVersions(i.url, name, false)
versions, err := i.h.ListVersions(i.url, name, false, nil)
if err != nil {
return nil, err
}
@@ -131,7 +131,7 @@ func (i versionedRegistry) loadAddon(ctx context.Context, name, version string)
return nil, fmt.Errorf("specified version %s not exist", version)
}
for _, chartURL := range addonVersion.URLs {
archive, err := common.HTTPGet(ctx, chartURL)
archive, err := common.HTTPGetWithOption(ctx, chartURL, nil)
if err != nil {
continue
}
+29 -4
View File
@@ -26,10 +26,12 @@ import (
v1 "github.com/oam-dev/kubevela/pkg/apiserver/rest/apis/v1"
"github.com/oam-dev/kubevela/pkg/apiserver/rest/utils/bcode"
"github.com/oam-dev/kubevela/pkg/oam"
"github.com/oam-dev/kubevela/pkg/utils/common"
"github.com/oam-dev/kubevela/pkg/utils/helm"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types2 "k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"helm.sh/helm/v3/pkg/repo"
@@ -61,8 +63,15 @@ type defaultHelmHandler struct {
}
func (d defaultHelmHandler) ListChartNames(ctx context.Context, url string, secretName string, skipCache bool) ([]string, error) {
// TODO(wangyikewxgm): support authority helm repo
charts, err := d.helper.ListChartsFromRepo(url, skipCache)
var opts *common.HTTPOption
var err error
if len(secretName) != 0 {
opts, err = helm.SetBasicAuthInfo(ctx, d.k8sClient, types2.NamespacedName{Namespace: types.DefaultKubeVelaNS, Name: secretName})
if err != nil {
return nil, bcode.ErrRepoBasicAuth
}
}
charts, err := d.helper.ListChartsFromRepo(url, skipCache, opts)
if err != nil {
log.Logger.Errorf("cannot fetch charts repo: %s, error: %s", url, err.Error())
return nil, bcode.ErrListHelmChart
@@ -71,7 +80,15 @@ func (d defaultHelmHandler) ListChartNames(ctx context.Context, url string, secr
}
func (d defaultHelmHandler) ListChartVersions(ctx context.Context, url string, chartName string, secretName string, skipCache bool) (repo.ChartVersions, error) {
chartVersions, err := d.helper.ListVersions(url, chartName, skipCache)
var opts *common.HTTPOption
var err error
if len(secretName) != 0 {
opts, err = helm.SetBasicAuthInfo(ctx, d.k8sClient, types2.NamespacedName{Namespace: types.DefaultKubeVelaNS, Name: secretName})
if err != nil {
return nil, bcode.ErrRepoBasicAuth
}
}
chartVersions, err := d.helper.ListVersions(url, chartName, skipCache, opts)
if err != nil {
log.Logger.Errorf("cannot fetch chart versions repo: %s, chart: %s error: %s", url, chartName, err.Error())
return nil, bcode.ErrListHelmVersions
@@ -84,7 +101,15 @@ func (d defaultHelmHandler) ListChartVersions(ctx context.Context, url string, c
}
func (d defaultHelmHandler) GetChartValues(ctx context.Context, url string, chartName string, version string, secretName string, skipCache bool) (map[string]interface{}, error) {
v, err := d.helper.GetValuesFromChart(url, chartName, version, skipCache)
var opts *common.HTTPOption
var err error
if len(secretName) != 0 {
opts, err = helm.SetBasicAuthInfo(ctx, d.k8sClient, types2.NamespacedName{Namespace: types.DefaultKubeVelaNS, Name: secretName})
if err != nil {
return nil, bcode.ErrRepoBasicAuth
}
}
v, err := d.helper.GetValuesFromChart(url, chartName, version, skipCache, opts)
if err != nil {
log.Logger.Errorf("cannot fetch chart values repo: %s, chart: %s, version: %s, error: %s", url, chartName, version, err.Error())
return nil, bcode.ErrGetChartValues
+102
View File
@@ -19,6 +19,10 @@ package usecase
import (
"context"
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
"testing"
. "github.com/onsi/ginkgo"
@@ -104,6 +108,90 @@ var _ = Describe("Test helm repo list", func() {
})
})
var _ = Describe("test helm usecasae", func() {
ctx := context.Background()
var repoSec v1.Secret
BeforeEach(func() {
Expect(k8sClient.Create(ctx, &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: "vela-system"}})).Should(SatisfyAny(BeNil(), util.AlreadyExistMatcher{}))
repoSec = v1.Secret{}
Expect(yaml.Unmarshal([]byte(repoSecret), &repoSec)).Should(BeNil())
Expect(k8sClient.Create(ctx, &repoSec)).Should(BeNil())
})
AfterEach(func() {
Expect(k8sClient.Delete(ctx, &repoSec)).Should(BeNil())
})
It("helm associated usecase interface test", func() {
var mockServer *httptest.Server
handler := http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
u, p, ok := request.BasicAuth()
if !ok || u != "admin" || p != "admin" {
writer.WriteHeader(401)
return
}
switch {
case request.URL.Path == "/index.yaml":
index, err := ioutil.ReadFile("./testdata/helm/index.yaml")
indexFile := string(index)
indexFile = strings.ReplaceAll(indexFile, "server-url", mockServer.URL)
if err != nil {
writer.Write([]byte(err.Error()))
return
}
writer.Write([]byte(indexFile))
return
case strings.Contains(request.URL.Path, "mysql-8.8.23.tgz"):
pkg, err := ioutil.ReadFile("./testdata/helm/mysql-8.8.23.tgz")
if err != nil {
writer.Write([]byte(err.Error()))
return
}
writer.Write(pkg)
return
default:
writer.Write([]byte("404 page not found"))
}
})
mockServer = httptest.NewServer(handler)
defer mockServer.Close()
u := NewHelmUsecase()
charts, err := u.ListChartNames(ctx, mockServer.URL, "repo-secret", false)
Expect(err).Should(BeNil())
Expect(len(charts)).Should(BeEquivalentTo(1))
Expect(charts[0]).Should(BeEquivalentTo("mysql"))
versions, err := u.ListChartVersions(ctx, mockServer.URL, "mysql", "repo-secret", false)
Expect(err).Should(BeNil())
Expect(len(versions)).Should(BeEquivalentTo(1))
Expect(versions[0].Version).Should(BeEquivalentTo("8.8.23"))
values, err := u.GetChartValues(ctx, mockServer.URL, "mysql", "8.8.23", "repo-secret", false)
Expect(err).Should(BeNil())
Expect(values).ShouldNot(BeNil())
Expect(len(values)).ShouldNot(BeEquivalentTo(0))
})
It("coverage not secret notExist error", func() {
u := NewHelmUsecase()
_, err := u.ListChartNames(ctx, "http://127.0.0.1:8080", "repo-secret-notExist", false)
Expect(err).ShouldNot(BeNil())
_, err = u.ListChartVersions(ctx, "http://127.0.0.1:8080", "mysql", "repo-secret-notExist", false)
Expect(err).ShouldNot(BeNil())
_, err = u.GetChartValues(ctx, "http://127.0.0.1:8080", "mysql", "8.8.23", "repo-secret-notExist", false)
Expect(err).ShouldNot(BeNil())
})
})
var (
src = `{
"OAMSpecVer":"v0.2",
@@ -266,5 +354,19 @@ metadata:
stringData:
url: https://kedacore.github.io/charts
type: Opaque
`
repoSecret = `
apiVersion: v1
kind: Secret
metadata:
name: repo-secret
namespace: vela-system
labels:
config.oam.dev/type: config-helm-repository
config.oam.dev/project: my-project-2
stringData:
username: admin
password: admin
type: Opaque
`
)
+36
View File
@@ -0,0 +1,36 @@
apiVersion: v1
entries:
mysql:
- annotations:
category: Database
apiVersion: v2
appVersion: 8.0.28
created: "2022-04-07T03:26:37.378966939Z"
dependencies:
- name: common
repository: https://charts.bitnami.com/bitnami
tags:
- bitnami-common
version: 1.x.x
description: Chart to create a Highly available MySQL cluster
digest: 96f79c6daba90fb40fc698979fab33f7a60987b1d23cd5080bc885129568a423
home: https://github.com/bitnami/charts/tree/master/bitnami/mysql
icon: https://bitnami.com/assets/stacks/mysql/img/mysql-stack-220x234.png
keywords:
- mysql
- database
- sql
- cluster
- high availability
maintainers:
- email: containers@bitnami.com
name: Bitnami
name: mysql
sources:
- https://github.com/bitnami/bitnami-docker-mysql
- https://mysql.com
urls:
- server-url/mysql-8.8.23.tgz
version: 8.8.23
generated: "2022-04-07T03:26:37Z"
serverInfo: {}
Binary file not shown.
@@ -30,3 +30,6 @@ var ErrChartNotExist = NewBcode(200, 13004, "this chart not exist in the reposit
// ErrSkipCacheParameter means the skip cache parameter miss config
var ErrSkipCacheParameter = NewBcode(400, 13005, "skip cache parameter miss config, the value only can be true or false")
// ErrRepoBasicAuth means extract repo auth info from secret error
var ErrRepoBasicAuth = NewBcode(400, 13006, "extract repo auth info from secret error")
+11 -2
View File
@@ -102,6 +102,12 @@ func init() {
// +kubebuilder:scaffold:scheme
}
// HTTPOption define the https options
type HTTPOption struct {
Username string
Password string
}
// InitBaseRestConfig will return reset config for create controller runtime client
func InitBaseRestConfig() (Args, error) {
args := Args{
@@ -134,13 +140,16 @@ func GetClient() (client.Client, error) {
return nil, errors.New("client not set, call SetGlobalClient first")
}
// HTTPGet will send GET http request with context
func HTTPGet(ctx context.Context, url string) ([]byte, error) {
// HTTPGetWithOption use HTTP option and default client to send get request
func HTTPGetWithOption(ctx context.Context, url string, opts *HTTPOption) ([]byte, error) {
// Change NewRequest to NewRequestWithContext and pass context it
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, err
}
if opts != nil && len(opts.Username) != 0 && len(opts.Password) != 0 {
req.SetBasicAuth(opts.Username, opts.Password)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
+86 -1
View File
@@ -75,7 +75,7 @@ func TestHTTPGet(t *testing.T) {
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
got, err := HTTPGet(ctx, tc.url)
got, err := HTTPGetWithOption(ctx, tc.url, nil)
if tc.want.errStr != "" {
if diff := cmp.Diff(tc.want.errStr, err.Error(), test.EquateErrors()); diff != "" {
t.Errorf("\n%s\nHTTPGet(...): -want error, +got error:\n%s", tc.reason, diff)
@@ -90,6 +90,91 @@ func TestHTTPGet(t *testing.T) {
}
func TestHTTPGetWithOption(t *testing.T) {
type want struct {
data string
}
var ctx = context.Background()
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
u, p, ok := r.BasicAuth()
if !ok {
w.Write([]byte("Error parsing basic auth"))
w.WriteHeader(401)
return
}
if u != "test-user" {
w.Write([]byte(fmt.Sprintf("Username provided is incorrect: %s", u)))
w.WriteHeader(401)
return
}
if p != "test-pass" {
w.Write([]byte(fmt.Sprintf("Password provided is incorrect: %s", p)))
w.WriteHeader(401)
return
}
w.Write([]byte("correct password"))
w.WriteHeader(200)
}))
defer testServer.Close()
cases := map[string]struct {
opts *HTTPOption
url string
want want
}{
"without auth case": {
opts: nil,
url: testServer.URL,
want: want{
data: "Error parsing basic auth",
},
},
"error user name case": {
opts: &HTTPOption{
Username: "no-user",
Password: "test-pass",
},
url: testServer.URL,
want: want{
data: "Username provided is incorrect: no-user",
},
},
"error password case": {
opts: &HTTPOption{
Username: "test-user",
Password: "error-pass",
},
url: testServer.URL,
want: want{
data: "Password provided is incorrect: error-pass",
},
},
"correct password case": {
opts: &HTTPOption{
Username: "test-user",
Password: "test-pass",
},
url: testServer.URL,
want: want{
data: "correct password",
},
},
}
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
got, err := HTTPGetWithOption(ctx, tc.url, tc.opts)
assert.NoError(t, err)
if diff := cmp.Diff(tc.want.data, string(got)); diff != "" {
t.Errorf("\n%s\nHTTPGet(...): -want, +got:\n%s", tc.want.data, diff)
}
})
}
}
func TestGetCUEParameterValue(t *testing.T) {
type want struct {
err error
+15
View File
@@ -17,12 +17,17 @@ limitations under the License.
package helm
import (
"context"
"fmt"
"io"
"log"
"os"
"strings"
v1 "k8s.io/api/core/v1"
types2 "k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/pkg/errors"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart"
@@ -268,3 +273,13 @@ func GetChart(client *action.Install, name string) (*chart.Chart, error) {
func InstallHelmChart(ioStreams cmdutil.IOStreams, c types.Chart) error {
return Install(ioStreams, c.Repo, c.URL, c.Name, c.Version, c.Namespace, c.Name, c.Values)
}
// SetBasicAuthInfo will read username and password from secret return a httpOption that contain these info.
func SetBasicAuthInfo(ctx context.Context, k8sClient client.Client, secretRef types2.NamespacedName) (*common.HTTPOption, error) {
sec := v1.Secret{}
err := k8sClient.Get(ctx, secretRef, &sec)
if err != nil {
return nil, err
}
return &common.HTTPOption{Username: string(sec.Data["username"]), Password: string(sec.Data["password"])}, nil
}
+11 -11
View File
@@ -75,11 +75,11 @@ func NewHelperWithCache() *Helper {
}
// LoadCharts load helm chart from local or remote
func (h *Helper) LoadCharts(chartRepoURL string) (*chart.Chart, error) {
func (h *Helper) LoadCharts(chartRepoURL string, opts *common.HTTPOption) (*chart.Chart, error) {
var err error
var chart *chart.Chart
if utils.IsValidURL(chartRepoURL) {
chartBytes, err := common.HTTPGet(context.Background(), chartRepoURL)
chartBytes, err := common.HTTPGetWithOption(context.Background(), chartRepoURL, opts)
if err != nil {
return nil, errors.New("error retrieving Helm Chart at " + chartRepoURL + ": " + err.Error())
}
@@ -194,8 +194,8 @@ func (h *Helper) UninstallRelease(releaseName, namespace string, config *rest.Co
}
// ListVersions list available versions from repo
func (h *Helper) ListVersions(repoURL string, chartName string, skipCache bool) (repo.ChartVersions, error) {
i, err := h.GetIndexInfo(repoURL, skipCache)
func (h *Helper) ListVersions(repoURL string, chartName string, skipCache bool, opts *common.HTTPOption) (repo.ChartVersions, error) {
i, err := h.GetIndexInfo(repoURL, skipCache, opts)
if err != nil {
return nil, err
}
@@ -203,7 +203,7 @@ func (h *Helper) ListVersions(repoURL string, chartName string, skipCache bool)
}
// GetIndexInfo get index.yaml form given repo url
func (h *Helper) GetIndexInfo(repoURL string, skipCache bool) (*repo.IndexFile, error) {
func (h *Helper) GetIndexInfo(repoURL string, skipCache bool, opts *common.HTTPOption) (*repo.IndexFile, error) {
if h.cache != nil && !skipCache {
if i := h.cache.Get(fmt.Sprintf(repoPatten, repoURL)); i != nil {
return i.(*repo.IndexFile), nil
@@ -218,7 +218,7 @@ func (h *Helper) GetIndexInfo(repoURL string, skipCache bool) (*repo.IndexFile,
parsedURL.RawPath = path.Join(parsedURL.RawPath, "index.yaml")
parsedURL.Path = path.Join(parsedURL.Path, "index.yaml")
indexURL := parsedURL.String()
body, err = common.HTTPGet(context.Background(), indexURL)
body, err = common.HTTPGetWithOption(context.Background(), indexURL, opts)
if err != nil {
return nil, fmt.Errorf("download index file from %s failure %w", repoURL, err)
}
@@ -300,8 +300,8 @@ func newActionConfig(config *rest.Config, namespace string, showDetail bool, log
}
// ListChartsFromRepo list available helm charts in a repo
func (h *Helper) ListChartsFromRepo(repoURL string, skipCache bool) ([]string, error) {
i, err := h.GetIndexInfo(repoURL, skipCache)
func (h *Helper) ListChartsFromRepo(repoURL string, skipCache bool, opts *common.HTTPOption) ([]string, error) {
i, err := h.GetIndexInfo(repoURL, skipCache, opts)
if err != nil {
return nil, err
}
@@ -315,13 +315,13 @@ func (h *Helper) ListChartsFromRepo(repoURL string, skipCache bool) ([]string, e
}
// GetValuesFromChart will extract the parameter from a helm chart
func (h *Helper) GetValuesFromChart(repoURL string, chartName string, version string, skipCache bool) (map[string]interface{}, error) {
func (h *Helper) GetValuesFromChart(repoURL string, chartName string, version string, skipCache bool, opts *common.HTTPOption) (map[string]interface{}, error) {
if h.cache != nil && !skipCache {
if v := h.cache.Get(fmt.Sprintf(valuesPatten, repoURL, chartName, version)); v != nil {
return v.(map[string]interface{}), nil
}
}
i, err := h.GetIndexInfo(repoURL, skipCache)
i, err := h.GetIndexInfo(repoURL, skipCache, opts)
if err != nil {
return nil, err
}
@@ -336,7 +336,7 @@ func (h *Helper) GetValuesFromChart(repoURL string, chartName string, version st
}
}
for _, u := range urls {
c, err := h.LoadCharts(u)
c, err := h.LoadCharts(u, opts)
if err != nil {
continue
}
+55 -5
View File
@@ -17,12 +17,20 @@ limitations under the License.
package helm
import (
"context"
"os"
"github.com/google/go-cmp/cmp"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/google/go-cmp/cmp"
v1 "k8s.io/api/core/v1"
v12 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/yaml"
types2 "github.com/oam-dev/kubevela/apis/types"
util2 "github.com/oam-dev/kubevela/pkg/oam/util"
"github.com/oam-dev/kubevela/pkg/utils/util"
)
@@ -30,7 +38,7 @@ var _ = Describe("Test helm helper", func() {
It("Test LoadCharts ", func() {
helper := NewHelper()
chart, err := helper.LoadCharts("./testdata/autoscalertrait-0.1.0.tgz")
chart, err := helper.LoadCharts("./testdata/autoscalertrait-0.1.0.tgz", nil)
Expect(err).Should(BeNil())
Expect(chart).ShouldNot(BeNil())
Expect(chart.Metadata).ShouldNot(BeNil())
@@ -39,7 +47,7 @@ var _ = Describe("Test helm helper", func() {
It("Test UpgradeChart", func() {
helper := NewHelper()
chart, err := helper.LoadCharts("./testdata/autoscalertrait-0.1.0.tgz")
chart, err := helper.LoadCharts("./testdata/autoscalertrait-0.1.0.tgz", nil)
Expect(err).Should(BeNil())
release, err := helper.UpgradeChart(chart, "autoscalertrait", "default", nil, UpgradeChartOptions{
Config: cfg,
@@ -60,15 +68,57 @@ var _ = Describe("Test helm helper", func() {
It("Test ListVersions ", func() {
helper := NewHelper()
versions, err := helper.ListVersions("./testdata", "autoscalertrait", true)
versions, err := helper.ListVersions("./testdata", "autoscalertrait", true, nil)
Expect(err).Should(BeNil())
Expect(cmp.Diff(len(versions), 2)).Should(BeEmpty())
})
It("Test getValues from chart", func() {
helper := NewHelper()
values, err := helper.GetValuesFromChart("./testdata", "autoscalertrait", "0.2.0", true)
values, err := helper.GetValuesFromChart("./testdata", "autoscalertrait", "0.2.0", true, nil)
Expect(err).Should(BeNil())
Expect(values).ShouldNot(BeEmpty())
})
})
var _ = Describe("Test helm associated func", func() {
ctx := context.Background()
var aSec v1.Secret
BeforeEach(func() {
Expect(k8sClient.Create(ctx, &v1.Namespace{ObjectMeta: v12.ObjectMeta{Name: "vela-system"}})).Should(SatisfyAny(BeNil(), util2.AlreadyExistMatcher{}))
aSec = v1.Secret{}
Expect(yaml.Unmarshal([]byte(authSecret), &aSec)).Should(BeNil())
Expect(k8sClient.Create(ctx, &aSec)).Should(SatisfyAny(BeNil(), util2.AlreadyExistMatcher{}))
})
It("Test auth info secret func", func() {
opts, err := SetBasicAuthInfo(context.Background(), k8sClient, types.NamespacedName{Namespace: types2.DefaultKubeVelaNS, Name: "auth-secret"})
Expect(err).Should(BeNil())
Expect(opts.Username).Should(BeEquivalentTo("admin"))
Expect(opts.Password).Should(BeEquivalentTo("admin"))
})
It("Test auth info secret func", func() {
_, err := SetBasicAuthInfo(context.Background(), k8sClient, types.NamespacedName{Namespace: types2.DefaultKubeVelaNS, Name: "auth-secret-1"})
Expect(err).ShouldNot(BeNil())
})
})
var (
authSecret = `
apiVersion: v1
kind: Secret
metadata:
name: auth-secret
namespace: vela-system
labels:
config.oam.dev/type: config-helm-repository
config.oam.dev/project: my-project-1
stringData:
url: https://kedacore.github.io/charts
username: admin
password: admin
type: Opaque
`
)
+7
View File
@@ -21,14 +21,18 @@ import (
"testing"
"time"
"github.com/oam-dev/kubevela/pkg/utils/common"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/client-go/rest"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
)
var cfg *rest.Config
var k8sClient client.Client
var testEnv *envtest.Environment
var _ = BeforeSuite(func(done Done) {
@@ -47,6 +51,9 @@ var _ = BeforeSuite(func(done Done) {
Expect(err).ShouldNot(HaveOccurred())
Expect(cfg).ToNot(BeNil())
k8sClient, err = client.New(cfg, client.Options{Scheme: common.Scheme})
Expect(err).Should(BeNil())
Expect(k8sClient).ToNot(BeNil())
close(done)
}, 240)
+1 -1
View File
@@ -165,7 +165,7 @@ func NewVersionListCommand(ioStream util.IOStreams) *cobra.Command {
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
helmHelper := helm.NewHelper()
versions, err := helmHelper.ListVersions(kubevelaInstallerHelmRepoURL, kubeVelaChartName, true)
versions, err := helmHelper.ListVersions(kubevelaInstallerHelmRepoURL, kubeVelaChartName, true, nil)
if err != nil {
return err
}
+1 -1
View File
@@ -108,7 +108,7 @@ func getPrompt(cmd *cobra.Command, reader *bufio.Reader, description string, pro
func loadYAMLBytesFromFileOrHTTP(pathOrURL string) ([]byte, error) {
if strings.HasPrefix(pathOrURL, "http://") || strings.HasPrefix(pathOrURL, "https://") {
return common.HTTPGet(context.Background(), pathOrURL)
return common.HTTPGetWithOption(context.Background(), pathOrURL, nil)
}
return os.ReadFile(path.Clean(pathOrURL))
}
+1 -1
View File
@@ -106,7 +106,7 @@ func NewInstallCommand(c common.Args, order string, ioStreams util.IOStreams) *c
if installArgs.ChartFilePath == "" {
installArgs.ChartFilePath = getKubeVelaHelmChartRepoURL(installArgs.Version)
}
chart, err := installArgs.helmHelper.LoadCharts(installArgs.ChartFilePath)
chart, err := installArgs.helmHelper.LoadCharts(installArgs.ChartFilePath, nil)
if err != nil {
return fmt.Errorf("loadding the helm chart of kubeVela control plane failure, %w", err)
}
+1 -1
View File
@@ -257,7 +257,7 @@ func ReadRemoteOrLocalPath(pathOrURL string) ([]byte, error) {
var body []byte
var err error
if utils.IsValidURL(pathOrURL) {
body, err = common.HTTPGet(context.Background(), pathOrURL)
body, err = common.HTTPGetWithOption(context.Background(), pathOrURL, nil)
if err != nil {
return nil, err
}
+1 -1
View File
@@ -270,7 +270,7 @@ func HandleTemplate(in *runtime.RawExtension, schematic *commontypes.Schematic,
}
}
if tmp.CueTemplateURI != "" {
b, err := common.HTTPGet(context.Background(), tmp.CueTemplateURI)
b, err := common.HTTPGetWithOption(context.Background(), tmp.CueTemplateURI, nil)
if err != nil {
return types.Capability{}, err
}