Skip to content

Commit

Permalink
Update manifests
Browse files Browse the repository at this point in the history
Signed-off-by: Yihong Wang <[email protected]>
  • Loading branch information
yhwang committed Jun 12, 2024
1 parent 43431ac commit 0345a39
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 124 deletions.
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
IMG ?= quay.io/yhwang/lm-eval-aas-controller:latest
IMG_DRIVER ?= quay.io/yhwang/lm-eval-aas-driver:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25.0

DOCKER_FILE ?= docker/Dockerfile.controller

DOCKER_FILE_DRIVER ?= docker/Dockerfile.driver

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
Expand Down Expand Up @@ -92,12 +97,20 @@ run: manifests generate fmt vet ## Run a controller from your host.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: docker-build
docker-build: ## Build docker image with the manager.
$(CONTAINER_TOOL) build -t ${IMG} .
$(CONTAINER_TOOL) build -t ${IMG} -f $(DOCKER_FILE) .

.PHONY: docker-build-driver
docker-build-driver: ## Build docker image with the manager.
$(CONTAINER_TOOL) build -t ${IMG_DRIVER} -f $(DOCKER_FILE_DRIVER) .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
$(CONTAINER_TOOL) push ${IMG}

.PHONY: docker-push-driver
docker-push-driver: ## Push docker image with the manager.
$(CONTAINER_TOOL) push ${IMG_DRIVER}

# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
Expand Down
44 changes: 27 additions & 17 deletions backend/controller/evaljob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ import (
)

const (
DriverPath = "/bin/driver"
DestDriverPath = "/opt/app-root/src/bin/driver"
PodImageKey = "pod-image"
DriverImageKey = "driver-image"
DefaultPodImage = "quay.io/yhwang/lm-eval-aas-flask:test"
DefaultDriverImage = "quay.io/yhwang/lm-eval-aas-driver:test"
DriverPath = "/bin/driver"
DestDriverPath = "/opt/app-root/src/bin/driver"
PodImageKey = "pod-image"
DriverImageKey = "driver-image"
DriverServiceAccountKey = "driver-serviceaccount"
DefaultPodImage = "quay.io/yhwang/lm-eval-aas-flask:test"
DefaultDriverImage = "quay.io/yhwang/lm-eval-aas-driver:test"
DefaultDriverServiceAccount = "driver"
)

// EvalJobReconciler reconciles a EvalJob object
Expand All @@ -62,15 +64,16 @@ type EvalJobReconciler struct {
}

type ServiceOptions struct {
PodImage string
DriverImage string
PodImage string
DriverImage string
DriverServiceAccount string
}

// +kubebuilder:rbac:groups=lm-eval-service.github.com,resources=evaljobs,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=lm-eval-service.github.com,resources=evaljobs/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=lm-eval-service.github.com,resources=evaljobs/finalizers,verbs=update
// +kubebuilder:rbac:groups="",resources=pods,verbs=get;list;watch;create;delete
// +kubebuilder:rbac:groups="",resources=configmaps,verbs=get;watch
// +kubebuilder:rbac:groups="",resources=configmaps,verbs=get;watch;list

func (r *EvalJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)
Expand Down Expand Up @@ -127,6 +130,11 @@ func (r *EvalJobReconciler) SetupWithManager(mgr ctrl.Manager) error {
types.NamespacedName{Namespace: r.Namespace, Name: r.ConfigMap},
&cm); err != nil {

ctrl.Log.WithName("setup").Error(err,
"failed to get configmap",
"namespace", r.Namespace,
"name", r.ConfigMap)

return err
}

Expand All @@ -140,6 +148,7 @@ func (r *EvalJobReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
// since we register the finalizer, no need to monitor deletion events
For(&lmevalservicev1beta1.EvalJob{}, builder.WithPredicates(predicate.Funcs{
// drop deletion events
DeleteFunc: func(event.DeleteEvent) bool {
return false
},
Expand All @@ -152,9 +161,6 @@ func (r *EvalJobReconciler) SetupWithManager(mgr ctrl.Manager) error {
CreateFunc: func(event.CreateEvent) bool {
return false
},
DeleteFunc: func(event.DeleteEvent) bool {
return true
},
UpdateFunc: func(event.UpdateEvent) bool {
return false
},
Expand All @@ -169,12 +175,16 @@ func (r *EvalJobReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *EvalJobReconciler) constructOptionsFromConfigMap(configmap *corev1.ConfigMap) error {
r.options.DriverImage = DefaultDriverImage
r.options.PodImage = DefaultPodImage
r.options.DriverServiceAccount = DefaultDriverServiceAccount
if v, found := configmap.Data[DriverImageKey]; found {
r.options.DriverImage = v
}
if v, found := configmap.Data[PodImageKey]; found {
r.options.PodImage = v
}
if v, found := configmap.Data[DriverServiceAccountKey]; found {
r.options.DriverServiceAccount = v
}
return nil
}

Expand Down Expand Up @@ -223,7 +233,7 @@ func (r *EvalJobReconciler) handleNewCR(ctx context.Context, log logr.Logger, jo

// construct a new pod and create a pod for the job
currentTime := v1.Now()
pod := createPod(job)
pod := r.createPod(job)
if err := r.Create(ctx, pod, &client.CreateOptions{}); err != nil {
// Failed to create the pod. Mark the status as complete with failed
job.Status.State = lmevalservicev1beta1.CompleteJobState
Expand Down Expand Up @@ -388,7 +398,7 @@ func (r *EvalJobReconciler) handleCancel(ctx context.Context, log logr.Logger, j
return ctrl.Result{}, err
}

func createPod(job *lmevalservicev1beta1.EvalJob) *corev1.Pod {
func (r *EvalJobReconciler) createPod(job *lmevalservicev1beta1.EvalJob) *corev1.Pod {
var allowPrivilegeEscalation = false
var runAsNonRootUser = true
var ownerRefController = true
Expand Down Expand Up @@ -420,7 +430,7 @@ func createPod(job *lmevalservicev1beta1.EvalJob) *corev1.Pod {
InitContainers: []corev1.Container{
{
Name: "driver",
Image: "quay.io/yhwang/lm-eval-aas-driver:test",
Image: r.options.DriverImage,
ImagePullPolicy: corev1.PullAlways,
Command: []string{DriverPath, "--copy", DestDriverPath},
SecurityContext: &corev1.SecurityContext{
Expand All @@ -443,7 +453,7 @@ func createPod(job *lmevalservicev1beta1.EvalJob) *corev1.Pod {
Containers: []corev1.Container{
{
Name: "main",
Image: "quay.io/yhwang/lm-eval-aas-flask:test",
Image: r.options.PodImage,
ImagePullPolicy: corev1.PullAlways,
Env: []corev1.EnvVar{
{
Expand Down Expand Up @@ -483,7 +493,7 @@ func createPod(job *lmevalservicev1beta1.EvalJob) *corev1.Pod {
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
},
ServiceAccountName: "driver",
ServiceAccountName: r.options.DriverServiceAccount,
Volumes: []corev1.Volume{
{
Name: "shared", VolumeSource: corev1.VolumeSource{
Expand Down
2 changes: 1 addition & 1 deletion cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func main() {
flag.BoolVar(&enableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
flag.StringVar(&configMap, "configmap", "lm-eval-service", "The configmap that stores settings for the controller")
flag.StringVar(&namespace, "namespace", "fms-lm-eval-service-system", "The namespace where the controller is running")
flag.StringVar(&namespace, "namespace", "lm-eval-aas", "The namespace where the controller is running")
opts := zap.Options{
Development: true,
}
Expand Down
2 changes: 1 addition & 1 deletion config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ patches:

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- path: patches/cainjection_in_evaljobs.yaml
- path: patches/cainjection_in_evaljobs.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

# [WEBHOOK] To enable webhook, uncomment the following section
Expand Down
Loading

0 comments on commit 0345a39

Please sign in to comment.