Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Nodeclaim/Machine provision to RAG Engine controller #616

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ package v1alpha1
type ConditionType string

const (
// WorkspaceConditionTypeMachineStatus is the state when checking machine status.
WorkspaceConditionTypeMachineStatus = ConditionType("MachineReady")
// ConditionTypeMachineStatus is the state when checking machine status.
ConditionTypeMachineStatus = ConditionType("MachineReady")

// WorkspaceConditionTypeNodeClaimStatus is the state when checking nodeClaim status.
WorkspaceConditionTypeNodeClaimStatus = ConditionType("NodeClaimReady")
// ConditionTypeNodeClaimStatus is the state when checking nodeClaim status.
ConditionTypeNodeClaimStatus = ConditionType("NodeClaimReady")

// WorkspaceConditionTypeResourceStatus is the state when Resource has been created.
WorkspaceConditionTypeResourceStatus = ConditionType("ResourceReady")
// ConditionTypeResourceStatus is the state when Resource has been created.
ConditionTypeResourceStatus = ConditionType("ResourceReady")

// WorkspaceConditionTypeInferenceStatus is the state when Inference service has been ready.
WorkspaceConditionTypeInferenceStatus = ConditionType("InferenceReady")
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/workspace_labels.go → api/v1alpha1/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ const (
// LabelWorkspaceName is the label for workspace name.
LabelWorkspaceName = KAITOPrefix + "workspace"

// LabelRAGEngineName is the label for ragengine name.
LabelRAGEngineName = KAITOPrefix + "ragengine"

// LabelWorkspaceName is the label for workspace namespace.
LabelWorkspaceNamespace = KAITOPrefix + "workspacenamespace"

// LabelRAGEngineNamespace is the label for ragengine namespace.
LabelRAGEngineNamespace = KAITOPrefix + "ragenginenamespace"

// WorkspaceRevisionAnnotation is the Annotations for revision number
WorkspaceRevisionAnnotation = "workspace.kaito.io/revision"
)
12 changes: 12 additions & 0 deletions api/v1alpha1/ragengine_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

package v1alpha1

import (
"context"
)

// SetDefaults for the RAG Engine
func (w *RAGEngine) SetDefaults(_ context.Context) {

Check warning on line 11 in api/v1alpha1/ragengine_default.go

View check run for this annotation

Codecov / codecov/patch

api/v1alpha1/ragengine_default.go#L11

Added line #L11 was not covered by tests
}
2 changes: 2 additions & 0 deletions api/v1alpha1/ragengine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ type RAGEngineStatus struct {
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=ragengines,scope=Namespaced,categories=ragengine
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Instance",type="string",JSONPath=".spec.compute.instanceType",description=""
// +kubebuilder:printcolumn:name="ResourceReady",type="string",JSONPath=".status.conditions[?(@.type==\"ResourceReady\")].status",description=""
type RAGEngine struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
36 changes: 36 additions & 0 deletions api/v1alpha1/ragenging_validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

package v1alpha1

import (
"context"
"fmt"

admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
"k8s.io/klog/v2"
"knative.dev/pkg/apis"
)

func (w *RAGEngine) SupportedVerbs() []admissionregistrationv1.OperationType {
return []admissionregistrationv1.OperationType{
admissionregistrationv1.Create,
admissionregistrationv1.Update,

Check warning on line 18 in api/v1alpha1/ragenging_validation.go

View check run for this annotation

Codecov / codecov/patch

api/v1alpha1/ragenging_validation.go#L15-L18

Added lines #L15 - L18 were not covered by tests
}
}

func (w *RAGEngine) Validate(ctx context.Context) (errs *apis.FieldError) {
base := apis.GetBaseline(ctx)
if base == nil {
klog.InfoS("Validate creation", "ragengine", fmt.Sprintf("%s/%s", w.Namespace, w.Name))
errs = errs.Also(w.validateCreate().ViaField("spec"))

Check warning on line 26 in api/v1alpha1/ragenging_validation.go

View check run for this annotation

Codecov / codecov/patch

api/v1alpha1/ragenging_validation.go#L22-L26

Added lines #L22 - L26 were not covered by tests
}
return errs

Check warning on line 28 in api/v1alpha1/ragenging_validation.go

View check run for this annotation

Codecov / codecov/patch

api/v1alpha1/ragenging_validation.go#L28

Added line #L28 was not covered by tests
}

func (w *RAGEngine) validateCreate() (errs *apis.FieldError) {
if w.Spec.InferenceService == nil {
errs = errs.Also(apis.ErrGeneric("InferenceService must be specified, not neither", ""))

Check warning on line 33 in api/v1alpha1/ragenging_validation.go

View check run for this annotation

Codecov / codecov/patch

api/v1alpha1/ragenging_validation.go#L31-L33

Added lines #L31 - L33 were not covered by tests
}
return errs

Check warning on line 35 in api/v1alpha1/ragenging_validation.go

View check run for this annotation

Codecov / codecov/patch

api/v1alpha1/ragenging_validation.go#L35

Added line #L35 was not covered by tests
}
12 changes: 11 additions & 1 deletion charts/kaito/ragengine/crds/kaito.sh_ragengines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ spec:
singular: ragengine
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- jsonPath: .spec.compute.instanceType
name: Instance
type: string
- jsonPath: .status.conditions[?(@.type=="ResourceReady")].status
name: ResourceReady
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
description: RAGEngine is the Schema for the ragengine API
Expand Down
9 changes: 9 additions & 0 deletions charts/kaito/ragengine/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ rules:
- apiGroups: ["kaito.sh"]
resources: ["ragengines/status"]
verbs: ["update", "patch","get","list","watch"]
- apiGroups: [""]
resources: ["nodes", "namespaces"]
verbs: ["get","list","watch","update", "patch"]
- apiGroups: [""]
resources: ["services"]
verbs: ["get","list","watch","create", "delete", "update", "patch"]
- apiGroups: [ "" ]
resources: [ "pods"]
verbs: ["get","list","watch","create", "update", "patch" ]
- apiGroups: [ "" ]
resources: [ "configmaps" ]
verbs: [ "get","list","watch","create", "delete" ]
Expand All @@ -24,6 +30,9 @@ rules:
- apiGroups: [ "apps" ]
resources: ["controllerrevisions" ]
verbs: [ "get","list","watch","create", "delete","update", "patch"]
- apiGroups: ["karpenter.sh"]
resources: ["machines", "machines/status", "nodeclaims", "nodeclaims/status"]
verbs: ["get","list","watch","create", "delete", "update", "patch"]
- apiGroups: ["admissionregistration.k8s.io"]
resources: ["validatingwebhookconfigurations"]
verbs: ["get","list","watch"]
Expand Down
18 changes: 14 additions & 4 deletions cmd/ragengine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import (
"syscall"
"time"

azurev1alpha2 "github.com/Azure/karpenter-provider-azure/pkg/apis/v1alpha2"
"github.com/aws/karpenter-core/pkg/apis/v1alpha5"
awsv1beta1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1beta1"
"github.com/azure/kaito/pkg/k8sclient"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

"github.com/azure/kaito/pkg/controllers"
"github.com/azure/kaito/pkg/webhooks"
"k8s.io/api/apps/v1beta1"
"k8s.io/klog/v2"
"knative.dev/pkg/injection/sharedmain"
"knative.dev/pkg/webhook"
Expand Down Expand Up @@ -53,6 +57,10 @@ var (
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(kaitov1alpha1.AddToScheme(scheme))
utilruntime.Must(v1alpha5.SchemeBuilder.AddToScheme(scheme))
utilruntime.Must(v1beta1.SchemeBuilder.AddToScheme(scheme))
utilruntime.Must(azurev1alpha2.SchemeBuilder.AddToScheme(scheme))
utilruntime.Must(awsv1beta1.SchemeBuilder.AddToScheme(scheme))

//+kubebuilder:scaffold:scheme
klog.InitFlags(nil)
Expand All @@ -63,13 +71,15 @@ func main() {
var enableLeaderElection bool
var enableWebhook bool
var probeAddr string
var featureGates string
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.BoolVar(&enableWebhook, "webhook", false,
"Enable webhook for controller manager. Default is false.")
flag.BoolVar(&enableWebhook, "webhook", true,
"Enable webhook for controller manager. Default is true.")
flag.StringVar(&featureGates, "feature-gates", "Karpenter=false", "Enable Kaito feature gates. Default, Karpenter=false.")
opts := zap.Options{
Development: true,
}
Expand Down Expand Up @@ -116,7 +126,7 @@ func main() {
)

if err = ragengineReconciler.SetupWithManager(mgr); err != nil {
klog.ErrorS(err, "unable to create controller", "controller", "Workspace")
klog.ErrorS(err, "unable to create controller", "controller", "RAG Eingine")
exitWithErrorFunc()
}
//+kubebuilder:scaffold:builder
Expand Down Expand Up @@ -144,7 +154,7 @@ func main() {
})
ctx = sharedmain.WithHealthProbesDisabled(ctx)
ctx = sharedmain.WithHADisabled(ctx)
go sharedmain.MainWithConfig(ctx, "webhook", ctrl.GetConfigOrDie(), webhooks.NewWebhooks()...)
go sharedmain.MainWithConfig(ctx, "webhook", ctrl.GetConfigOrDie(), webhooks.NewRAGEngineWebhooks()...)

// wait 2 seconds to allow reconciling webhookconfiguration and service endpoint.
time.Sleep(2 * time.Second)
Expand Down
2 changes: 1 addition & 1 deletion cmd/workspace/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func main() {
})
ctx = sharedmain.WithHealthProbesDisabled(ctx)
ctx = sharedmain.WithHADisabled(ctx)
go sharedmain.MainWithConfig(ctx, "webhook", ctrl.GetConfigOrDie(), webhooks.NewWebhooks()...)
go sharedmain.MainWithConfig(ctx, "webhook", ctrl.GetConfigOrDie(), webhooks.NewWorkspaceWebhooks()...)

// wait 2 seconds to allow reconciling webhookconfiguration and service endpoint.
time.Sleep(2 * time.Second)
Expand Down
12 changes: 11 additions & 1 deletion config/crd/bases/kaito.sh_ragengines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ spec:
singular: ragengine
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- jsonPath: .spec.compute.instanceType
name: Instance
type: string
- jsonPath: .status.conditions[?(@.type=="ResourceReady")].status
name: ResourceReady
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
description: RAGEngine is the Schema for the ragengine API
Expand Down
Loading