Skip to content

Commit

Permalink
Remove mentions to corev2.Locality and use our own Locality object
Browse files Browse the repository at this point in the history
Signed-off-by: eapolinario <[email protected]>
  • Loading branch information
eapolinario committed Sep 11, 2020
1 parent 1eda1a1 commit 9dead19
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
5 changes: 2 additions & 3 deletions internal/app/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"regexp"
"strings"

corev2 "github.com/envoyproxy/go-control-plane/envoy/api/v2/core"
"github.com/envoyproxy/xds-relay/internal/app/metrics"
"github.com/envoyproxy/xds-relay/internal/app/transport"

Expand Down Expand Up @@ -394,7 +393,7 @@ func getResultFragmentFromAction(
}

func getFragmentFromLocalityAction(
locality *corev2.Locality,
locality *transport.Locality,
action *aggregationv1.ResultPredicate_LocalityResultAction) (string, error) {
var matches []string
if action.RegionAction != nil {
Expand Down Expand Up @@ -449,7 +448,7 @@ func compareString(stringMatch *aggregationv1.StringMatch, nodeValue string) (bo
}

func compareLocality(localityMatch *aggregationv1.LocalityMatch,
reqNodeLocality *corev2.Locality) (bool, error) {
reqNodeLocality *transport.Locality) (bool, error) {
// TODO if we can reuse envoy's Locality object, make sure to use cmp.Equal
if reqNodeLocality == nil {
return false, fmt.Errorf("Locality Node field cannot be empty")
Expand Down
8 changes: 7 additions & 1 deletion internal/app/transport/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ type RequestVersion struct {
V3 *discoveryv3.DiscoveryRequest
}

type Locality struct {
Region string
Zone string
SubZone string
}

// Request is the generic interface to abstract v2 and v3 DiscoveryRequest types
type Request interface {
GetResourceNames() []string
Expand All @@ -25,7 +31,7 @@ type Request interface {
GetRegion() string
GetZone() string
GetSubZone() string
GetLocality() *corev2.Locality
GetLocality() *Locality
GetResponseNonce() string
GetRaw() *RequestVersion
CreateWatch() Watch
Expand Down
10 changes: 10 additions & 0 deletions internal/app/transport/requestv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ func (r *RequestV2) GetSubZone() string {
return r.r.GetNode().GetLocality().GetSubZone()
}

// GetLocality gets the node locality
func (r *RequestV2) GetLocality() *Locality {
locality := r.r.GetNode().GetLocality()
return &Locality{
Region: locality.GetRegion(),
Zone: locality.GetZone(),
SubZone: locality.GetSubZone(),
}
}

// GetRaw gets the error details
func (r *RequestV2) GetRaw() *RequestVersion {
return &RequestVersion{V2: r.r}
Expand Down
10 changes: 10 additions & 0 deletions internal/app/transport/requestv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ func (r *RequestV3) GetSubZone() string {
return r.r.GetNode().GetLocality().GetSubZone()
}

// GetLocality gets the node locality
func (r *RequestV3) GetLocality() *Locality {
locality := r.r.GetNode().GetLocality()
return &Locality{
Region: locality.GetRegion(),
Zone: locality.GetZone(),
SubZone: locality.GetSubZone(),
}
}

// GetRaw gets the error details
func (r *RequestV3) GetRaw() *RequestVersion {
return &RequestVersion{V3: r.r}
Expand Down

0 comments on commit 9dead19

Please sign in to comment.