Skip to content

Commit

Permalink
Merge pull request #149 from kubeflow/main
Browse files Browse the repository at this point in the history
[pull] main from kubeflow:main
  • Loading branch information
openshift-merge-bot[bot] authored Nov 28, 2024
2 parents 912cb90 + 4099d46 commit cb45245
Show file tree
Hide file tree
Showing 13 changed files with 528 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the model-registry binary
FROM --platform=$BUILDPLATFORM registry.access.redhat.com/ubi8/go-toolset:1.21 AS builder
FROM --platform=$BUILDPLATFORM registry.access.redhat.com/ubi8/go-toolset:1.22 AS builder
ARG TARGETOS
ARG TARGETARCH

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.odh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the model-registry binary
FROM registry.access.redhat.com/ubi8/go-toolset:1.21 AS builder
FROM registry.access.redhat.com/ubi8/go-toolset:1.22 AS builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
21 changes: 14 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ GO ?= "$(shell which go)"
BFF_PATH := $(PROJECT_PATH)/clients/ui/bff
UI_PATH := $(PROJECT_PATH)/clients/ui/frontend

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.29
ENVTEST ?= $(PROJECT_BIN)/setup-envtest

# add tools bin directory
PATH := $(PROJECT_BIN):$(PATH)

Expand Down Expand Up @@ -133,6 +137,9 @@ bin/protoc-gen-go:
bin/protoc-gen-go-grpc:
GOBIN=$(PROJECT_BIN) ${GO} install google.golang.org/grpc/cmd/[email protected]

bin/envtest:
GOBIN=$(PROJECT_BIN) ${GO} install sigs.k8s.io/controller-runtime/tools/[email protected]

GOLANGCI_LINT ?= ${PROJECT_BIN}/golangci-lint
bin/golangci-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(PROJECT_BIN) v1.61.0
Expand Down Expand Up @@ -164,7 +171,7 @@ clean/deps:
rm -Rf bin/*

.PHONY: deps
deps: bin/protoc bin/go-enum bin/protoc-gen-go bin/protoc-gen-go-grpc bin/golangci-lint bin/goverter bin/openapi-generator-cli
deps: bin/protoc bin/go-enum bin/protoc-gen-go bin/protoc-gen-go-grpc bin/golangci-lint bin/goverter bin/openapi-generator-cli bin/envtest

.PHONY: vendor
vendor:
Expand Down Expand Up @@ -200,16 +207,16 @@ lint:
${GOLANGCI_LINT} run cmd/... internal/... ./pkg/...

.PHONY: test
test: gen
${GO} test ./internal/... ./pkg/...
test: gen bin/envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" ${GO} test ./internal/... ./pkg/...

.PHONY: test-nocache
test-nocache: gen
${GO} test ./internal/... ./pkg/... -count=1
test-nocache: gen bin/envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" ${GO} test ./internal/... ./pkg/... -count=1

.PHONY: test-cover
test-cover: gen
${GO} test ./internal/... ./pkg/... -coverprofile=coverage.txt
test-cover: gen bin/envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" ${GO} test ./internal/... ./pkg/... -coverprofile=coverage.txt
${GO} tool cover -html=coverage.txt -o coverage.html

.PHONY: run/proxy
Expand Down
72 changes: 56 additions & 16 deletions clients/python/src/model_registry/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import logging
import os
from collections.abc import Mapping
from pathlib import Path
Expand All @@ -22,6 +23,30 @@
ModelTypes = Union[RegisteredModel, ModelVersion, ModelArtifact]
TModel = TypeVar("TModel", bound=ModelTypes)

logging.basicConfig(
format="%(asctime)s.%(msecs)03d - %(name)s:%(levelname)s: %(message)s",
datefmt="%H:%M:%S",
level=logging.WARNING, # the default loglevel
handlers=[
# logging.FileHandler(
# LOGS
# / "log-{}-{}.log".format(
# datetime.now(tz=datetime.now().astimezone().tzinfo).strftime(
# "%Y-%m-%d-%H-%M-%S"
# ),
# os.getpid(),
# ),
# encoding="utf-8",
# delay=False,
# ),
logging.StreamHandler(),
],
)

logger = logging.getLogger("model-registry")

DEFAULT_USER_TOKEN_ENVVAR = "KF_PIPELINES_SA_TOKEN_PATH" # noqa: S105


class ModelRegistry:
"""Model registry client."""
Expand All @@ -34,7 +59,10 @@ def __init__(
author: str,
is_secure: bool = True,
user_token: str | None = None,
user_token_envvar: str = DEFAULT_USER_TOKEN_ENVVAR,
custom_ca: str | None = None,
custom_ca_envvar: str | None = None,
log_level: int = logging.WARNING,
):
"""Constructor.
Expand All @@ -45,47 +73,59 @@ def __init__(
Keyword Args:
author: Name of the author.
is_secure: Whether to use a secure connection. Defaults to True.
user_token: The PEM-encoded user token as a string. Defaults to content of path on envvar KF_PIPELINES_SA_TOKEN_PATH.
custom_ca: Path to the PEM-encoded root certificates as a string. Defaults to path on envvar CERT.
user_token: The PEM-encoded user token as a string.
user_token_envvar: Environment variable to read the user token from if it's not passed as an arg. Defaults to KF_PIPELINES_SA_TOKEN_PATH.
custom_ca: Path to the PEM-encoded root certificates as a string.
custom_ca_envvar: Environment variable to read the custom CA from if it's not passed as an arg.
log_level: Log level. Defaults to logging.WARNING.
"""
logger.setLevel(log_level)

import nest_asyncio

logger.debug("Setting up reentrant async event loop")
nest_asyncio.apply()

# TODO: get remaining args from env
self._author = author

if not user_token:
if not user_token and user_token_envvar:
logger.info("Reading user token from %s", user_token_envvar)
# /var/run/secrets/kubernetes.io/serviceaccount/token
sa_token = os.environ.get("KF_PIPELINES_SA_TOKEN_PATH")
if sa_token:
if sa_token := os.environ.get(user_token_envvar):
if user_token_envvar == DEFAULT_USER_TOKEN_ENVVAR:
logger.warning(
f"Sourcing user token from default envvar: {DEFAULT_USER_TOKEN_ENVVAR}"
)
user_token = Path(sa_token).read_text()
else:
warn("User access token is missing", stacklevel=2)

if is_secure:
root_ca = None
if not custom_ca:
if cert := os.getenv("CERT"):
root_ca = cert
# client might have a default CA setup
else:
root_ca = custom_ca
if (
not custom_ca
and custom_ca_envvar
and (cert := os.getenv(custom_ca_envvar))
):
logger.info(
"Using custom CA envvar %s",
custom_ca_envvar,
)
custom_ca = cert
# client might have a default CA setup

if not user_token:
msg = "user token must be provided for secure connection"
raise StoreError(msg)

self._api = ModelRegistryAPIClient.secure_connection(
server_address, port, user_token=user_token, custom_ca=root_ca
server_address, port, user_token=user_token, custom_ca=custom_ca
)
elif custom_ca:
msg = "Custom CA provided without secure connection, conflicting options"
raise StoreError(msg)
else:
self._api = ModelRegistryAPIClient.insecure_connection(
server_address, port, user_token
)
self.get_registered_models().page_size(1)._next_page()

def async_runner(self, coro: Any) -> Any:
import asyncio
Expand Down
1 change: 1 addition & 0 deletions clients/ui/frontend/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass ${API_URL};
proxy_http_version 1.1;
}
}

9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ require (
github.com/go-logr/logr v1.4.1
github.com/golang/glog v1.2.2
github.com/kserve/kserve v0.12.1
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.30.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/testcontainers/testcontainers-go v0.33.0
go.uber.org/zap v1.26.0
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.35.1
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
sigs.k8s.io/controller-runtime v0.16.3
)

Expand All @@ -36,6 +40,7 @@ require (
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
Expand All @@ -61,6 +66,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
Expand All @@ -72,7 +78,6 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/sync v0.8.0 // indirect
Expand All @@ -83,9 +88,9 @@ require (
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apiextensions-apiserver v0.28.4 // indirect
k8s.io/client-go v0.29.0 // indirect
k8s.io/component-base v0.28.4 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231113174909-778a5567bc1e // indirect
Expand Down
Loading

0 comments on commit cb45245

Please sign in to comment.