MCPcopy Create free account
hub / github.com/FairwindsOps/gemini / NewController

Function NewController

pkg/controller/controller.go:73–101  ·  view source on GitHub ↗

NewController creates a new SnapshotGroup controller

()

Source from the content-addressed store, hash-verified

71
72// NewController creates a new SnapshotGroup controller
73func 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
103func (c *Controller) enqueue(sg interface{}, todo task) {
104 acc, _ := meta.Accessor(sg)

Callers 2

mainFunction · 0.92
newTestControllerFunction · 0.85

Calls 5

enqueueMethod · 0.95
GetClientFunction · 0.92
getRateLimiterFunction · 0.85
ListerMethod · 0.65
InformerMethod · 0.65

Tested by 1

newTestControllerFunction · 0.68