NewController creates a new SnapshotGroup controller
()
| 71 | |
| 72 | // NewController creates a new SnapshotGroup controller |
| 73 | func NewController() *Controller { |
| 74 | client := kube.GetClient() |
| 75 | controller := &Controller{ |
| 76 | sgLister: client.Informer.Lister(), |
| 77 | sgSynced: client.Informer.Informer().HasSynced, |
| 78 | workqueue: workqueue.NewNamedRateLimitingQueue(getRateLimiter(), "SnapshotGroups"), |
| 79 | snapshotReadyTimeoutSeconds: defaultSnapshotReadyTimeoutSeconds, |
| 80 | } |
| 81 | client.Informer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ |
| 82 | AddFunc: func(sg interface{}) { |
| 83 | controller.enqueue(sg, backupTask) |
| 84 | }, |
| 85 | UpdateFunc: func(old, sg interface{}) { |
| 86 | oldAcc, _ := meta.Accessor(old) |
| 87 | newAcc, _ := meta.Accessor(sg) |
| 88 | oldRestore := oldAcc.GetAnnotations()[snapshots.RestoreAnnotation] |
| 89 | newRestore := newAcc.GetAnnotations()[snapshots.RestoreAnnotation] |
| 90 | if newRestore != "" && oldRestore != newRestore { |
| 91 | controller.enqueue(sg, restoreTask) |
| 92 | } else { |
| 93 | controller.enqueue(sg, backupTask) |
| 94 | } |
| 95 | }, |
| 96 | DeleteFunc: func(sg interface{}) { |
| 97 | controller.enqueue(sg, deleteTask) |
| 98 | }, |
| 99 | }) |
| 100 | return controller |
| 101 | } |
| 102 | |
| 103 | func (c *Controller) enqueue(sg interface{}, todo task) { |
| 104 | acc, _ := meta.Accessor(sg) |