Skip to content

Commit

Permalink
Add filter on not ready nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaRocco authored and adamjensenbot committed Nov 18, 2022
1 parent 8c62ca6 commit 0a234ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
7 changes: 5 additions & 2 deletions pkg/remotemetrics/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/liqotech/liqo/pkg/consts"
liqoutils "github.com/liqotech/liqo/pkg/utils"
"github.com/liqotech/liqo/pkg/virtualKubelet/forge"
)

Expand Down Expand Up @@ -108,10 +109,12 @@ func (m *resourceGetter) GetNodeNames(ctx context.Context) []string {
})
utilruntime.Must(err)

res := make([]string, len(nodes.Items))
res := make([]string, 0)
for i := range nodes.Items {
node := &nodes.Items[i]
res[i] = node.Name
if liqoutils.IsNodeReady(node) {
res = append(res, node.Name)
}
}

klog.V(2).Infof("Scraping nodes %+v", res)
Expand Down
15 changes: 12 additions & 3 deletions pkg/remotemetrics/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ var _ = Context("Resources", func() {
var getter ResourceGetter
var ctx context.Context

var getNode = func(name string) *corev1.Node {
var getNode = func(name string, conditionReady corev1.ConditionStatus) *corev1.Node {
return &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Status: corev1.NodeStatus{
Conditions: []corev1.NodeCondition{
{
Type: corev1.NodeReady,
Status: conditionReady,
},
},
},
}
}

Expand Down Expand Up @@ -75,8 +83,9 @@ var _ = Context("Resources", func() {
ctx = context.Background()

cl = fake.NewClientBuilder().WithObjects(
getNode("node1"),
getNode("node2"),
getNode("node1", corev1.ConditionTrue),
getNode("node2", corev1.ConditionTrue),
getNode("node3", corev1.ConditionFalse),
getNamespace("ns1", "origNs1", "cluster1"),
getNamespace("ns2", "origNs2", "cluster2"),
getPod("pod1", "ns1", "cluster1", "node1"),
Expand Down

0 comments on commit 0a234ca

Please sign in to comment.