-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: fetch MR endpoint In this PR: - New kubernetes client (integrations/k8s.go) - Fetch model registries handler (model_registry_handler.go) Signed-off-by: Eder Ignatowicz <[email protected]> * Small reminder on a TODO Signed-off-by: Eder Ignatowicz <[email protected]> --------- Signed-off-by: Eder Ignatowicz <[email protected]>
- Loading branch information
Showing
15 changed files
with
411 additions
and
32 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
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
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,26 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/julienschmidt/httprouter" | ||
"net/http" | ||
) | ||
|
||
func (app *App) ModelRegistryHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | ||
|
||
registries, err := app.models.ModelRegistry.FetchAllModelRegistry(app.kubernetesClient) | ||
if err != nil { | ||
app.serverErrorResponse(w, r, err) | ||
return | ||
} | ||
|
||
modelRegistryRes := Envelope{ | ||
"model_registry": registries, | ||
} | ||
|
||
err = app.WriteJSON(w, http.StatusOK, modelRegistryRes, nil) | ||
|
||
if err != nil { | ||
app.serverErrorResponse(w, r, err) | ||
} | ||
|
||
} |
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,59 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/kubeflow/model-registry/ui/bff/data" | ||
"github.com/kubeflow/model-registry/ui/bff/internals/mocks" | ||
"github.com/stretchr/testify/assert" | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestModelRegistryHandler(t *testing.T) { | ||
mockK8sClient := new(mocks.KubernetesClientMock) | ||
mockK8sClient.On("FetchServiceNamesByComponent", "model-registry-server").Return([]string{"model-registry-dora", "model-registry-bella"}, nil) | ||
|
||
testApp := App{ | ||
kubernetesClient: mockK8sClient, | ||
} | ||
|
||
req, err := http.NewRequest(http.MethodGet, ModelRegistry, nil) | ||
assert.NoError(t, err) | ||
|
||
rr := httptest.NewRecorder() | ||
|
||
testApp.ModelRegistryHandler(rr, req, nil) | ||
rs := rr.Result() | ||
|
||
defer rs.Body.Close() | ||
body, err := io.ReadAll(rs.Body) | ||
assert.NoError(t, err) | ||
fmt.Println(string(body)) | ||
var modelRegistryRes Envelope | ||
err = json.Unmarshal(body, &modelRegistryRes) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, http.StatusOK, rr.Code) | ||
|
||
// Convert the unmarshalled data to the expected type | ||
actualModelRegistry := make([]data.ModelRegistryModel, 0) | ||
for _, v := range modelRegistryRes["model_registry"].([]interface{}) { | ||
model := v.(map[string]interface{}) | ||
actualModelRegistry = append(actualModelRegistry, data.ModelRegistryModel{Name: model["name"].(string)}) | ||
} | ||
modelRegistryRes["model_registry"] = actualModelRegistry | ||
|
||
var expected = Envelope{ | ||
"model_registry": []data.ModelRegistryModel{ | ||
{Name: "model-registry-dora"}, | ||
{Name: "model-registry-bella"}, | ||
}, | ||
} | ||
|
||
assert.Equal(t, expected, modelRegistryRes) | ||
|
||
mockK8sClient.AssertExpectations(t) | ||
} |
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,29 @@ | ||
package data | ||
|
||
import ( | ||
"fmt" | ||
|
||
k8s "github.com/kubeflow/model-registry/ui/bff/integrations" | ||
) | ||
|
||
type ModelRegistryModel struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
func (m ModelRegistryModel) FetchAllModelRegistry(client k8s.KubernetesClientInterface) ([]ModelRegistryModel, error) { | ||
|
||
resources, err := client.FetchServiceNamesByComponent(k8s.ModelRegistryServiceComponentSelector) | ||
if err != nil { | ||
return nil, fmt.Errorf("error fetching model registries: %w", err) | ||
} | ||
|
||
var registries []ModelRegistryModel = []ModelRegistryModel{} | ||
for _, item := range resources { | ||
registry := ModelRegistryModel{ | ||
Name: item, | ||
} | ||
registries = append(registries, registry) | ||
} | ||
|
||
return registries, 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
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
Oops, something went wrong.