Skip to content

Commit

Permalink
sync enterprise files with oss (#10705)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9c3af1a)
  • Loading branch information
Chris S. Kim committed Jul 28, 2021
1 parent ae34d7b commit 50ac64f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
20 changes: 9 additions & 11 deletions agent/agent_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,27 +410,22 @@ func TestAgent_Service(t *testing.T) {
}
fillAgentServiceEnterpriseMeta(expectedResponse, structs.DefaultEnterpriseMeta())
hash1, err := hashstructure.Hash(expectedResponse, nil)
if err != nil {
t.Fatalf("error generating hash: %v", err)
}
require.NoError(t, err, "failed to generate hash")
expectedResponse.ContentHash = fmt.Sprintf("%x", hash1)

// Copy and modify
updatedResponse := *expectedResponse
updatedResponse.Port = 9999
updatedResponse.ContentHash = "" // clear field before generating a new hash
updatedResponse.ContentHash = "" // clear field before hashing
hash2, err := hashstructure.Hash(updatedResponse, nil)
if err != nil {
t.Fatalf("error generating hash: %v", err)
}
require.NoError(t, err, "failed to generate hash")
updatedResponse.ContentHash = fmt.Sprintf("%x", hash2)

// Simple response for non-proxy service registered in TestAgent config
expectWebResponse := &api.AgentService{
ID: "web",
Service: "web",
Port: 8181,
ContentHash: "f012740ee2d8ce60",
ID: "web",
Service: "web",
Port: 8181,
Weights: api.AgentWeights{
Passing: 1,
Warning: 1,
Expand All @@ -446,6 +441,9 @@ func TestAgent_Service(t *testing.T) {
Datacenter: "dc1",
}
fillAgentServiceEnterpriseMeta(expectWebResponse, structs.DefaultEnterpriseMeta())
hash3, err := hashstructure.Hash(expectWebResponse, nil)
require.NoError(t, err, "failed to generate hash")
expectWebResponse.ContentHash = fmt.Sprintf("%x", hash3)

tests := []struct {
name string
Expand Down
5 changes: 3 additions & 2 deletions agent/structs/service_definition.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package structs

import (
"github.com/hashicorp/consul/lib"
"github.com/hashicorp/go-multierror"

"github.com/hashicorp/consul/lib"
)

// ServiceDefinition is used to JSON decode the Service definitions. For
Expand Down Expand Up @@ -86,7 +87,7 @@ func (s *ServiceDefinition) NodeService() *NodeService {
ns.Proxy.Upstreams[i].DestinationType = UpstreamDestTypeService
}

// If a proxy's namespace is not defined, inherit the server's namespace.
// If a proxy's namespace is not defined, inherit the proxied service's namespace.
// Applicable only to Consul Enterprise.
if ns.Proxy.Upstreams[i].DestinationNamespace == "" {
ns.Proxy.Upstreams[i].DestinationNamespace = ns.EnterpriseMeta.NamespaceOrEmpty()
Expand Down

0 comments on commit 50ac64f

Please sign in to comment.