mirror of
https://github.com/hanzo-ml/kuberay.git
synced 2026-10-30 19:48:47 +00:00
* add main code to podpool * add kubeletVersion function * fix k8s version and add makefile * remove some unused var * Update podpool/Makefile Signed-off-by: Rueian <[email protected]> * resolve cursor conversation --------- Signed-off-by: Rueian <[email protected]> Co-authored-by: Rueian <[email protected]>
148 lines
4.6 KiB
Go
148 lines
4.6 KiB
Go
package manager
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/virtual-kubelet/virtual-kubelet/trace"
|
|
corev1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/fields"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
"k8s.io/apimachinery/pkg/watch"
|
|
"k8s.io/client-go/kubernetes"
|
|
"k8s.io/client-go/tools/cache"
|
|
)
|
|
|
|
// CachePodManager implements the Virtual Kubelet PodLifecycleHandler, PodNotifier, and NodeProvider interfaces
|
|
type CachePodManager struct {
|
|
nodeName string
|
|
operatingSys string
|
|
arch string
|
|
client kubernetes.Interface
|
|
podInformer cache.SharedIndexInformer
|
|
}
|
|
|
|
// NewCachePodManager creates a new CachePodManager
|
|
func NewCachePodManager(nodeName, operatingSys, arch string, kubeClient kubernetes.Interface) (*CachePodManager, error) {
|
|
// Set up the pod informer to watch for pod changes
|
|
podInformer := cache.NewSharedIndexInformer(
|
|
&cache.ListWatch{
|
|
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
|
options.FieldSelector = fields.OneTermEqualSelector("spec.nodeName", nodeName).String()
|
|
return kubeClient.CoreV1().Pods(metav1.NamespaceAll).List(context.TODO(), options)
|
|
},
|
|
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
|
options.FieldSelector = fields.OneTermEqualSelector("spec.nodeName", nodeName).String()
|
|
return kubeClient.CoreV1().Pods(metav1.NamespaceAll).Watch(context.TODO(), options)
|
|
},
|
|
},
|
|
&corev1.Pod{},
|
|
0, // resync period (0 means no resync)
|
|
cache.Indexers{},
|
|
)
|
|
|
|
manager := &CachePodManager{
|
|
nodeName: nodeName,
|
|
operatingSys: operatingSys,
|
|
arch: arch,
|
|
client: kubeClient,
|
|
podInformer: podInformer,
|
|
}
|
|
|
|
return manager, nil
|
|
}
|
|
|
|
func (m *CachePodManager) ConfigureNode(context.Context, *corev1.Node) {
|
|
// TODO: Implement node configuration logic
|
|
}
|
|
|
|
// CreatePod implements the PodLifecycleHandler interface
|
|
func (m *CachePodManager) CreatePod(ctx context.Context, pod *corev1.Pod) error {
|
|
ctx, span := trace.StartSpan(ctx, "CreatePod")
|
|
defer span.End()
|
|
|
|
// TODO: Implement pod creation logic
|
|
return errors.New("CreatePod not implemented")
|
|
}
|
|
|
|
// UpdatePod implements the PodLifecycleHandler interface
|
|
func (m *CachePodManager) UpdatePod(ctx context.Context, pod *corev1.Pod) error {
|
|
ctx, span := trace.StartSpan(ctx, "UpdatePod")
|
|
defer span.End()
|
|
|
|
// TODO: Implement pod update logic
|
|
return errors.New("UpdatePod not implemented")
|
|
}
|
|
|
|
// DeletePod implements the PodLifecycleHandler interface
|
|
func (m *CachePodManager) DeletePod(ctx context.Context, pod *corev1.Pod) error {
|
|
ctx, span := trace.StartSpan(ctx, "DeletePod")
|
|
defer span.End()
|
|
|
|
// TODO: Implement pod deletion logic
|
|
return errors.New("DeletePod not implemented")
|
|
}
|
|
|
|
// GetPod implements the PodLifecycleHandler interface
|
|
func (m *CachePodManager) GetPod(ctx context.Context, namespace, name string) (*corev1.Pod, error) {
|
|
ctx, span := trace.StartSpan(ctx, "GetPod")
|
|
defer span.End()
|
|
|
|
// TODO: Implement pod retrieval logic
|
|
return nil, errors.New("GetPod not implemented")
|
|
}
|
|
|
|
// GetPodStatus implements the PodLifecycleHandler interface
|
|
func (m *CachePodManager) GetPodStatus(ctx context.Context, namespace, name string) (*corev1.PodStatus, error) {
|
|
ctx, span := trace.StartSpan(ctx, "GetPodStatus")
|
|
defer span.End()
|
|
|
|
// TODO: Implement pod status retrieval logic
|
|
return nil, errors.New("GetPodStatus not implemented")
|
|
}
|
|
|
|
// GetPods implements the PodLifecycleHandler interface
|
|
func (m *CachePodManager) GetPods(ctx context.Context) ([]*corev1.Pod, error) {
|
|
ctx, span := trace.StartSpan(ctx, "GetPods")
|
|
defer span.End()
|
|
|
|
// TODO: Implement pod listing logic
|
|
return nil, errors.New("GetPods not implemented")
|
|
}
|
|
|
|
// NotifyPods implements the PodNotifier interface
|
|
func (m *CachePodManager) NotifyPods(ctx context.Context, f func(*corev1.Pod)) {
|
|
// TODO: Implement pod notify logic
|
|
}
|
|
|
|
// Ping implements the NodeProvider interface
|
|
func (m *CachePodManager) Ping(ctx context.Context) error {
|
|
ctx, span := trace.StartSpan(ctx, "Ping")
|
|
defer span.End()
|
|
|
|
// TODO: Implement ping logic to verify connectivity
|
|
return nil // Return nil to indicate success
|
|
}
|
|
|
|
// NotifyNodeStatus implements the NodeProvider interface
|
|
func (m *CachePodManager) NotifyNodeStatus(ctx context.Context, cb func(*corev1.Node)) {
|
|
ctx, span := trace.StartSpan(ctx, "NotifyNodeStatus")
|
|
defer span.End()
|
|
|
|
// TODO: Implement node status notification logic
|
|
}
|
|
|
|
// Start starts the pod informer
|
|
func (m *CachePodManager) Start(ctx context.Context) error {
|
|
go m.podInformer.Run(ctx.Done())
|
|
|
|
// Wait for the cache to sync
|
|
if !cache.WaitForCacheSync(ctx.Done(), m.podInformer.HasSynced) {
|
|
return fmt.Errorf("failed to sync pod cache")
|
|
}
|
|
|
|
return nil
|
|
}
|