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

Add watcher for agent pods to endpoints controller #457

Merged
merged 1 commit into from
Mar 23, 2021

Conversation

thisisnotashwin
Copy link
Contributor

@thisisnotashwin thisisnotashwin commented Mar 17, 2021

Changes proposed in this PR:

  • This watcher watches for Consul Agent pods to be in a running phase and the condition ready to be true and then reconcile all endpoints that have a ready/not-ready address that share a node name with that of the consul agent pod.

How I've tested this PR:

  • Unit tests
  • Iryna tested it

How I expect reviewers to test this PR:

  • Code review

Will link an acceptance test run to show that behavior hasnt been impacted.

Checklist:

  • Tests added
  • CHANGELOG entry added (HashiCorp engineers only, community PRs should not add a changelog entry)

@thisisnotashwin thisisnotashwin force-pushed the reconcile-on-running-agent-pods branch from 65d5dca to ffc5ea1 Compare March 17, 2021 20:56
Copy link
Contributor

@ishustava ishustava left a comment

Choose a reason for hiding this comment

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

Looks great!! I've left some minor comments, but nothing blocking.

Re acceptance test, I think we'd need to write a new one for this case (currently we're not testing it). I think it's ok for it to come after the PR is merged, but it's up to you. I think we just need to make sure we have coverage before we merge the feature branch.

connect-inject/endpoints_controller.go Outdated Show resolved Hide resolved
connect-inject/endpoints_controller.go Outdated Show resolved Hide resolved
connect-inject/endpoints_controller.go Outdated Show resolved Hide resolved
connect-inject/endpoints_controller.go Outdated Show resolved Hide resolved
connect-inject/endpoints_controller.go Outdated Show resolved Hide resolved
connect-inject/endpoints_controller_test.go Show resolved Hide resolved
connect-inject/endpoints_controller_test.go Show resolved Hide resolved
connect-inject/endpoints_controller.go Outdated Show resolved Hide resolved
connect-inject/endpoints_controller_test.go Show resolved Hide resolved
@thisisnotashwin thisisnotashwin force-pushed the webhook-refactor branch 2 times, most recently from 6f5f8e7 to 2d1c75b Compare March 18, 2021 14:18
@thisisnotashwin thisisnotashwin force-pushed the reconcile-on-running-agent-pods branch from ffc5ea1 to 22a35ba Compare March 18, 2021 15:59
Copy link
Contributor

@ndhanushkodi ndhanushkodi left a comment

Choose a reason for hiding this comment

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

Great work Ashwin, it was really well structured, and the unit tests have great coverage and are easy to understand! I had a few nitpicky comment-related suggestions, and please to feel free to pick and choose which ones you like and ignore ones you don't!

connect-inject/endpoints_controller.go Outdated Show resolved Hide resolved
connect-inject/endpoints_controller.go Outdated Show resolved Hide resolved
connect-inject/endpoints_controller.go Outdated Show resolved Hide resolved
connect-inject/endpoints_controller.go Outdated Show resolved Hide resolved
connect-inject/endpoints_controller_test.go Show resolved Hide resolved
connect-inject/endpoints_controller.go Outdated Show resolved Hide resolved
@thisisnotashwin thisisnotashwin force-pushed the webhook-refactor branch 2 times, most recently from 9b36f01 to c2c32fb Compare March 23, 2021 14:21
- This watcher watches for Consul Agent pods to be in a running phase
  and the condition ready to be true and then reconcile all endpoints
that have a ready/not-ready address that share a node name with that of
the consul agent pod.
@thisisnotashwin thisisnotashwin force-pushed the reconcile-on-running-agent-pods branch from 22a35ba to b75098e Compare March 23, 2021 14:33
@thisisnotashwin thisisnotashwin merged commit 9504d0d into webhook-refactor Mar 23, 2021
@thisisnotashwin thisisnotashwin deleted the reconcile-on-running-agent-pods branch March 23, 2021 19:13
// which in this case are Pods. It only returns true if the Pod is a Consul Client Agent Pod. It reads the labels
// from the meta of the resource and uses the values of the "app" and "component" label to validate that
// the Pod is a Consul Client Agent.
func (r EndpointsController) filterAgentPods(meta metav1.Object, object runtime.Object) bool {
Copy link
Member

Choose a reason for hiding this comment

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

@thisisnotashwin These should be function pointers I think: r *EndpointsController

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry for the late response. They don't seem to use any values from the r struct. this might be something I dont quite understand here but why would it need to be a function pointer?

Copy link
Member

Choose a reason for hiding this comment

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

Just because the other functions in this struct do use the struct pointer so these should be consistent. Or if they're not accessing anything on the struct they could be functions instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is a good point. i looked at the other method and i think it does make sense to use pointers to keep them consistent. plus i could add some logging here just for some added information in which case i can use the logger from the struct! good catch!

Comment on lines +396 to +400
Watches(
&source.Kind{Type: &corev1.Pod{}},
&handler.EnqueueRequestsFromMapFunc{ToRequests: handler.ToRequestsFunc(r.requestsForRunningAgentPods)},
builder.WithPredicates(predicate.NewPredicateFuncs(r.filterAgentPods)),
).Complete(r)
Copy link
Member

Choose a reason for hiding this comment

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

woah this is fancy! Cool!

kschoche added a commit that referenced this pull request Apr 8, 2021
Remove the cleanup controller and replace it with the supporting logic from #457.
ishustava pushed a commit that referenced this pull request Apr 14, 2021
Remove the cleanup controller and replace it with the supporting logic from #457.
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.

5 participants