sriov-network-operator
sriov-network-operator copied to clipboard
How can I query which VF is allocated to which pod?
Now I can get this allocation info by running ibv_devices
inside the pod(container), is there a more elegant way to query it? Like exposed as a k8s API resource.
// infiniband_controller.go
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/kubernetes/client-go/kubernetes"
"github.com/kubernetes/client-go/rest"
"github.com/kubernetes/client-go/tools/clientcmd"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func main() {
// Initialize Kubernetes client
var config *rest.Config
if kubeconfig := os.Getenv("KUBECONFIG"); kubeconfig != "" {
config, _ = clientcmd.BuildConfigFromFlags("", kubeconfig)
} else {
config, _ = rest.InClusterConfig()
}
clientset, _ := kubernetes.NewForConfig(config)
// Watch for changes to pods
podClient := clientset.CoreV1().Pods("")
podWatch, _ := podClient.Watch(context.TODO(), metav1.ListOptions{})
// Start controller loop
for {
select {
case event := <-podWatch.ResultChan():
pod := event.Object.(*corev1.Pod)
// Logic to allocate InfiniBand devices to pod
// Update InfiniBandDevice CRD accordingly
fmt.Printf("Pod %s updated\n", pod.Name)
case <-time.After(30 * time.Second):
// Periodically reconcile state
fmt.Println("Reconciling state...")
}
}
}
// infiniband_controller.go
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/kubernetes/client-go/kubernetes"
"github.com/kubernetes/client-go/rest"
"github.com/kubernetes/client-go/tools/clientcmd"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func main() {
// Initialize Kubernetes client
var config *rest.Config
if kubeconfig := os.Getenv("KUBECONFIG"); kubeconfig != "" {
config, _ = clientcmd.BuildConfigFromFlags("", kubeconfig)
} else {
config, _ = rest.InClusterConfig()
}
clientset, _ := kubernetes.NewForConfig(config)
// Watch for changes to pods
podClient := clientset.CoreV1().Pods("")
podWatch, _ := podClient.Watch(context.TODO(), metav1.ListOptions{})
// Start controller loop
for {
select {
case event := <-podWatch.ResultChan():
pod := event.Object.(*corev1.Pod)
// Logic to allocate InfiniBand devices to pod
// Update InfiniBandDevice CRD accordingly
fmt.Printf("Pod %s updated\n", pod.Name)
case <-time.After(30 * time.Second):
// Periodically reconcile state
fmt.Println("Reconciling state...")
}
}
}
you should also be able to see in the pod network-status
annotation the PCI address
@Panlichen did the comments help? can we close this issue?
closing this issue