This repository was archived by the owner on Jun 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
188 lines (157 loc) · 5.93 KB
/
Copy pathMakefile
File metadata and controls
188 lines (157 loc) · 5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Variables
BINARY_NAME=externaldns-plugin
STANDALONE_BINARY=coredns-externaldns
DOCKER_IMAGE=coredns-externaldns
DOCKER_STANDALONE_IMAGE=coredns-externaldns-standalone
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "v0.1.0-dev")
REGISTRY?=ghcr.io/ionos-cloud
COMMIT?=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
# Build flags for version information
LDFLAGS_STANDALONE=-ldflags "-s -w \
-X main.appName=CoreDNS-ExternalDNS \
-X main.appVersion=$(VERSION)"
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
.PHONY: all build build-plugin build-standalone clean test deps docker-build docker-build-tag docker-push docker-run docker-run-custom version release-snapshot release-test help
# Default target
all: deps test build
# Build both plugin and standalone
build: build-plugin build-standalone
# Build the plugin (for use with existing CoreDNS)
build-plugin:
CGO_ENABLED=0 GOOS=linux $(GOBUILD) -a -installsuffix cgo -o $(BINARY_NAME) .
# Build standalone CoreDNS with plugin included
build-standalone:
CGO_ENABLED=0 GOOS=linux $(GOBUILD) $(LDFLAGS_STANDALONE) -a -installsuffix cgo -o $(STANDALONE_BINARY) ./cmd/coredns-externaldns
# Clean build artifacts
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME) $(STANDALONE_BINARY)
# Run tests
test:
$(GOTEST) -v -race ./...
# Download dependencies
deps:
$(GOMOD) download
$(GOMOD) tidy
# Verify dependencies
verify:
$(GOMOD) verify
# Show current version
version:
@echo "Current version: $(VERSION)"
# Run linter
lint:
golangci-lint run
# Build Docker image (standalone CoreDNS)
docker-build:
docker build -t $(DOCKER_STANDALONE_IMAGE):$(VERSION) .
# Build Docker image with custom tag
docker-build-tag:
docker build -t $(DOCKER_STANDALONE_IMAGE):$(VERSION) -t $(DOCKER_STANDALONE_IMAGE):latest .
# Push Docker image
docker-push: docker-build
docker tag $(DOCKER_STANDALONE_IMAGE):$(VERSION) $(REGISTRY)/$(DOCKER_STANDALONE_IMAGE):$(VERSION)
docker push $(REGISTRY)/$(DOCKER_STANDALONE_IMAGE):$(VERSION)
# Run Docker container locally for testing
docker-run: docker-build
docker run --rm -p 5353:53/udp $(DOCKER_STANDALONE_IMAGE):$(VERSION)
# Run Docker container with custom Corefile
docker-run-custom:
@echo "Mount your custom Corefile to /root/Corefile in the container"
docker run --rm -p 5353:53/udp -v $(PWD)/Corefile:/root/Corefile $(DOCKER_STANDALONE_IMAGE):$(VERSION)
# Install development dependencies
dev-deps:
$(GOGET) -u github.com/golangci/golangci-lint/cmd/golangci-lint
$(GOGET) -u github.com/goreleaser/goreleaser@latest
# Build release with GoReleaser (snapshot)
release-snapshot:
goreleaser release --snapshot --clean
# Test GoReleaser configuration
release-test:
goreleaser check
# Generate mocks (if needed for testing)
generate:
$(GOCMD) generate ./...
# Run the plugin locally (requires kubeconfig)
run-local:
./$(BINARY_NAME) -conf Corefile
# Apply Kubernetes manifests
k8s-apply:
kubectl apply -f deploy/k8s-deployment.yaml
# Apply example DNSEndpoints
examples-apply:
kubectl apply -f examples/dnsendpoint-examples.yaml
# Remove Kubernetes manifests
k8s-delete:
kubectl delete -f deploy/k8s-deployment.yaml
# Remove example DNSEndpoints
examples-delete:
kubectl delete -f examples/dnsendpoint-examples.yaml
# Check plugin status in cluster
k8s-status:
kubectl get pods -n kube-system -l k8s-app=coredns-externaldns
kubectl logs -n kube-system -l k8s-app=coredns-externaldns --tail=50
# Watch DNSEndpoints
watch-endpoints:
kubectl get dnsendpoints --all-namespaces -w
# Test DNS resolution (requires cluster DNS to be configured)
test-dns:
@echo "Testing DNS resolution..."
@echo "A record: app.example.com"
@nslookup app.example.com || true
@echo "CNAME record: www.example.com"
@nslookup www.example.com || true
@echo "MX record: example.com"
@nslookup -type=MX example.com || true
# Help target
help:
@echo "====================================================================="
@echo " CoreDNS ExternalDNS Plugin - Available Make Targets"
@echo "====================================================================="
@echo ""
@echo "Build Targets:"
@echo " build Build both plugin and standalone binaries"
@echo " build-plugin Build the plugin binary only (for existing CoreDNS)"
@echo " build-standalone Build standalone CoreDNS with plugin included"
@echo " clean Clean build artifacts"
@echo ""
@echo "Development Targets:"
@echo " test Run tests"
@echo " deps Download dependencies"
@echo " verify Verify dependencies"
@echo " lint Run linter"
@echo " dev-deps Install development dependencies"
@echo " generate Generate code (mocks, etc.)"
@echo " run-local Run plugin locally"
@echo " version Show current version"
@echo " release-snapshot Build release snapshot with GoReleaser"
@echo " release-test Test GoReleaser configuration"
@echo ""
@echo "Docker Targets:"
@echo " docker-build Build Docker image (standalone CoreDNS)"
@echo " docker-build-tag Build Docker image with latest tag"
@echo " docker-push Push Docker image to registry"
@echo " docker-run Run Docker container locally (port 5353)"
@echo " docker-run-custom Run with custom Corefile mounted"
@echo ""
@echo "Kubernetes Targets:"
@echo " k8s-apply Apply Kubernetes manifests"
@echo " k8s-delete Delete Kubernetes manifests"
@echo " k8s-status Check plugin status in cluster"
@echo " examples-apply Apply example DNSEndpoints"
@echo " examples-delete Delete example DNSEndpoints"
@echo " watch-endpoints Watch DNSEndpoint changes"
@echo ""
@echo "Testing Targets:"
@echo " test-dns Test DNS resolution"
@echo ""
@echo "Other:"
@echo " help Show this help"
@echo ""
@echo "====================================================================="