-
Notifications
You must be signed in to change notification settings - Fork 326
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
Endpoints controller with tests #455
Endpoints controller with tests #455
Conversation
9390339
to
affaf94
Compare
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.
This looks really good so far Nitya!! I do want to give it one more pass cuz it is complicated (not the code, mostly just the number of things it has to manage)!!
return ctrl.Result{}, err | ||
} | ||
|
||
r.Log.Info("retrieved service from kube", "serviceEndpoints", serviceEndpoints) |
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.
The whole serviceEndpoints object shouldn't be logged here, just the name, same for other logs. Make sure to decide what should be Debug vs Info. Should info logs log every reconcile or only debug?
return ctrl.Result{}, err | ||
} | ||
|
||
r.Log.Info("retrieved service from kube", "serviceEndpoints", serviceEndpoints) |
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.
I changed it to "retrieved Kubernetes Endpoints" since it's the endpoints object
10900d1
to
752eca4
Compare
* supports using serviceName annotation (different k8s service name) * supports using servicePort annotation * supports creating endpoints (with serviceName annotation) * supports updating endpoints (adding and removing addresses) * supports deleting endpoints (with different k8s service name) todo: * tags, meta, and upstreams from annotations + tests * cleaning up and refactoring code to run the endpoints controller with manager * deleting old service registration * testing with new connect-init command * testing end to end Co-authored-by: Iryna Shustava <[email protected]> Co-authored-by: Kyle Schochenmaier <[email protected]>
deregistration to use catalog api rather than agent api
* they needed the auth plugin import: _ "k8s.io/client-go/plugin/pkg/client/auth" * kubernetes/client-go#242
Todos left: * remove service name default annotation * make inject-connect unit tests pass without a kubeconfig * end to end testing
method. This way, additional edge case logic can be tested separately, rather than in TestReconcileCreateEndpoint.
This will be a part of a future PR that enables endpoints-controller and removes the old method of service registration.
752eca4
to
715854a
Compare
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.
Looking great!! Awesome work thinking through all the test case scenarios!
I've left some comments and questions, let me know what you think!
// "k8s-service-name". So, we query Consul services by "k8s-service-name" metadata, which is only exposed on the agent | ||
// API. Therefore, we need to query all agents who have services matching that metadata, and deregister each service | ||
// instance. When querying by the k8s service name and namespace, the request will return service instances and | ||
// associated proxy service instances. |
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.
great job on this func and the comments!! It was very easy to read!
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.
HARD AGREE
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.
Ok i gave this a thorough code review!! left a bunch of suggestions. Most of them are random tidy ups and some of them are questions.
I haven't actually run this but im guessing that will be within the scope of the glue PR.
Im ok with this getting merged when the suggestions and open comments have been resolved!!
This is excellent work @ndhanushkodi and the code is really easy to read for the nature of the complexity it is trying to solve!! Love the comments as well!! Amazing job overall!!
// "k8s-service-name". So, we query Consul services by "k8s-service-name" metadata, which is only exposed on the agent | ||
// API. Therefore, we need to query all agents who have services matching that metadata, and deregister each service | ||
// instance. When querying by the k8s service name and namespace, the request will return service instances and | ||
// associated proxy service instances. |
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.
HARD AGREE
if _, ok := endpointsAddressesMap[serviceRegistration.Address]; !ok { | ||
// If the service address is not in the Endpoints addresses, deregister it. | ||
if err = client.Agent().ServiceDeregister(svcID); err != nil { | ||
r.Log.Error(err, "failed to deregister service instance", "consul-service-id", svcID) |
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 we create a constant for "consul-service-id"
?
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.
It seems a little strange to me to make it a const since it's just a key in the log. Basically I am not sure what I would call the const to have it be more readable than the string "consul-service-id".
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.
Looks great!!
// Get the tags from the deprecated tags annotation and combine. | ||
if raw, ok := pod.Annotations[annotationConnectTags]; ok && raw != "" { | ||
tags = append(tags, strings.Split(raw, ",")...) | ||
} |
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.
It looks like the annotation was renamed in #141, and we've kept both names for backward compatibility. Since this is meant to be a refactor I think we can keep it. It seems relatively cheap to maintain.
Add basic endpoints controller with tests * reconciles k8s services with Consul * supports creating, updating, and deleting endpoints, both with matching Consul and k8s service names, and with different Consul and k8s service names Co-authored-by: Iryna Shustava <[email protected]> Co-authored-by: Kyle Schochenmaier <[email protected]>
Add basic endpoints controller with tests * reconciles k8s services with Consul * supports creating, updating, and deleting endpoints, both with matching Consul and k8s service names, and with different Consul and k8s service names Co-authored-by: Iryna Shustava <[email protected]> Co-authored-by: Kyle Schochenmaier <[email protected]>
Add basic endpoints controller with tests * reconciles k8s services with Consul * supports creating, updating, and deleting endpoints, both with matching Consul and k8s service names, and with different Consul and k8s service names Co-authored-by: Iryna Shustava <[email protected]> Co-authored-by: Kyle Schochenmaier <[email protected]>
0.21.0 release
The endpoints controller and test code is ready for review.
The only things expected to change at this point are code and tests in handler (to remove always setting the service-name annotation) and inject-connect (to get the command unit tests to pass since the manager takes a kubeconfig that's hard to fake out).
Changes in this PR:
Todos:
Future PR:
Co-authored-by: Iryna Shustava [email protected]
Co-authored-by: Kyle Schochenmaier [email protected]
How I've tested this PR:
How I expect reviewers to test this PR:
Checklist: