|
| 1 | +/* |
| 2 | +Copyright 2025 The Kubernetes Authors. |
| 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 server |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + |
| 22 | + corev1 "k8s.io/api/core/v1" |
| 23 | + "k8s.io/apimachinery/pkg/fields" |
| 24 | + "k8s.io/apimachinery/pkg/runtime" |
| 25 | + utilruntime "k8s.io/apimachinery/pkg/util/runtime" |
| 26 | + clientgoscheme "k8s.io/client-go/kubernetes/scheme" |
| 27 | + "k8s.io/client-go/rest" |
| 28 | + ctrl "sigs.k8s.io/controller-runtime" |
| 29 | + "sigs.k8s.io/controller-runtime/pkg/cache" |
| 30 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 31 | + "sigs.k8s.io/gateway-api-inference-extension/api/v1alpha2" |
| 32 | +) |
| 33 | + |
| 34 | +var scheme = runtime.NewScheme() |
| 35 | + |
| 36 | +func init() { |
| 37 | + utilruntime.Must(clientgoscheme.AddToScheme(scheme)) |
| 38 | + utilruntime.Must(v1alpha2.AddToScheme(scheme)) |
| 39 | +} |
| 40 | + |
| 41 | +// NewDefaultManager creates a new controller manager with default configuration. |
| 42 | +func NewDefaultManager(namespace, name string, restConfig *rest.Config) (ctrl.Manager, error) { |
| 43 | + manager, err := ctrl.NewManager(restConfig, ctrl.Options{ |
| 44 | + Scheme: scheme, |
| 45 | + Cache: cache.Options{ |
| 46 | + ByObject: map[client.Object]cache.ByObject{ |
| 47 | + &corev1.Pod{}: { |
| 48 | + Namespaces: map[string]cache.Config{ |
| 49 | + namespace: {}, |
| 50 | + }, |
| 51 | + }, |
| 52 | + &v1alpha2.InferencePool{}: { |
| 53 | + Namespaces: map[string]cache.Config{ |
| 54 | + namespace: { |
| 55 | + FieldSelector: fields.SelectorFromSet(fields.Set{ |
| 56 | + "metadata.name": name, |
| 57 | + }), |
| 58 | + }, |
| 59 | + }, |
| 60 | + }, |
| 61 | + &v1alpha2.InferenceModel{}: { |
| 62 | + Namespaces: map[string]cache.Config{ |
| 63 | + namespace: {}, |
| 64 | + }, |
| 65 | + }, |
| 66 | + }, |
| 67 | + }, |
| 68 | + }) |
| 69 | + if err != nil { |
| 70 | + return nil, fmt.Errorf("failed to create controller manager: %v", err) |
| 71 | + } |
| 72 | + return manager, nil |
| 73 | +} |
0 commit comments