@@ -17,7 +17,7 @@ package util
1717import (
1818 "context"
1919
20- v1 "k8s.io/api/core/v1"
20+ corev1 "k8s.io/api/core/v1"
2121 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2222 "k8s.io/apimachinery/pkg/labels"
2323 "k8s.io/client-go/kubernetes"
@@ -26,15 +26,48 @@ import (
2626 "github.com/liqotech/liqo/pkg/consts"
2727)
2828
29+ const (
30+ // controlPlaneTaintKey is the key of the taint applied to control-plane nodes.
31+ controlPlaneTaintKey = "node-role.kubernetes.io/control-plane"
32+ )
33+
34+ // IsNodeControlPlane checks if the node has the control-plane taint.
35+ func IsNodeControlPlane (taints []corev1.Taint ) bool {
36+ for _ , taint := range taints {
37+ if taint .Key == controlPlaneTaintKey {
38+ return true
39+ }
40+ }
41+ return false
42+ }
43+
2944// GetNodes returns the list of nodes of the cluster matching the given labels.
30- func GetNodes (ctx context.Context , client kubernetes.Interface , clusterID , labelSelector string ) (* v1.NodeList , error ) {
45+ func GetNodes (ctx context.Context , client kubernetes.Interface , clusterID , labelSelector string ) (* corev1.NodeList , error ) {
46+ remoteNodes , err := client .CoreV1 ().Nodes ().List (ctx , metav1.ListOptions {
47+ LabelSelector : labelSelector ,
48+ })
49+ if err != nil {
50+ klog .Errorf ("%s -> an error occurred while listing nodes: %s" , clusterID , err )
51+ return nil , err
52+ }
53+ return remoteNodes , nil
54+ }
55+
56+ // GetWorkerNodes returns the list of worker nodes of the cluster.
57+ func GetWorkerNodes (ctx context.Context , client kubernetes.Interface , clusterID , labelSelector string ) (* corev1.NodeList , error ) {
3158 remoteNodes , err := client .CoreV1 ().Nodes ().List (ctx , metav1.ListOptions {
3259 LabelSelector : labelSelector ,
3360 })
3461 if err != nil {
3562 klog .Errorf ("%s -> an error occurred while listing nodes: %s" , clusterID , err )
3663 return nil , err
3764 }
65+ var remoteNodeWorkers corev1.NodeList
66+ for i := range remoteNodes .Items {
67+ if ! IsNodeControlPlane (remoteNodes .Items [i ].Spec .Taints ) {
68+ remoteNodeWorkers .Items = append (remoteNodeWorkers .Items , remoteNodes .Items [i ])
69+ }
70+ }
3871 return remoteNodes , nil
3972}
4073
@@ -57,14 +90,14 @@ func CheckVirtualNodes(ctx context.Context, homeClusterClient kubernetes.Interfa
5790
5891 for index := range virtualNodes .Items {
5992 for _ , condition := range virtualNodes .Items [index ].Status .Conditions {
60- if condition .Type == v1 .NodeReady {
61- if condition .Status == v1 .ConditionFalse {
93+ if condition .Type == corev1 .NodeReady {
94+ if condition .Status == corev1 .ConditionFalse {
6295 klog .Infof ("Virtual nodes aren't yet ready: node %d has %s=%s" ,
6396 index , condition .Type , condition .Status )
6497 return false
6598 }
6699 } else {
67- if condition .Status == v1 .ConditionTrue {
100+ if condition .Status == corev1 .ConditionTrue {
68101 klog .Infof ("Virtual nodes aren't yet ready: node %d has %s=%s" ,
69102 index , condition .Type , condition .Status )
70103 return false
0 commit comments