diff --git a/.github/workflows/chart.yaml b/.github/workflows/chart.yaml index f88b765..7bd9b08 100644 --- a/.github/workflows/chart.yaml +++ b/.github/workflows/chart.yaml @@ -24,6 +24,7 @@ jobs: else echo ::set-output name=TAG::${GITHUB_REF#refs/tags/} fi + echo ::set-output name=GITVERSION::git-$(git rev-parse --short HEAD) - name: Login Docker Hub uses: docker/login-action@v1 with: @@ -46,6 +47,8 @@ jobs: push: ${{ github.event_name != 'pull_request' }} build-args: | GOPROXY=https://proxy.golang.org + VERSION=${{ steps.vars.outputs.TAG }} + GIT_VERSION=${{ steps.vars.outputs.GITVERSION }} tags: |- docker.io/oamdev/vela-workflow:${{ steps.vars.outputs.TAG }} diff --git a/Dockerfile b/Dockerfile index e7da2e3..d97eeea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,9 +20,10 @@ COPY version/ version/ # Build ARG TARGETARCH - +ARG VERSION +ARG GITVERSION RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} \ - go build -a -ldflags "-s -w" \ + go build -a -ldflags "-s -w -X github.com/kubevela/workflow/version.VelaVersion=${VERSION:-undefined} -X github.com/kubevela/workflow/version.GitRevision=${GITVERSION:-undefined}" \ -o vela-workflow-${TARGETARCH} cmd/main.go FROM ${BASE_IMAGE:-alpine:3.15} diff --git a/charts/vela-workflow/templates/workflow-controller.yaml b/charts/vela-workflow/templates/workflow-controller.yaml index 8851c56..01b689b 100644 --- a/charts/vela-workflow/templates/workflow-controller.yaml +++ b/charts/vela-workflow/templates/workflow-controller.yaml @@ -125,6 +125,7 @@ spec: - "--leader-elect" - "--health-probe-bind-address=:{{ .Values.healthCheck.port }}" - "--concurrent-reconciles={{ .Values.concurrentReconciles }}" + - "--ignore-workflow-without-controller-requirement={{ .Values.ignoreWorkflowWithoutControllerRequirement }}" - "--kube-api-qps={{ .Values.kubeClient.qps }}" - "--kube-api-burst={{ .Values.kubeClient.burst }}" - "--max-workflow-wait-backoff-time={{ .Values.workflow.backoff.maxTime.waitState }}" diff --git a/charts/vela-workflow/values.yaml b/charts/vela-workflow/values.yaml index a5eaa17..d0a4d45 100644 --- a/charts/vela-workflow/values.yaml +++ b/charts/vela-workflow/values.yaml @@ -9,6 +9,8 @@ systemDefinitionNamespace: ## @param concurrentReconciles concurrentReconciles is the concurrent reconcile number of the controller concurrentReconciles: 4 +## @param ignoreWorkflowWithoutControllerRequirement will determine whether to process the workflowrun without 'workflowrun.oam.dev/controller-version-require' annotation +ignoreWorkflowWithoutControllerRequirement: false ## @section KubeVela workflow parameters diff --git a/cmd/main.go b/cmd/main.go index 75bd0de..b9bc86d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -95,6 +95,7 @@ func main() { "The duration the LeaderElector clients should wait between tries of actions") flag.IntVar(&webhookPort, "webhook-port", 9443, "admission webhook listen address") flag.IntVar(&controllerArgs.ConcurrentReconciles, "concurrent-reconciles", 4, "concurrent-reconciles is the concurrent reconcile number of the controller. The default value is 4") + flag.BoolVar(&controllerArgs.IgnoreWorkflowWithoutControllerRequirement, "ignore-workflow-without-controller-requirement", false, "If true, workflow controller will not process the workflowrun without 'workflowrun.oam.dev/controller-version-require' annotation") flag.Float64Var(&qps, "kube-api-qps", 50, "the qps for reconcile clients. Low qps may lead to low throughput. High qps may give stress to api-server. Raise this value if concurrent-reconciles is set to be high.") flag.IntVar(&burst, "kube-api-burst", 100, "the burst for reconcile clients. Recommend setting it qps*2.") flag.StringVar(&pprofAddr, "pprof-addr", "", "The address for pprof to use while exporting profiling results. The default value is empty which means do not expose it. Set it to address like :6666 to expose it.") @@ -201,11 +202,12 @@ func main() { kubeClient := mgr.GetClient() if err = (&controllers.WorkflowRunReconciler{ - Client: kubeClient, - Scheme: mgr.GetScheme(), - PackageDiscover: pd, - Recorder: event.NewAPIRecorder(mgr.GetEventRecorderFor("WorkflowRun")), - Args: controllerArgs, + Client: kubeClient, + Scheme: mgr.GetScheme(), + PackageDiscover: pd, + Recorder: event.NewAPIRecorder(mgr.GetEventRecorderFor("WorkflowRun")), + ControllerVersion: version.VelaVersion, + Args: controllerArgs, }).SetupWithManager(mgr); err != nil { klog.Error(err, "unable to create controller", "controller", "WorkflowRun") os.Exit(1) diff --git a/controllers/workflowrun_controller.go b/controllers/workflowrun_controller.go index 096972f..8f4585e 100644 --- a/controllers/workflowrun_controller.go +++ b/controllers/workflowrun_controller.go @@ -49,14 +49,17 @@ import ( type Args struct { // ConcurrentReconciles is the concurrent reconcile number of the controller ConcurrentReconciles int + // IgnoreWorkflowWithoutControllerRequirement indicates that workflow controller will not process the workflowrun without 'workflowrun.oam.dev/controller-version-require' annotation. + IgnoreWorkflowWithoutControllerRequirement bool } // WorkflowRunReconciler reconciles a WorkflowRun object type WorkflowRunReconciler struct { client.Client - Scheme *runtime.Scheme - PackageDiscover *packages.PackageDiscover - Recorder event.Recorder + Scheme *runtime.Scheme + PackageDiscover *packages.PackageDiscover + Recorder event.Recorder + ControllerVersion string Args } @@ -90,6 +93,11 @@ func (r *WorkflowRunReconciler) Reconcile(ctx context.Context, req ctrl.Request) return ctrl.Result{}, client.IgnoreNotFound(err) } + if !r.matchControllerRequirement(run) { + logCtx.Info("skip workflowrun: not match the controller requirement of workflowrun") + return ctrl.Result{}, nil + } + timeReporter := timeReconcile(run) defer timeReporter() @@ -163,6 +171,18 @@ func (r *WorkflowRunReconciler) Reconcile(ctx context.Context, req ctrl.Request) return ctrl.Result{}, nil } +func (r *WorkflowRunReconciler) matchControllerRequirement(wr *v1alpha1.WorkflowRun) bool { + if wr.Annotations != nil { + if requireVersion, ok := wr.Annotations[types.AnnotationControllerRequirement]; ok { + return requireVersion == r.ControllerVersion + } + } + if r.IgnoreWorkflowWithoutControllerRequirement { + return false + } + return true +} + // SetupWithManager sets up the controller with the Manager. func (r *WorkflowRunReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). diff --git a/e2e/definition_test.go b/e2e/definition_test.go index 6db085c..23d8915 100644 --- a/e2e/definition_test.go +++ b/e2e/definition_test.go @@ -21,7 +21,6 @@ import ( "os" "time" - "github.com/kubevela/workflow/api/v1alpha1" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" @@ -30,7 +29,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/yaml" - "github.com/oam-dev/kubevela/pkg/oam/util" + "github.com/kubevela/workflow/api/v1alpha1" + "github.com/kubevela/workflow/pkg/utils" ) var _ = Describe("Test the workflow run with the built-in definitions", func() { @@ -45,7 +45,7 @@ var _ = Describe("Test the workflow run with the built-in definitions", func() { Eventually(func() error { return k8sClient.Create(ctx, &ns) - }, time.Second*3, time.Microsecond*300).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{})) + }, time.Second*3, time.Microsecond*300).Should(SatisfyAny(BeNil(), &utils.AlreadyExistMatcher{})) }) It("Test the workflow with config definition", func() { diff --git a/makefiles/const.mk b/makefiles/const.mk index 91ad725..7a3d77a 100644 --- a/makefiles/const.mk +++ b/makefiles/const.mk @@ -47,8 +47,8 @@ VELA_VERSION ?= master # Repo info GIT_COMMIT ?= git-$(shell git rev-parse --short HEAD) GIT_COMMIT_LONG ?= $(shell git rev-parse HEAD) -VELA_VERSION_KEY := github.com/oam-dev/kubevela/version.VelaVersion -VELA_GITVERSION_KEY := github.com/oam-dev/kubevela/version.GitRevision +VELA_VERSION_KEY := github.com/kubevela/workflow/version.VelaVersion +VELA_GITVERSION_KEY := github.com/kubevela/workflow/version.GitRevision LDFLAGS ?= "-s -w -X $(VELA_VERSION_KEY)=$(VELA_VERSION) -X $(VELA_GITVERSION_KEY)=$(GIT_COMMIT)" diff --git a/pkg/types/types.go b/pkg/types/types.go index 4325117..6d759b4 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -276,6 +276,8 @@ const ( const ( // AnnotationWorkflowRunDebug is the annotation for debug AnnotationWorkflowRunDebug = "workflowrun.oam.dev/debug" + // AnnotationControllerRequirement indicates the controller version that can process the workflow run + AnnotationControllerRequirement = "workflowrun.oam.dev/controller-version-require" ) // IsStepFinish will decide whether step is finish.