Skip to content

Commit

Permalink
Feat: add controller version in backup controller (#114)
Browse files Browse the repository at this point in the history
Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>

Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
  • Loading branch information
FogDong committed Jan 11, 2023
1 parent ad226c2 commit 555573c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ func main() {
os.Exit(1)
}
if err = (&controllers.BackupReconciler{
Client: kubeClient,
Scheme: mgr.GetScheme(),
Client: kubeClient,
Scheme: mgr.GetScheme(),
ControllerVersion: version.VelaVersion,
BackupArgs: controllers.BackupArgs{
BackupStrategy: backupStrategy,
IgnoreStrategy: backupIgnoreStrategy,
Expand Down
20 changes: 19 additions & 1 deletion controllers/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import (
// BackupReconciler reconciles a WorkflowRun object
type BackupReconciler struct {
client.Client
Scheme *runtime.Scheme
Scheme *runtime.Scheme
ControllerVersion string
BackupArgs
Args
}
Expand Down Expand Up @@ -87,6 +88,11 @@ func (r *BackupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
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
}

if !run.Status.Finished {
logCtx.Info("WorkflowRun is not finished, skip reconcile")
return ctrl.Result{}, nil
Expand Down Expand Up @@ -144,6 +150,18 @@ func (r *BackupReconciler) backup(ctx monitorContext.Context, cli client.Client,
return nil
}

func (r *BackupReconciler) 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 *BackupReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
Expand Down

0 comments on commit 555573c

Please sign in to comment.