Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package main

import (
"context"
"flag"
"os"
"os/signal"
"syscall"

corev1 "k8s.io/api/core/v1"
"github.com/spf13/cobra"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"

"github.com/ray-project/kuberay/podpool/manager"
)

var (
kubeconfig string
nodeName string
operatingSys string
arch string
)

func init() {
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig file")
flag.StringVar(&nodeName, "node-name", "cache-pod-node", "Name of the virtual node")
flag.StringVar(&operatingSys, "os", "linux", "Operating system of the virtual node")
flag.StringVar(&arch, "arch", "amd64", "Architecture of the virtual node")
}

func main() {
// Create a Cobra command to handle command line arguments
cmd := &cobra.Command{
Use: "cache-pod-manager",
Short: "Virtual Kubelet-based Cache Pod Manager",
Long: "A Virtual Kubelet implementation that manages cached pods",
Run: func(cmd *cobra.Command, args []string) {
run(cmd.Context())
},
}

// Execute the command
if err := cmd.Execute(); err != nil {
klog.Fatalf("Command execution failed: %v", err)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Command-line flags never parsed or connected to Cobra

High Severity

The flags (kubeconfig, node-name, os, arch) are defined using the standard flag package in init(), but the main() function uses Cobra for command execution without integrating these flags. Since neither flag.Parse() is called nor cmd.Flags().AddGoFlagSet(flag.CommandLine) is used to connect the standard library flags to Cobra, all command-line arguments will be ignored. The variables will always have their default values regardless of user input.

Fix in Cursor Fix in Web

}

func run(ctx context.Context) {
// Load the Kubernetes configuration
var config *clientcmd.ClientConfig
if kubeconfig != "" {
// Use the provided kubeconfig file
configOverride := &clientcmd.ConfigOverrides{}
config = &clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfig}.ClientConfig()
} else {
// Use in-cluster config if available, otherwise fall back to default config
config = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
clientcmd.NewDefaultClientConfigLoadingRules(),
&configOverride,
)
}

restConfig, err := config.ClientConfig()
if err != nil {
klog.Fatalf("Failed to create Kubernetes client config: %v", err)
}

// Create the Kubernetes client
clientset, err := kubernetes.NewForConfig(restConfig)
if err != nil {
klog.Fatalf("Failed to create Kubernetes client: %v", err)
}

// Create the CachePodManager
cachePodManager, err := manager.NewCachePodManager(nodeName, operatingSys, arch, clientset)
if err != nil {
klog.Fatalf("Failed to create CachePodManager: %v", err)
}

// Set up signal handling for graceful shutdown
ctx, cancel := context.WithCancel(ctx)
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)

// Start the CachePodManager
if err := cachePodManager.Start(ctx); err != nil {
klog.Fatalf("Failed to start CachePodManager: %v", err)
}

// Set up the pod notifier
cachePodManager.NotifyPods(ctx, func(pod *corev1.Pod) {
// Handle pod notifications
klog.Infof("Received pod notification for %s/%s", pod.Namespace, pod.Name)
})

// Wait for shutdown signal
select {
case <-sigCh:
klog.Info("Received shutdown signal")
case <-ctx.Done():
klog.Info("Context cancelled")
}

cancel()
}
21 changes: 21 additions & 0 deletions podpool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# KubeRay Pod Pool Virtual Kubelet

KubeRay Pod Pool Virtual Kubelet is an optional and standalone component of the KubeRay Ecosystem.
It provides warmed-up pod pools by registering itself as a virtual kubelet to a Kubernetes cluster.
When KubeRay requests pods from the virtual kubelet,
the actual pods are taken from one of the pod pools specified by the users and effectively skip:

* resource scheduling time
* image pulling time
* volume preparation time
because those pods are already active and waiting in pools.

<!-- TODO: Add docs for local development -->

## controller

pod pool controller

## manager

watch pod which scheduled by kubernetes, pick and sync pod status from pod pool to kubernetes
3 changes: 3 additions & 0 deletions podpool/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package main

func main() {}
1 change: 1 addition & 0 deletions podpool/controller/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package controller
50 changes: 50 additions & 0 deletions podpool/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module github.com/ray-project/kuberay/podpool

go 1.22.0

toolchain go1.24.8

require (
github.com/virtual-kubelet/virtual-kubelet v1.11.0
k8s.io/api v0.29.1
k8s.io/apimachinery v0.29.1
k8s.io/client-go v0.29.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
152 changes: 152 additions & 0 deletions podpool/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading