From d09cac0972cdd35a5245cbdb51835c2aca427a6e Mon Sep 17 00:00:00 2001 From: Christian Hoffmeister Date: Sat, 20 Nov 2021 12:51:34 +0100 Subject: [PATCH] chore --- .github/workflows/release.yml | 28 +++ .github/workflows/test.yml | 19 ++ .gitignore | 12 +- .goreleaser.yml | 26 +++ Dockerfile | 3 + Dockerfile.in | 21 --- Makefile | 171 ------------------ README.md | 4 +- RELEASE.md | 36 ---- build/build.sh | 41 ----- build/test.sh | 53 ------ ...onfig => default-gateway-agent-config.yaml | 0 default-gateway-agent.yaml | 2 +- go.mod | 31 ++-- go.sum | 47 +++-- .../fakefs/fakefs.go => internal/fs.go | 2 +- .../default-gateway-agent.go => main.go | 12 +- ...ault-gateway-agent_test.go => main_test.go | 20 +- pkg/version/version.go | 21 --- 19 files changed, 144 insertions(+), 405 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml create mode 100644 .goreleaser.yml create mode 100644 Dockerfile delete mode 100644 Dockerfile.in delete mode 100644 Makefile delete mode 100644 RELEASE.md delete mode 100755 build/build.sh delete mode 100755 build/test.sh rename agent-config/config => default-gateway-agent-config.yaml (100%) rename cmd/default-gateway-agent/testing/fakefs/fakefs.go => internal/fs.go (99%) rename cmd/default-gateway-agent/default-gateway-agent.go => main.go (97%) rename cmd/default-gateway-agent/default-gateway-agent_test.go => main_test.go (83%) delete mode 100644 pkg/version/version.go diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..24a7f3a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,28 @@ +name: release +on: + push: + tags: + - "*" +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v2 + with: + go-version: 1.17.x + - uses: docker/login-action@v1 + with: + registry: https://ghcr.io + username: airfocusio + password: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + distribution: goreleaser + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..3287ad9 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,19 @@ +name: test +on: + push: + branches: + - "*" + pull_request: + branches: + - main +env: + GO111MODULE: on +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v2 + with: + go-version: 1.17.x + - uses: actions/checkout@v2 + - run: go test . diff --git a/.gitignore b/.gitignore index c3c2a0b..849ddff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1 @@ -/bin -/.go -/.go-cache -/.push-* -/.container-* -/.dockerfile-* - -# Emacs save files -*~ -\#*\# -.\#* +dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..5c7c0e2 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,26 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com +before: + hooks: + - go mod tidy +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + goarch: + - amd64 +dockers: + - image_templates: + - "ghcr.io/airfocusio/{{ .ProjectName }}:{{ .Tag }}" + - "ghcr.io/airfocusio/{{ .ProjectName }}:latest" +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "0.0.0-dev" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f1b07dd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM scratch +ENTRYPOINT ["/bin/default-gateway-agent"] +COPY default-gateway-agent /bin/default-gateway-agent diff --git a/Dockerfile.in b/Dockerfile.in deleted file mode 100644 index b026051..0000000 --- a/Dockerfile.in +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2016 The Kubernetes Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FROM ARG_FROM - -MAINTAINER Michael Taufen - -ADD bin/ARG_ARCH/ARG_BIN /ARG_BIN - -ENTRYPOINT ["/ARG_BIN"] diff --git a/Makefile b/Makefile deleted file mode 100644 index df1b649..0000000 --- a/Makefile +++ /dev/null @@ -1,171 +0,0 @@ -# Copyright 2016 The Kubernetes Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# The binary to build (just the basename). -BIN := default-gateway-agent - -# This repo's root import path (under GOPATH). -PKG := github.com/choffmeister/default-gateway-agent - -# Where to push the docker image. -REGISTRY ?= choffmeister - -# Which architecture to build - see $(ALL_ARCH) for options. -ARCH ?= amd64 - -# This version-strategy uses git tags to set the version string -VERSION := $(shell git describe --tags --always --dirty) -# -# This version-strategy uses a manual value to set the version string -#VERSION := 1.2.3 - -### -### These variables should not need tweaking. -### - -SRC_DIRS := cmd pkg # directories which hold app source (not vendored) - -ALL_ARCH := amd64 arm arm64 ppc64le - -# Ensure that the docker command line supports the manifest images -export DOCKER_CLI_EXPERIMENTAL=enabled - -# docker interactive console -INTERACTIVE := $(shell [ -t 0 ] && echo 1 || echo 0) -TTY= -ifeq ($(INTERACTIVE), 1) - TTY=t -endif - -# Set default base image dynamically for each arch -ifeq ($(ARCH),amd64) - BASEIMAGE?=k8s.gcr.io/debian-iptables-amd64:v11.0.2 -endif -ifeq ($(ARCH),arm) - BASEIMAGE?=k8s.gcr.io/debian-iptables-arm:v11.0.2 -endif -ifeq ($(ARCH),arm64) - BASEIMAGE?=k8s.gcr.io/debian-iptables-arm64:v11.0.2 -endif -ifeq ($(ARCH),ppc64le) - BASEIMAGE?=k8s.gcr.io/debian-iptables-ppc64le:v11.0.2 -endif - -IMAGE := $(REGISTRY)/$(BIN)-$(ARCH) -MANIFEST_IMAGE := $(REGISTRY)/$(BIN) - -BUILD_IMAGE ?= golang:1.14-alpine - -# If you want to build all binaries, see the 'all-build' rule. -# If you want to build all containers, see the 'all-container' rule. -# If you want to build AND push all containers, see the 'all-push' rule. -all: build - -build-%: - @$(MAKE) --no-print-directory ARCH=$* build - -container-%: - @$(MAKE) --no-print-directory ARCH=$* container - -push-%: - @$(MAKE) --no-print-directory ARCH=$* push - -all-build: $(addprefix build-, $(ALL_ARCH)) - -all-container: $(addprefix container-, $(ALL_ARCH)) - -all-push: $(addprefix push-, $(ALL_ARCH)) - docker manifest create --amend $(MANIFEST_IMAGE):$(VERSION) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(MANIFEST_IMAGE)\-&:$(VERSION)~g") - @for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${MANIFEST_IMAGE}:${VERSION} ${MANIFEST_IMAGE}-$${arch}:${VERSION}; done - docker manifest push --purge ${MANIFEST_IMAGE}:${VERSION} - -build: bin/$(ARCH)/$(BIN) - -bin/$(ARCH)/$(BIN): build-dirs - @echo "building: $@" - @docker pull $(BUILD_IMAGE) - @docker run \ - -$(TTY)i \ - -u $$(id -u):$$(id -g) \ - -v $$(pwd)/.go:/go \ - -v $$(pwd)/.go-cache:/.cache \ - -v $$(pwd):/go/src/$(PKG) \ - -v $$(pwd)/bin/$(ARCH):/go/bin \ - -v $$(pwd)/bin/$(ARCH):/go/bin/linux_$(ARCH) \ - -v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \ - -w /go/src/$(PKG) \ - $(BUILD_IMAGE) \ - /bin/sh -c " \ - ARCH=$(ARCH) \ - VERSION=$(VERSION) \ - PKG=$(PKG) \ - ./build/build.sh \ - " - -DOTFILE_IMAGE = $(subst :,_,$(subst /,_,$(IMAGE))-$(VERSION)) - -container: .container-$(DOTFILE_IMAGE) container-name -.container-$(DOTFILE_IMAGE): bin/$(ARCH)/$(BIN) Dockerfile.in - @sed \ - -e 's|ARG_BIN|$(BIN)|g' \ - -e 's|ARG_ARCH|$(ARCH)|g' \ - -e 's|ARG_FROM|$(BASEIMAGE)|g' \ - Dockerfile.in > .dockerfile-$(ARCH) - @docker build --pull -t $(IMAGE):$(VERSION) -f .dockerfile-$(ARCH) . - @docker images -q $(IMAGE):$(VERSION) > $@ - -container-name: - @echo "container: $(IMAGE):$(VERSION)" - -push: .push-$(DOTFILE_IMAGE) push-name -.push-$(DOTFILE_IMAGE): .container-$(DOTFILE_IMAGE) -ifeq ($(findstring gcr.io,$(REGISTRY)),gcr.io) - @gcloud docker -- push $(IMAGE):$(VERSION) -else - @docker push $(IMAGE):$(VERSION) -endif - @docker images -q $(IMAGE):$(VERSION) > $@ - -push-name: - @echo "pushed: $(IMAGE):$(VERSION)" - -version: - @echo $(VERSION) - -test: build-dirs - @docker run \ - -$(TTY)i \ - -u $$(id -u):$$(id -g) \ - -v $$(pwd)/.go:/go \ - -v $$(pwd)/.go-cache:/.cache \ - -v $$(pwd):/go/src/$(PKG) \ - -v $$(pwd)/bin/$(ARCH):/go/bin \ - -v $$(pwd)/.go/std/$(ARCH):/usr/local/go/pkg/linux_$(ARCH)_static \ - -w /go/src/$(PKG) \ - $(BUILD_IMAGE) \ - /bin/sh -c " \ - ./build/test.sh $(SRC_DIRS) \ - " - -build-dirs: - @mkdir -p bin/$(ARCH) - @mkdir -p .go/src/$(PKG) .go/pkg .go/bin .go/std/$(ARCH) .go-cache - -clean: container-clean bin-clean - -container-clean: - rm -rf .container-* .dockerfile-* .push-* - -bin-clean: - rm -rf .go bin diff --git a/README.md b/README.md index 6057666..e5ae4eb 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ The spec in `default-gateway-agent.yaml` specifies the `kube-system` namespace f TODO ``` -kubectl create configmap default-gateway-agent --from-file=agent-config --namespace=kube-system +kubectl create configmap default-gateway-agent --from-file=default-gatway-agent-config.yaml --namespace=kube-system ``` Note that we created the `ConfigMap` in the same namespace as the DaemonSet Pods, and named the `ConfigMap` to match the spec in `default-gateway-agent.yaml`. This is necessary for the `ConfigMap` to appear in the Pods' filesystems. @@ -32,7 +32,7 @@ See [RELEASE](RELEASE.md). ## Developing -Clone the repo to `$GOPATH/src/github.com/choffmeister/default-gateway-agent`. +Clone the repo to `$GOPATH/src/github.com/airfocusio/default-gateway-agent`. The build tooling is based on [thockin/go-build-template](https://github.com/thockin/go-build-template). diff --git a/RELEASE.md b/RELEASE.md deleted file mode 100644 index da7cc0a..0000000 --- a/RELEASE.md +++ /dev/null @@ -1,36 +0,0 @@ -# Release Process - -The default-gateway-agent is released on an as-needed basis. The process is as follows: - -1. Someone must file an issue proposing a new release with a changelog since the last release. -1. All [OWNERS](OWNERS) must LGTM this release. -1. An OWNER (who must have push access to the `google_containers` project): - 1. Tags the commit approved for release with `git tag -s vx.x.x`. The `vx.x.x` is semver with a leading `v`. - 1. Runs `make push`, to build and push the container image for the release to `google_containers`. - 1. Pushes the tag with `git push vx.x.x`. -1. The release issue is closed. -1. An announcement email is sent to `kubernetes-dev@googlegroups.com` with the subject `[ANNOUNCE] default-gateway-agent vx.x.x is released`. - -Example: - -``` -$ git tag -v0.2.0 -v0.2.1 -v0.3.1 -v0.4.0 -v1.0.0 -v2.0.0 - -# Pick the next release number - -$ git tag -am "v2.0.1" v2.0.1 - -$ make container TAG=v2.0.1 -<...lots of output...> -container: choffmeister/default-gateway-agent-amd64:v2.0.1 - -$ gcloud docker -- push choffmeister/default-gateway-agent-amd64:v2.0.1 -<...lots of output...> -v2.0.1: digest: sha256:504833aedf3f14379e73296240ed44d54aecd4c02367b004452dfeca2465e5bf size: 950 -``` diff --git a/build/build.sh b/build/build.sh deleted file mode 100755 index 51402e2..0000000 --- a/build/build.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh - -# Copyright 2016 The Kubernetes Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -o errexit -set -o nounset -set -o pipefail - -if [ -z "${PKG}" ]; then - echo "PKG must be set" - exit 1 -fi -if [ -z "${ARCH}" ]; then - echo "ARCH must be set" - exit 1 -fi -if [ -z "${VERSION}" ]; then - echo "VERSION must be set" - exit 1 -fi - -export CGO_ENABLED=0 -export GOARCH="${ARCH}" - -go mod download -go install \ - -installsuffix "static" \ - -ldflags "-s -w -X ${PKG}/pkg/version.VERSION=${VERSION}" \ - ./... diff --git a/build/test.sh b/build/test.sh deleted file mode 100755 index 03bdfbb..0000000 --- a/build/test.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh - -# Copyright 2016 The Kubernetes Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -o errexit -set -o nounset -set -o pipefail - -export CGO_ENABLED=0 - -TARGETS=$(for d in "$@"; do echo ./$d/...; done) - -echo "Running tests:" -go mod download -go test -i -installsuffix "static" ${TARGETS} -go test -installsuffix "static" ${TARGETS} -echo - -echo -n "Checking gofmt: " -ERRS=$(find "$@" -type f -name \*.go | xargs gofmt -l 2>&1 || true) -if [ -n "${ERRS}" ]; then - echo "FAIL - the following files need to be gofmt'ed:" - for e in ${ERRS}; do - echo " $e" - done - echo - exit 1 -fi -echo "PASS" -echo - -echo -n "Checking go vet: " -ERRS=$(go vet ${TARGETS} 2>&1 || true) -if [ -n "${ERRS}" ]; then - echo "FAIL" - echo "${ERRS}" - echo - exit 1 -fi -echo "PASS" -echo diff --git a/agent-config/config b/default-gateway-agent-config.yaml similarity index 100% rename from agent-config/config rename to default-gateway-agent-config.yaml diff --git a/default-gateway-agent.yaml b/default-gateway-agent.yaml index 2d550e1..445d12a 100644 --- a/default-gateway-agent.yaml +++ b/default-gateway-agent.yaml @@ -15,7 +15,7 @@ spec: hostNetwork: true containers: - name: default-gateway-agent - image: choffmeister/default-gateway-agent-amd64:latest + image: ghcr.io/airfocusio/default-gateway-agent:latest imagePullPolicy: Always # args: ["--cleanup"] securityContext: diff --git a/go.mod b/go.mod index 05c2292..3989bc0 100644 --- a/go.mod +++ b/go.mod @@ -1,22 +1,27 @@ -module github.com/choffmeister/default-gateway-agent +module github.com/airfocusio/default-gateway-agent -go 1.14 +go 1.17 require ( - github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680 // indirect - github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55 // indirect + github.com/go-ping/ping v0.0.0-20211014180314-6e2b003bffdd github.com/golang/glog v0.0.0-20141105023935-44145f04b68c - github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect - github.com/sparrc/go-ping v0.0.0-20190613174326-4e5b6552494c - github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff // indirect github.com/vishvananda/netlink v1.1.1-0.20200625175047-bca67dfc8220 - github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae // indirect - golang.org/x/net v0.0.0-20200707034311-ab3426394381 // indirect - golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1 // indirect - gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect - gopkg.in/yaml.v2 v2.0.0-20150924142314-53feefa2559f // indirect k8s.io/apimachinery v0.0.0-20170416202754-ce019b30a1f4 k8s.io/apiserver v0.0.0-20170417203629-48bf36441a1c k8s.io/kubernetes v1.13.0-alpha.0.0.20180917200753-80fb2be3e42e - k8s.io/utils v0.0.0-20180817171939-982821ea41da + k8s.io/utils v0.0.0-20211116205334-6203023598ed +) + +require ( + github.com/ghodss/yaml v1.0.0 // indirect + github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55 // indirect + github.com/google/uuid v1.2.0 // indirect + github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect + github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff // indirect + github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae // indirect + golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4 // indirect + golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect + golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005 // indirect + gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 0b40220..56bab6d 100644 --- a/go.sum +++ b/go.sum @@ -1,45 +1,56 @@ -github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680 h1:ZktWZesgun21uEDrwW7iEV1zPCGQldM2atlJZ3TdvVM= -github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= +github.com/go-ping/ping v0.0.0-20211014180314-6e2b003bffdd h1:WwvAAgvP2MO5bxYtSlDovMFWiTd9vi+Ey7CJ54wAUrc= +github.com/go-ping/ping v0.0.0-20211014180314-6e2b003bffdd/go.mod h1:xIFjORFzTxqIV/tDVGO4eDy/bLuSyawEeojSm3GfRGk= github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55 h1:oIgNYSrSUbNH5DJh6DMhU1PiOKOYIHNxrV3djLsLpEI= github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= github.com/golang/glog v0.0.0-20141105023935-44145f04b68c h1:CbdkBQ1/PiAo0FYJhQGwASD8wrgNvTdf01g6+O9tNuA= github.com/golang/glog v0.0.0-20141105023935-44145f04b68c/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs= +github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/sparrc/go-ping v0.0.0-20190613174326-4e5b6552494c h1:gqEdF4VwBu3lTKGHS9rXE9x1/pEaSwCXRLOZRF6qtlw= -github.com/sparrc/go-ping v0.0.0-20190613174326-4e5b6552494c/go.mod h1:eMyUVp6f/5jnzM+3zahzl7q6UXLbgSc3MKg/+ow9QW0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff h1:VARhShG49tiji6mdRNp7JTNDtJ0FhuprF93GBQ37xGU= github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/vishvananda/netlink v1.1.1-0.20200625175047-bca67dfc8220 h1:aujxWpC+gtqeG8yxX1cF8GkcBzRIl74K0DzxJrUFvv8= github.com/vishvananda/netlink v1.1.1-0.20200625175047-bca67dfc8220/go.mod h1:FSQhuTO7eHT34mPzX+B04SUAjiqLxtXs1et0S6l9k4k= github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU= github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae h1:4hwBBUfQCFe3Cym0ZtKyq7L16eZUtYKs+BaHDN6mAns= github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU= -golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4 h1:b0LrWgu8+q7z4J+0Y3Umo5q1dL7NXBkKBWkaVkAq17E= +golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20200121082415-34d275377bf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1 h1:sIky/MyNRSHTrdxfsiUSS4WIAMvInbeXljJz+jDjeYE= -golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005 h1:pDMpM2zh2MT0kHy037cKlSby2nEhD50SYqwQk76Nm40= +golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.0.0-20150924142314-53feefa2559f h1:sOheF02XWNGQor9t3gRZtN/HlgP6sv3NozSahoTEmiM= -gopkg.in/yaml.v2 v2.0.0-20150924142314-53feefa2559f/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= k8s.io/apimachinery v0.0.0-20170416202754-ce019b30a1f4 h1:tYdiXYGbxLVC25f93o3pXNz8lnytvBNx52hjp6wa7N4= k8s.io/apimachinery v0.0.0-20170416202754-ce019b30a1f4/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0= k8s.io/apiserver v0.0.0-20170417203629-48bf36441a1c h1:0Y0ta+ZoLxhn8yNkehHClk026b/aj3JPSoVBqn2fALA= k8s.io/apiserver v0.0.0-20170417203629-48bf36441a1c/go.mod h1:6bqaTSOSJavUIXUtfaR9Os9JtTCm8ZqH2SUl2S60C4w= +k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/kubernetes v1.13.0-alpha.0.0.20180917200753-80fb2be3e42e h1:WCxanXOCAZjLXyYFnPE+QNlsQ56aJu2JWxTehWMs9fI= k8s.io/kubernetes v1.13.0-alpha.0.0.20180917200753-80fb2be3e42e/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= -k8s.io/utils v0.0.0-20180817171939-982821ea41da h1:iSRsIrQWeKa5IIqOOpvhnN2E/7iz+v8VingQHJ3lGhI= -k8s.io/utils v0.0.0-20180817171939-982821ea41da/go.mod h1:8k8uAuAQ0rXslZKaEWd0c3oVhZz7sSzSiPnVZayjIX0= +k8s.io/utils v0.0.0-20211116205334-6203023598ed h1:ck1fRPWPJWsMd8ZRFsWc6mh/zHp5fZ/shhbrgPUxDAE= +k8s.io/utils v0.0.0-20211116205334-6203023598ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= diff --git a/cmd/default-gateway-agent/testing/fakefs/fakefs.go b/internal/fs.go similarity index 99% rename from cmd/default-gateway-agent/testing/fakefs/fakefs.go rename to internal/fs.go index c479b4c..fad94b4 100644 --- a/cmd/default-gateway-agent/testing/fakefs/fakefs.go +++ b/internal/fs.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package fakefs +package internal import ( "errors" diff --git a/cmd/default-gateway-agent/default-gateway-agent.go b/main.go similarity index 97% rename from cmd/default-gateway-agent/default-gateway-agent.go rename to main.go index 8faf0ee..a295142 100644 --- a/cmd/default-gateway-agent/default-gateway-agent.go +++ b/main.go @@ -27,8 +27,8 @@ import ( "strings" "time" - "github.com/choffmeister/default-gateway-agent/cmd/default-gateway-agent/testing/fakefs" - "github.com/sparrc/go-ping" + "github.com/airfocusio/default-gateway-agent/internal" + "github.com/go-ping/ping" "github.com/vishvananda/netlink" utilyaml "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/apiserver/pkg/util/logs" @@ -205,15 +205,15 @@ func (m *GatewayDaemon) RunCleanup() { } func (m *GatewayDaemon) osSyncConfig() error { - // the fakefs.FileSystem interface allows us to mock the fs from tests - // fakefs.DefaultFS implements fakefs.FileSystem using os.Stat and io/ioutil.ReadFile - var fs fakefs.FileSystem = fakefs.DefaultFS{} + // the internal.FileSystem interface allows us to mock the fs from tests + // internal.DefaultFS implements internal.FileSystem using os.Stat and io/ioutil.ReadFile + var fs internal.FileSystem = internal.DefaultFS{} return m.syncConfig(fs) } // Syncs the config to the file at ConfigPath, or uses defaults if the file could not be found // Error if the file is found but cannot be parsed. -func (m *GatewayDaemon) syncConfig(fs fakefs.FileSystem) error { +func (m *GatewayDaemon) syncConfig(fs internal.FileSystem) error { var err error c := NewAgentConfig(*ignoreAllReservedRangesFlag) defer func() { diff --git a/cmd/default-gateway-agent/default-gateway-agent_test.go b/main_test.go similarity index 83% rename from cmd/default-gateway-agent/default-gateway-agent_test.go rename to main_test.go index 41d274b..875a915 100644 --- a/cmd/default-gateway-agent/default-gateway-agent_test.go +++ b/main_test.go @@ -24,7 +24,7 @@ import ( "testing" "time" - "github.com/choffmeister/default-gateway-agent/cmd/default-gateway-agent/testing/fakefs" + "github.com/airfocusio/default-gateway-agent/internal" iptest "k8s.io/kubernetes/pkg/util/iptables/testing" ) @@ -79,13 +79,13 @@ func TestConfigValidate(t *testing.T) { // specs for testing loading config from fs var syncConfigTests = []struct { - desc string // human readable description of the fs used for the test e.g. "no config file" - fs fakefs.FileSystem // filesystem interface - err error // expected error from GatewayDaemon.syncConfig(fs) - cfg *AgentConfig // expected values of the configuration after loading from fs + desc string // human readable description of the fs used for the test e.g. "no config file" + fs internal.FileSystem // filesystem interface + err error // expected error from GatewayDaemon.syncConfig(fs) + cfg *AgentConfig // expected values of the configuration after loading from fs }{ // valid yaml - {"valid yaml file, all keys", fakefs.StringFS{File: ` + {"valid yaml file, all keys", internal.StringFS{File: ` ipTables: mark: 1 ipRule: @@ -107,10 +107,10 @@ resyncInterval: 5s ResyncInterval: Duration(5 * time.Second)}}, // invalid yaml - {"invalid yaml file", fakefs.StringFS{File: `*`}, fmt.Errorf("yaml: did not find expected alphabetic or numeric character"), NewAgentConfigEmpty()}, + {"invalid yaml file", internal.StringFS{File: `*`}, fmt.Errorf("yaml: did not find expected alphabetic or numeric character"), NewAgentConfigEmpty()}, // valid json - {"valid json file, all keys", fakefs.StringFS{File: ` + {"valid json file, all keys", internal.StringFS{File: ` { "ipTables": {"mark":1}, "ipRule": {"table":1, "priority":30000}, @@ -129,10 +129,10 @@ resyncInterval: 5s ResyncInterval: Duration(5 * time.Second)}}, // invalid json - {"invalid json file", fakefs.StringFS{File: `{*`}, fmt.Errorf("invalid character '*' looking for beginning of object key string"), NewAgentConfigEmpty()}, + {"invalid json file", internal.StringFS{File: `{*`}, fmt.Errorf("invalid character '*' looking for beginning of object key string"), NewAgentConfigEmpty()}, // file does not exist - {"no config file", fakefs.NotExistFS{}, nil, NewAgentConfigEmpty()}, // If the file does not exist, defaults should be used + {"no config file", internal.NotExistFS{}, nil, NewAgentConfigEmpty()}, // If the file does not exist, defaults should be used } // tests GatewayDaemon.syncConfig diff --git a/pkg/version/version.go b/pkg/version/version.go deleted file mode 100644 index 1064717..0000000 --- a/pkg/version/version.go +++ /dev/null @@ -1,21 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package version - -// VERSION is the app-global version string, which should be substituted with a -// real value during build. -var VERSION = "UNKNOWN"