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

✨ Export HTTP server manager runnable implementation #2473

Merged

Conversation

joelanford
Copy link
Member

In operator-framework, we have run into a few situations where we need to run a custom HTTP server inside a controller process. In order to decouple from assumptions made by the metrics server (which allows extra handlers to be added), we need a fully separate server. Since controller-runtime already has a generic HTTP server runnable for use with health probes and pprof handlers, it seems useful to export this implementation to users as well so that they can run their own HTTP servers without having to worry about implementing the manager.Runnable interface correctly.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 7, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: joelanford

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 7, 2023
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 7, 2023
@joelanford joelanford changed the title Export HTTP server manager runnable implementation ✨ Export HTTP server manager runnable implementation Sep 7, 2023
// among multiple servers.
Kind string

// Log is the logger used by the server. If not set, a logger will be derived from the context passed to Start.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not only have one way to pass it in?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to require a Server struct to be setup with a logger in advance. I don't have a strong opinion here though.

Copy link
Member

Choose a reason for hiding this comment

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

Could we remove the Log here, and just inherit the logger from Start?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was already present in the unexported server struct, so I wasn't going to change it.

There is existing code in the pprof and health probe server setup that explicitly sets the servers' logger to the controller manager's logger (which comes from manager.Options.Logger).

There's a bunch of context plumbing that makes it difficult to tell which contexts are used where, but I can't find anywhere that injects the controllerManager's logger into the context that is used to start the http servers.

We could potentially make a custom context with the logger injected and use that context just with the HTTPServers group to preserve existing behavior.

WDYT?

Copy link
Contributor

@stevekuznetsov stevekuznetsov left a comment

Choose a reason for hiding this comment

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

Looks good, some minor comments

pkg/manager/server.go Outdated Show resolved Hide resolved
Comment on lines +100 to +95
// NeedLeaderElection returns true if the server should only be started when the manager is the leader.
func (s *Server) NeedLeaderElection() bool {
return s.OnlyServeWhenLeader
}
Copy link
Member

Choose a reason for hiding this comment

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

Is there a use case for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

The use case I have in mind is when there is a strong coupling between what is being reconciled and what is being served. One example might be an API that represents OCI images, where creating an instance of that API makes the OCI image contents available as a tar archive via the HTTP server.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 22, 2023
@sbueringer
Copy link
Member

@joelanford Are you still interested in this PR?

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 2, 2024
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 3, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 3, 2024
…able

Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
@joelanford joelanford removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 4, 2024
Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

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

Just one nit, otherwise lgtm

pkg/manager/internal.go Show resolved Hide resolved
@sbueringer
Copy link
Member

/lgtm

Will fix the nit in a follow up

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 19, 2024
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 5e942e32c0322a50d35fbf4b19a3e60ef8e056b3

@k8s-ci-robot k8s-ci-robot merged commit e2191b5 into kubernetes-sigs:main Apr 19, 2024
9 checks passed
@joelanford joelanford deleted the export-runnable-server branch April 24, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants