Skip to content

Commit

Permalink
consul backend add wan ip as public only if it n ot equal to lan
Browse files Browse the repository at this point in the history
  • Loading branch information
Shareed2k committed Feb 14, 2021
1 parent 7d089e6 commit 0ef3c9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
17 changes: 9 additions & 8 deletions pkg/backend/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ var (

type (
Backend struct {
opt Options
c *api.Client
opt Options
client *api.Client
}

// Options defines the configuration for this backend
Expand Down Expand Up @@ -54,8 +54,8 @@ func NewBackend(ctx context.Context, m configmap.Mapper) (place.Backend, error)
}

return &Backend{
opt: *opt,
c: client,
opt: *opt,
client: client,
}, nil
}

Expand All @@ -68,7 +68,7 @@ func (b *Backend) CacheKeyName(pattern string) string {
}

func (b *Backend) List(ctx context.Context, pattern string) (place.Printable, error) {
nodes, _, err := b.c.Catalog().Nodes(&api.QueryOptions{
nodes, _, err := b.client.Catalog().Nodes(&api.QueryOptions{
Filter: fmt.Sprintf(`Node contains "%s"`, pattern),
})
if err != nil {
Expand All @@ -77,13 +77,14 @@ func (b *Backend) List(ctx context.Context, pattern string) (place.Printable, er

instances := make([]*place.Instance, len(nodes))
for i, node := range nodes {
hc, _, err := b.c.Health().Node(node.Node, &api.QueryOptions{})
hc, _, err := b.client.Health().Node(node.Node, &api.QueryOptions{})
if err != nil {
return nil, err
}

privateIP := node.Address
publicIP := ""
if wan, ok := node.TaggedAddresses["wan"]; ok {
if wan, ok := node.TaggedAddresses["wan"]; ok && privateIP != wan {
publicIP = wan
}

Expand All @@ -94,7 +95,7 @@ func (b *Backend) List(ctx context.Context, pattern string) (place.Printable, er
Name: node.Node,
Type: "node",
Status: hc.AggregatedStatus(),
PrivateIP: node.Address,
PrivateIP: privateIP,
PublicIP: publicIP,
},
Raw: node,
Expand Down
10 changes: 5 additions & 5 deletions pkg/backend/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ var (

type (
Backend struct {
c *kubernetes.Clientset
opt Options
client *kubernetes.Clientset
opt Options
}

Options struct {
Expand Down Expand Up @@ -104,8 +104,8 @@ func NewBackend(ctx context.Context, m configmap.Mapper) (place.Backend, error)
}

return &Backend{
c: clientset,
opt: *opt,
client: clientset,
opt: *opt,
}, nil
}

Expand All @@ -130,7 +130,7 @@ func (b *Backend) List(ctx context.Context, pattern string) (place.Printable, er
return nil, errors.Wrap(err, "failed to compile regular expression from query")
}

pods, err := b.c.
pods, err := b.client.
CoreV1().
Pods(ns).
List(ctx, metav1.ListOptions{})
Expand Down

0 comments on commit 0ef3c9a

Please sign in to comment.