122f7cffdb
Based on our experiences today with GKE, it will be easier for our users to configure Ingress health checks if the healthz endpoint is available on the same public port as the OIDC endpoints. Also add an integration test for the healthz endpoint now that it is public. Also add the optional `containers[].ports.containerPort` to the supervisor Deployment because the GKE docs say that GKE will look at that field while inferring how to invoke the health endpoint. See https://cloud.google.com/kubernetes-engine/docs/concepts/ingress#def_inf_hc
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package integration
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.pinniped.dev/test/library"
|
|
)
|
|
|
|
// The Supervisor health endpoint is public because that makes it easier
|
|
// for users to create an Ingress for the supervisor on platforms like
|
|
// GKE where the Ingress wants to perform a health check. It's somewhere
|
|
// between inconvenient and impossible to make that Ingress health check
|
|
// happen on a private container port at this time.
|
|
// This test checks that it is working and that it is public.
|
|
func TestSupervisorHealthz(t *testing.T) {
|
|
env := library.IntegrationEnv(t)
|
|
|
|
if env.SupervisorHTTPAddress == "" {
|
|
t.Skip("PINNIPED_TEST_SUPERVISOR_HTTP_ADDRESS not defined")
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
|
defer cancel()
|
|
|
|
requestHealthEndpoint, err := http.NewRequestWithContext(
|
|
ctx,
|
|
http.MethodGet,
|
|
fmt.Sprintf("http://%s/healthz", env.SupervisorHTTPAddress),
|
|
nil,
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
httpClient := &http.Client{}
|
|
response, err := httpClient.Do(requestHealthEndpoint) //nolint:bodyclose
|
|
require.NoError(t, err)
|
|
require.Equal(t, http.StatusOK, response.StatusCode)
|
|
|
|
responseBody, err := ioutil.ReadAll(response.Body)
|
|
require.NoError(t, err)
|
|
err = response.Body.Close()
|
|
require.NoError(t, err)
|
|
require.Equal(t, "ok", string(responseBody))
|
|
}
|