Skip to content

Commit

Permalink
Add support for listening on unix socket for introspection endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
adammw authored and mogren committed Nov 11, 2019
1 parent 3b4fd50 commit 7eab704
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ Default: `127.0.0.1:61679`

Specifies the bind address for the introspection endpoint.

A Unix Domain Socket can be specified with the `unix:` prefix before the socket path.

---

`DISABLE_INTROSPECTION`
Expand Down
20 changes: 18 additions & 2 deletions ipamd/introspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ package ipamd

import (
"encoding/json"
"net"
"net/http"
"os"
"strconv"
"strings"
"sync"
"time"

log "github.com/cihub/seelog"

"github.com/aws/amazon-vpc-cni-k8s/pkg/networkutils"
"github.com/aws/amazon-vpc-cni-k8s/pkg/utils/retry"
log "github.com/cihub/seelog"
)

const (
Expand Down Expand Up @@ -62,7 +65,20 @@ func (c *IPAMContext) ServeIntrospection() {
for {
once := sync.Once{}
_ = retry.RetryWithBackoff(retry.NewSimpleBackoff(time.Second, time.Minute, 0.2, 2), func() error {
err := server.ListenAndServe()
var ln net.Listener
var err error

if strings.HasPrefix(server.Addr, "unix:") {
socket := strings.TrimPrefix(server.Addr, "unix:")
ln, err = net.Listen("unix", socket)
} else {
ln, err = net.Listen("tcp", server.Addr)
}

if err == nil {
err = server.Serve(ln)
}

once.Do(func() {
log.Error("Error running http API: ", err)
})
Expand Down

0 comments on commit 7eab704

Please sign in to comment.