Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ By participating in this project, you agree to abide by our [Code of Conduct](.g
- [Commit Message Guidelines](#commit-message-guidelines)
- [Testing](#testing)
- [Linting](#linting)
- [Pre-Commit Hooks](#pre-commit-hooks)
- [Documentation](#documentation)
- [Component-Specific Guidelines](#component-specific-guidelines)
- [Backporting Changes](#backporting-changes)
Expand All @@ -38,19 +39,19 @@ If you discover a bug, have a feature request, or need to provide feedback, plea

When you're ready to contribute code:

1. **Fork and Clone**
1. **Fork and Clone**
Fork the repository and clone it to your local machine.
2. **Create a Branch**
2. **Create a Branch**
Create a feature branch from the appropriate base branch (typically `main`).
3. **Make Changes**
3. **Make Changes**
Implement your changes, ensuring they adhere to the project's coding standards.
4. **Run Tests**
4. **Run Tests**
Verify that all tests pass locally. Refer to the testing section below for more details.
5. **Update Documentation**
5. **Update Documentation**
Update or add documentation as needed in the corresponding directories.
6. **Commit and Push**
6. **Commit and Push**
Write clear commit messages that reference the related issue (e.g., "fix: Description of fix").
7. **Open a Pull Request**
7. **Open a Pull Request**
Submit a pull request (PR) with a detailed description of your changes and link any related issues.

---
Expand Down Expand Up @@ -106,6 +107,35 @@ Linting rules are configured in `.golangci.yml` at the repository root. The conf

---

## Pre-Commit Hooks

We use pre-commit hooks to catch issues before code is committed.
Local hooks are optional; by default nothing runs on commit unless you install hooks yourself.

### Quick setup

Run: `make pre-commit-setup` (bootstraps `.venv` and installs Go tools into `.tools/bin`).

### Run hooks manually

Run: `make pre-commit`.

### Optional: enable pre-commit on every commit

Run: `make pre-commit-install`.

### Troubleshooting

If setup fails, you can run the steps individually:

- Run: `make pre-commit-install-tool`.
- Run: `make pre-commit-tools`.
- Run: `make pre-commit-install`.

<!-- todo? remove scope later when all old lint errors are fixed -->
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove leftover TODO comment.

The HTML comment <!-- todo? remove scope later when all old lint errors are fixed --> appears to be a development note that shouldn't be in the final user-facing documentation.

🧹 Proposed fix
-<!-- todo? remove scope later when all old lint errors are fixed -->
-
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<!-- todo? remove scope later when all old lint errors are fixed -->
🤖 Prompt for AI Agents
In @.github/CONTRIBUTING.md at line 135, Remove the leftover HTML TODO comment
"<!-- todo? remove scope later when all old lint errors are fixed -->" from the
CONTRIBUTING.md content; simply delete that line so the user-facing
documentation no longer includes the development note and leave surrounding text
intact.


---

## Documentation

Contributions to documentation are highly valued. If you find any documentation gaps or errors:
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: pre-commit

on:
push:
branches:
- main
pull_request:
merge_group:
workflow_dispatch:

permissions:
contents: read

jobs:
pre-commit:
name: pre-commit
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
cache: true

- name: Add Go bin to PATH
run: echo "${{ github.workspace }}/.tools/bin" >> $GITHUB_PATH

- name: Install pre-commit
run: python -m pip install --upgrade pip pre-commit

- name: Install Go tools
run: |
mkdir -p .tools/bin
GOBIN="${{ github.workspace }}/.tools/bin" go install golang.org/x/tools/cmd/goimports@v0.30.0
GOBIN="${{ github.workspace }}/.tools/bin" go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2

- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure
Comment thread
coderabbitai[bot] marked this conversation as resolved.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ config/**/charts
*~

.claude
.venv
.tools

/zxporter-netmon
*.o
Expand Down
32 changes: 32 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
default_stages:
- pre-commit

repos:
- repo: local
hooks:
- id: gofmt
name: gofmt
entry: gofmt -w
language: system
types: [go]
- id: goimports
name: goimports
entry: ./.tools/bin/goimports -w
language: system
types: [go]
- id: golangci-lint
name: golangci-lint
entry: ./.tools/bin/golangci-lint run --timeout=5m
language: system
pass_filenames: false
Comment thread
coderabbitai[bot] marked this conversation as resolved.
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
- id: check-yaml
args: ["--allow-multiple-documents"]
exclude: ^helm-chart/.*/templates/
- id: check-added-large-files
args: ["--maxkb=1024"]
Comment on lines +22 to +32
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

CI warning: formatting hooks are modifying files—run pre-commit locally and commit the results.

The job warning indicates trailing-whitespace / end-of-file-fixer applied changes; CI will keep failing until those edits are included in the PR commit(s).

🤖 Prompt for AI Agents
In @.pre-commit-config.yaml around lines 22 - 32, CI shows that formatting hooks
(trailing-whitespace and end-of-file-fixer) modified files, so run the
configured pre-commit hooks locally (e.g., install hooks and run pre-commit run
--all-files), stage and commit the resulting changes, and push the updated
commit(s) so the repository contains the corrected formatting before re-running
CI.

40 changes: 33 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ DAKR_URL ?= https://dakr.devzero.io
# PROMETHEUS URL for metrics collection
PROMETHEUS_URL ?= http://prometheus-dz-prometheus-server.$(DEVZERO_MONITORING_NAMESPACE).svc.cluster.local:80
# TARGET_NAMESPACES for limiting collection to specific namespaces (comma-separated)
TARGET_NAMESPACES ?=
TARGET_NAMESPACES ?=
# COLLECTION_FILE is used to control the collectionpolicies.
COLLECTION_FILE ?= env_configmap.yaml
# ENV_CONFIGMAP_FILE is used to control the zxporter-manager deployment.
Expand Down Expand Up @@ -162,6 +162,32 @@ lint: golangci-lint ## Run golangci-lint linter
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
$(GOLANGCI_LINT) run --fix

PRE_COMMIT ?= .venv/bin/pre-commit

.venv/bin/pre-commit:
python3 -m venv .venv
.venv/bin/pip install --upgrade pip pre-commit

.PHONY: pre-commit-install
pre-commit-install: .venv/bin/pre-commit ## Install pre-commit hooks (optional).
$(PRE_COMMIT) install --install-hooks

.PHONY: pre-commit
pre-commit: pre-commit-tools .venv/bin/pre-commit ## Run pre-commit on all files.
PATH="$(PWD)/.tools/bin:$$PATH" $(PRE_COMMIT) run --all-files

.PHONY: pre-commit-tools
pre-commit-tools: ## Install Go tools needed by pre-commit.
@mkdir -p .tools/bin
GOBIN="$(PWD)/.tools/bin" go install golang.org/x/tools/cmd/goimports@v0.30.0
GOBIN="$(PWD)/.tools/bin" go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2
Comment on lines +179 to +183
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

latest version golang.org/x/tools goimports 2025 2026

💡 Result:

goimports is distributed inside the golang.org/x/tools module and doesn’t have its own independent release tag — its version follows the golang.org/x/tools module release. To install the latest published version (resolves to the module’s latest tag or pseudo-version):

go install golang.org/x/tools/cmd/goimports@latest

(Documentation: pkg.go.dev). [1][2]

References:

  • golang.org/x/tools (pkg.go.dev) — goimports cmd and install instructions. [1]
  • golang/tools releases (GitHub) — module/release history (goimports is part of this repo). [2]

🌐 Web query:

golang.org/x/tools latest version 2025 2026 release

💡 Result:

Latest notable release: gopls (part of golang.org/x/tools) v0.21.0 — released Dec 17, 2025. [1][2]

References:

  • golang/tools GitHub releases (gopls/v0.21.0). [1]
  • go.dev gopls release pages / gopls release notes. [2]

🌐 Web query:

golang.org/x/tools module latest version v0.30.0 vs current releases

💡 Result:

v0.30.0 is not the latest — the golang.org/x/tools module has newer releases (e.g. v0.31.0 and later) and its downstream projects (like gopls) have continued releasing after v0.30.0. (pkg.go.dev)

Citations:


Update goimports to a more recent version.

The golangci-lint version correctly matches GOLANGCI_LINT_VERSION defined at line 545. However, goimports v0.30.0 is outdated; golang.org/x/tools has released v0.31.0 and later. Consider updating to a recent version or using @latest.

🤖 Prompt for AI Agents
In @Makefile around lines 179 - 183, Update the goimports install in the
pre-commit-tools target: the line installing
golang.org/x/tools/cmd/goimports@v0.30.0 should be changed to a newer release
(e.g., @v0.31.0) or to @latest to keep it current; modify the go install
invocation within the pre-commit-tools recipe so GOBIN="$(PWD)/.tools/bin" go
install golang.org/x/tools/cmd/goimports@v0.31.0 (or @latest) instead of
@v0.30.0.


.PHONY: pre-commit-install-tool
pre-commit-install-tool: .venv/bin/pre-commit ## Install pre-commit into a local virtualenv.

.PHONY: pre-commit-setup
pre-commit-setup: pre-commit-install-tool pre-commit-tools ## Install pre-commit and tools (hooks are optional).

Comment thread
coderabbitai[bot] marked this conversation as resolved.
GITVERSION ?= $(shell git describe --tags 2>/dev/null || echo "v0.0.0-$(shell git rev-parse --short HEAD)")

ifeq ($(shell echo $(GITVERSION) | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+"),)
Expand Down Expand Up @@ -354,7 +380,7 @@ build-installer: manifests generate kustomize yq ## Generate a consolidated YAML
# @cat $(METRICS_SERVER) >> $(DIST_INSTALL_BUNDLE)
# @echo "# ----- END METRICS SERVER -----" >> $(DIST_INSTALL_BUNDLE)
@echo "---" >> $(DIST_INSTALL_BUNDLE)

@echo "[INFO] Append zxporter-manager to the installer bundle"
@cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}

Expand Down Expand Up @@ -396,11 +422,11 @@ HELM_CHART_PACKAGE_DIR := helm-chart/packages
helm-chart-build: helm ## Build and package the Helm chart
@echo "[INFO] Building Helm chart..."
@mkdir -p $(HELM_CHART_PACKAGE_DIR)

# Update chart version and appVersion
@$(YQ) eval '.version = "$(VERSION)"' -i $(HELM_CHART_DIR)/Chart.yaml
@$(YQ) eval '.appVersion = "$(VERSION)"' -i $(HELM_CHART_DIR)/Chart.yaml

# Package the chart
@$(HELM) package $(HELM_CHART_DIR) --destination $(HELM_CHART_PACKAGE_DIR)
@echo "[INFO] Helm chart packaged successfully"
Expand Down Expand Up @@ -681,7 +707,7 @@ install-buf: ## Install buf if not already installed
echo "$(BUF_BINARY_NAME) is already installed."; \
fi

# (for local dev) Get metadata to generate a Dakr client.
# (for local dev) Get metadata to generate a Dakr client.
.PHONY: generate-proto
generate-proto: install-buf ## Fetch latest Dakr protobuf
@PROTO_DIR="$(PWD)/proto"; \
Expand All @@ -693,7 +719,7 @@ generate-proto: install-buf ## Fetch latest Dakr protobuf
cp "$(DAKR_MPA_PROTO)" "$$PROTO_DIR/api/v1"; \
find "$$PROTO_DIR" -type f -name "*.yaml" -exec perl -pi -e 's|github.com/devzero-inc/services/dakr/gen|github.com/devzero-inc/zxporter/gen|g' {} +; \
buf build "$(DAKR_DIR)" --path "$(DAKR_METRICS_COLLECTOR_PROTO)" --path "$(DAKR_CLUSTER_PROTO)" -o "$$PROTO_DIR"/dakr_proto_descriptor.bin; \
buf generate --include-imports "$$PROTO_DIR"/dakr_proto_descriptor.bin;
buf generate --include-imports "$$PROTO_DIR"/dakr_proto_descriptor.bin;
buf generate --verbose --include-imports --timeout=5m .

# Lima Verification
Expand All @@ -714,7 +740,7 @@ verify-local: setup-lima
@chmod +x verification/verify_local.sh
@./verification/verify_local.sh $(LIMA_INSTANCE)

# for local, this will be something like:
# for local, this will be something like:
# make verify-e2e CLUSTER_CONTEXT=kind-zxporter-e2e NAMESPACE=devzero-zxporter
.PHONY: verify-e2e
verify-e2e: ## Run E2E verification on a Kind or Cloud cluster
Expand Down
Loading