From d9302ff98299fa013d9b84bf55a4c8737f5d460a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E5=85=83?= Date: Wed, 14 Oct 2020 22:47:58 +0800 Subject: [PATCH] add args for vela install and fix E2E with fresh image build --- .github/workflows/e2e.yml | 3 +++ Makefile | 5 +++++ cmd/core/main.go | 2 ++ e2e/cli.go | 2 -- pkg/commands/system.go | 40 +++++++++++++++++++++++++++++++++++---- 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index a3373096b..82b16df13 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -34,6 +34,9 @@ jobs: with: version: "v0.7.0" + - name: Load Image to kind cluster + run: make kind-load + - name: install Kubebuilder uses: RyanSiu1995/kubebuilder-action@v1 diff --git a/Makefile b/Makefile index 88d9c7088..7be0e491d 100644 --- a/Makefile +++ b/Makefile @@ -76,6 +76,7 @@ docker-push: docker push ${IMG} e2e-setup: + bin/vela install --image-pull-policy IfNotPresent --image-repo vela-core-test --image-tag $(GIT_COMMIT) ginkgo version ginkgo -v -r e2e/setup kubectl wait --for=condition=Ready pod -l app.kubernetes.io/name=vela-core,app.kubernetes.io/instance=kubevela -n vela-system --timeout=600s @@ -92,6 +93,10 @@ e2e-api-test: e2e-cleanup: # Clean up +# load docker image to the kind cluster +kind-load: + docker build -t vela-core-test:$(GIT_COMMIT) . + kind load docker-image vela-core-test:$(GIT_COMMIT) || { echo >&2 "kind not installed or error loading image: $(IMAGE)"; exit 1; } # Image URL to use all building/pushing image targets IMG ?= vela-core:latest diff --git a/cmd/core/main.go b/cmd/core/main.go index 5ce720909..5090dd876 100644 --- a/cmd/core/main.go +++ b/cmd/core/main.go @@ -31,6 +31,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/log/zap" + velacoreoamdev "github.com/oam-dev/kubevela/api/core.oam.dev/v1alpha2" velacore "github.com/oam-dev/kubevela/api/v1alpha1" velacontroller "github.com/oam-dev/kubevela/pkg/controller" "github.com/oam-dev/kubevela/pkg/controller/dependency" @@ -54,6 +55,7 @@ func init() { _ = oamcore.AddToScheme(scheme) _ = monitoring.AddToScheme(scheme) _ = velacore.AddToScheme(scheme) + _ = velacoreoamdev.AddToScheme(scheme) _ = injectorv1alpha1.AddToScheme(scheme) _ = certmanager.AddToScheme(scheme) diff --git a/e2e/cli.go b/e2e/cli.go index 856fc7060..db4b7a4b6 100644 --- a/e2e/cli.go +++ b/e2e/cli.go @@ -85,8 +85,6 @@ func InteractiveExec(cli string, consoleFn func(*expect.Console)) (string, error } func BeforeSuit() { - _, err := Exec("vela install") - gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) //Without this line, will hit issue like `: Error: unknown command "scale" for "vela"` _, _ = Exec("vela system update") } diff --git a/pkg/commands/system.go b/pkg/commands/system.go index e98deeb90..5a6ced86b 100644 --- a/pkg/commands/system.go +++ b/pkg/commands/system.go @@ -10,6 +10,7 @@ import ( "github.com/spf13/cobra" "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart/loader" + "helm.sh/helm/v3/pkg/strvals" "sigs.k8s.io/controller-runtime/pkg/client" "github.com/oam-dev/kubevela/api/types" @@ -22,6 +23,13 @@ type initCmd struct { ioStreams cmdutil.IOStreams client client.Client chartPath string + chartArgs chartArgs +} + +type chartArgs struct { + imageRepo string + imageTag string + imagePullPolicy string } type infoCmd struct { @@ -92,6 +100,9 @@ func NewInstallCommand(c types.Args, chartContent string, ioStreams cmdutil.IOSt flag := cmd.Flags() flag.StringVarP(&i.chartPath, "vela-chart-path", "p", "", "path to vela core chart to override default chart") + flag.StringVarP(&i.chartArgs.imagePullPolicy, "image-pull-policy", "", "Always", "vela core image pull policy, this will align to chart value image.pullPolicy") + flag.StringVarP(&i.chartArgs.imageRepo, "image-repo", "", "oamdev/vela-core", "vela core image repo, this will align to chart value image.repo") + flag.StringVarP(&i.chartArgs.imageTag, "image-tag", "", "latest", "vela core image repo, this will align to chart value image.tag") return cmd } @@ -112,7 +123,12 @@ func (i *initCmd) run(ioStreams cmdutil.IOStreams, chartSource string) error { if oam.IsHelmReleaseRunning(types.DefaultOAMReleaseName, types.DefaultOAMRuntimeChartName, i.ioStreams) { i.ioStreams.Info("Vela system along with OAM runtime already exist.") } else { - if err := InstallOamRuntime(i.chartPath, chartSource, ioStreams); err != nil { + vals, err := i.resolveValues() + if err != nil { + i.ioStreams.Errorf("resolve values for vela-core chart err %v, will install with default values", err) + vals = make(map[string]interface{}) + } + if err := InstallOamRuntime(i.chartPath, chartSource, vals, ioStreams); err != nil { return err } } @@ -124,7 +140,24 @@ func (i *initCmd) run(ioStreams cmdutil.IOStreams, chartSource string) error { return nil } -func InstallOamRuntime(chartPath, chartSource string, ioStreams cmdutil.IOStreams) error { +func (i *initCmd) resolveValues() (map[string]interface{}, error) { + finalValues := map[string]interface{}{} + valuesConfig := []string{ + //TODO(wonderflow) values here could give more arguments in command line + fmt.Sprintf("image.repository=%s", i.chartArgs.imageRepo), + fmt.Sprintf("image.tag=%s", i.chartArgs.imageTag), + fmt.Sprintf("image.pullPolicy=%s", i.chartArgs.imagePullPolicy), + } + for _, val := range valuesConfig { + // parses Helm strvals line and merges into a map for the final overrides for values.yaml + if err := strvals.ParseInto(val, finalValues); err != nil { + return nil, err + } + } + return finalValues, nil +} + +func InstallOamRuntime(chartPath, chartSource string, vals map[string]interface{}, ioStreams cmdutil.IOStreams) error { var err error var chartRequested *chart.Chart if chartPath != "" { @@ -143,8 +176,7 @@ func InstallOamRuntime(chartPath, chartSource string, ioStreams cmdutil.IOStream if err != nil { return fmt.Errorf("error create helm install client: %s", err) } - //TODO(wonderflow) values here could give more arguments in command line - release, err := installClient.Run(chartRequested, nil) + release, err := installClient.Run(chartRequested, vals) if err != nil { ioStreams.Errorf("Failed to install the chart with error: %+v\n", err) return err