-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathMakefile
More file actions
300 lines (264 loc) · 10.9 KB
/
Makefile
File metadata and controls
300 lines (264 loc) · 10.9 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
include .bingo/Variables.mk
.DEFAULT_GOAL := help
GO ?= go
GOFMT ?= gofmt
# Binary output directory and name
BIN_DIR := bin
BINARY_NAME := $(BIN_DIR)/hyperfleet-adapter
# Version information
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
GIT_SHA ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
GIT_DIRTY ?= $(shell [ -z "$$(git status --porcelain 2>/dev/null)" ] || echo "-modified")
APP_VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "0.0.0-dev")
# Go build flags
GOFLAGS ?= -trimpath
VERSION_PKG := github.com/openshift-hyperfleet/hyperfleet-adapter/pkg/version
LDFLAGS := -s -w \
-X $(VERSION_PKG).Version=$(APP_VERSION) \
-X $(VERSION_PKG).Commit=$(GIT_SHA) \
-X $(VERSION_PKG).BuildDate=$(BUILD_DATE)
# Container tool (docker or podman)
CONTAINER_TOOL ?= $(shell command -v podman 2>/dev/null || command -v docker 2>/dev/null)
# Container build configuration
PLATFORM ?= linux/amd64
DEV_BASE_IMAGE ?= registry.access.redhat.com/ubi9/ubi-minimal:latest
# =============================================================================
# Image Configuration
# =============================================================================
IMAGE_REGISTRY ?= quay.io/openshift-hyperfleet
IMAGE_NAME ?= hyperfleet-adapter
IMAGE_TAG ?= $(APP_VERSION)
# Dev image configuration - set QUAY_USER to push to personal registry
# Usage: QUAY_USER=myuser make image-dev
QUAY_USER ?=
DEV_TAG ?= dev-$(GIT_SHA)
# Test parameters
TEST_TIMEOUT := 30m
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-22s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: build
build: ## Build the adapter binary
@mkdir -p $(BIN_DIR)
$(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BINARY_NAME) ./cmd/adapter
.PHONY: install
install: build ## Build and install binary to GOPATH/bin
$(GO) install $(GOFLAGS) -ldflags "$(LDFLAGS)" ./cmd/adapter
.PHONY: clean
clean: ## Remove build artifacts
rm -rf $(BIN_DIR)
rm -f coverage.out coverage.html
##@ Testing
.PHONY: test
test: ## Run unit tests with race detection
$(GO) test -v -race -coverprofile=coverage.out -timeout $(TEST_TIMEOUT) \
$$($(GO) list ./... | grep -v /test/)
.PHONY: test-coverage
test-coverage: test ## Run tests and show coverage
$(GO) tool cover -html=coverage.out
.PHONY: test-integration
test-integration: ## Run integration tests (requires Docker/Podman)
@TEST_TIMEOUT=$(TEST_TIMEOUT) bash scripts/run-integration-tests.sh
.PHONY: image-integration-test
image-integration-test: ## Build integration test image with envtest
@bash scripts/build-integration-image.sh
.PHONY: test-all
test-all: lint test test-integration test-helm ## Run all checks (lint, unit, integration, helm)
.PHONY: test-helm
test-helm: ## Test Helm charts (lint, template, validate)
@if ! command -v helm > /dev/null; then \
echo "ERROR: helm not found. Please install Helm:"; \
echo " brew install helm # macOS"; \
echo " curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash # Linux"; \
exit 1; \
fi
@echo "Linting Helm chart..."
helm lint charts/ \
--set image.registry=quay.io \
--set image.repository=openshift-hyperfleet/hyperfleet-adapter \
--set image.tag=test
@echo ""
@echo "Testing template rendering with minimal required values..."
helm template test-release charts/ \
--set image.registry=quay.io \
--set image.repository=openshift-hyperfleet/hyperfleet-adapter \
--set image.tag=test \
--set adapterConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set adapterTaskConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" > /dev/null
@echo "Minimal required values template OK"
@echo ""
@echo "Testing template with broker enabled..."
helm template test-release charts/ \
--set image.registry=quay.io \
--set image.repository=openshift-hyperfleet/hyperfleet-adapter \
--set image.tag=test \
--set adapterConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set adapterTaskConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set broker.create=true \
--set broker.googlepubsub.subscriptionId=test-sub \
--set broker.googlepubsub.topic=test-topic \
--set broker.type=googlepubsub > /dev/null
@echo "Broker config template OK"
@echo ""
@echo "Testing template with HyperFleet API config..."
helm template test-release charts/ \
--set image.registry=quay.io \
--set image.repository=openshift-hyperfleet/hyperfleet-adapter \
--set image.tag=test \
--set adapterConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set adapterTaskConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set adapterConfig.hyperfleetApi.baseUrl=http://localhost:8000 \
--set adapterConfig.hyperfleetApi.version=v1 > /dev/null
@echo "HyperFleet API config template OK"
@echo ""
@echo "Testing template with PDB enabled..."
helm template test-release charts/ \
--set image.registry=quay.io \
--set image.repository=openshift-hyperfleet/hyperfleet-adapter \
--set image.tag=test \
--set adapterConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set adapterTaskConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set podDisruptionBudget.enabled=true \
--set podDisruptionBudget.minAvailable=1 \
--set podDisruptionBudget.maxUnavailable=null > /dev/null
@echo "PDB config template OK"
@echo ""
@echo "Testing template with autoscaling..."
helm template test-release charts/ \
--set image.registry=quay.io \
--set image.repository=openshift-hyperfleet/hyperfleet-adapter \
--set image.tag=test \
--set adapterConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set adapterTaskConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set autoscaling.enabled=true \
--set autoscaling.minReplicas=2 \
--set autoscaling.maxReplicas=5 > /dev/null
@echo "Autoscaling config template OK"
@echo ""
@echo "Testing template with probes enabled..."
helm template test-release charts/ \
--set image.registry=quay.io \
--set image.repository=openshift-hyperfleet/hyperfleet-adapter \
--set image.tag=test \
--set adapterConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set adapterTaskConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set livenessProbe.enabled=true \
--set readinessProbe.enabled=true \
--set startupProbe.enabled=true > /dev/null
@echo "Probes config template OK"
@echo ""
@echo "Testing template with ServiceMonitor enabled..."
@helm template test-release charts/ \
--set image.registry=quay.io \
--set image.repository=openshift-hyperfleet/hyperfleet-adapter \
--set image.tag=test \
--set adapterConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set adapterTaskConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set serviceMonitor.enabled=true \
--api-versions monitoring.coreos.com/v1/ServiceMonitor | grep -q 'kind: ServiceMonitor' \
|| { echo "ERROR: ServiceMonitor not rendered"; exit 1; }
@echo "ServiceMonitor enabled template OK"
@echo ""
@echo "Testing template with ServiceMonitor enabled but CRD unavailable..."
@output=$$(helm template test-release charts/ \
--set image.registry=quay.io \
--set image.repository=openshift-hyperfleet/hyperfleet-adapter \
--set image.tag=test \
--set adapterConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set adapterTaskConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set serviceMonitor.enabled=true) \
&& ! echo "$$output" | grep -q 'kind: ServiceMonitor' \
|| { echo "ERROR: ServiceMonitor rendered without CRD"; exit 1; }
@echo "ServiceMonitor CRD-missing template OK"
@echo ""
@echo "Testing template with ServiceMonitor disabled..."
@output=$$(helm template test-release charts/ \
--set image.registry=quay.io \
--set image.repository=openshift-hyperfleet/hyperfleet-adapter \
--set image.tag=test \
--set adapterConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set adapterTaskConfig.yaml="apiVersion: hyperfleet.redhat.com/v1alpha1" \
--set serviceMonitor.enabled=false \
--api-versions monitoring.coreos.com/v1/ServiceMonitor) \
&& ! echo "$$output" | grep -q 'kind: ServiceMonitor' \
|| { echo "ERROR: ServiceMonitor rendered while disabled"; exit 1; }
@echo "ServiceMonitor disabled template OK"
##@ Code Quality
.PHONY: fmt
fmt: $(GOIMPORTS) ## Format code with goimports
$(GOIMPORTS) -w .
.PHONY: fmt-check
fmt-check: ## Check if code is formatted
@diff=$$($(GOFMT) -s -d .); \
if [ -n "$$diff" ]; then \
echo "Code is not formatted. Run 'make fmt' to fix:"; \
echo "$$diff"; \
exit 1; \
fi
.PHONY: vet
vet: ## Run go vet
$(GO) vet ./...
.PHONY: lint
lint: $(GOLANGCI_LINT) ## Run golangci-lint
$(GOLANGCI_LINT) run
.PHONY: verify
verify: fmt-check vet ## Run all verification checks
##@ Dependencies
.PHONY: tidy
tidy: ## Tidy go.mod
$(GO) mod tidy
.PHONY: download
download: ## Download dependencies
$(GO) mod download
##@ Container Images
.PHONY: check-container-tool
check-container-tool:
ifndef CONTAINER_TOOL
@echo "Error: No container tool found (podman or docker)"
@echo ""
@echo "Please install one of:"
@echo " brew install podman # macOS"
@echo " brew install docker # macOS"
@echo " dnf install podman # Fedora/RHEL"
@exit 1
endif
.PHONY: image
image: check-container-tool ## Build container image
@echo "Building image $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) ..."
$(CONTAINER_TOOL) build \
--platform $(PLATFORM) \
--build-arg GIT_SHA=$(GIT_SHA) \
--build-arg GIT_DIRTY=$(GIT_DIRTY) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg APP_VERSION=$(APP_VERSION) \
-t $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) .
@echo "Image built: $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)"
.PHONY: image-push
image-push: check-container-tool image ## Build and push container image
@echo "Pushing image $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) ..."
$(CONTAINER_TOOL) push $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
@echo "Image pushed: $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)"
.PHONY: image-dev
image-dev: check-container-tool ## Build and push to personal Quay registry (requires QUAY_USER)
ifndef QUAY_USER
@echo "Error: QUAY_USER is not set"
@echo ""
@echo "Usage: QUAY_USER=myuser make image-dev"
@echo ""
@echo "This will build and push to: quay.io/$$QUAY_USER/$(IMAGE_NAME):$(DEV_TAG)"
@exit 1
endif
@echo "Building dev image quay.io/$(QUAY_USER)/$(IMAGE_NAME):$(DEV_TAG) ..."
$(CONTAINER_TOOL) build \
--platform $(PLATFORM) \
--build-arg BASE_IMAGE=$(DEV_BASE_IMAGE) \
--build-arg GIT_SHA=$(GIT_SHA) \
--build-arg GIT_DIRTY=$(GIT_DIRTY) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg APP_VERSION=0.0.0-dev \
-t quay.io/$(QUAY_USER)/$(IMAGE_NAME):$(DEV_TAG) .
@echo "Pushing dev image..."
$(CONTAINER_TOOL) push quay.io/$(QUAY_USER)/$(IMAGE_NAME):$(DEV_TAG)
@echo ""
@echo "Dev image pushed: quay.io/$(QUAY_USER)/$(IMAGE_NAME):$(DEV_TAG)"