-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Recreate gateway resources deleted during running phase * Move hasher to common * Delete gateway resources on spec change * Fix service update condition * Return error * Refactor common code * Handle resource change on error * Use slower rate limiter * Fix group version kind * Apply resource recreation to sensors * Fix state change condition * Add more tests * Remove unnecessary imports * Update Gopkg.lock * Fix tests * Add informer event tests * Compare GroupVersionKind instead of just Kind * Fix data race * Rename owner variables * Improve gateway resource update logic * Refactor the resource handling context * Refactor sensor resource context * Refactor gateway resource recreation * Improve sensor resource update logic * Fix state change condition * Improve error handling * Update types of resource specs * Set up containers surely * Fix wrong label and annotation names * Update sensor examples * Fix tests * Fix race condition * Improve fake controllers
- Loading branch information
1 parent
e362cbc
commit cb8ebd8
Showing
77 changed files
with
3,635 additions
and
1,164 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,86 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
|
||
"k8s.io/apimachinery/pkg/api/meta" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/client-go/informers" | ||
informersv1 "k8s.io/client-go/informers/core/v1" | ||
"k8s.io/client-go/tools/cache" | ||
"k8s.io/client-go/util/workqueue" | ||
) | ||
|
||
// ArgoEventInformerFactory holds values to create SharedInformerFactory of argo-events | ||
type ArgoEventInformerFactory struct { | ||
OwnerGroupVersionKind schema.GroupVersionKind | ||
OwnerInformer cache.SharedIndexInformer | ||
informers.SharedInformerFactory | ||
Queue workqueue.RateLimitingInterface | ||
} | ||
|
||
// NewPodInformer returns a PodInformer of argo-events | ||
func (c *ArgoEventInformerFactory) NewPodInformer() informersv1.PodInformer { | ||
podInformer := c.SharedInformerFactory.Core().V1().Pods() | ||
podInformer.Informer().AddEventHandler( | ||
cache.ResourceEventHandlerFuncs{ | ||
DeleteFunc: func(obj interface{}) { | ||
owner, err := c.getOwner(obj) | ||
if err != nil { | ||
return | ||
} | ||
key, err := cache.MetaNamespaceKeyFunc(owner) | ||
if err == nil { | ||
c.Queue.Add(key) | ||
} | ||
}, | ||
}, | ||
) | ||
return podInformer | ||
} | ||
|
||
// NewServiceInformer returns a ServiceInformer of argo-events | ||
func (c *ArgoEventInformerFactory) NewServiceInformer() informersv1.ServiceInformer { | ||
svcInformer := c.SharedInformerFactory.Core().V1().Services() | ||
svcInformer.Informer().AddEventHandler( | ||
cache.ResourceEventHandlerFuncs{ | ||
DeleteFunc: func(obj interface{}) { | ||
owner, err := c.getOwner(obj) | ||
if err != nil { | ||
return | ||
} | ||
key, err := cache.MetaNamespaceKeyFunc(owner) | ||
if err == nil { | ||
c.Queue.Add(key) | ||
} | ||
}, | ||
}, | ||
) | ||
return svcInformer | ||
} | ||
|
||
func (c *ArgoEventInformerFactory) getOwner(obj interface{}) (interface{}, error) { | ||
m, err := meta.Accessor(obj) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, owner := range m.GetOwnerReferences() { | ||
|
||
if owner.APIVersion == c.OwnerGroupVersionKind.GroupVersion().String() && | ||
owner.Kind == c.OwnerGroupVersionKind.Kind { | ||
key := owner.Name | ||
if len(m.GetNamespace()) > 0 { | ||
key = m.GetNamespace() + "/" + key | ||
} | ||
obj, exists, err := c.OwnerInformer.GetIndexer().GetByKey(key) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !exists { | ||
return nil, fmt.Errorf("failed to get object from cache") | ||
} | ||
return obj, nil | ||
} | ||
} | ||
return nil, fmt.Errorf("no owner found") | ||
} |
Oops, something went wrong.