Skip to content
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

Merged
merged 8 commits into from Sep 7, 2020

Conversation

rahulchheda
Copy link

@rahulchheda rahulchheda commented Apr 9, 2020

ISSUE TYPE
  • Feature Pull Request
  • Bug fix Pull Request
  • Docs Pull Request

Feature Pull Request

SUMMARY
- 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

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

@rahulchheda rahulchheda changed the title (feat) Creation of SharedInformer from Dynamic ClientSet [WIP] (feat) Creation of SharedInformer from Dynamic ClientSet Apr 9, 2020
pkg/utils/utils.go Outdated Show resolved Hide resolved
@rahulchheda rahulchheda force-pushed the dynamicInformer branch 2 times, most recently from 0c5c579 to 1642253 Compare April 13, 2020 22:42
pkg/controller/controller.go Outdated Show resolved Hide resolved
@@ -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)
Copy link
Collaborator

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/utils/utils.go Show resolved Hide resolved
pkg/utils/utils.go Outdated Show resolved Hide resolved
Comment on lines 9 to 30
//auth package for GCP
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
Copy link
Collaborator

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, let me check.

Copy link
Collaborator

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 Show resolved Hide resolved
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))
Copy link
Collaborator

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)?

Copy link
Author

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.

pkg/filterengine/filters/utils.go Outdated Show resolved Hide resolved
pkg/utils/utils.go Outdated Show resolved Hide resolved
pkg/utils/utils.go Outdated Show resolved Hide resolved
pkg/utils/utils.go Outdated Show resolved Hide resolved
pkg/utils/utils.go Outdated Show resolved Hide resolved
pkg/utils/utils.go Show resolved Hide resolved
pkg/utils/utils.go Outdated Show resolved Hide resolved
@PrasadG193 PrasadG193 added this to In progress in v1.0.0 May 9, 2020
@PrasadG193 PrasadG193 moved this from In progress to Review in progress in v1.0.0 May 9, 2020
@PrasadG193
Copy link
Collaborator

@rahulchheda did you get a chance to look at the review comments?

@rahulchheda
Copy link
Author

@PrasadG193 Can you start resolving the comments that are fixed, might help me in keeping a track of those.
Thanks.

pkg/controller/controller.go Outdated Show resolved Hide resolved
}
eventObj, ok := obj.(*coreV1.Event)
if !ok {
//log.Logger.Infof("Printing Event Object: %v", eventObj)
Copy link
Collaborator

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/controller/controller.go Outdated Show resolved Hide resolved
pkg/events/events.go Outdated Show resolved Hide resolved
replicationController = "v1/replicationcontrollers"
daemonSet = "apps/v1/daemonsets"
clusterRole = "rbac.authorization.k8s.io/v1/clusterroles"
)
Copy link
Collaborator

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

pkg/utils/utils.go Show resolved Hide resolved
test/fake_resource_config.yaml Outdated Show resolved Hide resolved
@PrasadG193
Copy link
Collaborator

@rahulchheda Please rebase with develop so that it can run CI against GitHub actions

@rahulchheda
Copy link
Author

Added an example CR in resource_config.yaml to test out the changes install their respective CRD's from here: docs.litmuschaos.io

@PrasadG193
Copy link
Collaborator

@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

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()
Copy link
Collaborator

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

Suggested change
unstructuredObject := obj.(*unstructured.Unstructured).DeepCopy()
unstructuredObject, ok := obj.(*unstructured.Unstructured)
if !ok {
// log and return
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not resolved yet.

typeMeta = object.TypeMeta
case *rbacV1.ClusterRoleBinding:
typeMeta = object.TypeMeta
k := obj.(*unstructured.Unstructured)
Copy link
Collaborator

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

resource_config.yaml Outdated Show resolved Hide resolved
test/resource_config.yaml Outdated Show resolved Hide resolved
@PrasadG193
Copy link
Collaborator

@rahulchheda Please have a look at CI failures. Let me know if you have any doubts

@rahulchheda rahulchheda changed the title [WIP] (feat) Creation of SharedInformer from Dynamic ClientSet (feat.) creation of SharedInformer from Dynamic ClientSet Jun 13, 2020
@PrasadG193
Copy link
Collaborator

@rahulchheda Please updated deploy-all-in-one*.yaml and helm chart as per the new config syntax

@PrasadG193
Copy link
Collaborator

@rahulchheda Could you please also confirm if we are able to monitor custom resource events?
Ideally, we should add a test case in our e2e test framework.

@PrasadG193 PrasadG193 added this to In progress in v0.11.0 via automation Aug 3, 2020
@PrasadG193 PrasadG193 removed this from Review in progress in v1.0.0 Aug 3, 2020
@PrasadG193 PrasadG193 removed this from In progress in v0.11.0 Aug 3, 2020
    - 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>
@PrasadG193
Copy link
Collaborator

@rahulchheda The build is failing. Can you please take a look?

Rahul M Chheda added 2 commits September 5, 2020 23:47
Signed-off-by: Rahul M Chheda <rchheda@infracloud.io>
…o dynamicInformer

Signed-off-by: Rahul M Chheda <rchheda@infracloud.io>
@PrasadG193
Copy link
Collaborator

@rahulchheda Have you tested this with Custom Resource? Are we able to monitor CRs?

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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not resolved yet.

resource_config.yaml Show resolved Hide resolved
resource_config.yaml Outdated Show resolved Hide resolved
resource_config.yaml Outdated Show resolved Hide resolved
test/resource_config.yaml Outdated Show resolved Hide resolved
pkg/config/config.go Outdated Show resolved Hide resolved
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should log here

resource_config.yaml Outdated Show resolved Hide resolved
test/e2e/env/env.go Outdated Show resolved Hide resolved
test/resource_config.yaml Outdated Show resolved Hide resolved
@PrasadG193
Copy link
Collaborator

Let's merge this now and address pending items in the followup.

Things to address:

  • Pending review comments from this PR
  • Add e2e test for Custom Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support to monitor custom resources
2 participants