New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(feat.) creation of SharedInformer from Dynamic ClientSet #253
Conversation
0c5c579
to
1642253
Compare
pkg/controller/controller.go
Outdated
@@ -125,6 +125,7 @@ func registerEventHandlers(c *config.Config, notifiers []notify.Notifier, resour | |||
func sendEvent(obj, oldObj interface{}, c *config.Config, notifiers []notify.Notifier, kind string, eventType config.EventType) { | |||
// Filter namespaces | |||
objectMeta := utils.GetObjectMetaData(obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can get object name and namespace with unstructured.GetName()
and unstructured.GetNamespace()
pkg/config/config.go
Outdated
//auth package for GCP | ||
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please check if it increases binary size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, let me check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rahulchheda Please revert this if not sure about the binary size
pkg/controller/controller.go
Outdated
if err != nil { | ||
log.Logger.Errorf("Failed to get MetaNamespaceKey from event resource") | ||
return | ||
log.Logger.Errorf("Unable to tranform object type: %v, into type: %v", reflect.TypeOf(obj), reflect.TypeOf(eventObj)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we return from here?
Also could you please check what will be the behaviour if we try to register informer on unregistered resource (for eg custom resource without CRD)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, let me create such a scenario.
@rahulchheda did you get a chance to look at the review comments? |
@PrasadG193 Can you start resolving the comments that are fixed, might help me in keeping a track of those. |
pkg/controller/controller.go
Outdated
} | ||
eventObj, ok := obj.(*coreV1.Event) | ||
if !ok { | ||
//log.Logger.Infof("Printing Event Object: %v", eventObj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove commented code
pkg/utils/utils.go
Outdated
replicationController = "v1/replicationcontrollers" | ||
daemonSet = "apps/v1/daemonsets" | ||
clusterRole = "rbac.authorization.k8s.io/v1/clusterroles" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can get GVR info from event.InvolvedObject. Since it is of type ObjectReference (https://godoc.org/k8s.io/api/core/v1#ObjectReference). One of our goals is to remove the hardcoded mappings like this so that we support any k8s resource including Custom Resources
@rahulchheda Please rebase with develop so that it can run CI against GitHub actions |
808d355
to
d17fdbe
Compare
Added an example CR in |
@rahulchheda Please don't force push. It becomes hard to check if the comments are resolved or not. We anyways squash all into one while merging |
pkg/utils/utils.go
Outdated
objectMeta = object.ObjectMeta | ||
// pass InvolvedObject`s annotations into Event`s annotations | ||
// for filtering event objects based on InvolvedObject`s annotations | ||
unstructuredObject := obj.(*unstructured.Unstructured).DeepCopy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check if assertion is possible first, otherwise, this would cause panic
unstructuredObject := obj.(*unstructured.Unstructured).DeepCopy() | |
unstructuredObject, ok := obj.(*unstructured.Unstructured) | |
if !ok { | |
// log and return | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not resolved yet.
pkg/utils/utils.go
Outdated
typeMeta = object.TypeMeta | ||
case *rbacV1.ClusterRoleBinding: | ||
typeMeta = object.TypeMeta | ||
k := obj.(*unstructured.Unstructured) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check if assertion is possible for safety
@rahulchheda Please have a look at CI failures. Let me know if you have any doubts |
@rahulchheda Please updated deploy-all-in-one*.yaml and helm chart as per the new config syntax |
@rahulchheda Could you please also confirm if we are able to monitor custom resource events? |
- Added creation of Dynamic ClientSet - Replaced the current k8s resources to DynamicInformer - Added logic to create metav1.ObjectMeta/ metav1.TypeMeta from obj interface{} - Added GKE auth pkg - Modified fns to get ObjectMeta, and ObjectTypeMeta - Added function to create *coreV1.Event from the obj interface{} - Improved switch case for event.New() - Added for loop to create informer - Changed Name for fn GetAnnotaion to GetAnnotationFromEvent - Changed Parsing Logic for GCR (using '/') - Added logic in FilterEngine, to get the appropriate data - Full deprecate kubeClient init - Added logic to fetch resources from DynamicKubeClient - Added a fn to transform a object form ibj interface{} - Added REST Mapper to map all resources present on the cluster - Declared this REST Mapper as global for further use - Removed logic to filter out the Kubernetes resources according to Involved Object kind - Removed constants from utils.go Signed-off-by: Rahul M Chheda <rchheda@infracloud.io>
Signed-off-by: Rahul M Chheda <rchheda@infracloud.io>
cdad04a
to
925f3cd
Compare
@rahulchheda The build is failing. Can you please take a look? |
Signed-off-by: Rahul M Chheda <rchheda@infracloud.io>
…o dynamicInformer Signed-off-by: Rahul M Chheda <rchheda@infracloud.io>
@rahulchheda Have you tested this with Custom Resource? Are we able to monitor CRs? |
pkg/utils/utils.go
Outdated
objectMeta = object.ObjectMeta | ||
// pass InvolvedObject`s annotations into Event`s annotations | ||
// for filtering event objects based on InvolvedObject`s annotations | ||
unstructuredObject := obj.(*unstructured.Unstructured).DeepCopy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not resolved yet.
Signed-off-by: Rahul M Chheda <rchheda@infracloud.io>
// pass InvolvedObject`s annotations into Event`s annotations | ||
// for filtering event objects based on InvolvedObject`s annotations | ||
unstructuredObject, ok := obj.(*unstructured.Unstructured) | ||
if !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should log here
Let's merge this now and address pending items in the followup. Things to address:
|
ISSUE TYPE
Feature Pull Request
SUMMARY
In the latest commit:
- To pass the e2e tests, just replaced all kubernetes resources informer, with dynamic informer.
- Unable to pass the e2e test suite (will paste the error in the comments.)
Fixes #200