-
Notifications
You must be signed in to change notification settings - Fork 71
Fix service delete event #255
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,24 +28,48 @@ func NewEqueueRequestServiceEvent(client client.Client) handler.EventHandler { | |
| } | ||
|
|
||
| func (h *enqueueRequetsForServiceEvent) Create(e event.CreateEvent, queue workqueue.RateLimitingInterface) { | ||
| glog.V(6).Info("Event: service create") | ||
| service := e.Object.(*corev1.Service) | ||
| h.enqueueImpactedService(queue, service) | ||
| h.enqueueImpactedServiceExport(queue, service) | ||
| } | ||
|
|
||
| func (h *enqueueRequetsForServiceEvent) Update(e event.UpdateEvent, queue workqueue.RateLimitingInterface) { | ||
| } | ||
|
|
||
| func (h *enqueueRequetsForServiceEvent) Delete(e event.DeleteEvent, queue workqueue.RateLimitingInterface) { | ||
| glog.V(6).Info("Event: service delete") | ||
| service := e.Object.(*corev1.Service) | ||
| h.enqueueImpactedService(queue, service) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
| h.enqueueImpactedServiceExport(queue, service) | ||
| } | ||
|
|
||
| func (h *enqueueRequetsForServiceEvent) Generic(e event.GenericEvent, queue workqueue.RateLimitingInterface) { | ||
|
|
||
| } | ||
|
|
||
| func (h *enqueueRequetsForServiceEvent) enqueueImpactedService(queue workqueue.RateLimitingInterface, ep *corev1.Service) { | ||
| glog.V(6).Infof("Event: enqueueImpactedService: %v\n", ep) | ||
|
|
||
| srv := &corev1.Service{} | ||
| namespacedName := types.NamespacedName{ | ||
| Namespace: ep.Namespace, | ||
| Name: ep.Name, | ||
| } | ||
|
|
||
| if err := h.client.Get(context.TODO(), namespacedName, srv); err != nil { | ||
| glog.V(6).Infof("Event: enqueueImpactedService, service not found %v\n", err) | ||
| return | ||
| } | ||
|
|
||
| queue.Add(reconcile.Request{ | ||
| NamespacedName: namespacedName, | ||
| }) | ||
|
|
||
| } | ||
|
|
||
| func (h *enqueueRequetsForServiceEvent) enqueueImpactedServiceExport(queue workqueue.RateLimitingInterface, ep *corev1.Service) { | ||
| glog.V(6).Infof("enqueueImpactedServiceExport: %v\n", ep) | ||
| glog.V(6).Infof("Event: enqueueImpactedServiceExport: %v\n", ep) | ||
|
|
||
| srvExport := &mcs_api.ServiceExport{} | ||
| namespacedName := types.NamespacedName{ | ||
|
|
@@ -54,7 +78,7 @@ func (h *enqueueRequetsForServiceEvent) enqueueImpactedServiceExport(queue workq | |
| } | ||
|
|
||
| if err := h.client.Get(context.TODO(), namespacedName, srvExport); err != nil { | ||
| glog.V(6).Infof("enqueueImpactedServiceExport, serviceexport not found %v\n", err) | ||
| glog.V(6).Infof("Event: enqueueImpactedServiceExport, serviceexport not found %v\n", err) | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -91,7 +115,7 @@ func (h *enqueueHTTPRequetsForServiceEvent) Generic(e event.GenericEvent, queue | |
| } | ||
|
|
||
| func (h *enqueueHTTPRequetsForServiceEvent) enqueueImpactedHTTPRoute(queue workqueue.RateLimitingInterface, ep *corev1.Service) { | ||
| glog.V(6).Infof("enqueueImpactedHTTPRoute: %v\n", ep) | ||
| glog.V(6).Infof("Event: enqueueImpactedHTTPRoute: %v\n", ep) | ||
|
|
||
| httpRouteList := &gateway_api.HTTPRouteList{} | ||
|
|
||
|
|
@@ -101,7 +125,7 @@ func (h *enqueueHTTPRequetsForServiceEvent) enqueueImpactedHTTPRoute(queue workq | |
| if !isServiceUsedByHTTPRoute(httpRoute, ep) { | ||
| continue | ||
| } | ||
| glog.V(6).Infof("enqueueImpactedHTTPRoute --> httproute %v \n", httpRoute) | ||
| glog.V(6).Infof("Event: enqueueImpactedHTTPRoute --> httproute %v \n", httpRoute) | ||
| namespacedName := types.NamespacedName{ | ||
| Namespace: httpRoute.Namespace, | ||
| Name: httpRoute.Name, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |
| "context" | ||
| "fmt" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/golang/mock/gomock" | ||
| "github.com/stretchr/testify/assert" | ||
|
|
@@ -26,6 +27,7 @@ func Test_Targets(t *testing.T) { | |
| srvExportName string | ||
| srvExportNamespace string | ||
| endPoints []corev1.Endpoints | ||
| svc corev1.Service | ||
| inDataStore bool | ||
| refByServiceExport bool | ||
| refByService bool | ||
|
|
@@ -50,6 +52,13 @@ func Test_Targets(t *testing.T) { | |
| }, | ||
| }, | ||
| }, | ||
| svc: corev1.Service{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Namespace: "ns1", | ||
| Name: "export1", | ||
| DeletionTimestamp: nil, | ||
| }, | ||
| }, | ||
| inDataStore: true, | ||
| refByServiceExport: true, | ||
| wantErrIsNil: true, | ||
|
|
@@ -72,6 +81,57 @@ func Test_Targets(t *testing.T) { | |
| }, | ||
| }, | ||
| }, | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a unit test to test service delete ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unit test is covered at line 85-115
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, can u add a new test for just service add without HTTProute stuff...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created issue for adding e2etest: #257 |
||
| name: "Delete svc and all endpoints to build spec", | ||
| srvExportName: "export1", | ||
| srvExportNamespace: "ns1", | ||
| endPoints: []corev1.Endpoints{ | ||
| { | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Namespace: "ns1", | ||
| Name: "export1", | ||
| }, | ||
| Subsets: []corev1.EndpointSubset{ | ||
| { | ||
| Addresses: []corev1.EndpointAddress{{IP: "10.10.1.1"}, {IP: "10.10.2.2"}}, | ||
| Ports: []corev1.EndpointPort{{Name: "a", Port: 8675}, {Name: "b", Port: 309}}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| svc: corev1.Service{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Namespace: "ns1", | ||
| Name: "export1", | ||
| DeletionTimestamp: &metav1.Time{ | ||
| Time: time.Now(), | ||
| }, | ||
| }, | ||
| }, | ||
| inDataStore: true, | ||
| refByServiceExport: true, | ||
| wantErrIsNil: true, | ||
| expectedTargetList: nil, | ||
| }, | ||
| { | ||
| name: "Delete svc and no endpoints to build spec", | ||
| srvExportName: "export1", | ||
| srvExportNamespace: "ns1", | ||
| endPoints: []corev1.Endpoints{}, | ||
| svc: corev1.Service{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Namespace: "ns1", | ||
| Name: "export1", | ||
| DeletionTimestamp: &metav1.Time{ | ||
| Time: time.Now(), | ||
| }, | ||
| }, | ||
| }, | ||
| inDataStore: true, | ||
| refByServiceExport: true, | ||
| wantErrIsNil: true, | ||
| expectedTargetList: nil, | ||
| }, | ||
| { | ||
| name: "Endpoints without TargetGroup", | ||
| srvExportName: "export2", | ||
|
|
@@ -90,6 +150,13 @@ func Test_Targets(t *testing.T) { | |
| }, | ||
| }, | ||
| }, | ||
| svc: corev1.Service{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Namespace: "ns1", | ||
| Name: "export1", | ||
| DeletionTimestamp: nil, | ||
| }, | ||
| }, | ||
| inDataStore: false, | ||
| refByServiceExport: true, | ||
| wantErrIsNil: false, | ||
|
|
@@ -112,6 +179,13 @@ func Test_Targets(t *testing.T) { | |
| }, | ||
| }, | ||
| }, | ||
| svc: corev1.Service{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Namespace: "ns1", | ||
| Name: "export1", | ||
| DeletionTimestamp: nil, | ||
| }, | ||
| }, | ||
| inDataStore: true, | ||
| refByServiceExport: false, | ||
| refByService: false, | ||
|
|
@@ -124,6 +198,13 @@ func Test_Targets(t *testing.T) { | |
| inDataStore: false, | ||
| refByServiceExport: true, | ||
| wantErrIsNil: false, | ||
| svc: corev1.Service{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Namespace: "ns1", | ||
| Name: "export1", | ||
| DeletionTimestamp: nil, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| name: "Add all endpoints to build spec", | ||
|
|
@@ -143,6 +224,13 @@ func Test_Targets(t *testing.T) { | |
| }, | ||
| }, | ||
| }, | ||
| svc: corev1.Service{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Namespace: "ns1", | ||
| Name: "export5", | ||
| DeletionTimestamp: nil, | ||
| }, | ||
| }, | ||
| inDataStore: true, | ||
| refByService: true, | ||
| wantErrIsNil: true, | ||
|
|
@@ -180,6 +268,8 @@ func Test_Targets(t *testing.T) { | |
| assert.NoError(t, k8sClient.Create(ctx, tt.endPoints[0].DeepCopy())) | ||
| } | ||
|
|
||
| assert.NoError(t, k8sClient.Create(ctx, tt.svc.DeepCopy())) | ||
|
|
||
| ds := latticestore.NewLatticeDataStore() | ||
|
|
||
| if tt.inDataStore { | ||
|
|
||
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.
being consistent , can we add glog.V(6) here