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

🌱 Pass Object's GVK version when reconcile. #1570

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Pass Object's GVK version when reconcile.
  • Loading branch information
haosdent committed Jun 27, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit c35caf628d79e90f4fea9088c243cc7d0537f571
55 changes: 35 additions & 20 deletions pkg/handler/enqueue.go
Original file line number Diff line number Diff line change
@@ -41,25 +41,34 @@ func (e *EnqueueRequestForObject) Create(evt event.CreateEvent, q workqueue.Rate
enqueueLog.Error(nil, "CreateEvent received with no metadata", "event", evt)
return
}
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
Name: evt.Object.GetName(),
Namespace: evt.Object.GetNamespace(),
}})
q.Add(reconcile.Request{
NamespacedName: types.NamespacedName{
Name: evt.Object.GetName(),
Namespace: evt.Object.GetNamespace(),
},
GroupVersionKind: evt.Object.GetObjectKind().GroupVersionKind(),
})
}

// Update implements EventHandler.
func (e *EnqueueRequestForObject) Update(evt event.UpdateEvent, q workqueue.RateLimitingInterface) {
switch {
case evt.ObjectNew != nil:
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
Name: evt.ObjectNew.GetName(),
Namespace: evt.ObjectNew.GetNamespace(),
}})
q.Add(reconcile.Request{
NamespacedName: types.NamespacedName{
Name: evt.ObjectNew.GetName(),
Namespace: evt.ObjectNew.GetNamespace(),
},
GroupVersionKind: evt.ObjectNew.GetObjectKind().GroupVersionKind(),
})
case evt.ObjectOld != nil:
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
Name: evt.ObjectOld.GetName(),
Namespace: evt.ObjectOld.GetNamespace(),
}})
q.Add(reconcile.Request{
NamespacedName: types.NamespacedName{
Name: evt.ObjectOld.GetName(),
Namespace: evt.ObjectOld.GetNamespace(),
},
GroupVersionKind: evt.ObjectOld.GetObjectKind().GroupVersionKind(),
})
default:
enqueueLog.Error(nil, "UpdateEvent received with no metadata", "event", evt)
}
@@ -71,10 +80,13 @@ func (e *EnqueueRequestForObject) Delete(evt event.DeleteEvent, q workqueue.Rate
enqueueLog.Error(nil, "DeleteEvent received with no metadata", "event", evt)
return
}
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
Name: evt.Object.GetName(),
Namespace: evt.Object.GetNamespace(),
}})
q.Add(reconcile.Request{
NamespacedName: types.NamespacedName{
Name: evt.Object.GetName(),
Namespace: evt.Object.GetNamespace(),
},
GroupVersionKind: evt.Object.GetObjectKind().GroupVersionKind(),
})
}

// Generic implements EventHandler.
@@ -83,8 +95,11 @@ func (e *EnqueueRequestForObject) Generic(evt event.GenericEvent, q workqueue.Ra
enqueueLog.Error(nil, "GenericEvent received with no metadata", "event", evt)
return
}
q.Add(reconcile.Request{NamespacedName: types.NamespacedName{
Name: evt.Object.GetName(),
Namespace: evt.Object.GetNamespace(),
}})
q.Add(reconcile.Request{
NamespacedName: types.NamespacedName{
Name: evt.Object.GetName(),
Namespace: evt.Object.GetNamespace(),
},
GroupVersionKind: evt.Object.GetObjectKind().GroupVersionKind(),
})
}
13 changes: 10 additions & 3 deletions pkg/handler/enqueue_owner.go
Original file line number Diff line number Diff line change
@@ -134,9 +134,16 @@ func (e *EnqueueRequestForOwner) getOwnerReconcileRequest(object metav1.Object,
// object in the event.
if ref.Kind == e.groupKind.Kind && refGV.Group == e.groupKind.Group {
// Match found - add a Request for the object referred to in the OwnerReference
request := reconcile.Request{NamespacedName: types.NamespacedName{
Name: ref.Name,
}}
request := reconcile.Request{
NamespacedName: types.NamespacedName{
Name: ref.Name,
},
GroupVersionKind: schema.GroupVersionKind{
Group: refGV.Group,
Version: refGV.Version,
Kind: ref.Kind,
},
}

// if owner is not namespaced then we should set the namespace to the empty
mapping, err := e.mapper.RESTMapping(e.groupKind, refGV.Version)
2 changes: 2 additions & 0 deletions pkg/reconcile/reconcile.go
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ import (
"context"
"time"

"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
)

@@ -47,6 +48,7 @@ func (r *Result) IsZero() bool {
type Request struct {
// NamespacedName is the name and namespace of the object to reconcile.
types.NamespacedName
schema.GroupVersionKind
}

/*