Skip to content

Commit def5e8b

Browse files
shaloulcyshaloulcyZiMengSheng
authored
koordlet: support extension controllers (#2459)
Signed-off-by: shaloulcy <[email protected]> Co-authored-by: shaloulcy <[email protected]> Co-authored-by: wangjianyu <[email protected]>
1 parent f960d17 commit def5e8b

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

cmd/koordlet/options/options.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ func InstallExtendedHTTPHandler(mux *http.ServeMux) {
4040
klog.V(4).Infof("extended HTTP handler is registered on path %s", path)
4141
}
4242
}
43+
44+
func RegisterHTTPHandler(path string, handler func() http.HandlerFunc) {
45+
ExtendedHTTPHandlerRegistry[path] = handler
46+
}

pkg/koordlet/extension/interface.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright 2022 The Koordinator 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 extension
18+
19+
import (
20+
clientset "k8s.io/client-go/kubernetes"
21+
22+
"github.com/koordinator-sh/koordinator/pkg/koordlet/statesinformer"
23+
)
24+
25+
type Controller interface {
26+
Run(stopCh <-chan struct{}) error
27+
Name() string
28+
}
29+
30+
type ControllerInitFunc = func(nodeName string, kubeClient clientset.Interface, statesInformer statesinformer.StatesInformer) Controller

pkg/koordlet/koordlet.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
clientsetbeta1 "github.com/koordinator-sh/koordinator/pkg/client/clientset/versioned"
3333
"github.com/koordinator-sh/koordinator/pkg/client/clientset/versioned/typed/scheduling/v1alpha1"
3434
"github.com/koordinator-sh/koordinator/pkg/koordlet/config"
35+
"github.com/koordinator-sh/koordinator/pkg/koordlet/extension"
3536
"github.com/koordinator-sh/koordinator/pkg/koordlet/metriccache"
3637
"github.com/koordinator-sh/koordinator/pkg/koordlet/metrics"
3738
"github.com/koordinator-sh/koordinator/pkg/koordlet/metricsadvisor"
@@ -47,6 +48,8 @@ import (
4748

4849
var (
4950
scheme = apiruntime.NewScheme()
51+
52+
extensionControllerInitFuncs = map[string]extension.ControllerInitFunc{}
5053
)
5154

5255
func init() {
@@ -65,6 +68,8 @@ type daemon struct {
6568
runtimeHook runtimehooks.RuntimeHook
6669
predictServer prediction.PredictServer
6770
executor resourceexecutor.ResourceUpdateExecutor
71+
72+
extensionControllers []extension.Controller
6873
}
6974

7075
func NewDaemon(config *config.Configuration) (Daemon, error) {
@@ -111,6 +116,11 @@ func NewDaemon(config *config.Configuration) (Daemon, error) {
111116
return nil, err
112117
}
113118

119+
extensionControllers := []extension.Controller{}
120+
for _, initFunc := range extensionControllerInitFuncs {
121+
extensionControllers = append(extensionControllers, initFunc(nodeName, kubeClient, statesInformer))
122+
}
123+
114124
d := &daemon{
115125
metricAdvisor: collectorService,
116126
statesInformer: statesInformer,
@@ -119,6 +129,8 @@ func NewDaemon(config *config.Configuration) (Daemon, error) {
119129
runtimeHook: runtimeHook,
120130
predictServer: predictServer,
121131
executor: resourceexecutor.NewResourceUpdateExecutor(),
132+
133+
extensionControllers: extensionControllers,
122134
}
123135

124136
return d, nil
@@ -182,6 +194,16 @@ func (d *daemon) Run(stopCh <-chan struct{}) {
182194
}
183195
}()
184196

197+
for _, c := range d.extensionControllers {
198+
go func(controller extension.Controller) {
199+
name := controller.Name()
200+
klog.Infof("starting extension controller %v", name)
201+
if err := controller.Run(stopCh); err != nil {
202+
klog.Fatalf("Unable to start the extension controller %v, err: %v", name, err)
203+
}
204+
}(c)
205+
}
206+
185207
klog.Info("Start daemon successfully")
186208
<-stopCh
187209
klog.Info("Shutting down daemon")

0 commit comments

Comments
 (0)