Skip to content

Commit

Permalink
Adds description, displayName properties to GET /api/v1/model-registr…
Browse files Browse the repository at this point in the history
…y endpoint response
  • Loading branch information
alexcreasy committed Aug 12, 2024
1 parent 869fb58 commit 5d4f0a6
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 21 deletions.
2 changes: 1 addition & 1 deletion clients/ui/bff/api/model_registry_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

func (app *App) ModelRegistryHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

registries, err := app.models.ModelRegistry.FetchAllModelRegistry(app.kubernetesClient)
registries, err := app.models.ModelRegistry.FetchAllModelRegistries(app.kubernetesClient)
if err != nil {
app.serverErrorResponse(w, r, err)
return
Expand Down
8 changes: 4 additions & 4 deletions clients/ui/bff/api/model_registry_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ func TestModelRegistryHandler(t *testing.T) {
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)})
actualModelRegistry = append(actualModelRegistry, data.ModelRegistryModel{Name: model["name"].(string), Description: model["description"].(string), DisplayName: model["displayName"].(string)})
}
modelRegistryRes["model_registry"] = actualModelRegistry

var expected = Envelope{
"model_registry": []data.ModelRegistryModel{
{Name: "model-registry"},
{Name: "model-registry-dora"},
{Name: "model-registry-bella"},
{Name: "model-registry", Description: "Model registry description", DisplayName: "Model Registry"},
{Name: "model-registry-dora", Description: "Model registry dora description", DisplayName: "Model Registry Dora"},
{Name: "model-registry-bella", Description: "Model registry bella description", DisplayName: "Model Registry Bella"},
},
}

Expand Down
14 changes: 9 additions & 5 deletions clients/ui/bff/data/model_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ import (
)

type ModelRegistryModel struct {
Name string `json:"name"`
Name string `json:"name"`
DisplayName string `json:"displayName"`
Description string `json:"description"`
}

func (m ModelRegistryModel) FetchAllModelRegistry(client k8s.KubernetesClientInterface) ([]ModelRegistryModel, error) {
func (m ModelRegistryModel) FetchAllModelRegistries(client k8s.KubernetesClientInterface) ([]ModelRegistryModel, error) {

resources, err := client.GetServiceNames()
resources, err := client.GetServiceDetails()
if err != nil {
return nil, fmt.Errorf("error fetching model registries: %w", err)
}

var registries []ModelRegistryModel = []ModelRegistryModel{}
var registries []ModelRegistryModel
for _, item := range resources {
registry := ModelRegistryModel{
Name: item,
Name: item.Name,
Description: item.Description,
DisplayName: item.DisplayName,
}
registries = append(registries, registry)
}
Expand Down
8 changes: 4 additions & 4 deletions clients/ui/bff/data/model_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ func TestFetchAllModelRegistry(t *testing.T) {

model := ModelRegistryModel{}

registries, err := model.FetchAllModelRegistry(mockK8sClient)
registries, err := model.FetchAllModelRegistries(mockK8sClient)

assert.NoError(t, err)

expectedRegistries := []ModelRegistryModel{
{Name: "model-registry"},
{Name: "model-registry-dora"},
{Name: "model-registry-bella"},
{Name: "model-registry", Description: "Model registry description", DisplayName: "Model Registry"},
{Name: "model-registry-dora", Description: "Model registry dora description", DisplayName: "Model Registry Dora"},
{Name: "model-registry-bella", Description: "Model registry bella description", DisplayName: "Model Registry Bella"},
}
assert.Equal(t, expectedRegistries, registries)

Expand Down
43 changes: 36 additions & 7 deletions clients/ui/bff/integrations/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ import (
type KubernetesClientInterface interface {
GetServiceNames() ([]string, error)
GetServiceDetailsByName(serviceName string) (ServiceDetails, error)
GetServiceDetails() ([]ServiceDetails, error)
BearerToken() (string, error)
}

type ServiceDetails struct {
Name string
ClusterIP string
HTTPPort int32
Name string
DisplayName string
Description string
ClusterIP string
HTTPPort int32
}

type KubernetesClient struct {
Expand Down Expand Up @@ -79,7 +82,6 @@ func buildModelRegistryServiceCache(logger *slog.Logger, services v1.ServiceList
serviceCache := make(map[string]ServiceDetails)
for _, service := range services.Items {
if svcComponent, exists := service.Spec.Selector["component"]; exists && svcComponent == "model-registry-server" {

var httpPort int32
hasHTTPPort := false
for _, port := range service.Spec.Ports {
Expand All @@ -98,10 +100,22 @@ func buildModelRegistryServiceCache(logger *slog.Logger, services v1.ServiceList
continue
}

var description, displayName string

if annotation, exists := service.Annotations["openshift.io/description"]; exists {
description = annotation
}

if annotation, exists := service.Annotations["openshift.io/display-name"]; exists {
displayName = annotation
}

serviceCache[service.Name] = ServiceDetails{
Name: service.Name,
ClusterIP: service.Spec.ClusterIP,
HTTPPort: httpPort,
Name: service.Name,
Description: description,
DisplayName: displayName,
ClusterIP: service.Spec.ClusterIP,
HTTPPort: httpPort,
}
}
}
Expand All @@ -123,6 +137,21 @@ func (kc *KubernetesClient) GetServiceNames() ([]string, error) {
return serviceNames, nil
}

func (kc *KubernetesClient) GetServiceDetails() ([]ServiceDetails, error) {
var services []ServiceDetails

for _, service := range kc.ServiceCache {
if service.Name != "" {
services = append(services, ServiceDetails{
Name: service.Name,
DisplayName: service.DisplayName,
Description: service.Description,
})
}
}
return services, nil
}

func (kc *KubernetesClient) GetServiceDetailsByName(serviceName string) (ServiceDetails, error) {

service, exists := kc.ServiceCache[serviceName]
Expand Down
8 changes: 8 additions & 0 deletions clients/ui/bff/internals/mocks/k8s_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ func (m *KubernetesClientMock) GetServiceNames() ([]string, error) {
return []string{"model-registry", "model-registry-dora", "model-registry-bella"}, nil
}

func (m *KubernetesClientMock) GetServiceDetails() ([]k8s.ServiceDetails, error) {
return []k8s.ServiceDetails{
{Name: "model-registry", Description: "Model registry description", DisplayName: "Model Registry"},
{Name: "model-registry-dora", Description: "Model registry dora description", DisplayName: "Model Registry Dora"},
{Name: "model-registry-bella", Description: "Model registry bella description", DisplayName: "Model Registry Bella"},
}, nil
}

func (m *KubernetesClientMock) BearerToken() (string, error) {
return "FAKE BEARER TOKEN", nil
}
Expand Down

0 comments on commit 5d4f0a6

Please sign in to comment.