Skip to content

Add pre-commit configuration #862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2023
Merged
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
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ A clear and concise description of what you expected to happen.
* Kubernetes platform (e.g. Mini-kube or GCP)
* Details on how you expose the NGINX Gateway Pod (e.g. Service of type LoadBalancer or port-forward)
* Logs of NGINX container: `kubectl -n nginx-gateway logs -l app=nginx-gateway -c nginx`
* NGINX Configuration: `kubectl -n nginx-gateway exec <gateway-pod> -c nginx -- nginx -T`
* NGINX Configuration: `kubectl -n nginx-gateway exec <gateway-pod> -c nginx -- nginx -T`

**Additional context**
Add any other context about the problem here. Any log files you want to share.
Add any other context about the problem here. Any log files you want to share.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/enhancement.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
name: Enhancement Request
about: Suggest an enhancement for this project
name: Enhancement Request
about: Suggest an enhancement for this project
labels: 'enhancement'
---

<!--
WARNING: Prior to submitting an enhancement request, we ask that you create a discussion. If you have not yet
WARNING: Prior to submitting an enhancement request, we ask that you create a discussion. If you have not yet
created a discussion related to your request, please do so now: https://github.com/nginxinc/nginx-kubernetes-gateway/discussions/new?category=ideas
-->

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ jobs:
name: Gateway Conformance Tests
runs-on: ubuntu-22.04
needs: vars
if: ${{ github.ref_type != 'tag' }}
if: ${{ github.ref_type != 'tag' }}
steps:
- name: Checkout Repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
Expand All @@ -163,7 +163,7 @@ jobs:

- name: Docker Buildx
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1 # v2.9.1

- name: Docker meta
id: meta
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4.6.0
Expand All @@ -182,7 +182,7 @@ jobs:
nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2)
make update-nkg-manifest NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag}
working-directory: ./conformance

- name: Build binary
uses: goreleaser/goreleaser-action@336e29918d653399e599bfca99fadc1d7ffbc9f7 # v4.3.0
with:
Expand All @@ -202,7 +202,7 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max
pull: true

- name: Build Test Docker Image
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
with:
Expand Down
5 changes: 5 additions & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1e4b4d2f9e11f8ea7a1cced14889e3e59a049f46:internal/state/secrets_test.go:private-key:42
1e4b4d2f9e11f8ea7a1cced14889e3e59a049f46:internal/state/graph_test.go:private-key:42
68d1f6eb80d23c8650c11629459dd6a06c986ca1:internal/state/graph/graph_test.go:private-key:44
890fddb787ff3560b9b743647a36b649d498ae51:internal/state/graph/secret_test.go:private-key:35
890fddb787ff3560b9b743647a36b649d498ae51:internal/state/change_processor_test.go:private-key:211
52 changes: 52 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
args: [--allow-multiple-documents]
- id: check-added-large-files
- id: check-merge-conflict
- id: check-case-conflict
- id: check-vcs-permalinks
- id: check-json
- id: pretty-format-json
args: [--autofix, --no-sort-keys, --no-ensure-ascii]
- id: mixed-line-ending
args: [--fix=lf]
- id: no-commit-to-branch
- id: detect-private-key
exclude: (^examples/|^docs/|.*_test.go$)

- repo: https://github.com/gitleaks/gitleaks
rev: v8.17.0
hooks:
- id: gitleaks

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0
hooks:
- id: prettier
types:
- javascript

- repo: local
hooks:
- id: golang-diff
name: create-go-diff
entry: bash -c 'git diff -p origin/main > /tmp/diff.patch'
language: system
types: [go]
pass_filenames: false

- repo: https://github.com/golangci/golangci-lint
rev: v1.53.3
hooks:
- id: golangci-lint
args: [--new-from-patch=/tmp/diff.patch]

ci:
skip: [golang-diff, golangci-lint, prettier]
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ DEPENDENCIES:

COMPATIBILITY:
- The Gateway API version: `0.5.1`
- NGINX version: `1.21.x` *
- NGINX version: `1.21.x` *
- Kubernetes version: `1.21+`

\*the installation manifests use the `nginx:1.21` image, which always points to the latest version of 1.21.x releases.
Expand Down Expand Up @@ -146,7 +146,7 @@ If you'd like to give us feedback or get involved, see the [README](https://gith

COMPATIBILITY:
- The Gateway API version: `0.5.0`
- NGINX version: `1.21.3`
- NGINX version: `1.21.3`
- Kubernetes version: `1.19+`

CONTAINER IMAGES:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Before beginning development, familiarize yourself with the following documents:
- [Pull Request Guidelines](/docs/developer/pull-request.md): A guide for both pull request submitters and reviewers,
outlining guidelines and best practices to ensure smooth and efficient pull request processes.
- [Go Style Guide](/docs/developer/go-style-guide.md): A coding style guide for Go. Contains best practices and
conventions to follow when writing Go code for the project.
conventions to follow when writing Go code for the project.
- [Architecture](/docs/architecture.md): A high-level overview of the project's architecture.
- [Design Principles](/docs/developer/design-principles.md): An overview of the project's design principles.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ For a list of supported Gateway API resources and features, see the [Gateway API
> Warning: This project is actively in development (beta feature state) and should not be deployed in a production environment.
> All APIs, SDKs, designs, and packages are subject to change.

Learn about our [design principles](/docs/developer/design-principles.md) and [architecture](/docs/architecture.md).
Learn about our [design principles](/docs/developer/design-principles.md) and [architecture](/docs/architecture.md).

## Getting Started

Expand Down
2 changes: 1 addition & 1 deletion conformance/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ load-images: preload-nginx-container ## Load NKG and NGINX containers on configu
.PHONY: prepare-nkg-dependencies
prepare-nkg-dependencies: ## Install NKG dependencies on configured kind cluster
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.7.1/standard-install.yaml
kubectl wait --for=condition=available --timeout=60s deployment gateway-api-admission-server -n gateway-system
kubectl wait --for=condition=available --timeout=60s deployment gateway-api-admission-server -n gateway-system
kubectl apply -f ../deploy/manifests/namespace.yaml
kubectl create configmap njs-modules --from-file=../internal/mode/static/nginx/modules/src/httpmatches.js -n nginx-gateway
kubectl apply -f ../deploy/manifests/nginx-conf.yaml
Expand Down
2 changes: 1 addition & 1 deletion conformance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ make install-nkg-local-build
```makefile
make install-nkg-local-no-build
```
**Note:** You can optionally skip the actual *build* step. However, if choosing
**Note:** You can optionally skip the actual *build* step. However, if choosing
this option, the following step *must* be completed manually *before* the build step:
* Set NKG_PREFIX=<nkg_repo_name> NKG_TAG=<nkg_image_tag> to preferred values.
* Navigate to `deploy/manifests` and update values in `deployment.yaml` as specified in below code-block.
Expand Down
4 changes: 2 additions & 2 deletions conformance/provisioner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ https://github.com/nginxinc/nginx-kubernetes-gateway/issues/634). However, it ca
tests, which expect a Gateway API implementation to provision an independent data plane per Gateway.

> Note: Provisioner uses [this manifest](/deploy/manifests/deployment.yaml) to create an NKG static mode Deployment.
This manifest gets included into the NKG binary during the NKG build. To customize the Deployment, modify the manifest
This manifest gets included into the NKG binary during the NKG build. To customize the Deployment, modify the manifest
and **re-build** NKG.

How to deploy:
Expand All @@ -33,7 +33,7 @@ How to deploy:
```
1. Confirm the provisioner is running in nginx-gateway namespace:
```shell
kubectl get pods -n nginx-gateway
kubectl get pods -n nginx-gateway
```
```console
NAME READY STATUS RESTARTS AGE
Expand Down
2 changes: 1 addition & 1 deletion deploy/manifests/service/nodeport.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: nginx-gateway
namespace: nginx-gateway
spec:
type: NodePort
type: NodePort
ports: # Update the following ports to match your Gateway Listener ports
- port: 80
targetPort: 80
Expand Down
2 changes: 1 addition & 1 deletion docs/cli-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This document describes the commands available in the `gateway` binary of `nginx

## Static Mode

This command configures NGINX in the scope of a single Gateway resource.
This command configures NGINX in the scope of a single Gateway resource.

Usage:

Expand Down
2 changes: 1 addition & 1 deletion docs/developer/design-principles.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ users monitor the health of NGINX Kubernetes Gateway and to assist in diagnosing

NGINX Kubernetes Gateway must be easy and intuitive to use. This means that it should be easy to install, easy to
configure, and easy to monitor. Its defaults should be sane and should lead to "out-of-box" success. The documentation
should be clear and provide meaningful examples that customer's can use to inform their deployments and configurations.
should be clear and provide meaningful examples that customer's can use to inform their deployments and configurations.
26 changes: 13 additions & 13 deletions docs/developer/go-style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func longFunctionDefinition(
paramZ bool,
) (string, error){}

// and
// and

s := myStruct{
field1: 1,
Expand All @@ -73,14 +73,14 @@ func longFunctionDefinition(paramX int, paramY string,
paramZ bool,
) (string, error){}

// or
// or

func longFunctionDefinition(
paramX int, paramY string,
paramZ bool,
) (string, error){}

// or
// or
s := myStruct{field1: 1, field2: 2,
field3: 3}

Expand Down Expand Up @@ -174,9 +174,9 @@ dependencies adds side-effects which complicates testing.

DO NOT:

```go
```go
func(int required, int optional) {
if optional {...}
if optional {...}
}
```

Expand All @@ -188,13 +188,13 @@ type Option func (o *Object)
func Optional(string optional) Option {
return func (o *Object) {
o.optional = optional
}
}
}

func (int required, ...Options) {
for o := range Options {
o(self)
}
}
}
```

Expand Down Expand Up @@ -270,14 +270,14 @@ Example:

```go
func onError(err error) {
// got an asynchronous error
// got an asynchronous error
}

func ReadAsync(r io.Reader, onError) {
err := r()
if err != nil {
onError(err)
}
}
}

go ReadAsync(reader, onError)
Expand Down Expand Up @@ -307,12 +307,12 @@ func readFile(filename string) ([]byte, error) {
return nil, fmt.Errorf("failed to open file: %w", err)
}
defer file.Close()

data, err := ioutil.ReadAll(file)
if err != nil {
return nil, fmt.Errorf("failed to read file: %w", err)
}

return data, nil
}

Expand Down Expand Up @@ -454,7 +454,7 @@ type Object struct{
func New() *Object {
return &Object{
subobject: &SubObject{},
}
}
}
```

Expand All @@ -477,7 +477,7 @@ DO NOT:
```go
func(s string) *string {
s := s + "more strings"
return &s // this will move to heap
return &s // this will move to heap
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/developer/pull-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ A FIXME is for things that should be fixed in the future. If FIXMEs cannot be ad
merged, but they _MUST_ include your username and a link to the issue. For example:

```go
// FIXME(username): This is currently a hack to work around known issue X.
// FIXME(username): This is currently a hack to work around known issue X.
// Issue <LINK TO GITHUB ISSUE> will remove need for this work around.
```
12 changes: 11 additions & 1 deletion docs/developer/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ Follow these steps to set up your development environment.
```shell
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
```
- [pre-commit](https://pre-commit.com/#install):

```shell
brew install pre-commit
```
and then run
```shell
pre-commit install
```
in the project root directory to install the git hooks.

2. [Fork the project repository](https://github.com/nginxinc/nginx-kubernetes-gateway/fork)
3. Clone your repository, and install the project dependencies:
Expand Down Expand Up @@ -77,7 +87,7 @@ This will build the docker image `nginx-kubernetes-gateway:<your-user>`.
Alternatively, you can update the image name and pull policy by using the following command when applying
`deployment.yaml`:

```shell
```shell
cat deploy/manifests/deployment.yaml | sed "s|image: ghcr.io/nginxinc/nginx-kubernetes-gateway.*|image: nginx-kubernetes-gateway:$(whoami)|" | sed "s|imagePullPolicy: Always|imagePullPolicy: IfNotPresent|" | kubectl apply -f -
```

Expand Down
8 changes: 4 additions & 4 deletions docs/developer/testing.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Testing

This document provides guidelines for testing, including instructions on running the unit tests, accessing the code
coverage report, performing manual testing, and running the conformance tests. By following these guidelines, you will
coverage report, performing manual testing, and running the conformance tests. By following these guidelines, you will
gain a thorough understanding of the project's approach to unit testing, enabling you to ensure code quality, validate
functionality, and maintain robust test coverage.

Expand Down Expand Up @@ -78,13 +78,13 @@ Follow the steps below for manual testing:
```
- The statuses of the Gateway API Resources. Make sure they look correct.
```shell
kubectl describe <resource> <resource name>
kubectl describe <resource> <resource name>
```
- NGINX proxies traffic successfully (when applicable).
- NGINX proxies traffic successfully (when applicable).
- [Examples](/examples) work correctly. This will ensure that your changes have not introduced any regressions.

> **Note**
>
>
> Don't limit yourself to happy path testing. Make an effort to cover various scenarios, including edge cases and potential error conditions. By testing a wide range of scenarios, you can uncover hidden issues and ensure the robustness of your changes.

Performing manual testing helps guarantee the stability, reliability, and effectiveness of your changes before
Expand Down
4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ This guide walks you through how to install NGINX Kubernetes Gateway on a generi
You can gain access to NGINX Kubernetes Gateway by creating a `NodePort` Service or a `LoadBalancer` Service.

> Important
>
>
> The Service manifests expose NGINX Kubernetes Gateway on ports 80 and 443, which exposes any Gateway [Listener](https://gateway-api.sigs.k8s.io/references/spec/#gateway.networking.k8s.io/v1beta1.Listener) configured for those ports. If you'd like to use different ports in your listeners,
> update the manifests accordingly.
> update the manifests accordingly.

### Create a NodePort Service

Expand Down
Loading