-
Notifications
You must be signed in to change notification settings - Fork 334
/
Copy pathcontroller.go
76 lines (63 loc) · 2.84 KB
/
controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
Copyright 2024 The Aibrix Team.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package controller
import (
"github.com/vllm-project/aibrix/pkg/config"
"github.com/vllm-project/aibrix/pkg/controller/kvcache"
"github.com/vllm-project/aibrix/pkg/controller/modeladapter"
"github.com/vllm-project/aibrix/pkg/controller/modelrouter"
"github.com/vllm-project/aibrix/pkg/controller/podautoscaler"
"github.com/vllm-project/aibrix/pkg/controller/rayclusterfleet"
"github.com/vllm-project/aibrix/pkg/controller/rayclusterreplicaset"
"github.com/vllm-project/aibrix/pkg/features"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/manager"
)
// Borrowed logic from Kruise
// Original source: https://github.com/openkruise/kruise/blob/master/pkg/controller/controllers.go
// Reason: We have single controller-manager as well and use the controller-runtime libraries.
// Instead of registering every controller in the main.go, kruise's registration flow is much cleaner.
var controllerAddFuncs []func(manager.Manager, config.RuntimeConfig) error
func Initialize() {
if features.IsControllerEnabled(features.PodAutoscalerController) {
controllerAddFuncs = append(controllerAddFuncs, podautoscaler.Add)
}
if features.IsControllerEnabled(features.ModelAdapterController) {
controllerAddFuncs = append(controllerAddFuncs, modeladapter.Add)
}
if features.IsControllerEnabled(features.ModelRouteController) {
controllerAddFuncs = append(controllerAddFuncs, modelrouter.Add)
}
if features.IsControllerEnabled(features.DistributedInferenceController) {
// TODO: only enable them if KubeRay is installed (check RayCluster CRD exist)
controllerAddFuncs = append(controllerAddFuncs, rayclusterreplicaset.Add)
controllerAddFuncs = append(controllerAddFuncs, rayclusterfleet.Add)
}
if features.IsControllerEnabled(features.KVCacheController) {
controllerAddFuncs = append(controllerAddFuncs, kvcache.Add)
}
}
// SetupWithManager sets up the controller with the Manager.
func SetupWithManager(m manager.Manager, runtimeConfig config.RuntimeConfig) error {
for _, f := range controllerAddFuncs {
if err := f(m, runtimeConfig); err != nil {
if kindMatchErr, ok := err.(*meta.NoKindMatchError); ok {
klog.InfoS("CRD is not installed, its controller will perform noops!", "CRD", kindMatchErr.GroupKind)
continue
}
return err
}
}
return nil
}