diff --git a/pkg/clustertree/cluster-manager/utils/leaf_model_handler.go b/pkg/clustertree/cluster-manager/utils/leaf_model_handler.go index ed1ac579c..acc8b6fdf 100644 --- a/pkg/clustertree/cluster-manager/utils/leaf_model_handler.go +++ b/pkg/clustertree/cluster-manager/utils/leaf_model_handler.go @@ -8,6 +8,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + utilerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/client-go/kubernetes" "k8s.io/client-go/util/retry" "k8s.io/klog/v2" @@ -104,6 +105,7 @@ func (h ClassificationHandler) GetLeafPods(ctx context.Context, rootNode *corev1 // UpdateRootNodeStatus updates the node's status in root cluster func (h ClassificationHandler) UpdateRootNodeStatus(ctx context.Context, nodesInRoot []*corev1.Node, leafNodeSelector map[string]kosmosv1alpha1.NodeSelector) error { + errors := []error{} for _, node := range nodesInRoot { nodeNameInRoot := node.Name listOptions := metav1.ListOptions{} @@ -114,6 +116,8 @@ func (h ClassificationHandler) UpdateRootNodeStatus(ctx context.Context, nodesIn continue } listOptions.LabelSelector = metav1.FormatLabelSelector(selector.LabelSelector) + } else if h.leafMode == Node { + listOptions.FieldSelector = fmt.Sprintf("metadata.name=%s", nodeNameInRoot) } err := retry.RetryOnConflict(retry.DefaultRetry, func() error { @@ -162,10 +166,10 @@ func (h ClassificationHandler) UpdateRootNodeStatus(ctx context.Context, nodesIn return nil }) if err != nil { - return err + errors = append(errors, err) } } - return nil + return utilerrors.NewAggregate(errors) } func createNode(ctx context.Context, clientset kubernetes.Interface, clusterName, nodeName, gitVersion string, listenPort int32) (*corev1.Node, error) {