Skip to content

Commit df96e6e

Browse files
authored
Add go ci/makefile (#25)
Signed-off-by: Brent Salisbury <bsalisbu@redhat.com>
1 parent 64550e5 commit df96e6e

File tree

4 files changed

+181
-11
lines changed

4 files changed

+181
-11
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Key Manager Build
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'deployment/kuadrant-openshift/key-manager/**'
7+
- 'Makefile'
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v5
15+
16+
- uses: actions/setup-go@v5
17+
with:
18+
go-version: '1.24.2'
19+
20+
- name: Check code formatting
21+
run: make fmt-check
22+
23+
- name: Build image
24+
run: make build-image
25+

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ dist/
66
build/
77
.idea/
88
.claude
9+
10+
# Go test coverage files
11+
deployment/kuadrant-openshift/key-manager/coverage.out
12+
deployment/kuadrant-openshift/key-manager/coverage.html
13+
bin/

Makefile

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# MaaS Billing Makefile
2+
3+
# Container Engine to be used for building image and with kind
4+
CONTAINER_ENGINE ?= docker
5+
ifeq (podman,$(CONTAINER_ENGINE))
6+
CONTAINER_ENGINE_EXTRA_FLAGS ?= --load
7+
endif
8+
9+
# Image settings
10+
REPO ?= ghcr.io/your-org/maas-key-manager
11+
TAG ?= latest
12+
FULL_IMAGE ?= $(REPO):$(TAG)
13+
14+
# Key Manager settings
15+
KEY_MANAGER_DIR := deployment/kuadrant-openshift/key-manager
16+
BINARY_NAME := key-manager
17+
BUILD_DIR := ./bin
18+
CMD_DIR := $(KEY_MANAGER_DIR)/cmd/key-manager
19+
20+
# Go settings
21+
GO_VERSION := 1.24.2
22+
GOOS ?= linux
23+
GOARCH ?= amd64
24+
CGO_ENABLED ?= 0
25+
26+
# Git settings
27+
GIT_COMMIT := $(shell git rev-parse --short HEAD)
28+
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
29+
BUILD_TIME := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
30+
31+
# Ldflags for build info
32+
LDFLAGS := -ldflags "-s -w -X main.version=$(TAG) -X main.commit=$(GIT_COMMIT) -X main.buildTime=$(BUILD_TIME)"
33+
34+
.PHONY: help
35+
help: ## Show this help message
36+
@echo "MaaS Billing Makefile"
37+
@echo ""
38+
@echo "Usage: make <target> [REPO=your-repo] [TAG=your-tag]"
39+
@echo ""
40+
@echo "Examples:"
41+
@echo " make build-image REPO=ghcr.io/myorg/key-manager TAG=v1.0.0"
42+
@echo " make push-image REPO=ghcr.io/myorg/key-manager TAG=latest"
43+
@echo ""
44+
@echo "Targets:"
45+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
46+
47+
.PHONY: fmt
48+
fmt: ## Format Go code using gofmt
49+
@echo "Formatting Go code..."
50+
@cd $(KEY_MANAGER_DIR) && gofmt -s -w .
51+
@echo "Code formatting complete"
52+
53+
.PHONY: fmt-check
54+
fmt-check: ## Check if Go code is formatted
55+
@echo "Checking Go code formatting..."
56+
@cd $(KEY_MANAGER_DIR) && if [ -n "$$(gofmt -l .)" ]; then \
57+
echo "The following files need formatting:"; \
58+
gofmt -l .; \
59+
exit 1; \
60+
fi
61+
@echo "All Go code is properly formatted"
62+
63+
.PHONY: vet
64+
vet: ## Run go vet
65+
@echo "Running go vet..."
66+
@cd $(KEY_MANAGER_DIR) && go vet ./...
67+
68+
.PHONY: lint
69+
lint: fmt-check vet ## Run all linting checks
70+
@echo "All linting checks passed"
71+
72+
.PHONY: tidy
73+
tidy: ## Tidy Go modules
74+
@echo "Tidying Go modules..."
75+
@cd $(KEY_MANAGER_DIR) && go mod tidy
76+
@cd $(KEY_MANAGER_DIR) && go mod verify
77+
78+
.PHONY: deps
79+
deps: ## Download Go dependencies
80+
@echo "Downloading Go dependencies..."
81+
@cd $(KEY_MANAGER_DIR) && go mod download
82+
83+
.PHONY: build
84+
build: fmt deps ## Build the key-manager binary
85+
@echo "Building $(BINARY_NAME)..."
86+
@mkdir -p $(BUILD_DIR)
87+
@cd $(KEY_MANAGER_DIR) && CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) go build $(LDFLAGS) -o ../../$(BUILD_DIR)/$(BINARY_NAME) ./cmd/key-manager
88+
@echo "Built $(BUILD_DIR)/$(BINARY_NAME)"
89+
90+
.PHONY: test
91+
test: ## Run Go tests
92+
@echo "Running tests..."
93+
@cd $(KEY_MANAGER_DIR) && go test -v -race -coverprofile=coverage.out ./...
94+
@cd $(KEY_MANAGER_DIR) && go tool cover -html=coverage.out -o coverage.html
95+
@echo "Test coverage report generated: $(KEY_MANAGER_DIR)/coverage.html"
96+
97+
.PHONY: test-short
98+
test-short: ## Run Go tests (short mode)
99+
@echo "Running tests (short mode)..."
100+
@cd $(KEY_MANAGER_DIR) && go test -short -v ./...
101+
102+
.PHONY: build-image
103+
build-image: ## Build container image (use REPO= and TAG= to specify image)
104+
@if [ -z "$(REPO)" ]; then \
105+
echo "Error: REPO is required. Usage: make build-image REPO=ghcr.io/myorg/key-manager"; \
106+
exit 1; \
107+
fi
108+
@echo "Building container image $(FULL_IMAGE)..."
109+
@cd $(KEY_MANAGER_DIR) && $(CONTAINER_ENGINE) build $(CONTAINER_ENGINE_EXTRA_FLAGS) -t $(FULL_IMAGE) .
110+
@echo "Container image $(FULL_IMAGE) built successfully"
111+
112+
.PHONY: push-image
113+
push-image: ## Push container image (use REPO= and TAG= to specify image)
114+
@if [ -z "$(REPO)" ]; then \
115+
echo "Error: REPO is required. Usage: make push-image REPO=ghcr.io/myorg/key-manager"; \
116+
exit 1; \
117+
fi
118+
@echo "Pushing container image $(FULL_IMAGE)..."
119+
@$(CONTAINER_ENGINE) push $(FULL_IMAGE)
120+
@echo "Container image $(FULL_IMAGE) pushed successfully"
121+
122+
.PHONY: build-push-image
123+
build-push-image: build-image push-image ## Build and push container image
124+
125+
.PHONY: run
126+
run: build ## Run the key-manager locally
127+
@echo "Running $(BINARY_NAME)..."
128+
@$(BUILD_DIR)/$(BINARY_NAME)
129+
130+
.PHONY: version
131+
version: ## Show version information
132+
@echo "Image: $(FULL_IMAGE)"
133+
@echo "Git Commit: $(GIT_COMMIT)"
134+
@echo "Git Branch: $(GIT_BRANCH)"
135+
@echo "Build Time: $(BUILD_TIME)"
136+
@echo "Go Version: $(GO_VERSION)"
137+
138+
# Default target
139+
.DEFAULT_GOAL := help
140+

deployment/kuadrant-openshift/key-manager/internal/keys/manager.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ func (m *Manager) CreateTeamKey(teamID string, req *CreateTeamKeyRequest) (*Crea
6868
if userEmail == "" {
6969
userEmail = fmt.Sprintf("%s@company.com", req.UserID)
7070
}
71-
71+
7272
// Get team details for member creation
7373
teamDetails, err := m.teamMgr.Get(teamID)
7474
if err != nil {
7575
return nil, fmt.Errorf("failed to get team details: %w", err)
7676
}
77-
77+
7878
teamMember = &teams.TeamMember{
7979
UserID: req.UserID,
8080
UserEmail: userEmail,
@@ -321,15 +321,15 @@ func (m *Manager) createKeySecret(teamID string, req *CreateTeamKeyRequest, apiK
321321
Name: secretName,
322322
Namespace: m.keyNamespace,
323323
Labels: map[string]string{
324-
"kuadrant.io/auth-secret": "true", // Required for working AuthPolicy
325-
"kuadrant.io/apikeys-by": "rhcl-keys", // Required for key listing functions
326-
"app": "llm-gateway", // Required for working AuthPolicy
327-
"authorino.kuadrant.io/managed-by": "authorino", // Ensure Authorino always sees it
328-
"maas/user-id": req.UserID,
329-
"maas/team-id": teamID,
330-
"maas/team-role": teamMember.Role,
331-
"maas/key-sha256": keyHash[:32],
332-
"maas/resource-type": "team-key",
324+
"kuadrant.io/auth-secret": "true", // Required for working AuthPolicy
325+
"kuadrant.io/apikeys-by": "rhcl-keys", // Required for key listing functions
326+
"app": "llm-gateway", // Required for working AuthPolicy
327+
"authorino.kuadrant.io/managed-by": "authorino", // Ensure Authorino always sees it
328+
"maas/user-id": req.UserID,
329+
"maas/team-id": teamID,
330+
"maas/team-role": teamMember.Role,
331+
"maas/key-sha256": keyHash[:32],
332+
"maas/resource-type": "team-key",
333333
// Policy targeting label - this is how Kuadrant policies find API keys
334334
fmt.Sprintf("maas/policy-%s", teamMember.Policy): "true",
335335
},

0 commit comments

Comments
 (0)