-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c6a6c3
commit c47f6e3
Showing
14 changed files
with
1,015 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
project_name: external-dns-vultr-webhook | ||
version: 2 | ||
|
||
builds: | ||
- main: ./cmd/webhook | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
goarch: | ||
- amd64 | ||
- arm64 | ||
|
||
ldflags: | ||
- -X 'main.Version={{.Version}}' | ||
- -X 'main.Gitsha={{.ShortCommit}}' | ||
archives: | ||
- format: tar.gz | ||
# this name template makes the OS and Arch compatible with the results of uname. | ||
name_template: >- | ||
{{ .ProjectName }}_ | ||
{{- title .Os }}_ | ||
{{- if eq .Arch "amd64" }}x86_64 | ||
{{- else if eq .Arch "386" }}i386 | ||
{{- else }}{{ .Arch }}{{ end }} | ||
{{- if .Arm }}v{{ .Arm }}{{ end }} | ||
# use zip for windows archives | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
dockers: | ||
- id: external-dns-vultr-webhook-amd64 | ||
use: buildx | ||
image_templates: | ||
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-amd64" | ||
goos: linux | ||
goarch: amd64 | ||
build_flag_templates: | ||
- --platform=linux/amd64 | ||
- --label=org.opencontainers.image.title={{ .ProjectName }} | ||
- --label=org.opencontainers.image.description=vultr DNS webhook for external-dns | ||
- --label=org.opencontainers.image.url=https://{{ .Env.GITHUB_SERVER_URL }}/{{ .Env.GITHUB_REPOSITORY}} | ||
- --label=org.opencontainers.image.source=https://{{ .Env.GITHUB_SERVER_URL }}/{{ .Env.GITHUB_REPOSITORY}} | ||
- --label=org.opencontainers.image.version={{ .Version }} | ||
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }} | ||
- --label=org.opencontainers.image.revision={{ .FullCommit }} | ||
- --label=org.opencontainers.image.licenses=Apache-2.0 | ||
- id: external-dns-vultr-webhook-arm64 | ||
use: buildx | ||
image_templates: | ||
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-arm64" | ||
goos: linux | ||
goarch: arm64 | ||
build_flag_templates: | ||
- --platform=linux/arm64/v8 | ||
- --label=org.opencontainers.image.title={{ .ProjectName }} | ||
- --label=org.opencontainers.image.description=vultr DNS webhook for external-dns | ||
- --label=org.opencontainers.image.url=https://{{ .Env.GITHUB_SERVER_URL }}/{{ .Env.GITHUB_REPOSITORY}} | ||
- --label=org.opencontainers.image.source=https://{{ .Env.GITHUB_SERVER_URL }}/{{ .Env.GITHUB_REPOSITORY}} | ||
- --label=org.opencontainers.image.version={{ .Version }} | ||
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }} | ||
- --label=org.opencontainers.image.revision={{ .FullCommit }} | ||
- --label=org.opencontainers.image.licenses=Apache-2.0 | ||
docker_manifests: | ||
- name_template: "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}" | ||
image_templates: | ||
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-amd64" | ||
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-arm64" | ||
- name_template: "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .ShortCommit }}" | ||
image_templates: | ||
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-amd64" | ||
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-arm64" | ||
- name_template: "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:latest" | ||
image_templates: | ||
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-amd64" | ||
- "{{ .Env.REGISTRY }}/{{ .Env.IMAGE_NAME }}:{{ .Tag }}-arm64" | ||
checksum: | ||
disable: false | ||
name_template: "{{ .ProjectName }}_{{ .Version }}_checksums.txt" | ||
|
||
snapshot: | ||
version_template: "{{ incpatch .Version }}-next" | ||
|
||
changelog: | ||
use: github | ||
sort: asc | ||
filters: | ||
exclude: | ||
- "^docs:" | ||
- "^test:" | ||
# The lines beneath this are called `modelines`. See `:help modeline` | ||
# Feel free to remove those if you don't want/use them. | ||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json | ||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM gcr.io/distroless/static-debian11:nonroot | ||
|
||
USER 20000:20000 | ||
ADD --chmod=555 external-dns-vultr-webhook /opt/external-dns-vultr-webhook/app | ||
|
||
ENTRYPOINT ["/opt/external-dns-vultr-webhook/app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
GO_TEST = go run gotest.tools/gotestsum --format pkgname | ||
|
||
LICENCES_IGNORE_LIST = $(shell cat licences/licences-ignore-list.txt) | ||
|
||
ifndef $(GOPATH) | ||
GOPATH=$(shell go env GOPATH) | ||
export GOPATH | ||
endif | ||
|
||
ARTIFACT_NAME = external-dns-vultr-webhook | ||
|
||
|
||
REGISTRY ?= localhost:5001 | ||
IMAGE_NAME ?= external-dns-vultr-webhook | ||
IMAGE_TAG ?= latest | ||
IMAGE = $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) | ||
|
||
##@ General | ||
|
||
.PHONY: help | ||
help: ## Display this help. | ||
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | ||
|
||
show: ## Show variables | ||
@echo "GOPATH: $(GOPATH)" | ||
@echo "ARTIFACT_NAME: $(ARTIFACT_NAME)" | ||
@echo "REGISTRY: $(REGISTRY)" | ||
@echo "IMAGE_NAME: $(IMAGE_NAME)" | ||
@echo "IMAGE_TAG: $(IMAGE_TAG)" | ||
@echo "IMAGE: $(IMAGE)" | ||
|
||
|
||
##@ Code analysis | ||
|
||
.PHONY: vet | ||
vet: ## Run go vet against code. | ||
go vet ./... | ||
|
||
.PHONY: lint | ||
lint: ## Run golangci-lint against code. | ||
mkdir -p build/reports | ||
go run github.com/golangci/golangci-lint/cmd/golangci-lint run --timeout 2m | ||
|
||
.PHONY: static-analysis | ||
static-analysis: lint vet ## Run static analysis against code. | ||
|
||
##@ GO | ||
|
||
.PHONY: clean | ||
clean: ## Clean the build directory | ||
rm -rf ./dist | ||
rm -rf ./build | ||
rm -rf ./vendor | ||
|
||
.PHONY: build | ||
build: ## Build the binary | ||
CGO_ENABLED=0 go build -o build/bin/$(ARTIFACT_NAME) ./cmd/webhook | ||
|
||
.PHONY: run | ||
run:build ## Run the binary on local machine | ||
build/bin/external-dns-vultr-webhook | ||
|
||
##@ Docker | ||
|
||
.PHONY: docker-build | ||
docker-build: build ## Build the docker image | ||
docker build ./ -f localbuild.Dockerfile -t $(IMAGE) | ||
|
||
.PHONY: docker-push | ||
docker-push: ## Push the docker image | ||
docker push $(IMAGE) | ||
|
||
##@ Test | ||
|
||
.PHONY: unit-test | ||
unit-test: ## Run unit tests | ||
mkdir -p build/reports | ||
$(GO_TEST) --junitfile build/reports/unit-test.xml -- -race ./... -count=1 -short -cover -coverprofile build/reports/unit-test-coverage.out | ||
|
||
|
||
##@ Release | ||
|
||
.PHONY: release-check | ||
release-check: ## Check if the release will work | ||
GITHUB_SERVER_URL=github.com GITHUB_REPOSITORY=vultr/external-dns-vultr-webhook REGISTRY=$(REGISTRY) IMAGE_NAME=$(IMAGE_NAME) goreleaser release --snapshot --clean --skip=publish | ||
|
||
##@ License | ||
|
||
.PHONY: license-check | ||
license-check: ## Run go-licenses check against code. | ||
go install github.com/google/go-licenses | ||
mkdir -p build/reports | ||
echo "$(LICENCES_IGNORE_LIST)" | ||
$(GOPATH)/bin/go-licenses check --include_tests --ignore "$(LICENCES_IGNORE_LIST)" ./... | ||
|
||
.PHONY: license-report | ||
license-report: ## Create licenses report against code. | ||
go install github.com/google/go-licenses | ||
mkdir -p build/reports/licenses | ||
$(GOPATH)/bin/go-licenses report --include_tests --ignore "$(LICENCES_IGNORE_LIST)" ./... >build/reports/licenses/licenses-list.csv | ||
cat licences/licenses-manual-list.csv >> build/reports/licenses/licenses-list.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/codingconcepts/env" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/vultr/external-dns-vultr-webhook/internal/server" | ||
"github.com/vultr/external-dns-vultr-webhook/internal/vultr" | ||
"os" | ||
"os/signal" | ||
"sigs.k8s.io/external-dns/provider/webhook/api" | ||
"syscall" | ||
) | ||
|
||
// loop waits for a SIGTERM or a SIGINT and then shuts down the server. | ||
func loop(status *server.HealthStatus) { | ||
exitSignal := make(chan os.Signal, 1) | ||
signal.Notify(exitSignal, syscall.SIGINT, syscall.SIGTERM) | ||
signal := <-exitSignal | ||
|
||
log.Infof("Signal %s received. Shutting down the webhook.", signal.String()) | ||
status.SetHealth(false) | ||
status.SetReady(false) | ||
} | ||
|
||
func main() { | ||
// Read server options | ||
serverOptions := &server.ServerOptions{} | ||
if err := env.Set(serverOptions); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Start health server | ||
log.Infof("Starting liveness and readiness server on %s", serverOptions.GetHealthAddress()) | ||
healthStatus := server.HealthStatus{} | ||
healthServer := server.HealthServer{} | ||
go healthServer.Start(&healthStatus, nil, *serverOptions) | ||
|
||
// Read provider configuration | ||
providerConfig := &vultr.Configuration{} | ||
if err := env.Set(providerConfig); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// instantiate the Vultr provider | ||
provider := vultr.NewProvider(providerConfig) | ||
|
||
// Start the webhook | ||
log.Infof("Starting webhook server on %s", serverOptions.GetWebhookAddress()) | ||
startedChan := make(chan struct{}) | ||
go api.StartHTTPApi( | ||
provider, startedChan, | ||
serverOptions.GetReadTimeout(), | ||
serverOptions.GetWriteTimeout(), | ||
serverOptions.GetWebhookAddress(), | ||
) | ||
|
||
// Wait for the HTTP server to start and then set the healthy and ready flags | ||
<-startedChan | ||
healthStatus.SetHealth(true) | ||
healthStatus.SetReady(true) | ||
|
||
// Loops until a signal tells us to exit | ||
loop(&healthStatus) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module github.com/vultr/external-dns-vultr-webhook | ||
|
||
go 1.23.1 | ||
|
||
require ( | ||
github.com/codingconcepts/env v0.0.0-20240618133406-5b0845441187 | ||
github.com/sirupsen/logrus v1.9.3 | ||
github.com/vultr/govultr/v3 v3.9.1 | ||
golang.org/x/oauth2 v0.23.0 | ||
sigs.k8s.io/external-dns v0.15.0 | ||
) | ||
|
||
require ( | ||
github.com/aws/aws-sdk-go v1.55.5 // indirect | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.3.0 // indirect | ||
github.com/fxamacker/cbor/v2 v2.7.0 // indirect | ||
github.com/go-logr/logr v1.4.2 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/google/go-cmp v0.6.0 // indirect | ||
github.com/google/go-querystring v1.1.0 // indirect | ||
github.com/google/gofuzz v1.2.0 // indirect | ||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect | ||
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect | ||
github.com/jmespath/go-jmespath v0.4.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/kr/text v0.2.0 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
github.com/prometheus/client_golang v1.20.0 // indirect | ||
github.com/prometheus/client_model v0.6.1 // indirect | ||
github.com/prometheus/common v0.55.0 // indirect | ||
github.com/prometheus/procfs v0.15.1 // indirect | ||
github.com/x448/float16 v0.8.4 // indirect | ||
golang.org/x/net v0.28.0 // indirect | ||
golang.org/x/sys v0.23.0 // indirect | ||
golang.org/x/text v0.17.0 // indirect | ||
google.golang.org/protobuf v1.34.2 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
k8s.io/apimachinery v0.31.0 // indirect | ||
k8s.io/klog/v2 v2.130.1 // indirect | ||
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect | ||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect | ||
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect | ||
) |
Oops, something went wrong.