diff --git a/clients/ui/bff/api/model_registry_handler.go b/clients/ui/bff/api/model_registry_handler.go index eb1396ba9..5a99b84f1 100644 --- a/clients/ui/bff/api/model_registry_handler.go +++ b/clients/ui/bff/api/model_registry_handler.go @@ -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 diff --git a/clients/ui/bff/api/model_registry_handler_test.go b/clients/ui/bff/api/model_registry_handler_test.go index 47a91b6cd..8f05372e7 100644 --- a/clients/ui/bff/api/model_registry_handler_test.go +++ b/clients/ui/bff/api/model_registry_handler_test.go @@ -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"}, }, } diff --git a/clients/ui/bff/data/model_registry.go b/clients/ui/bff/data/model_registry.go index b15014a4a..15f4516be 100644 --- a/clients/ui/bff/data/model_registry.go +++ b/clients/ui/bff/data/model_registry.go @@ -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) } diff --git a/clients/ui/bff/data/model_registry_test.go b/clients/ui/bff/data/model_registry_test.go index 0a8bb5432..4f137edd7 100644 --- a/clients/ui/bff/data/model_registry_test.go +++ b/clients/ui/bff/data/model_registry_test.go @@ -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) diff --git a/clients/ui/bff/integrations/k8s.go b/clients/ui/bff/integrations/k8s.go index 15d83ecb0..126f962f3 100644 --- a/clients/ui/bff/integrations/k8s.go +++ b/clients/ui/bff/integrations/k8s.go @@ -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 { @@ -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 { @@ -98,6 +100,8 @@ func buildModelRegistryServiceCache(logger *slog.Logger, services v1.ServiceList continue } + //TODO (acreasy) DisplayName and Description need to be included and not given a zero value once we + // know how this will be implemented. serviceCache[service.Name] = ServiceDetails{ Name: service.Name, ClusterIP: service.Spec.ClusterIP, @@ -123,6 +127,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] diff --git a/clients/ui/bff/internals/mocks/k8s_mock.go b/clients/ui/bff/internals/mocks/k8s_mock.go index 5652ed547..abbe46102 100644 --- a/clients/ui/bff/internals/mocks/k8s_mock.go +++ b/clients/ui/bff/internals/mocks/k8s_mock.go @@ -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 }