Skip to content

Commit

Permalink
fix: existing clusters and secretes
Browse files Browse the repository at this point in the history
Signed-off-by: Huabing Zhao <[email protected]>
  • Loading branch information
zhaohuabing committed Nov 12, 2024
1 parent ec56a83 commit bda736c
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 21 deletions.
5 changes: 2 additions & 3 deletions internal/xds/translator/accesslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package translator

import (
"errors"
"sort"
"strings"

Expand Down Expand Up @@ -545,7 +544,7 @@ func processClusterForAccessLog(tCtx *types.ResourceVersionTable, al *ir.AccessL
backendConnection: traffic.BackendConnection,
dns: traffic.DNS,
http2Settings: traffic.HTTP2,
}); err != nil && !errors.Is(err, ErrXdsClusterExists) {
}); err != nil {
return err
}
}
Expand Down Expand Up @@ -573,7 +572,7 @@ func processClusterForAccessLog(tCtx *types.ResourceVersionTable, al *ir.AccessL
backendConnection: traffic.BackendConnection,
dns: traffic.DNS,
http2Settings: traffic.HTTP2,
}); err != nil && !errors.Is(err, ErrXdsClusterExists) {
}); err != nil {
return err
}
}
Expand Down
6 changes: 2 additions & 4 deletions internal/xds/translator/extauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,12 @@ func (*extAuth) patchResources(tCtx *types.ResourceVersionTable,
}
if route.Security.ExtAuth.HTTP != nil {
if err := createExtServiceXDSCluster(
&route.Security.ExtAuth.HTTP.Destination, route.Security.ExtAuth.Traffic, tCtx); err != nil && !errors.Is(
err, ErrXdsClusterExists) {
&route.Security.ExtAuth.HTTP.Destination, route.Security.ExtAuth.Traffic, tCtx); err != nil {
errs = errors.Join(errs, err)
}
} else {
if err := createExtServiceXDSCluster(
&route.Security.ExtAuth.GRPC.Destination, route.Security.ExtAuth.Traffic, tCtx); err != nil && !errors.Is(
err, ErrXdsClusterExists) {
&route.Security.ExtAuth.GRPC.Destination, route.Security.ExtAuth.Traffic, tCtx); err != nil {
errs = errors.Join(errs, err)
}
}
Expand Down
3 changes: 1 addition & 2 deletions internal/xds/translator/extproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ func (*extProc) patchResources(tCtx *types.ResourceVersionTable,
for i := range route.EnvoyExtensions.ExtProcs {
ep := route.EnvoyExtensions.ExtProcs[i]
if err := createExtServiceXDSCluster(
&ep.Destination, ep.Traffic, tCtx); err != nil && !errors.Is(
err, ErrXdsClusterExists) {
&ep.Destination, ep.Traffic, tCtx); err != nil {
errs = errors.Join(errs, err)
}
}
Expand Down
7 changes: 3 additions & 4 deletions internal/xds/translator/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ func createOAuthServerClusters(tCtx *types.ResourceVersionTable,
// If the OIDC provider has a destination, use it.
if oidc.Provider.Destination != nil && len(oidc.Provider.Destination.Settings) > 0 {
if err := createExtServiceXDSCluster(
oidc.Provider.Destination, oidc.Provider.Traffic, tCtx); err != nil && !errors.Is(
err, ErrXdsClusterExists) {
oidc.Provider.Destination, oidc.Provider.Traffic, tCtx); err != nil {
errs = errors.Join(errs, err)
}
} else {
Expand Down Expand Up @@ -372,11 +371,11 @@ func createOAuth2TokenEndpointCluster(tCtx *types.ResourceVersionTable,
clusterArgs.tSocket = tSocket
}

if err = addXdsCluster(tCtx, clusterArgs); err != nil && !errors.Is(err, ErrXdsClusterExists) {
if err = addXdsCluster(tCtx, clusterArgs); err != nil {
return err
}

return err
return nil
}

// createOAuth2Secrets creates OAuth2 client and HMAC secrets from the provided
Expand Down
3 changes: 1 addition & 2 deletions internal/xds/translator/ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package translator

import (
"bytes"
"errors"
"net/url"
"strconv"
"strings"
Expand Down Expand Up @@ -498,7 +497,7 @@ func (t *Translator) createRateLimitServiceCluster(tCtx *types.ResourceVersionTa
tSocket: tSocket,
endpointType: EndpointTypeDNS,
metrics: metrics,
}); err != nil && !errors.Is(err, ErrXdsClusterExists) {
}); err != nil {
return err
}

Expand Down
3 changes: 1 addition & 2 deletions internal/xds/translator/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package translator

import (
"errors"
"fmt"
"sort"

Expand Down Expand Up @@ -191,7 +190,7 @@ func processClusterForTracing(tCtx *types.ResourceVersionTable, tracing *ir.Trac
backendConnection: traffic.BackendConnection,
dns: traffic.DNS,
http2Settings: traffic.HTTP2,
}); err != nil && !errors.Is(err, ErrXdsClusterExists) {
}); err != nil {
return err
}
return nil
Expand Down
4 changes: 3 additions & 1 deletion internal/xds/translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,12 @@ func addXdsSecret(tCtx *types.ResourceVersionTable, secret *tlsv3.Secret) error
return nil
}

// addXdsCluster adds a xds cluster with args.
// If the cluster already exists, it skips adding the cluster and returns
func addXdsCluster(tCtx *types.ResourceVersionTable, args *xdsClusterArgs) error {
// Return early if cluster with the same name exists
if c := findXdsCluster(tCtx, args.name); c != nil {
return ErrXdsClusterExists
return nil
}

xdsCluster := buildXdsCluster(args)
Expand Down
4 changes: 2 additions & 2 deletions internal/xds/translator/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func createExtServiceXDSCluster(rd *ir.RouteDestination, traffic *ir.TrafficFeat
endpointType: endpointType,
dns: traffic.DNS,
http2Settings: traffic.HTTP2,
}); err != nil && !errors.Is(err, ErrXdsClusterExists) {
}); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -198,7 +198,7 @@ func addClusterFromURL(url string, tCtx *types.ResourceVersionTable) error {
clusterArgs.tSocket = tSocket
}

if err = addXdsCluster(tCtx, clusterArgs); err != nil && !errors.Is(err, ErrXdsClusterExists) {
if err = addXdsCluster(tCtx, clusterArgs); err != nil {
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion release-notes/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ new features: |
# Fixes for bugs identified in previous versions.
bug fixes: |
Add a bug fix here
Fixed xDS translation failed when oidc, jwt, and authorization are specified in the same SecurityPolicy
# Enhancements that improve performance.
performance improvements: |
Expand Down

0 comments on commit bda736c

Please sign in to comment.