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

pkg/server/api: Add /healthz for load-balancer health checks #239

Closed
wants to merge 2 commits into from

Commits on Dec 19, 2018

  1. pkg/server: Trim public API to return *http.Server

    The previous API required consumers to construct a handler and pass
    that handler back into a separate function to create a server based on
    the handler.  With this commit, I've rerolled the API to return the
    handler directly, and the new public API is just NewBootstrapServer
    and NewClusterServer.  To serve both HTTP and HTTPS from the returned
    server, I'm making shallow copies and altering Addr to set the
    per-protocol ports in those copies.
    
    I've also made some "server" -> "config" renames in the types that
    have getConfig methods.  And APIHandler is now configHandler.  That
    helps consolidate the /config/* handling under a consistent name, so
    we have:
    
    * An http.Server that is the server (e.g. as returned by
      NewClusterServer).
    * That server's handler is a muxer, and one of the muxer handlers is
      the configHandler for /config/*.
    * The configHandler structure holds a getConfig function, and we have
      bootstrapConfig and clusterConfig which can supply getConfig.  Using
      a function type for this avoids the need for an interface and mock
      getConfig type.
    
    The defaultHandler gives us our usual empty 404s for requests that
    don't match our other handlers.  Without it, we'd have returned Go's
    default:
    
      404 page not found
    
    body, and had unit-test failures like:
    
      --- FAIL: TestHandler (0.00s)
          --- FAIL: TestHandler/GET_/does-not-exist (0.00s)
              api_test.go:93: response body length 19 does not match Content-Length -1
    wking committed Dec 19, 2018
    Configuration menu
    Copy the full SHA
    6cfa51c View commit details
    Browse the repository at this point in the history
  2. pkg/server/api: Add /healthz for load-balancer health checks

    The server currently 404s the root path.  From a master:
    
      [core@ip-10-0-26-134 ~]$ curl -ik https://wking-api.devcluster.openshift.com:49500/
      HTTP/1.1 404 Not Found
      Content-Type: text/plain; charset=utf-8
      X-Content-Type-Options: nosniff
      Date: Sun, 16 Dec 2018 06:30:14 GMT
      Content-Length: 19
    
      404 page not found
    
    but we need a reliable response on the range 200-399 to satisfy our
    network load balancer health checks, which do not support configurable
    response status codes [1,2] (these are Terraform links, but they
    discuss an AWS restriction that is not Terraform-specific).  This
    commit adds a /healthz endpoint which always 204s (when the server is
    alive to handle it).
    
    [1]: hashicorp/terraform-provider-aws#2708 (comment)
    [2]: https://github.com/terraform-providers/terraform-provider-aws/pull/2906/files#diff-375aea487c27a6ada86edfd817ba2401R612
    wking committed Dec 19, 2018
    Configuration menu
    Copy the full SHA
    50f1439 View commit details
    Browse the repository at this point in the history