Skip to content

Commit

Permalink
Remove unnecessary matchesConsul methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashwin Venkatesh committed Sep 29, 2020
1 parent 8bbe1ea commit 638d806
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 103 deletions.
13 changes: 0 additions & 13 deletions api/v1alpha1/proxydefaults_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,6 @@ func (in *ProxyDefaults) Validate() error {
return nil
}

// matchesConfig compares the values of the config on the spec and that on the
// the consul proxy-default and returns true if they match and false otherwise.
func (in *ProxyDefaults) matchesConfig(config map[string]interface{}) bool {
if in.Spec.Config == nil || config == nil {
return in.Spec.Config == nil && config == nil
}
var inConfig map[string]interface{}
if err := json.Unmarshal(in.Spec.Config, &inConfig); err != nil {
return false
}
return cmp.Equal(inConfig, config)
}

// convertConfig converts the config of type json.RawMessage which is stored
// by the resource into type map[string]interface{} which is saved by the
// consul API.
Expand Down
29 changes: 0 additions & 29 deletions api/v1alpha1/servicedefaults_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,35 +193,6 @@ type ExposePath struct {
Protocol string `json:"protocol,omitempty"`
}

// matches returns true if the expose config of the entry is the same as the struct
func (e ExposeConfig) matches(expose capi.ExposeConfig) bool {
if e.Checks != expose.Checks {
return false
}

if len(e.Paths) != len(expose.Paths) {
return false
}

for _, path := range e.Paths {
found := false
for _, entryPath := range expose.Paths {
if path.Protocol == entryPath.Protocol &&
path.Path == entryPath.Path &&
path.ListenerPort == entryPath.ListenerPort &&
path.LocalPathPort == entryPath.LocalPathPort {
found = true
break
}
}

if !found {
return false
}
}
return true
}

// toConsul returns the ExposeConfig for the entry
func (e ExposeConfig) toConsul() capi.ExposeConfig {
var paths []capi.ExposePath
Expand Down
56 changes: 0 additions & 56 deletions api/v1alpha1/serviceresolver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,34 +373,13 @@ func (in ServiceResolverSubsetMap) toConsul() map[string]capi.ServiceResolverSub
return m
}

func (in ServiceResolverSubsetMap) matchesConsul(candidate map[string]capi.ServiceResolverSubset) bool {
if len(in) != len(candidate) {
return false
}

for thisKey, thisVal := range in {
candidateVal, ok := candidate[thisKey]
if !ok {
return false
}
if !thisVal.matchesConsul(candidateVal) {
return false
}
}
return true
}

func (in ServiceResolverSubset) toConsul() capi.ServiceResolverSubset {
return capi.ServiceResolverSubset{
Filter: in.Filter,
OnlyPassing: in.OnlyPassing,
}
}

func (in ServiceResolverSubset) matchesConsul(candidate capi.ServiceResolverSubset) bool {
return in.OnlyPassing == candidate.OnlyPassing && in.Filter == candidate.Filter
}

func (in *ServiceResolverRedirect) toConsul() *capi.ServiceResolverRedirect {
if in == nil {
return nil
Expand All @@ -413,16 +392,6 @@ func (in *ServiceResolverRedirect) toConsul() *capi.ServiceResolverRedirect {
}
}

func (in *ServiceResolverRedirect) matchesConsul(candidate *capi.ServiceResolverRedirect) bool {
if in == nil || candidate == nil {
return in == nil && candidate == nil
}
return in.Service == candidate.Service &&
in.ServiceSubset == candidate.ServiceSubset &&
in.Namespace == candidate.Namespace &&
in.Datacenter == candidate.Datacenter
}

func (in ServiceResolverFailoverMap) toConsul() map[string]capi.ServiceResolverFailover {
if in == nil {
return nil
Expand All @@ -434,24 +403,6 @@ func (in ServiceResolverFailoverMap) toConsul() map[string]capi.ServiceResolverF
return m
}

func (in ServiceResolverFailoverMap) matchesConsul(candidate map[string]capi.ServiceResolverFailover) bool {
if len(in) != len(candidate) {
return false
}

for thisKey, thisVal := range in {
candidateVal, ok := candidate[thisKey]
if !ok {
return false
}

if !thisVal.matchesConsul(candidateVal) {
return false
}
}
return true
}

func (in ServiceResolverFailover) toConsul() capi.ServiceResolverFailover {
return capi.ServiceResolverFailover{
Service: in.Service,
Expand All @@ -461,13 +412,6 @@ func (in ServiceResolverFailover) toConsul() capi.ServiceResolverFailover {
}
}

func (in ServiceResolverFailover) matchesConsul(candidate capi.ServiceResolverFailover) bool {
return in.Service == candidate.Service &&
in.ServiceSubset == candidate.ServiceSubset &&
in.Namespace == candidate.Namespace &&
cmp.Equal(in.Datacenters, candidate.Datacenters)
}

func (in *LoadBalancer) toConsul() *capi.LoadBalancer {
if in == nil {
return nil
Expand Down
10 changes: 5 additions & 5 deletions api/v1alpha1/servicesplitter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ func (in *ServiceSplitter) ToConsul() capi.ConfigEntry {
}

func (in *ServiceSplitter) MatchesConsul(candidate capi.ConfigEntry) bool {
serviceSplitterCandidate, ok := candidate.(*capi.ServiceSplitterConfigEntry)
configEntry, ok := candidate.(*capi.ServiceSplitterConfigEntry)
if !ok {
return false
}
// Zero out fields from consul that we don't want to compare on.
serviceSplitterCandidate.Namespace = ""
serviceSplitterCandidate.CreateIndex = 0
serviceSplitterCandidate.ModifyIndex = 0
configEntry.Namespace = ""
configEntry.CreateIndex = 0
configEntry.ModifyIndex = 0

return cmp.Equal(in.ToConsul(), candidate, cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty())
return cmp.Equal(in.ToConsul(), configEntry, cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty())
}

func (in *ServiceSplitter) Validate() error {
Expand Down

0 comments on commit 638d806

Please sign in to comment.