Skip to content

Commit e3671f8

Browse files
committed
Add hyperNode controller framework and provider
Signed-off-by: Monokaix <changxuzheng@huawei.com>
1 parent 1d69621 commit e3671f8

File tree

4 files changed

+415
-0
lines changed

4 files changed

+415
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
Copyright 2025 The Volcano 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 hypernode
18+
19+
import (
20+
"k8s.io/klog/v2"
21+
vcclientset "volcano.sh/apis/pkg/client/clientset/versioned"
22+
vcinformer "volcano.sh/apis/pkg/client/informers/externalversions"
23+
topologyinformerv1alpha1 "volcano.sh/apis/pkg/client/informers/externalversions/topology/v1alpha1"
24+
topologylisterv1alpha1 "volcano.sh/apis/pkg/client/listers/topology/v1alpha1"
25+
26+
"volcano.sh/volcano/pkg/controllers/framework"
27+
"volcano.sh/volcano/pkg/controllers/hypernode/provider"
28+
)
29+
30+
func init() {
31+
framework.RegisterController(&hyperNodeController{})
32+
}
33+
34+
const (
35+
name = "hyperNode-controller"
36+
)
37+
38+
type hyperNodeController struct {
39+
vcClient vcclientset.Interface
40+
vcInformerFactory vcinformer.SharedInformerFactory
41+
hyperNodeInformer topologyinformerv1alpha1.HyperNodeInformer
42+
hyperNodeLister topologylisterv1alpha1.HyperNodeLister
43+
provider provider.Provider
44+
}
45+
46+
// Run starts the hyperNode controller.
47+
func (hn *hyperNodeController) Run(stopCh <-chan struct{}) {
48+
hn.vcInformerFactory.Start(stopCh)
49+
for informerType, ok := range hn.vcInformerFactory.WaitForCacheSync(stopCh) {
50+
if !ok {
51+
klog.ErrorS(nil, "Failed to sync cache", "type", informerType)
52+
return
53+
}
54+
}
55+
56+
go hn.provider.Provision(stopCh)
57+
}
58+
59+
// Name returns the name of the hyperNode controller.
60+
func (hn *hyperNodeController) Name() string {
61+
return name
62+
}
63+
64+
// Initialize initializes the hyperNode controller.
65+
func (hn *hyperNodeController) Initialize(opt *framework.ControllerOption) error {
66+
hn.vcClient = opt.VolcanoClient
67+
factory := opt.VCSharedInformerFactory
68+
hn.vcInformerFactory = factory
69+
hn.hyperNodeInformer = factory.Topology().V1alpha1().HyperNodes()
70+
hn.hyperNodeLister = hn.hyperNodeInformer.Lister()
71+
hn.provider = provider.NewProvider(hn.vcClient, factory)
72+
return nil
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
Copyright 2025 The Volcano 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 provider
18+
19+
import (
20+
"fmt"
21+
"time"
22+
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
"volcano.sh/apis/pkg/apis/topology/v1alpha1"
25+
topologyinformerv1alpha1 "volcano.sh/apis/pkg/client/informers/externalversions/topology/v1alpha1"
26+
)
27+
28+
// ExampleProvider is an example provider of hyperNodes.
29+
type ExampleProvider struct {
30+
hyperNodeInformer topologyinformerv1alpha1.HyperNodeInformer
31+
}
32+
33+
// Name returns the name of the vendor.
34+
func (e *ExampleProvider) Name() string {
35+
return "ExampleProvider"
36+
}
37+
38+
// Start starts the vendor provider.
39+
func (e *ExampleProvider) Start(eventCh chan<- Event, controlCh <-chan Reply, informer topologyinformerv1alpha1.HyperNodeInformer) error {
40+
e.hyperNodeInformer = informer
41+
go func() {
42+
for {
43+
select {
44+
default:
45+
event := Event{
46+
Type: EventAdd,
47+
HyperNode: v1alpha1.HyperNode{
48+
Spec: v1alpha1.HyperNodeSpec{
49+
Tier: 1,
50+
Members: []v1alpha1.MemberSpec{
51+
{
52+
Type: v1alpha1.MemberTypeNode,
53+
Selector: v1alpha1.MemberSelector{
54+
ExactMatch: &v1alpha1.ExactMatch{
55+
Name: "node-1",
56+
},
57+
},
58+
},
59+
},
60+
},
61+
Status: v1alpha1.HyperNodeStatus{
62+
NodeCount: 1,
63+
Conditions: []metav1.Condition{
64+
{
65+
Type: "Ready",
66+
Status: metav1.ConditionTrue,
67+
Reason: "NodeAdded",
68+
Message: "Node added successfully",
69+
},
70+
},
71+
},
72+
},
73+
}
74+
eventCh <- event
75+
time.Sleep(5 * time.Second)
76+
}
77+
}
78+
}()
79+
80+
return nil
81+
}
82+
83+
// Stop stops the provider.
84+
func (e *ExampleProvider) Stop() error {
85+
fmt.Println("ExampleProvider stopped")
86+
return nil
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Copyright 2025 The Volcano 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 provider
18+
19+
import (
20+
topologyv1alpha1 "volcano.sh/apis/pkg/apis/topology/v1alpha1"
21+
topologyapplyv1alpha1 "volcano.sh/apis/pkg/client/applyconfiguration/topology/v1alpha1"
22+
topologyinformerv1alpha1 "volcano.sh/apis/pkg/client/informers/externalversions/topology/v1alpha1"
23+
)
24+
25+
// EventType defines the event type.
26+
type EventType string
27+
28+
const (
29+
// EventAdd is the event type for adding hyperNode.
30+
EventAdd EventType = "Add"
31+
// EventUpdate is the event type for updating hyperNode.
32+
EventUpdate EventType = "Update"
33+
// EventDelete is the event type for deleting hyperNode.
34+
EventDelete EventType = "Delete"
35+
)
36+
37+
// Event defines the event from hyperNode provider.
38+
type Event struct {
39+
// Type is the event type.
40+
Type EventType
41+
// HyperNodeName is the name of the hyperNode event.
42+
HyperNodeName string
43+
// HyperNode is the hyperNode object to add.
44+
HyperNode topologyv1alpha1.HyperNode
45+
// Patch is the hyperNode apply configuration, only used for update event.
46+
Patch topologyapplyv1alpha1.HyperNodeApplyConfiguration
47+
}
48+
49+
// Reply is the reply message to hyperNode provider when processed hyperNode event failed,
50+
// and vendor should be aware of that and retry or som.
51+
type Reply struct {
52+
// HyperNodeName is the name of the hyperNode.
53+
HyperNodeName string
54+
// Error is the error message of hyperNode event processing.
55+
Error error
56+
}
57+
58+
// Plugin is the interface for the hyperNode provider, vendors should implement this
59+
// and hyperNode controller call the plugin to populate hyperNodes.
60+
type Plugin interface {
61+
// Name is the name of the plugin.
62+
Name() string
63+
// Start starts the plugin.
64+
Start(eventCh chan<- Event, controlCh <-chan Reply, informer topologyinformerv1alpha1.HyperNodeInformer) error
65+
// Stop stops the plugin.
66+
Stop() error
67+
}

0 commit comments

Comments
 (0)