diff --git a/clients/ui/bff/Makefile b/clients/ui/bff/Makefile index dec0984d3..7120284bf 100644 --- a/clients/ui/bff/Makefile +++ b/clients/ui/bff/Makefile @@ -3,6 +3,7 @@ IMG ?= model-registry-bff:latest PORT ?= 4000 MOCK_K8S_CLIENT ?= false MOCK_MR_CLIENT ?= false +DEV_MODE ?= false # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = 1.29.0 @@ -45,7 +46,7 @@ build: fmt vet test .PHONY: run run: fmt vet envtest ENVTEST_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" \ - go run ./cmd/main.go --port=$(PORT) --mock-k8s-client=$(MOCK_K8S_CLIENT) --mock-mr-client=$(MOCK_MR_CLIENT) + go run ./cmd/main.go --port=$(PORT) --mock-k8s-client=$(MOCK_K8S_CLIENT) --mock-mr-client=$(MOCK_MR_CLIENT) --dev-mode=$(DEV_MODE) .PHONY: docker-build docker-build: diff --git a/clients/ui/bff/cmd/main.go b/clients/ui/bff/cmd/main.go index 25c367c3f..58564003c 100644 --- a/clients/ui/bff/cmd/main.go +++ b/clients/ui/bff/cmd/main.go @@ -4,11 +4,12 @@ import ( "context" "flag" "fmt" - "github.com/kubeflow/model-registry/ui/bff/internal/api" - "github.com/kubeflow/model-registry/ui/bff/internal/config" "os/signal" "syscall" + "github.com/kubeflow/model-registry/ui/bff/internal/api" + "github.com/kubeflow/model-registry/ui/bff/internal/config" + "log/slog" "net/http" "os" @@ -21,6 +22,7 @@ func main() { flag.IntVar(&cfg.Port, "port", getEnvAsInt("PORT", 4000), "API server port") flag.BoolVar(&cfg.MockK8Client, "mock-k8s-client", false, "Use mock Kubernetes client") flag.BoolVar(&cfg.MockMRClient, "mock-mr-client", false, "Use mock Model Registry client") + flag.BoolVar(&cfg.DevMode, "dev-mode", false, "Use development mode for access to local K8s cluster") flag.Parse() logger := slog.New(slog.NewTextHandler(os.Stdout, nil)) diff --git a/clients/ui/bff/internal/api/middleware.go b/clients/ui/bff/internal/api/middleware.go index 743cd2567..036f004f9 100644 --- a/clients/ui/bff/internal/api/middleware.go +++ b/clients/ui/bff/internal/api/middleware.go @@ -3,9 +3,10 @@ package api import ( "context" "fmt" + "net/http" + "github.com/julienschmidt/httprouter" "github.com/kubeflow/model-registry/ui/bff/internal/integrations" - "net/http" ) type contextKey string @@ -41,7 +42,7 @@ func (app *App) AttachRESTClient(handler func(http.ResponseWriter, *http.Request modelRegistryID := ps.ByName(ModelRegistryId) - modelRegistryBaseURL, err := resolveModelRegistryURL(modelRegistryID, app.kubernetesClient) + modelRegistryBaseURL, err := resolveModelRegistryURL(modelRegistryID, app) if err != nil { app.serverErrorResponse(w, r, fmt.Errorf("failed to resolve model registry base URL): %v", err)) return @@ -83,11 +84,16 @@ func resolveBearerToken(k8s integrations.KubernetesClientInterface, header http. return bearerToken, nil } -func resolveModelRegistryURL(id string, client integrations.KubernetesClientInterface) (string, error) { - serviceDetails, err := client.GetServiceDetailsByName(id) +func resolveModelRegistryURL(id string, app *App) (string, error) { + serviceDetails, err := app.kubernetesClient.GetServiceDetailsByName(id) if err != nil { return "", err } + + if app.config.DevMode { + serviceDetails.ClusterIP = "localhost" + } + url := fmt.Sprintf("http://%s:%d/api/model_registry/v1alpha3", serviceDetails.ClusterIP, serviceDetails.HTTPPort) return url, nil } diff --git a/clients/ui/bff/internal/config/environment.go b/clients/ui/bff/internal/config/environment.go index f7b10bf63..d2b39238e 100644 --- a/clients/ui/bff/internal/config/environment.go +++ b/clients/ui/bff/internal/config/environment.go @@ -4,4 +4,5 @@ type EnvConfig struct { Port int MockK8Client bool MockMRClient bool + DevMode bool }