Skip to content

Commit

Permalink
refactor transport socket merge logic (istio#36619)
Browse files Browse the repository at this point in the history
* refactor transport socket merge logic

Signed-off-by: Rama Chavali <rama.rao@salesforce.com>

* review comments

Signed-off-by: Rama Chavali <rama.rao@salesforce.com>

* move under if

Signed-off-by: Rama Chavali <rama.rao@salesforce.com>

* some more refactor

Signed-off-by: Rama Chavali <rama.rao@salesforce.com>
  • Loading branch information
ramaraochavali committed Dec 31, 2021
1 parent f2e05be commit 17ac63d
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions pilot/pkg/networking/core/v1alpha3/envoyfilter/cluster_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ func mergeTransportSocketCluster(c *cluster.Cluster, cp *model.EnvoyFilterConfig
return false, fmt.Errorf("cast of cp.Value failed: %v", okCpCast)
}

// Check if cluster patch has a transport socket.
if cpValueCast.GetTransportSocket() == nil {
return false, nil
}
var tsmPatch *core.TransportSocket

// Test if the patch contains a config for TransportSocket
// and if the cluster contains a config for Transport Socket Matches
if cpValueCast.GetTransportSocket() != nil && c.GetTransportSocketMatches() != nil {
// First check if the transport socket matches with any cluster transport socket matches.
if len(c.GetTransportSocketMatches()) > 0 {
for _, tsm := range c.GetTransportSocketMatches() {
if tsm.GetTransportSocket() != nil && cpValueCast.GetTransportSocket().Name == tsm.GetTransportSocket().Name {
tsmPatch = tsm.GetTransportSocket()
Expand All @@ -90,17 +93,16 @@ func mergeTransportSocketCluster(c *cluster.Cluster, cp *model.EnvoyFilterConfig
// to merge it again
return true, nil
}
} else if cpValueCast.GetTransportSocket() != nil && c.GetTransportSocket() != nil {
} else if c.GetTransportSocket() != nil {
if cpValueCast.GetTransportSocket().Name == c.GetTransportSocket().Name {
tsmPatch = c.GetTransportSocket()
} else {
// There is a name mismatch, so we cannot do a deep merge. Instead just replace the transport socket
c.TransportSocket = cpValueCast.TransportSocket
return true, nil
}
}

if tsmPatch != nil {
// This means either there is a name mismatch or cluster does not have transport socket matches/transport socket.
// We cannot do a deep merge. Instead just replace the transport socket
if tsmPatch == nil {
c.TransportSocket = cpValueCast.TransportSocket
} else {
// Merge the patch and the cluster at a lower level
dstCluster := tsmPatch.GetTypedConfig()
srcPatch := cpValueCast.GetTransportSocket().GetTypedConfig()
Expand All @@ -114,11 +116,9 @@ func mergeTransportSocketCluster(c *cluster.Cluster, cp *model.EnvoyFilterConfig

// Merge the above result with the whole cluster
proto.Merge(dstCluster, retVal)
return true, nil
}
}

return false, nil
return true, nil
}

// ShouldKeepCluster checks if there is a REMOVE patch on the cluster, returns false if there is on so that it is removed.
Expand Down

0 comments on commit 17ac63d

Please sign in to comment.