Skip to content

Commit

Permalink
Merge pull request hashicorp#63 from hashicorp/bug/deregister
Browse files Browse the repository at this point in the history
Register all kubernetes services to the `k8s-sync` node
  • Loading branch information
Rebecca Zanzig authored Feb 4, 2019
2 parents b7bdcb7 + ca2f384 commit ae7c501
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 21 deletions.
8 changes: 0 additions & 8 deletions catalog/from-k8s/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,6 @@ func (t *ServiceResource) generateRegistrations(key string) {
r.Service = &rs
r.Service.ID = serviceID(r.Service.Service, address.Address)
r.Service.Address = address.Address
r.Node = *subsetAddr.NodeName
r.Address = address.Address

t.consulMap[key] = append(t.consulMap[key], &r)
}
Expand All @@ -459,8 +457,6 @@ func (t *ServiceResource) generateRegistrations(key string) {
r.Service = &rs
r.Service.ID = serviceID(r.Service.Service, address.Address)
r.Service.Address = address.Address
r.Node = *subsetAddr.NodeName
r.Address = address.Address

t.consulMap[key] = append(t.consulMap[key], &r)
}
Expand Down Expand Up @@ -505,10 +501,6 @@ func (t *ServiceResource) generateRegistrations(key string) {
r.Service = &rs
r.Service.ID = serviceID(r.Service.Service, addr)
r.Service.Address = addr
if subsetAddr.NodeName != nil {
r.Node = *subsetAddr.NodeName
r.Address = addr
}

t.consulMap[key] = append(t.consulMap[key], &r)
}
Expand Down
26 changes: 13 additions & 13 deletions catalog/from-k8s/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,11 +623,11 @@ func TestServiceResource_nodePort(t *testing.T) {
require.Equal("foo", actual[0].Service.Service)
require.Equal("1.2.3.4", actual[0].Service.Address)
require.Equal(30000, actual[0].Service.Port)
require.Equal(node1, actual[0].Node)
require.Equal("k8s-sync", actual[0].Node)
require.Equal("foo", actual[1].Service.Service)
require.Equal("2.3.4.5", actual[1].Service.Address)
require.Equal(30000, actual[1].Service.Port)
require.Equal(node2, actual[1].Node)
require.Equal("k8s-sync", actual[1].Node)
require.NotEqual(actual[0].Service.ID, actual[1].Service.ID)
}

Expand Down Expand Up @@ -727,7 +727,7 @@ func TestServiceResource_nodePort_singleEndpoint(t *testing.T) {
require.Equal("foo", actual[0].Service.Service)
require.Equal("1.2.3.4", actual[0].Service.Address)
require.Equal(30000, actual[0].Service.Port)
require.Equal(node1, actual[0].Node)
require.Equal("k8s-sync", actual[0].Node)
}

// Test that a NodePort created earlier works (doesn't require an Endpoints
Expand Down Expand Up @@ -838,11 +838,11 @@ func TestServiceResource_nodePortInitial(t *testing.T) {
require.Equal("foo", actual[0].Service.Service)
require.Equal("1.2.3.4", actual[0].Service.Address)
require.Equal(30000, actual[0].Service.Port)
require.Equal(node1, actual[0].Node)
require.Equal("k8s-sync", actual[0].Node)
require.Equal("foo", actual[1].Service.Service)
require.Equal("2.3.4.5", actual[1].Service.Address)
require.Equal(30000, actual[1].Service.Port)
require.Equal(node2, actual[1].Node)
require.Equal("k8s-sync", actual[1].Node)
}

// Test that the proper registrations are generated for a NodePort with annotated port.
Expand Down Expand Up @@ -954,11 +954,11 @@ func TestServiceResource_nodePortAnnotatedPort(t *testing.T) {
require.Equal("foo", actual[0].Service.Service)
require.Equal("1.2.3.4", actual[0].Service.Address)
require.Equal(30001, actual[0].Service.Port)
require.Equal(node1, actual[0].Node)
require.Equal("k8s-sync", actual[0].Node)
require.Equal("foo", actual[1].Service.Service)
require.Equal("2.3.4.5", actual[1].Service.Address)
require.Equal(30001, actual[1].Service.Port)
require.Equal(node2, actual[1].Node)
require.Equal("k8s-sync", actual[1].Node)
require.NotEqual(actual[0].Service.ID, actual[1].Service.ID)
}

Expand Down Expand Up @@ -1070,11 +1070,11 @@ func TestServiceResource_nodePortUnnamedPort(t *testing.T) {
require.Equal("foo", actual[0].Service.Service)
require.Equal("1.2.3.4", actual[0].Service.Address)
require.Equal(30000, actual[0].Service.Port)
require.Equal(node1, actual[0].Node)
require.Equal("k8s-sync", actual[0].Node)
require.Equal("foo", actual[1].Service.Service)
require.Equal("2.3.4.5", actual[1].Service.Address)
require.Equal(30000, actual[1].Service.Port)
require.Equal(node2, actual[1].Node)
require.Equal("k8s-sync", actual[1].Node)
require.NotEqual(actual[0].Service.ID, actual[1].Service.ID)
}

Expand Down Expand Up @@ -1186,11 +1186,11 @@ func TestServiceResource_nodePort_internalOnlySync(t *testing.T) {
require.Equal("foo", actual[0].Service.Service)
require.Equal("4.5.6.7", actual[0].Service.Address)
require.Equal(30000, actual[0].Service.Port)
require.Equal(node1, actual[0].Node)
require.Equal("k8s-sync", actual[0].Node)
require.Equal("foo", actual[1].Service.Service)
require.Equal("3.4.5.6", actual[1].Service.Address)
require.Equal(30000, actual[1].Service.Port)
require.Equal(node2, actual[1].Node)
require.Equal("k8s-sync", actual[1].Node)
require.NotEqual(actual[0].Service.ID, actual[1].Service.ID)
}

Expand Down Expand Up @@ -1301,11 +1301,11 @@ func TestServiceResource_nodePort_externalFirstSync(t *testing.T) {
require.Equal("foo", actual[0].Service.Service)
require.Equal("4.5.6.7", actual[0].Service.Address)
require.Equal(30000, actual[0].Service.Port)
require.Equal(node1, actual[0].Node)
require.Equal("k8s-sync", actual[0].Node)
require.Equal("foo", actual[1].Service.Service)
require.Equal("2.3.4.5", actual[1].Service.Address)
require.Equal(30000, actual[1].Service.Port)
require.Equal(node2, actual[1].Node)
require.Equal("k8s-sync", actual[1].Node)
require.NotEqual(actual[0].Service.ID, actual[1].Service.ID)
}

Expand Down
Loading

0 comments on commit ae7c501

Please sign in to comment.