8000 remove unnecessary loop and condition evaluation by ramaraochavali · Pull Request #56533 · istio/istio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

remove unnecessary loop and condition evaluation #56533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions pilot/pkg/networking/core/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,6 @@ func (p clusterPatcher) patch(hosts []host.Name, c *cluster.Cluster) *discovery.
}

func (p clusterPatcher) doPatch(hosts []host.Name, c *cluster.Cluster) *cluster.Cluster {
if !envoyfilter.ShouldKeepCluster(p.pctx, p.efw, c, hosts) {
return nil
}
return envoyfilter.ApplyClusterMerge(p.pctx, p.efw, c, hosts)
}

Expand Down
22 changes: 6 additions & 16 deletions pilot/pkg/networking/core/envoyfilter/cluster_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func ApplyClusterMerge(pctx networking.EnvoyFilter_PatchContext, efw *model.Merg
}
for _, cp := range efw.Patches[networking.EnvoyFilter_CLUSTER] {
applied := false
// For removed patches, skip the merge if the patch matches.
if cp.Operation == networking.EnvoyFilter_Patch_REMOVE &&
commonConditionMatch(pctx, cp) &&
clusterMatch(c, cp, hosts) {
return nil
}
if cp.Operation != networking.EnvoyFilter_Patch_MERGE {
IncrementEnvoyFilterMetric(cp.Key(), Cluster, applied)
continue
Expand Down Expand Up @@ -120,22 +126,6 @@ func mergeTransportSocketCluster(c *cluster.Cluster, cp *model.EnvoyFilterConfig
return true, nil
}

// ShouldKeepCluster checks if there is a REMOVE patch on the cluster, returns false if there is one so that it is removed.
func ShouldKeepCluster(pctx networking.EnvoyFilter_PatchContext, efw *model.MergedEnvoyFilterWrapper, c *cluster.Cluster, hosts []host.Name) bool {
if efw == nil {
return true
}
for _, cp := range efw.Patches[networking.EnvoyFilter_CLUSTER] {
if cp.Operation != networking.EnvoyFilter_Patch_REMOVE {
continue
}
if commonConditionMatch(pctx, cp) && clusterMatch(c, cp, hosts) {
return false
}
}
return true
}

// InsertedClusters collects all clusters that are added via ADD operation and match the patch context.
func InsertedClusters(pctx networking.EnvoyFilter_PatchContext, efw *model.MergedEnvoyFilterWrapper) []*cluster.Cluster {
if efw == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,7 @@ func TestClusterPatching(t *testing.T) {
efw := push.EnvoyFilters(tc.proxy)
output := []*cluster.Cluster{}
for _, c := range tc.input {
if ShouldKeepCluster(tc.patchContext, efw, c, []host.Name{host.Name(tc.host)}) {
pc := ApplyClusterMerge(tc.patchContext, efw, c, []host.Name{host.Name(tc.host)})
if pc := ApplyClusterMerge(tc.patchContext, efw, c, []host.Name{host.Name(tc.host)}); pc != nil {
output = append(output, pc)
}
}
Expand Down
0