diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 8b7c7ba34e..44349beb12 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -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 -c nginx -- nginx -T` +* NGINX Configuration: `kubectl -n nginx-gateway exec -c nginx -- nginx -T` **Additional context** -Add any other context about the problem here. Any log files you want to share. \ No newline at end of file +Add any other context about the problem here. Any log files you want to share. diff --git a/.github/ISSUE_TEMPLATE/enhancement.md b/.github/ISSUE_TEMPLATE/enhancement.md index f6cf0344a8..e0fa12e99f 100644 --- a/.github/ISSUE_TEMPLATE/enhancement.md +++ b/.github/ISSUE_TEMPLATE/enhancement.md @@ -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' --- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae277aee51..f7ae183370 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 @@ -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: @@ -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: diff --git a/.gitleaksignore b/.gitleaksignore new file mode 100644 index 0000000000..9cc154248f --- /dev/null +++ b/.gitleaksignore @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..e0938e48be --- /dev/null +++ b/.pre-commit-config.yaml @@ -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] diff --git a/CHANGELOG.md b/CHANGELOG.md index a0772addea..9a517e9d21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. @@ -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: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3fef1c0f53..ceb9bd67a2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/README.md b/README.md index 024b1b87ce..bd64beb68d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/conformance/Makefile b/conformance/Makefile index e256a9445d..c211b51972 100644 --- a/conformance/Makefile +++ b/conformance/Makefile @@ -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 diff --git a/conformance/README.md b/conformance/README.md index 629ed8e42d..c74d264b64 100644 --- a/conformance/README.md +++ b/conformance/README.md @@ -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_TAG= to preferred values. * Navigate to `deploy/manifests` and update values in `deployment.yaml` as specified in below code-block. diff --git a/conformance/provisioner/README.md b/conformance/provisioner/README.md index bb5be928be..c04409f74d 100644 --- a/conformance/provisioner/README.md +++ b/conformance/provisioner/README.md @@ -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: @@ -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 diff --git a/deploy/manifests/service/nodeport.yaml b/deploy/manifests/service/nodeport.yaml index be7dd2c0e9..759e83fe89 100644 --- a/deploy/manifests/service/nodeport.yaml +++ b/deploy/manifests/service/nodeport.yaml @@ -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 diff --git a/docs/cli-help.md b/docs/cli-help.md index 41387ed114..0ba6b040d8 100644 --- a/docs/cli-help.md +++ b/docs/cli-help.md @@ -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: diff --git a/docs/developer/design-principles.md b/docs/developer/design-principles.md index 423780fda2..29151a7612 100644 --- a/docs/developer/design-principles.md +++ b/docs/developer/design-principles.md @@ -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. diff --git a/docs/developer/go-style-guide.md b/docs/developer/go-style-guide.md index 6e004d2ce3..b624d79013 100644 --- a/docs/developer/go-style-guide.md +++ b/docs/developer/go-style-guide.md @@ -57,7 +57,7 @@ func longFunctionDefinition( paramZ bool, ) (string, error){} -// and +// and s := myStruct{ field1: 1, @@ -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} @@ -174,9 +174,9 @@ dependencies adds side-effects which complicates testing. DO NOT: -```go +```go func(int required, int optional) { - if optional {...} + if optional {...} } ``` @@ -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) - } + } } ``` @@ -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) @@ -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 } @@ -454,7 +454,7 @@ type Object struct{ func New() *Object { return &Object{ subobject: &SubObject{}, - } + } } ``` @@ -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 } ``` diff --git a/docs/developer/pull-request.md b/docs/developer/pull-request.md index 2809c623f7..6b00f3f8c6 100644 --- a/docs/developer/pull-request.md +++ b/docs/developer/pull-request.md @@ -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 will remove need for this work around. ``` diff --git a/docs/developer/quickstart.md b/docs/developer/quickstart.md index 8781c523bf..3508b668e9 100644 --- a/docs/developer/quickstart.md +++ b/docs/developer/quickstart.md @@ -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: @@ -77,7 +87,7 @@ This will build the docker image `nginx-kubernetes-gateway:`. 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 - ``` diff --git a/docs/developer/testing.md b/docs/developer/testing.md index 8d124024dc..452133a020 100644 --- a/docs/developer/testing.md +++ b/docs/developer/testing.md @@ -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. @@ -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 + kubectl describe ``` - - 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 diff --git a/docs/installation.md b/docs/installation.md index 1b90541fa7..47eb653d06 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -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 diff --git a/docs/release-process.md b/docs/release-process.md index 8cff25205e..130601ea60 100644 --- a/docs/release-process.md +++ b/docs/release-process.md @@ -32,7 +32,7 @@ To create a new release, follow these steps: 4. If a problem is found, prepare a fix PR, merge it into the main branch and return to the previous step. 5. Create a release branch with a name that follows the `release-X.Y` format. 6. Prepare and merge a PR into the release branch to update the repo files for the release: - 1. Update the tag of NKG container images used in the installation manifests (both the + 1. Update the tag of NKG container images used in the installation manifests (both the [deployment manifest](../deploy/manifests/deployment.yaml) and the [provisioner manifest](../conformance/provisioner/provisioner.yaml)) and docs to `X.Y.Z`. 2. Ensure that the `imagePullPolicy` is `IfNotPresent` in the installation manifests. diff --git a/docs/resource-validation.md b/docs/resource-validation.md index 721fd20d4d..62e1eda28c 100644 --- a/docs/resource-validation.md +++ b/docs/resource-validation.md @@ -53,7 +53,7 @@ For example, if you create an HTTPRoute with an invalid hostname `cafe.!@#$%exam with the following error: ```shell -kubectl apply -f coffee-route.yaml +kubectl apply -f coffee-route.yaml ``` ``` The HTTPRoute "coffee" is invalid: spec.hostnames[0]: Invalid value: "cafe.!@#$%example.com": spec.hostnames[0] in body should match '^(\*\.)?[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$' @@ -70,7 +70,7 @@ you create a Gateway resource with a TCP listener that configures a hostname, th following error: ```shell -kubectl apply -f prod-gateway.yaml +kubectl apply -f prod-gateway.yaml ``` ``` Error from server: error when creating "prod-gateway.yaml": admission webhook "validate.gateway.networking.k8s.io" denied the request: spec.listeners[1].hostname: Forbidden: should be empty for protocol TCP diff --git a/docs/running-on-kind.md b/docs/running-on-kind.md index ad7b5671ed..8734a9b2b2 100644 --- a/docs/running-on-kind.md +++ b/docs/running-on-kind.md @@ -14,10 +14,10 @@ Create a cluster with `kind`. You can follow their [instructions](https://kind.s ```makefile make create-kind-cluster ``` - + ## Deploy NGINX Kubernetes Gateway -Follow the [installation](./installation.md) instructions to deploy NGINX Kubernetes Gateway on your Kind cluster. +Follow the [installation](./installation.md) instructions to deploy NGINX Kubernetes Gateway on your Kind cluster. ## Access NGINX Kubernetes Gateway @@ -27,7 +27,7 @@ Forward local ports 8080 and 8443 to ports 80 and 443 of the nginx-gateway Pod: kubectl -n nginx-gateway port-forward 8080:80 8443:443 ``` -> Note: NGINX will not listen on any ports until you configure a [Gateway](https://gateway-api.sigs.k8s.io/api-types/gateway/#gateway) resource with a valid listener. +> Note: NGINX will not listen on any ports until you configure a [Gateway](https://gateway-api.sigs.k8s.io/api-types/gateway/#gateway) resource with a valid listener. ## Use NGINX Kubernetes Gateway To get started, follow the tutorials in the [examples](../examples) directory. diff --git a/examples/advanced-routing/README.md b/examples/advanced-routing/README.md index fabd77d957..9855ca47bd 100644 --- a/examples/advanced-routing/README.md +++ b/examples/advanced-routing/README.md @@ -1,11 +1,11 @@ # Advanced Routing -In this example we will deploy NGINX Kubernetes Gateway and configure advanced routing rules for a simple cafe application. +In this example we will deploy NGINX Kubernetes Gateway and configure advanced routing rules for a simple cafe application. We will use `HTTPRoute` resources to route traffic to the cafe application based on a combination of the request method, headers, and query parameters. The cafe application consists of four Services: `coffee-v1-svc`, `coffee-v2-svc`, `tea-svc`, and `tea-post-svc`. In the next section we will create the following routing rules for the cafe application: - For the path `/coffee` route requests with the header `version` set to `v2` or with the query param `TEST` set to `v2` to `coffee-v2-svc`, and all other requests to `coffee-v1-svc`. -- For the path `/tea` route POST requests to `tea-post-svc`, and all other requests, such as `GET` requests, to `tea-svc`. +- For the path `/tea` route POST requests to `tea-post-svc`, and all other requests, such as `GET` requests, to `tea-svc`. ## Running the Example @@ -14,21 +14,21 @@ The cafe application consists of four Services: `coffee-v1-svc`, `coffee-v2-svc` 1. Follow the [installation instructions](/docs/installation.md) to deploy NGINX Gateway. 1. Save the public IP address of NGINX Kubernetes Gateway into a shell variable: - + ``` GW_IP=XXX.YYY.ZZZ.III ``` 1. Save the port of NGINX Kubernetes Gateway: - + ``` GW_PORT= ``` -## 2. Deploy the Cafe Application +## 2. Deploy the Cafe Application 1. Create the coffee and the tea Deployments and Services: - + ```shell kubectl apply -f cafe.yaml ``` @@ -49,11 +49,11 @@ The cafe application consists of four Services: `coffee-v1-svc`, `coffee-v2-svc` ## 3. Configure Routing 1. Create the `Gateway`: - + ```shell kubectl apply -f gateway.yaml ``` - + 1. Create the `HTTPRoute` resources: ```shell diff --git a/examples/cafe-example/README.md b/examples/cafe-example/README.md index f01224feb2..2c9d374fb6 100644 --- a/examples/cafe-example/README.md +++ b/examples/cafe-example/README.md @@ -9,21 +9,21 @@ In this example we deploy NGINX Kubernetes Gateway, a simple web application, an 1. Follow the [installation instructions](/docs/installation.md) to deploy NGINX Gateway. 1. Save the public IP address of NGINX Kubernetes Gateway into a shell variable: - + ``` GW_IP=XXX.YYY.ZZZ.III ``` 1. Save the port of NGINX Kubernetes Gateway: - + ``` GW_PORT= ``` -## 2. Deploy the Cafe Application +## 2. Deploy the Cafe Application 1. Create the coffee and the tea Deployments and Services: - + ```shell kubectl apply -f cafe.yaml ``` @@ -55,7 +55,7 @@ In this example we deploy NGINX Kubernetes Gateway, a simple web application, an ## 4. Test the Application -To access the application, we will use `curl` to send requests to the `coffee` and `tea` Services. +To access the application, we will use `curl` to send requests to the `coffee` and `tea` Services. To get coffee: diff --git a/examples/http-header-filter/README.md b/examples/http-header-filter/README.md index f61a4ba161..713c1b1822 100644 --- a/examples/http-header-filter/README.md +++ b/examples/http-header-filter/README.md @@ -1,7 +1,7 @@ # Example In this example we will deploy NGINX Kubernetes Gateway and configure traffic routing for a simple echo server. -We will use `HTTPRoute` resources to route traffic to the echo server, using the RequestHeaderModifier filter to modify +We will use `HTTPRoute` resources to route traffic to the echo server, using the RequestHeaderModifier filter to modify headers to the request. ## Running the Example @@ -10,21 +10,21 @@ headers to the request. 1. Follow the [installation instructions](/docs/installation.md) to deploy NGINX Gateway. 1. Save the public IP address of NGINX Kubernetes Gateway into a shell variable: - + ``` GW_IP=XXX.YYY.ZZZ.III ``` 1. Save the port of NGINX Kubernetes Gateway: - + ``` GW_PORT= ``` -## 2. Deploy the Cafe Application +## 2. Deploy the Cafe Application 1. Create the headers Deployment and Service: - + ```shell kubectl apply -f headers.yaml ``` @@ -55,9 +55,9 @@ headers to the request. ## 4. Test the Application -To access the application, we will use `curl` to send requests to the `headers` Service, including sending headers with +To access the application, we will use `curl` to send requests to the `headers` Service, including sending headers with our request. -Notice our configured header values can be seen in the `requestHeaders` section below, and that the `User-Agent` header +Notice our configured header values can be seen in the `requestHeaders` section below, and that the `User-Agent` header is absent. ```shell diff --git a/examples/traffic-splitting/README.md b/examples/traffic-splitting/README.md index c8e00526d0..36a1a793a4 100644 --- a/examples/traffic-splitting/README.md +++ b/examples/traffic-splitting/README.md @@ -53,9 +53,9 @@ We will use `HTTPRoute` resources to split traffic between two versions of the a ```shell kubectl apply -f cafe-route.yaml ``` - -This `HTTPRoute` resource defines a route for the path `/coffee` that sends 80% of the requests to `coffee-v1` and 20% to `coffee-v2`. -In this example, we use 80 and 20; however, the weights are calculated proportionally and do not need to sum to 100. + +This `HTTPRoute` resource defines a route for the path `/coffee` that sends 80% of the requests to `coffee-v1` and 20% to `coffee-v2`. +In this example, we use 80 and 20; however, the weights are calculated proportionally and do not need to sum to 100. For example, the weights of 8 and 2, 16 and 4, or 32 and 8 all evaluate to the same relative proportions. ## 4. Test the Application @@ -82,7 +82,7 @@ Server name: coffee-v2-698f66dc46-vcb6r ### 5. Modify the Traffic Split Configuration -Let's shift more of the traffic to `coffee-v2`. To do this we will update the `HTTPRoute` resource and change the weight +Let's shift more of the traffic to `coffee-v2`. To do this we will update the `HTTPRoute` resource and change the weight of the `coffee-v2` backend to 80. Backends with equal weights will receive an equal share of traffic. 1. Apply the updated `HTTPRoute` resource: @@ -90,14 +90,14 @@ of the `coffee-v2` backend to 80. Backends with equal weights will receive an eq ```shell kubectl apply -f cafe-route-equal-weight.yaml ``` - + 2. Test the application again: ```shell curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/coffee ``` -The responses will now be split evenly between `coffee-v1` and `coffee-v2`. +The responses will now be split evenly between `coffee-v1` and `coffee-v2`. -We can continue modifying the weights of the backends to shift more and more traffic to `coffee-v2`. If there's an issue +We can continue modifying the weights of the backends to shift more and more traffic to `coffee-v2`. If there's an issue with `coffee-v2`, we can quickly shift traffic back to `coffee-v1`. diff --git a/internal/mode/static/nginx/config/maps_template.go b/internal/mode/static/nginx/config/maps_template.go index 5d63bb4eea..ebbbbe3ff8 100644 --- a/internal/mode/static/nginx/config/maps_template.go +++ b/internal/mode/static/nginx/config/maps_template.go @@ -9,7 +9,7 @@ map {{ $m.Source }} {{ $m.Variable }} { } {{- end }} -# Set $gw_api_compliant_host variable to the value of $http_host unless $http_host is empty, then set it to the value +# Set $gw_api_compliant_host variable to the value of $http_host unless $http_host is empty, then set it to the value # of $host. We prefer $http_host because it contains the original value of the host header, which is required by the # Gateway API. However, in an HTTP/1.0 request, it's possible that $http_host can be empty. In this case, we will use # the value of $host. See http://nginx.org/en/docs/http/ngx_http_core_module.html#var_host. diff --git a/internal/mode/static/nginx/config/servers_template.go b/internal/mode/static/nginx/config/servers_template.go index 09d7080146..8691823bd3 100644 --- a/internal/mode/static/nginx/config/servers_template.go +++ b/internal/mode/static/nginx/config/servers_template.go @@ -68,7 +68,7 @@ server { server { listen unix:/var/lib/nginx/nginx-500-server.sock; access_log off; - + return 500; } ` diff --git a/internal/mode/static/nginx/config/upstreams_template.go b/internal/mode/static/nginx/config/upstreams_template.go index c0c2ed24c5..ff9a4f9198 100644 --- a/internal/mode/static/nginx/config/upstreams_template.go +++ b/internal/mode/static/nginx/config/upstreams_template.go @@ -8,7 +8,7 @@ var upstreamsTemplateText = ` upstream {{ $u.Name }} { random two least_conn; zone {{ $u.Name }} 512k; - {{ range $server := $u.Servers }} + {{ range $server := $u.Servers }} server {{ $server.Address }}; {{- end }} } diff --git a/internal/mode/static/nginx/modules/README.md b/internal/mode/static/nginx/modules/README.md index 6962bf78ed..398a43a681 100644 --- a/internal/mode/static/nginx/modules/README.md +++ b/internal/mode/static/nginx/modules/README.md @@ -1,15 +1,15 @@ # NGINX JavaScript Modules -This directory contains the [njs](http://nginx.org/en/docs/njs/) modules for NGINX Kubernetes Gateway. +This directory contains the [njs](http://nginx.org/en/docs/njs/) modules for NGINX Kubernetes Gateway. ## Prerequisites We recommend using [nvm](https://github.com/nvm-sh/nvm/blob/master/README.md) to install the following dependencies: -- [Node.js](https://nodejs.org/en/) (version 1.18) +- [Node.js](https://nodejs.org/en/) (version 1.18) - [npm](https://docs.npmjs.com/) -Once you've installed Node.js and npm, run `npm install` in this directory to install the rest of the project's dependencies. +Once you've installed Node.js and npm, run `npm install` in this directory to install the rest of the project's dependencies. ## Modules @@ -32,10 +32,10 @@ This project uses the [Mocha](https://mochajs.org/) test framework and the [Chai To run unit tests against the [httpmatches](./src/httpmatches.js) modules you must: - Use the [default import statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#importing_defaults) to import the module. -- Run mocha with the `--require esm` option. +- Run mocha with the `--require esm` option. - Mock the [NGINX HTTP Request Object](http://nginx.org/en/docs/njs/reference.html#http) and pass it to the exported function. Not all functions and fields on the HTTP request object need to be mocked, just the ones that are used in the module. -### Run Unit Tests +### Run Unit Tests To run the unit tests: