Skip to content

Commit 7e1a712

Browse files
yhwangruivieira
andauthored
Add lm-eval-service controller (#258)
* feat: Initial database support (#246) * Initial database support - Add status checking - Add better storage flags - Add spec.storage.format validation - Add DDL -Add HIBERNATE format to DB (test) - Update service image - Revert identifier to DATABASE - Update CR options (remove mandatory data) * Remove default DDL generation env var * Update service image to latest tag * Add migration awareness * Add updating pods for migration * Change JDBC url from mysql to mariadb * Fix TLS mount * Revert images * Remove redundant logic * Fix comments * feat: Add TLS certificate mount on ModelMesh (#255) * feat: Add TLS certificate mount on ModelMesh * Revert from http to https until kserve/modelmesh#147 is merged * Add lm-eval-service controller refactor the existing TrustyAIService controller and add LMEvalService controller Signed-off-by: Yihong Wang <[email protected]> --------- Signed-off-by: Yihong Wang <[email protected]> Co-authored-by: Rui Vieira <[email protected]>
1 parent 45027a6 commit 7e1a712

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+5764
-983
lines changed

.github/workflows/controller-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Setup Go
1414
uses: actions/setup-go@v4
1515
with:
16-
go-version: '1.19.0'
16+
go-version: '1.21.12'
1717

1818
- name: Download & install envtest binaries
1919
run: |

.yamllint.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ rules:
66
level: warning
77
hyphens:
88
max-spaces-after: 1
9-
level: warning
9+
level: warning
10+
indentation:
11+
indent-sequences: consistent

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM registry.access.redhat.com/ubi8/go-toolset:1.21 as builder
2+
FROM registry.access.redhat.com/ubi8/go-toolset:1.21 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

@@ -12,7 +12,7 @@ COPY go.sum go.sum
1212
RUN go mod download
1313

1414
# Copy the go source
15-
COPY main.go main.go
15+
COPY cmd/ cmd/
1616
COPY api/ api/
1717
COPY controllers/ controllers/
1818

@@ -22,7 +22,7 @@ COPY controllers/ controllers/
2222
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2323
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
2424
USER root
25-
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
25+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/operator/main.go
2626

2727
# Use distroless as minimal base image to package the manager binary
2828
# Refer to https://github.com/GoogleContainerTools/distroless for more details

Dockerfile.driver

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM registry.access.redhat.com/ubi8/go-toolset:1.21 AS builder
2+
3+
WORKDIR /go/src/github.com/trustyai-explainability/trustyai-service-operator
4+
COPY . .
5+
6+
RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build -tags netgo -ldflags '-extldflags "-static"' -o /bin/driver ./cmd/lmes_driver/*.go
7+
8+
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
9+
10+
COPY --from=builder /bin/driver /bin/driver
11+
12+
USER 65532:65532
13+
14+
WORKDIR /bin
15+
16+
ENTRYPOINT [ "/bin/driver" ]

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ VERSION ?= 1.17.0
77

88
BUILD_TOOL ?= podman
99

10+
# enable TrustyAIService by default for `make run`
11+
ENABLED_SERVICES ?= TAS
12+
1013
# CHANNELS define the bundle channels used in the bundle.
1114
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
1215
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
@@ -111,11 +114,11 @@ test: manifests generate fmt vet envtest ## Run tests.
111114

112115
.PHONY: build
113116
build: manifests generate fmt vet ## Build manager binary.
114-
go build -o bin/manager main.go
117+
go build -o bin/manager cmd/operator/main.go
115118

116119
.PHONY: run
117120
run: manifests generate fmt vet ## Run a controller from your host.
118-
go run ./main.go
121+
go run ./cmd/operator/main.go --enable-services $(ENABLED_SERVICES)
119122

120123
# If you wish built the manager image targeting other platforms you can use the --platform flag.
121124
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.

PROJECT

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# More info: https://book.kubebuilder.io/reference/project-config.html
55
domain: opendatahub.io
66
layout:
7-
- go.kubebuilder.io/v3
7+
- go.kubebuilder.io/v4
88
plugins:
99
manifests.sdk.operatorframework.io/v2: {}
1010
scorecard.sdk.operatorframework.io/v2: {}
@@ -18,6 +18,19 @@ resources:
1818
domain: opendatahub.io
1919
group: trustyai
2020
kind: TrustyAIService
21-
path: github.com/trustyai-explainability/trustyai-service-operator/api/v1alpha1
21+
path: github.com/trustyai-explainability/trustyai-service-operator/api/tas/v1alpha1
2222
version: v1alpha1
23+
- api:
24+
crdVersion: v1
25+
namespaced: true
26+
controller: true
27+
domain: opendatahub.io
28+
group: trustyai
29+
kind: LMEvalJob
30+
path: github.com/trustyai-explainability/trustyai-service-operator/api/lmes/v1alpha1
31+
version: v1alpha1
32+
webhooks:
33+
defaulting: true
34+
validation: true
35+
webhookVersion: v1
2336
version: "3"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2024.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1alpha1 contains API Schema definitions for the trustyai.opendatahub.io v1alpha1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=trustyai.opendatahub.io
20+
package v1alpha1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
const (
28+
GroupName = "trustyai.opendatahub.io"
29+
Version = "v1alpha1"
30+
KindName = "LMEvalJob"
31+
FinalizerName = "trustyai.opendatahub.io/lmes-finalizer"
32+
)
33+
34+
var (
35+
// GroupVersion is group version used to register these objects
36+
GroupVersion = schema.GroupVersion{Group: GroupName, Version: Version}
37+
38+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
39+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
40+
41+
// AddToScheme adds the types in this group-version to the given scheme.
42+
AddToScheme = SchemeBuilder.AddToScheme
43+
)

api/lmes/v1alpha1/lmevaljob_types.go

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
Copyright 2024.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
26+
27+
// Represent a job's status
28+
// +kubebuilder:validation:Enum=New;Scheduled;Running;Complete;Cancelled
29+
type JobState string
30+
31+
const (
32+
// The job is just created
33+
NewJobState JobState = "New"
34+
// The job is scheduled and waiting for available resources to run it
35+
ScheduledJobState JobState = "Scheduled"
36+
// The job is running
37+
RunningJobState JobState = "Running"
38+
// The job is complete
39+
CompleteJobState JobState = "Complete"
40+
// The job is cancelled
41+
CancelledJobState JobState = "Cancelled"
42+
)
43+
44+
// +kubebuilder:validation:Enum=NoReason;Succeeded;Failed;Cancelled
45+
type Reason string
46+
47+
const (
48+
// Job is still running and no final result yet
49+
NoReason Reason = "NoReason"
50+
// Job finished successfully
51+
SucceedReason Reason = "Succeeded"
52+
// Job failed
53+
FailedReason Reason = "Failed"
54+
// Job is cancelled
55+
CancelledReason Reason = "Cancelled"
56+
)
57+
58+
type Arg struct {
59+
Name string `json:"name"`
60+
Value string `json:"value,omitempty"`
61+
}
62+
63+
type EnvSecret struct {
64+
// Environment's name
65+
Env string `json:"env"`
66+
// The secret is from a secret object
67+
// +optional
68+
SecretRef *corev1.SecretKeySelector `json:"secretRef,omitempty"`
69+
// The secret is from a plain text
70+
// +optional
71+
Secret *string `json:"secret,omitempty"`
72+
}
73+
74+
type FileSecret struct {
75+
// The secret object
76+
SecretRef corev1.SecretVolumeSource `json:"secretRef,omitempty"`
77+
// The path to mount the secret
78+
MountPath string `json:"mountPath"`
79+
}
80+
81+
// LMEvalJobSpec defines the desired state of LMEvalJob
82+
type LMEvalJobSpec struct {
83+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
84+
// Important: Run "make" to regenerate code after modifying this file
85+
86+
// Model name
87+
Model string `json:"model"`
88+
// Args for the model
89+
// +optional
90+
ModelArgs []Arg `json:"modelArgs,omitempty"`
91+
// Evaluation tasks
92+
Tasks []string `json:"tasks"`
93+
// Sets the number of few-shot examples to place in context
94+
// +optional
95+
NumFewShot *int `json:"numFewShot,omitempty"`
96+
// Accepts an integer, or a float between 0.0 and 1.0 . If passed, will limit
97+
// the number of documents to evaluate to the first X documents (if an integer)
98+
// per task or first X% of documents per task
99+
// +optional
100+
Limit string `json:"limit,omitempty"`
101+
// Map to `--gen_kwargs` parameter for the underlying library.
102+
// +optional
103+
GenArgs []Arg `json:"genArgs,omitempty"`
104+
// If this flag is passed, then the model's outputs, and the text fed into the
105+
// model, will be saved at per-document granularity
106+
// +optional
107+
LogSamples *bool `json:"logSamples,omitempty"`
108+
// Assign secrets to the environment variables
109+
// +optional
110+
EnvSecrets []EnvSecret `json:"envSecrets,omitempty"`
111+
// Use secrets as files
112+
FileSecrets []FileSecret `json:"fileSecrets,omitempty"`
113+
}
114+
115+
// LMEvalJobStatus defines the observed state of LMEvalJob
116+
type LMEvalJobStatus struct {
117+
// Important: Run "make" to regenerate code after modifying this file
118+
119+
// The name of the Pod that runs the evaluation job
120+
// +optional
121+
PodName string `json:"podName,omitempty"`
122+
// State of the job
123+
// +optional
124+
State JobState `json:"state,omitempty"`
125+
// Final result of the job
126+
// +optional
127+
Reason Reason `json:"reason,omitempty"`
128+
// Message about the current/final status
129+
// +optional
130+
Message string `json:"message,omitempty"`
131+
// Information when was the last time the job was successfully scheduled.
132+
// +optional
133+
LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"`
134+
// Information when the job's state changes to Complete.
135+
// +optional
136+
CompleteTime *metav1.Time `json:"completeTime,omitempty"`
137+
// Evaluation results
138+
// +optional
139+
Results string `json:"results,omitempty"`
140+
}
141+
142+
// +kubebuilder:object:root=true
143+
// +kubebuilder:subresource:status
144+
145+
// LMEvalJob is the Schema for the lmevaljobs API
146+
type LMEvalJob struct {
147+
metav1.TypeMeta `json:",inline"`
148+
metav1.ObjectMeta `json:"metadata,omitempty"`
149+
150+
Spec LMEvalJobSpec `json:"spec,omitempty"`
151+
Status LMEvalJobStatus `json:"status,omitempty"`
152+
}
153+
154+
// +kubebuilder:object:root=true
155+
156+
// LMEvalJobList contains a list of LMEvalJob
157+
type LMEvalJobList struct {
158+
metav1.TypeMeta `json:",inline"`
159+
metav1.ListMeta `json:"metadata,omitempty"`
160+
Items []LMEvalJob `json:"items"`
161+
}
162+
163+
func init() {
164+
SchemeBuilder.Register(&LMEvalJob{}, &LMEvalJobList{})
165+
}

0 commit comments

Comments
 (0)