Skip to content
Merged
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
9 changes: 9 additions & 0 deletions internal/k8s/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ func GetPodsByLabels(ctx context.Context, client *kubernetes.Clientset, namespac
return client.CoreV1().Pods(namespace).List(ctx, opt)
}

func IsPodReady(pod *corev1.Pod) bool {
for _, cond := range pod.Status.Conditions {
if cond.Type == corev1.PodReady && cond.Status == corev1.ConditionTrue {
return true
}
}
return false
}

func GetDaemonSetPods(ctx context.Context, client *kubernetes.Clientset, name, namespace, nodename string) (*corev1.PodList, error) {
ds, err := client.AppsV1().DaemonSets(namespace).Get(ctx, name, metav1.GetOptions{})
if err != nil {
Expand Down
82 changes: 82 additions & 0 deletions internal/k8s/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2025 NVIDIA CORPORATION
* SPDX-License-Identifier: Apache-2.0
*/

package k8s

import (
"testing"

"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
)

func TestIsPodReady(t *testing.T) {
testCases := []struct {
name string
pod *corev1.Pod
ready bool
}{
{
name: "Case 1: ready",
pod: &corev1.Pod{
Status: corev1.PodStatus{
Conditions: []corev1.PodCondition{
{
Type: corev1.DisruptionTarget,
Status: corev1.ConditionUnknown,
},
{
Type: corev1.PodReady,
Status: corev1.ConditionTrue,
},
},
},
},
ready: true,
},
{
name: "Case 2: implicit not ready",
pod: &corev1.Pod{
Status: corev1.PodStatus{
Conditions: []corev1.PodCondition{
{
Type: corev1.DisruptionTarget,
Status: corev1.ConditionUnknown,
},
{
Type: corev1.ContainersReady,
Status: corev1.ConditionTrue,
},
},
},
},
ready: false,
},
{
name: "Case 3: explicit not ready",
pod: &corev1.Pod{
Status: corev1.PodStatus{
Conditions: []corev1.PodCondition{
{
Type: corev1.DisruptionTarget,
Status: corev1.ConditionUnknown,
},
{
Type: corev1.PodReady,
Status: corev1.ConditionFalse,
},
},
},
},
ready: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
require.Equal(t, tc.ready, IsPodReady(tc.pod))
})
}
}
3 changes: 3 additions & 0 deletions pkg/engines/slinky/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ func (eng *SlinkyEngine) GetComputeInstances(ctx context.Context, _ engines.Envi
// map k8s host name to SLURM host name
nodeMap := make(map[string]string)
for _, pod := range pods.Items {
if !k8s.IsPodReady(&pod) {
continue
}
host, ok := pod.Labels["slurm.node.name"]
if !ok {
host = pod.Spec.Hostname
Expand Down
18 changes: 9 additions & 9 deletions pkg/node_observer/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
)

type Controller struct {
ctx context.Context
client kubernetes.Interface
nodeInformer *NodeInformer
ctx context.Context
client kubernetes.Interface
statusInformer *StatusInformer
}

func NewController(ctx context.Context, client kubernetes.Interface, cfg *Config) (*Controller, error) {
Expand All @@ -50,23 +50,23 @@ func NewController(ctx context.Context, client kubernetes.Interface, cfg *Config
req.Header.Set("Content-Type", "application/json")
return req, nil
}
nodeInformer, err := NewNodeInformer(ctx, client, &cfg.Trigger, f)
statusInformer, err := NewStatusInformer(ctx, client, &cfg.Trigger, f)
if err != nil {
return nil, err
}
return &Controller{
ctx: ctx,
client: client,
nodeInformer: nodeInformer,
ctx: ctx,
client: client,
statusInformer: statusInformer,
}, nil
}

func (c *Controller) Start() error {
klog.Infof("Starting state observer")
return c.nodeInformer.Start()
return c.statusInformer.Start()
}

func (c *Controller) Stop(err error) {
klog.Infof("Stopping state observer")
c.nodeInformer.Stop(err)
c.statusInformer.Stop(err)
}
127 changes: 0 additions & 127 deletions pkg/node_observer/node_informer.go

This file was deleted.

Loading