-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Watch of Velero Backup and remove Backup controller
Change which removes Backup Controller and adds the Watch of the Backup object within NonAdminBackup Controller. Added two main predicates with 'upper' logic within composite predicate to easily distinguish between predicate for NonAdminBackup and the Backup one. The reconcile loop updates the Status and the Spec of the NonAdminBackup from the Velero Backup object. The Spec in the Velero Backup is updated by the Velero, so we use similar logic to update our NonAdminBackup one. Signed-off-by: Michal Pryc <[email protected]>
- Loading branch information
Showing
11 changed files
with
301 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,6 @@ rules: | |
- backups | ||
verbs: | ||
- create | ||
- delete | ||
- get | ||
- list | ||
- patch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// composite_predicate.go | ||
|
||
package controller | ||
|
||
import ( | ||
"context" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/event" | ||
) | ||
|
||
type CompositePredicate struct { | ||
NonAdminBackupPredicate NonAdminBackupPredicate | ||
VeleroBackupPredicate VeleroBackupPredicate | ||
Context context.Context | ||
} | ||
|
||
func (p CompositePredicate) Create(evt event.CreateEvent) bool { | ||
// If NonAdminBackupPredicate returns true, ignore VeleroBackupPredicate | ||
if p.NonAdminBackupPredicate.Create(p.Context, evt) { | ||
return true | ||
} | ||
// Otherwise, apply VeleroBackupPredicate | ||
return p.VeleroBackupPredicate.Create(p.Context, evt) | ||
} | ||
|
||
func (p CompositePredicate) Update(evt event.UpdateEvent) bool { | ||
// If NonAdminBackupPredicate returns true, ignore VeleroBackupPredicate | ||
if p.NonAdminBackupPredicate.Update(p.Context, evt) { | ||
return true | ||
} | ||
// Otherwise, apply VeleroBackupPredicate | ||
return p.VeleroBackupPredicate.Update(p.Context, evt) | ||
} | ||
|
||
func (p CompositePredicate) Delete(evt event.DeleteEvent) bool { | ||
// If NonAdminBackupPredicate returns true, ignore VeleroBackupPredicate | ||
if p.NonAdminBackupPredicate.Delete(p.Context, evt) { | ||
return true | ||
} | ||
// Otherwise, apply VeleroBackupPredicate | ||
return p.VeleroBackupPredicate.Delete(p.Context, evt) | ||
} | ||
|
||
func (p CompositePredicate) Generic(evt event.GenericEvent) bool { | ||
// If NonAdminBackupPredicate returns true, ignore VeleroBackupPredicate | ||
if p.NonAdminBackupPredicate.Generic(p.Context, evt) { | ||
return true | ||
} | ||
// Otherwise, apply VeleroBackupPredicate | ||
return p.VeleroBackupPredicate.Generic(p.Context, evt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// velerobackup_predicate.go | ||
|
||
package controller | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-logr/logr" | ||
nacv1alpha1 "github.com/migtools/oadp-non-admin/api/v1alpha1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/event" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
) | ||
|
||
type NonAdminBackupPredicate struct { | ||
Logger logr.Logger | ||
} | ||
|
||
func getNonAdminBackupPredicateLogger(ctx context.Context, name, namespace string) logr.Logger { | ||
return log.FromContext(ctx).WithValues("NonAdminBackupPredicate", types.NamespacedName{Name: name, Namespace: namespace}) | ||
} | ||
|
||
func (predicate NonAdminBackupPredicate) Create(ctx context.Context, evt event.CreateEvent) bool { | ||
|
||
if _, ok := evt.Object.(*nacv1alpha1.NonAdminBackup); ok { | ||
nameSpace := evt.Object.GetNamespace() | ||
name := evt.Object.GetName() | ||
log := getNonAdminBackupPredicateLogger(ctx, name, nameSpace) | ||
log.V(1).Info("Received Create NonAdminBackupPredicate") | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
func (predicate NonAdminBackupPredicate) Update(ctx context.Context, evt event.UpdateEvent) bool { | ||
if _, ok := evt.ObjectNew.(*nacv1alpha1.NonAdminBackup); ok { | ||
nameSpace := evt.ObjectNew.GetNamespace() | ||
name := evt.ObjectNew.GetName() | ||
log := getNonAdminBackupPredicateLogger(ctx, name, nameSpace) | ||
log.V(1).Info("Received Update NonAdminBackupPredicate") | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func (predicate NonAdminBackupPredicate) Delete(ctx context.Context, evt event.DeleteEvent) bool { | ||
if _, ok := evt.Object.(*nacv1alpha1.NonAdminBackup); ok { | ||
nameSpace := evt.Object.GetNamespace() | ||
name := evt.Object.GetName() | ||
log := getNonAdminBackupPredicateLogger(ctx, name, nameSpace) | ||
log.V(1).Info("Received Delete NonAdminBackupPredicate") | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func (predicate NonAdminBackupPredicate) Generic(ctx context.Context, evt event.GenericEvent) bool { | ||
if _, ok := evt.Object.(*nacv1alpha1.NonAdminBackup); ok { | ||
nameSpace := evt.Object.GetNamespace() | ||
name := evt.Object.GetName() | ||
log := getNonAdminBackupPredicateLogger(ctx, name, nameSpace) | ||
log.V(1).Info("Received Generic NonAdminBackupPredicate") | ||
return true | ||
} | ||
return false | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.