add args for vela install and fix E2E with fresh image build

This commit is contained in:
天元 2020-10-14 22:47:58 +08:00
parent 3751b98e7a
commit d9302ff982
5 changed files with 46 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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 `<string>: Error: unknown command "scale" for "vela"`
_, _ = Exec("vela system update")
}

View File

@ -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