Skip to content

Commit

Permalink
optmize the logic of listNamespacesForDistributor func (openkruise#952)
Browse files Browse the repository at this point in the history
Signed-off-by: hantmac <hantmac@outlook.com>

exclude redundant list

Signed-off-by: hantmac <hantmac@outlook.com>
Signed-off-by: Liu Zhenwei <zwliu@thoughtworks.com>
  • Loading branch information
hantmac authored and diannaowa committed Sep 14, 2022
1 parent fb14240 commit b18144f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pkg/controller/resourcedistribution/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,15 @@ func listNamespacesForDistributor(handlerClient client.Client, targets *appsv1al
for _, namespace := range namespacesList.Items {
matchedSet.Insert(namespace.Name)
}
} else if len(targets.NamespaceLabelSelector.MatchLabels) != 0 || len(targets.NamespaceLabelSelector.MatchExpressions) != 0 {
// 2. select the namespaces via targets.NamespaceLabelSelector
} else {
// 2. select the namespaces via targets.IncludedNamespaces
for _, namespace := range targets.IncludedNamespaces.List {
matchedSet.Insert(namespace.Name)
}
}

if !targets.AllNamespaces && (len(targets.NamespaceLabelSelector.MatchLabels) != 0 || len(targets.NamespaceLabelSelector.MatchExpressions) != 0) {
// 3. select the namespaces via targets.NamespaceLabelSelector
selectors, err := util.GetFastLabelSelector(&targets.NamespaceLabelSelector)
if err != nil {
return nil, nil, err
Expand All @@ -308,11 +315,6 @@ func listNamespacesForDistributor(handlerClient client.Client, targets *appsv1al
}
}

// 3. select the namespaces via targets.IncludedNamespaces
for _, namespace := range targets.IncludedNamespaces.List {
matchedSet.Insert(namespace.Name)
}

// 4. exclude the namespaces via target.ExcludedNamespaces
for _, namespace := range targets.ExcludedNamespaces.List {
matchedSet.Delete(namespace.Name)
Expand Down

0 comments on commit b18144f

Please sign in to comment.