forked from kubeflow/pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(backend): fixes healthz response by adding json content type. Fixes
- Loading branch information
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package api_server | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/go-openapi/strfmt" | ||
apiclient "github.com/kubeflow/pipelines/backend/api/go_http_client/healthz_client" | ||
params "github.com/kubeflow/pipelines/backend/api/go_http_client/healthz_client/healthz_service" | ||
model "github.com/kubeflow/pipelines/backend/api/go_http_client/healthz_model" | ||
"github.com/kubeflow/pipelines/backend/src/common/util" | ||
"k8s.io/client-go/tools/clientcmd" | ||
) | ||
|
||
type HealthzInterface interface { | ||
GetHealthz() (*params.GetHealthzOK, error) | ||
} | ||
|
||
type HealthzClient struct { | ||
apiClient *apiclient.Healthz | ||
} | ||
|
||
func NewHealthzClient(clientConfig clientcmd.ClientConfig, debug bool) (*HealthzClient, error) { | ||
runtime, err := NewHTTPRuntime(clientConfig, debug) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
apiClient := apiclient.New(runtime, strfmt.Default) | ||
|
||
// Creating upload client | ||
return &HealthzClient{ | ||
apiClient: apiClient, | ||
}, nil | ||
} | ||
|
||
func (c *HealthzClient) GetHealthz() (*model.APIGetHealthzResponse, error) { | ||
parameters := params.NewGetHealthzParamsWithTimeout(apiServerDefaultTimeout) | ||
response, err := c.apiClient.HealthzService.GetHealthz(parameters, PassThroughAuth) | ||
if err != nil { | ||
if defaultError, ok := err.(*params.GetHealthzDefault); ok { | ||
err = CreateErrorFromAPIStatus(defaultError.Payload.Error, defaultError.Payload.Code) | ||
} else { | ||
err = CreateErrorCouldNotRecoverAPIStatus(err) | ||
} | ||
|
||
return nil, util.NewUserError(err, | ||
fmt.Sprintf("Failed to get Healthz. Params: '%+v'", parameters), | ||
fmt.Sprintf("Failed to get Healthz. Params: '%+v'", parameters)) | ||
|
||
} | ||
return response.Payload, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/glog" | ||
"github.com/kubeflow/pipelines/backend/src/common/client/api_server" | ||
"github.com/kubeflow/pipelines/backend/test" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type HealthzApiTest struct { | ||
suite.Suite | ||
namespace string | ||
healthzClient *api_server.HealthzClient | ||
} | ||
|
||
// Check the namespace have ML job installed and ready | ||
func (s *HealthzApiTest) SetupTest() { | ||
if !*runIntegrationTests { | ||
s.T().SkipNow() | ||
return | ||
} | ||
|
||
if !*isDevMode { | ||
err := test.WaitForReady(*namespace, *initializeTimeout) | ||
if err != nil { | ||
glog.Exitf("Failed to initialize test. Error: %v", err) | ||
} | ||
} | ||
s.namespace = *namespace | ||
clientConfig := test.GetClientConfig(*namespace) | ||
var err error | ||
s.healthzClient, err = api_server.NewHealthzClient(clientConfig, false) | ||
if err != nil { | ||
glog.Exitf("Failed to get healthz client. Error: %v", err) | ||
} | ||
s.cleanUp() | ||
} | ||
|
||
func (s *HealthzApiTest) TearDownSuite() { | ||
if *runIntegrationTests { | ||
if !*isDevMode { | ||
s.cleanUp() | ||
} | ||
} | ||
} | ||
|
||
func (s *HealthzApiTest) cleanUp() { | ||
} | ||
|
||
func (s *HealthzApiTest) TestHealthzAPI() { | ||
t := s.T() | ||
|
||
/* ---------- Verify healthz response ---------- */ | ||
healthzResp, err := s.healthzClient.GetHealthz() | ||
assert.Nil(t, err) | ||
assert.NotNil(t, healthzResp) | ||
} | ||
|
||
func TestHealthzAPI(t *testing.T) { | ||
suite.Run(t, new(HealthzApiTest)) | ||
} |