-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hyperNode controller framework and provider
Signed-off-by: Monokaix <changxuzheng@huawei.com>
- Loading branch information
Showing
15 changed files
with
571 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,3 +135,5 @@ vendor | |
|
||
# helm dependency files | ||
installer/helm/chart/volcano/requirements.lock | ||
|
||
*.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
FROM golang:1.22.2 AS builder | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y sudo | ||
|
||
RUN wget http://musl.libc.org/releases/musl-1.2.1.tar.gz && \ | ||
tar -xf musl-1.2.1.tar.gz && \ | ||
cd musl-1.2.1 && \ | ||
./configure --prefix=/usr/local/musl && \ | ||
make && sudo make install | ||
|
||
# Build plugin | ||
WORKDIR /volcano | ||
COPY . . | ||
RUN CC=/usr/local/musl/bin/musl-gcc CGO_ENABLED=1 \ | ||
go build -buildmode=plugin -ldflags '-linkmode=external' \ | ||
-o example/hypernode-provider/example-provider.so example/hypernode-provider/example_provider.go | ||
|
||
# Build VC controller base manager image with plugin enabled | ||
FROM golang:1.22.2 AS base | ||
WORKDIR /go/src/volcano.sh/ | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
ADD . volcano | ||
RUN cd volcano && SUPPORT_PLUGINS=yes make vc-controller-manager | ||
|
||
# VC controller manager image with plugin | ||
FROM volcanosh/vc-controller-manager:latest | ||
COPY --from=base /go/src/volcano.sh/volcano/_output/bin/vc-controller-manager /vc-controller-manager | ||
COPY --from=builder /volcano/example/hypernode-provider/example-provider.so / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
# Overview | ||
|
||
As stared in the [network topology aware scheduling](https://github.com/volcano-sh/volcano/blob/master/docs/design/Network%20Topology%20Aware%20Scheduling.md#network-topology-generation-and-update), datacenter's network topology details are different, besides create and update hyperNodes CRD manually, Volcano should also support a method that auto-discovery the network topology and update the hyperNodes CRD automatically, this need the cooperation with under-layer hardware vendors, Volcano controller supports the basic hyperNodes reconcile framework, and expose an interface which can interactive with the hardware vendors, the vendors behaves as a hyeprNodes providers and reconcile hyperNodes such as creating/updating/reporting healthy status, through which Volcano can adapt any hardware vendors with auto-discovery network topology tools supported, and vendors just need to focus on the auto-discovery mechanism while Volcnao supports a basic framework and integrate them with an extensible way. This is similar to the [cloud provider mechanism](https://github.com/kubernetes/cloud-provider) in kubernetes. | ||
|
||
# How to use | ||
|
||
## Write your provider | ||
Write your codes locally and implement the `Plugin` interface in file `pkg/controllers/hypernode/provider/interface.go`, there are two critical params that you need to concern: | ||
`eventCh chan<- Event`: Vendors should send the hyperNode create/update/delete event to this channel, and Volcano controller will communicate to API Server to store them. | ||
`replyCh <-chan Reply`: Volcano will reply errors to vendor providers through this channel when an unexpected error occurs when communicating with the API Server and the retry does not succeed, providers should be aware of that and should resend the event or perform fault-tolerant processing. | ||
|
||
There in an example in `example/hypernode-provider/example_provider.go` demonstrated how to write a provider. | ||
|
||
## Build the provider with volcano controller | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
Copyright 2025 The Volcano Authors. | ||
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 main | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/klog/v2" | ||
"volcano.sh/apis/pkg/apis/topology/v1alpha1" | ||
topologyinformerv1alpha1 "volcano.sh/apis/pkg/client/informers/externalversions/topology/v1alpha1" | ||
|
||
"volcano.sh/volcano/pkg/controllers/hypernode/provider" | ||
) | ||
|
||
func New() provider.Plugin { | ||
return &exampleProvider{ | ||
stopChan: make(chan struct{}), | ||
} | ||
} | ||
|
||
// exampleProvider is an example provider of hyperNodes. | ||
type exampleProvider struct { | ||
stopChan chan struct{} | ||
hyperNodeInformer topologyinformerv1alpha1.HyperNodeInformer | ||
} | ||
|
||
// Name returns the name of the vendor. | ||
func (e *exampleProvider) Name() string { | ||
return "example-provider" | ||
} | ||
|
||
// Start starts the vendor provider. | ||
func (e *exampleProvider) Start(eventCh chan<- provider.Event, replyCh <-chan provider.Reply, informer topologyinformerv1alpha1.HyperNodeInformer) error { | ||
e.hyperNodeInformer = informer | ||
go e.receiveReply(replyCh) | ||
go e.sendEvent(eventCh) | ||
return nil | ||
} | ||
|
||
// Stop stops the provider. | ||
func (e *exampleProvider) Stop() error { | ||
klog.InfoS("exampleProvider stopped") | ||
close(e.stopChan) | ||
return nil | ||
} | ||
|
||
func (e *exampleProvider) sendEvent(eventCh chan<- provider.Event) { | ||
for { | ||
i := 0 | ||
select { | ||
case <-e.stopChan: | ||
klog.InfoS("Stop signal received, exiting sendEvent") | ||
return | ||
default: | ||
hn := v1alpha1.HyperNode{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "hypernode-" + strconv.Itoa(i), | ||
}, | ||
Spec: v1alpha1.HyperNodeSpec{ | ||
Tier: 1, | ||
Members: []v1alpha1.MemberSpec{ | ||
{ | ||
Type: v1alpha1.MemberTypeNode, | ||
Selector: v1alpha1.MemberSelector{ | ||
ExactMatch: &v1alpha1.ExactMatch{ | ||
Name: "node-" + strconv.Itoa(i), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
event := provider.Event{Type: provider.EventAdd, HyperNode: hn} | ||
eventCh <- event | ||
klog.InfoS("Successfully sent add event", "event", event.Type, "hyperNodeName", hn.Name) | ||
time.Sleep(5 * time.Second) // analog sending interval | ||
i++ | ||
if i == 3 { | ||
return | ||
} | ||
} | ||
} | ||
} | ||
|
||
func (e *exampleProvider) receiveReply(replyCh <-chan provider.Reply) { | ||
for { | ||
select { | ||
case reply, ok := <-replyCh: | ||
if !ok { | ||
klog.InfoS("Reply channel closed, exiting receiveReply") | ||
return | ||
} | ||
klog.ErrorS(reply.Error, "Failed to process hyperNode event", "hyperNodeName", reply.HyperNodeName) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Copyright 2025 The Volcano Authors. | ||
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 hypernode | ||
|
||
import ( | ||
"k8s.io/klog/v2" | ||
vcclientset "volcano.sh/apis/pkg/client/clientset/versioned" | ||
vcinformer "volcano.sh/apis/pkg/client/informers/externalversions" | ||
topologyinformerv1alpha1 "volcano.sh/apis/pkg/client/informers/externalversions/topology/v1alpha1" | ||
topologylisterv1alpha1 "volcano.sh/apis/pkg/client/listers/topology/v1alpha1" | ||
|
||
"volcano.sh/volcano/pkg/controllers/framework" | ||
"volcano.sh/volcano/pkg/controllers/hypernode/provider" | ||
) | ||
|
||
func init() { | ||
framework.RegisterController(&hyperNodeController{}) | ||
} | ||
|
||
const ( | ||
name = "hyperNode-controller" | ||
) | ||
|
||
type hyperNodeController struct { | ||
vcClient vcclientset.Interface | ||
vcInformerFactory vcinformer.SharedInformerFactory | ||
hyperNodeInformer topologyinformerv1alpha1.HyperNodeInformer | ||
hyperNodeLister topologylisterv1alpha1.HyperNodeLister | ||
provider provider.Provider | ||
} | ||
|
||
// Run starts the hyperNode controller. | ||
func (hn *hyperNodeController) Run(stopCh <-chan struct{}) { | ||
hn.vcInformerFactory.Start(stopCh) | ||
for informerType, ok := range hn.vcInformerFactory.WaitForCacheSync(stopCh) { | ||
if !ok { | ||
klog.ErrorS(nil, "Failed to sync cache", "type", informerType) | ||
return | ||
} | ||
} | ||
|
||
go hn.provider.Provision(stopCh) | ||
} | ||
|
||
// Name returns the name of the hyperNode controller. | ||
func (hn *hyperNodeController) Name() string { | ||
return name | ||
} | ||
|
||
// Initialize initializes the hyperNode controller. | ||
func (hn *hyperNodeController) Initialize(opt *framework.ControllerOption) error { | ||
hn.vcClient = opt.VolcanoClient | ||
factory := opt.VCSharedInformerFactory | ||
hn.vcInformerFactory = factory | ||
hn.hyperNodeInformer = factory.Topology().V1alpha1().HyperNodes() | ||
hn.hyperNodeLister = hn.hyperNodeInformer.Lister() | ||
hn.provider = provider.NewProvider(hn.vcClient, opt.HyperNodeProviderDir) | ||
return nil | ||
} |
Oops, something went wrong.