-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMakefile
More file actions
186 lines (149 loc) · 7.38 KB
/
Makefile
File metadata and controls
186 lines (149 loc) · 7.38 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
# Makefile for obs-mcp server
.DEFAULT_GOAL := run
CONTAINER_CLI ?= docker
IMAGE ?= ghcr.io/rhobs/obs-mcp
TAG ?= $(shell git rev-parse --short HEAD)
TOOLS_DIR := hack/tools
ROOT_DIR := $(shell pwd)
TOOLS_BIN_DIR := $(ROOT_DIR)/tmp/bin
.PHONY: help
help: ## Show this help message
@echo "obs-mcp - Available commands:"
@echo ""
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
.PHONY: check-tools
check-tools: ## Check if required tools are installed
@command -v go >/dev/null 2>&1 || { echo "Error: go is required but not installed."; exit 1; }
@command -v $(CONTAINER_CLI) >/dev/null 2>&1 || echo "Warning: $(CONTAINER_CLI) is not installed. Container builds will fail."
@echo "✓ All required tools are installed"
.PHONY: build
build: ## Build obs-mcp binary for local development
go build -mod=mod -tags strictfipsruntime -o obs-mcp ./cmd/obs-mcp
.PHONY: build-linux
build-linux: ## Build obs-mcp binary for linux/amd64
GOOS=linux GOARCH=amd64 go build -mod=mod -tags strictfipsruntime -o obs-mcp ./cmd/obs-mcp
.PHONY: test-unit
test-unit: ## Run obs-mcp unit tests
go test -mod=mod -v -race ./...
.PHONY: clean
clean: ## Clean obs-mcp build artifacts
go clean && rm -f obs-mcp
.PHONY: tag
tag: ## Create a release tag (usage: make tag VERSION=0.1.0)
ifndef VERSION
$(error VERSION is required. Usage: make tag VERSION=0.1.0)
endif
git tag -s "v$(VERSION)" -m "v$(VERSION)"
@echo "Tag v$(VERSION) created."
.PHONY: container
container: build-linux ## Build obs-mcp container image
$(CONTAINER_CLI) build --load -f Containerfile -t $(IMAGE):$(TAG) .
.PHONY: format
format: ## Format all code
go fmt ./...
$(TOOLS_BIN_DIR):
mkdir -p $(TOOLS_BIN_DIR)
$(TOOLS_BIN_DIR)/golangci-lint: $(TOOLS_DIR)/go.mod | $(TOOLS_BIN_DIR)
cd $(TOOLS_DIR) && go build -o $(TOOLS_BIN_DIR)/golangci-lint github.com/golangci/golangci-lint/v2/cmd/golangci-lint
.PHONY: lint
lint: $(TOOLS_BIN_DIR)/golangci-lint ## Run golangci-lint
$(TOOLS_BIN_DIR)/golangci-lint run --timeout=10m ./...
.PHONY: lint-fix
lint-fix: $(TOOLS_BIN_DIR)/golangci-lint ## Run golangci-lint with fix
$(TOOLS_BIN_DIR)/golangci-lint run --timeout=10m --fix ./...
.PHONY: setup
setup: check-tools ## Install dependencies for all components
go mod download
cd $(TOOLS_DIR) && go mod download
.PHONY: generate-tools-doc
generate-tools-doc: ## Generate TOOLS.md from tool definitions
go run ./cmd/generate-tools-doc/main.go
.PHONY: check-tools-doc
check-tools-doc: generate-tools-doc ## Check if TOOLS.md is up to date
@git diff --exit-code TOOLS.md || { \
echo ""; \
echo "❌ TOOLS.md is out of sync with tool definitions!"; \
echo ""; \
echo "To fix, run: make generate-tools-doc"; \
echo "Then commit the updated TOOLS.md"; \
echo ""; \
exit 1; \
}
# Run targets - for local testing
LISTEN_ADDR ?= :9100
LOG_LEVEL ?= debug
AUTH_MODE ?= kubeconfig
.PHONY: run
run: build ## Run obs-mcp in HTTP mode (use LOG_LEVEL=debug to see backend call timings)
@echo "Tip: Override backend URLs with PROMETHEUS_URL=https://... ALERTMANAGER_URL=https://... make run"
@echo "Note: AUTH_MODE=serviceaccount or header requires PROMETHEUS_URL and ALERTMANAGER_URL to be set"
./obs-mcp --listen $(LISTEN_ADDR) --auth-mode $(AUTH_MODE) --insecure --log-level $(LOG_LEVEL)
.PHONY: run-prometheus
run-prometheus: build ## Run obs-mcp with Prometheus as the metrics backend
@echo "Tip: Override backend URL with PROMETHEUS_URL=https://... make run-prometheus"
./obs-mcp --listen $(LISTEN_ADDR) --auth-mode $(AUTH_MODE) --metrics-backend prometheus --insecure --log-level $(LOG_LEVEL)
.PHONY: pf-alertmanager
pf-alertmanager: ## Port-forward alertmanager-main-0:9093 in background (prerequisite for pf targets)
@oc port-forward -n openshift-monitoring pod/alertmanager-main-0 9093:9093 &
@sleep 2
.PHONY: run-openshift-pf-prometheus
run-openshift-pf-prometheus: build pf-alertmanager ## Port-forward prometheus-k8s-0:9090 + alertmanager-main-0:9093 and start obs-mcp with header auth (requires oc login)
@echo "Port-forwarding prometheus-k8s-0:9090..."
@oc port-forward -n openshift-monitoring pod/prometheus-k8s-0 9090:9090 & \
PF_PID=$$!; \
sleep 2; \
trap "kill $$PF_PID 2>/dev/null" EXIT; \
PROMETHEUS_URL=http://localhost:9090 ALERTMANAGER_URL=http://localhost:9093 \
./obs-mcp --listen $(LISTEN_ADDR) --auth-mode header --log-level $(LOG_LEVEL)
.PHONY: inspect
inspect: COMPOSE_HOST_GATEWAY = $(if $(filter podman,$(CONTAINER_CLI)),host.containers.internal,host.docker.internal)
inspect: ## Start obs-mcp + MCP Inspector via compose (port-forward Prometheus/Alertmanager first)
CONTAINER_HOST_GATEWAY=$(COMPOSE_HOST_GATEWAY) $(CONTAINER_CLI) compose -f compose.yaml up --build
.PHONY: run-no-guardrails
run-no-guardrails: build ## Run obs-mcp in HTTP mode with guardrails disabled
@echo "Tip: Override backend URLs with PROMETHEUS_URL=https://... ALERTMANAGER_URL=https://... make run-no-guardrails"
@echo "Note: AUTH_MODE=serviceaccount or header requires PROMETHEUS_URL and ALERTMANAGER_URL to be set"
./obs-mcp --listen $(LISTEN_ADDR) --auth-mode $(AUTH_MODE) --insecure --log-level $(LOG_LEVEL) --guardrails none
# E2E Testing
KIND_CLUSTER_NAME ?= obs-mcp-e2e
.PHONY: test-e2e-setup
test-e2e-setup: ## Setup Kind cluster with kube-prometheus for E2E tests
chmod +x hack/e2e/setup-cluster.sh
CLUSTER_NAME=$(KIND_CLUSTER_NAME) ./hack/e2e/setup-cluster.sh
.PHONY: test-e2e-images
test-e2e-images: container ## Build and load obs-mcp image into Kind cluster
ifeq ($(CONTAINER_CLI),podman)
mkdir -p tmp
$(CONTAINER_CLI) save --quiet -o tmp/obs-mcp.tar $(IMAGE):$(TAG)
kind load image-archive --name $(KIND_CLUSTER_NAME) tmp/obs-mcp.tar
rm -f tmp/obs-mcp.tar
else
kind load docker-image --name $(KIND_CLUSTER_NAME) $(IMAGE):$(TAG)
endif
.PHONY: test-e2e-deploy
test-e2e-deploy: test-e2e-images ## Deploy obs-mcp to Kind cluster
kubectl apply -f manifests/kubernetes/
kubectl set image deployment/obs-mcp -n obs-mcp obs-mcp=$(IMAGE):$(TAG)
kubectl apply -f hack/e2e/manifests/network_policy_to_access_prometheus.yaml
kubectl -n obs-mcp rollout status deployment/obs-mcp --timeout=3m
.PHONY: test-e2e
test-e2e: ## Run E2E tests (requires cluster to be running)
go test -mod=mod -v -tags=e2e -timeout=10m ./tests/e2e/...
.PHONY: test-e2e-teardown
test-e2e-teardown: ## Teardown E2E test cluster
chmod +x hack/e2e/teardown-cluster.sh
CLUSTER_NAME=$(KIND_CLUSTER_NAME) ./hack/e2e/teardown-cluster.sh
.PHONY: test-e2e-full
test-e2e-full: test-e2e-setup test-e2e-deploy test-e2e test-e2e-teardown ## Run full E2E test cycle (setup, test, teardown)
# OpenShift E2E Testing
# In CI, deploy-obs-mcp step calls test-e2e-openshift-deploy, then the step registry runs test-e2e && test-e2e-openshift.
# CI config: https://github.com/openshift/release/blob/main/ci-operator/config/rhobs/obs-mcp/rhobs-obs-mcp-main.yaml
# Step registry: https://github.com/openshift/release/blob/main/ci-operator/step-registry/rhobs/obs-mcp-e2e-tests/rhobs-obs-mcp-e2e-tests-commands.sh
.PHONY: test-e2e-openshift-deploy
test-e2e-openshift-deploy: ## Deploy obs-mcp to OpenShift (uses IMAGE env var from CI)
oc apply -f manifests/openshift_e2e/
oc set image deployment/obs-mcp -n obs-mcp obs-mcp=$(IMAGE)
oc -n obs-mcp rollout status deployment/obs-mcp --timeout=3m
.PHONY: test-e2e-openshift
test-e2e-openshift: ## Run OpenShift route discovery E2E tests (requires oc login)
go test -mod=mod -v -tags=e2e,openshift -timeout=5m ./tests/e2e/...