Skip to content

Commit

Permalink
Make etcd's stored data more flexible and configurable
Browse files Browse the repository at this point in the history
Signed-off-by: duanmengkk <[email protected]>
  • Loading branch information
duanmengkk committed Jun 27, 2024
1 parent 304964c commit 9309613
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 78 deletions.

This file was deleted.

20 changes: 17 additions & 3 deletions pkg/kubenest/controller/virtualcluster_init_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1"
"github.com/kosmos.io/kosmos/pkg/generated/clientset/versioned"
"github.com/kosmos.io/kosmos/pkg/kubenest/constants"
"github.com/kosmos.io/kosmos/pkg/kubenest/controller/virtualcluster.node.controller/selector"
"github.com/kosmos.io/kosmos/pkg/kubenest/util"
)

Expand Down Expand Up @@ -454,10 +453,24 @@ func retrieveAssignedNodesByPolicy(virtualCluster *v1alpha1.VirtualCluster, poli
return nodesAssignedMatchedPolicy, nil
}

func matchesWithLabelSelector(metaLabels labels.Set, labelSelector *metav1.LabelSelector) (bool, error) {
if labelSelector == nil {
return true, nil
}

sel, err := metav1.LabelSelectorAsSelector(labelSelector)
if err != nil {
return false, err
}

match := sel.Matches(metaLabels)
return match, nil
}

func retrieveGlobalNodesWithLabelSelector(nodes []v1alpha1.GlobalNode, labelSelector *metav1.LabelSelector) ([]v1alpha1.GlobalNode, error) {
matchedNodes := make([]v1alpha1.GlobalNode, 0)
for _, node := range nodes {
matched, err := selector.MatchesWithLabelSelector(node.Spec.Labels, labelSelector)
matched, err := matchesWithLabelSelector(node.Spec.Labels, labelSelector)
if err != nil {
return nil, err
}
Expand All @@ -474,7 +487,8 @@ func (c *VirtualClusterInitController) setGlobalNodeUsageStatus(virtualCluster *
if err != nil {
if apierrors.IsNotFound(err) {
klog.Errorf("globalnode %s not found. This should not happen normally", node.Name)
return nil // 如果节点不存在,则不执行更新并返回nil
// 如果节点不存在,则不执行更新并返回nil
return nil
}
return fmt.Errorf("failed to get globalNode %s: %v", node.Name, err)
}
Expand Down

0 comments on commit 9309613

Please sign in to comment.