Skip to content

Commit

Permalink
Remove inet.af/netaddr dependency (#13)
Browse files Browse the repository at this point in the history
* fix(api): Tailscale v1.32.3 compatibility (#10)

* fix(api): Tailscale v1.32.3 compatibility

* ci: Update build pipeline (#3)

* chore(cicd): Update build pipeline (#11)

* Update actions

* update actions

* use golang 1.19

* clean up

* Replace inet.af/netaddr with net/netip

* Remove dependency on deprecated ioutil package

---------

Co-authored-by: Jan Georgens <jd.georgens@gmail.com>
  • Loading branch information
cfunkhouser and thinkJD authored Dec 24, 2023
1 parent 982e941 commit 99bfa9d
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 48 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,29 @@ on:
jobs:
docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v4
with:
images: ghcr.io/cfunkhouser/tailscalesd
- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ jobs:
name: Build and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.16
go-version: 1
- name: Lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: latest
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: Release tailscalesd
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Build tailscalesd
run: make dist
- name: Release tailscalesd
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM golang:1 AS builder
FROM golang:1.19 AS builder
LABEL maintainer="Simon Elsbrock <simon@iodev.org>"
LABEL org.opencontainers.image.description="Prometheus Service Discovery for Tailscale"

COPY . ./build/tailscalesd/
RUN cd ./build/tailscalesd && make

FROM golang:1
FROM golang:1.19
COPY --from=builder /go/build/tailscalesd/tailscalesd /tailscalesd

ENTRYPOINT ["/tailscalesd"]
Expand Down
19 changes: 15 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
module github.com/cfunkhouser/tailscalesd

go 1.16
go 1.20

require (
github.com/google/go-cmp v0.5.7
github.com/prometheus/client_golang v1.12.1
inet.af/netaddr v0.0.0-20211027220019-c74959edd3b6
github.com/google/go-cmp v0.5.9
github.com/prometheus/client_golang v1.14.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
google.golang.org/protobuf v1.28.1 // indirect
)
46 changes: 24 additions & 22 deletions go.sum

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions localapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"fmt"
"net"
"net/http"
"net/netip"
"time"

"github.com/prometheus/client_golang/prometheus"
"inet.af/netaddr"
)

// LocalAPISocket is the path to the Unix domain socket on which tailscaled
Expand All @@ -23,7 +23,7 @@ const LocalAPISocket = "/run/tailscale/tailscaled.sock"
// borrowed from version 1.22.2. For field details, see:
// https://pkg.go.dev/tailscale.com@v1.22.2/ipn/ipnstate?utm_source=gopls#Status
type interestingStatusSubset struct {
TailscaleIPs []netaddr.IP // Tailscale IP(s) assigned to this node
TailscaleIPs []netip.Addr // Tailscale IP(s) assigned to this node
Self *interestingPeerStatusSubset
Peer map[string]*interestingPeerStatusSubset
}
Expand All @@ -35,7 +35,7 @@ type interestingPeerStatusSubset struct {
HostName string
DNSName string
OS string
TailscaleIPs []netaddr.IP
TailscaleIPs []netip.Addr
Tags []string `json:",omitempty"`
}

Expand All @@ -56,7 +56,7 @@ func (a *localAPIClient) status(ctx context.Context) (interestingStatusSubset, e
}()

var status interestingStatusSubset
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://localhost/localapi/v0/status", nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://local-tailscaled.sock/localapi/v0/status", nil)
if err != nil {
return status, err
}
Expand Down
8 changes: 4 additions & 4 deletions localapi_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package tailscalesd

import (
"net/netip"
"testing"

"github.com/google/go-cmp/cmp"
"inet.af/netaddr"
)

func TestTranslatePeerToDevice(t *testing.T) {
Expand All @@ -29,9 +29,9 @@ func TestTranslatePeerToDevice(t *testing.T) {
HostName: "somethingclever",
DNSName: "this is currently ignored",
OS: "beos",
TailscaleIPs: []netaddr.IP{
netaddr.MustParseIP("100.2.3.4"),
netaddr.MustParseIP("fd7a::1234"),
TailscaleIPs: []netip.Addr{
netip.MustParseAddr("100.2.3.4"),
netip.MustParseAddr("fd7a::1234"),
},
Tags: []string{
"tag:foo",
Expand Down
4 changes: 2 additions & 2 deletions tailscalesd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tailscalesd
import (
"context"
"errors"
"io/ioutil"
"io"
"log"
"net/http"
"net/http/httptest"
Expand All @@ -15,7 +15,7 @@ import (

func TestMain(m *testing.M) {
// No log output during test runs.
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
os.Exit(m.Run())
}

Expand Down

0 comments on commit 99bfa9d

Please sign in to comment.