mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
refactor extend trait feature and doc
Signed-off-by: 天元 <jianbo.sjb@alibaba-inc.com>
This commit is contained in:
@@ -33,7 +33,6 @@ import (
|
||||
|
||||
"github.com/oam-dev/kubevela/api/types"
|
||||
cmdutil "github.com/oam-dev/kubevela/pkg/commands/util"
|
||||
"github.com/oam-dev/kubevela/pkg/oam"
|
||||
"github.com/oam-dev/kubevela/pkg/utils/helm"
|
||||
)
|
||||
|
||||
@@ -48,7 +47,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
helmInstallFunc = oam.InstallHelmChart
|
||||
helmInstallFunc = helm.InstallHelmChart
|
||||
}
|
||||
|
||||
// Setup vela dependency.
|
||||
@@ -66,7 +65,7 @@ func Install(kubecli client.Client) {
|
||||
return
|
||||
}
|
||||
for key, chart := range velaConfig.Data {
|
||||
err := installHelmChart(kubecli, []byte(chart), log)
|
||||
err := installHelmChart([]byte(chart), log)
|
||||
if err != nil {
|
||||
log.Error(err, fmt.Sprintf("failed to install helm chart for %s", key))
|
||||
}
|
||||
@@ -103,7 +102,7 @@ func fetchVelaConfig(kubecli client.Client) (*v1.ConfigMap, error) {
|
||||
return velaConfig, nil
|
||||
}
|
||||
|
||||
func installHelmChart(client client.Client, chart []byte, log logr.Logger) error {
|
||||
func installHelmChart(chart []byte, log logr.Logger) error {
|
||||
ioStreams := cmdutil.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}
|
||||
var helmChart types.Chart
|
||||
err := json.Unmarshal(chart, &helmChart)
|
||||
@@ -111,20 +110,6 @@ func installHelmChart(client client.Client, chart []byte, log logr.Logger) error
|
||||
return errors.Wrap(err, "failed to unmarshal the helm chart data")
|
||||
}
|
||||
log.Info("installing helm chart", "chart name", helmChart.Name)
|
||||
// create the namespace
|
||||
if helmChart.Namespace != types.DefaultAppNamespace {
|
||||
if len(helmChart.Namespace) > 0 {
|
||||
exist, err := cmdutil.DoesNamespaceExist(client, helmChart.Namespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exist {
|
||||
if err = cmdutil.NewNamespace(client, helmChart.Namespace); err != nil {
|
||||
return fmt.Errorf("create namespace (%s) failed for chart %s", helmChart.Namespace, helmChart.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err = helmInstallFunc(ioStreams, helmChart); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,12 +5,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
crdv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||
|
||||
"github.com/oam-dev/kubevela/api/types"
|
||||
"github.com/oam-dev/kubevela/api/v1alpha1"
|
||||
@@ -18,29 +15,8 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
scheme *runtime.Scheme
|
||||
errHelm = fmt.Errorf("err")
|
||||
velaConfigBase = v1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: VelaConfigName,
|
||||
Namespace: types.DefaultOAMNS,
|
||||
Labels: map[string]string{"vela": "dependency"},
|
||||
},
|
||||
Data: map[string]string{
|
||||
"certificates.cert-manager.io": `{
|
||||
"repo": "jetstack",
|
||||
"urL": "https://charts.jetstack.io",
|
||||
"name": "cert-manager",
|
||||
"version": "v1.0.0"
|
||||
}`,
|
||||
"prometheuses.monitoring.coreos.com": `{
|
||||
"repo": "jetstack",
|
||||
"urL": "https://charts.jetstack.io",
|
||||
"name": "cert-manager",
|
||||
"version": "v1.0.0"
|
||||
}`,
|
||||
},
|
||||
}
|
||||
scheme *runtime.Scheme
|
||||
errHelm = fmt.Errorf("err")
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -52,23 +28,14 @@ func init() {
|
||||
|
||||
func TestSuccessfulInstall(t *testing.T) {
|
||||
helmInstallFunc = successHelmInstall
|
||||
velaConfig := velaConfigBase.DeepCopy()
|
||||
crd := crdv1.CustomResourceDefinition{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "certificates.cert-manager.io",
|
||||
},
|
||||
}
|
||||
client := fake.NewFakeClientWithScheme(scheme, velaConfig, &crd)
|
||||
if err := installHelmChart(client, []byte("{}"), log); err != nil {
|
||||
if err := installHelmChart([]byte("{}"), log); err != nil {
|
||||
t.Errorf("failed to install dependency error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailedInstall(t *testing.T) {
|
||||
helmInstallFunc = failedHelmInstall
|
||||
velaConfig := velaConfigBase.DeepCopy()
|
||||
client := fake.NewFakeClientWithScheme(scheme, velaConfig)
|
||||
if err := installHelmChart(client, []byte("{}"), log); errors.Cause(err) != errHelm {
|
||||
if err := installHelmChart([]byte("{}"), log); errors.Cause(err) != errHelm {
|
||||
t.Errorf("failed to get install dependency error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user