Skip to content

Commit

Permalink
Reconfigure make targets and define kubernetes version only once
Browse files Browse the repository at this point in the history
  • Loading branch information
ciarams87 committed Jun 29, 2023
1 parent c726876 commit 3606730
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 87 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ jobs:
run: |
nkg_prefix=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1)
nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2)
yq -i "with(.spec.template.spec.containers[0]; .image = \"${nkg_prefix}:${nkg_tag}\" | .imagePullPolicy = \"Never\")" deploy/manifests/deployment.yaml
make update-nkg-manifest NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag}
working-directory: ./conformance

- name: Build Docker Image
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
Expand Down Expand Up @@ -205,15 +206,15 @@ jobs:
- name: Deploy Kubernetes
id: k8s
run: |
kind create cluster --image kindest/node:v1.27.1 --kubeconfig kube-${{ github.run_id }}
make create-kind-cluster KIND_KUBE_CONFIG=kube-${{ github.run_id }}
echo "KUBECONFIG=kube-${{ github.run_id }}" >> "$GITHUB_ENV"
working-directory: ./conformance

- name: Setup conformance tests
run: |
nkg_prefix=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1)
nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2)
make install-nkg-local-build NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag} BUILD_NKG=false
make install-nkg-local-no-build NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag}
working-directory: ./conformance

- name: Run conformance tests
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ deps: ## Add missing and remove unused modules, verify deps and download them to

.PHONY: create-kind-cluster
create-kind-cluster: ## Create a kind cluster
kind create cluster --image kindest/node:v1.27.1
$(eval KIND_IMAGE=$(shell grep -m1 'FROM kindest/node' <conformance/tests/Dockerfile | awk -F'[ ]' '{print $$2}'))
kind create cluster --image $(KIND_IMAGE)
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG_FOLDER)/config

.PHONY: delete-kind-cluster
Expand Down
30 changes: 20 additions & 10 deletions conformance/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ NKG_TAG = edge
NKG_PREFIX = nginx-kubernetes-gateway
GATEWAY_CLASS = nginx
SUPPORTED_FEATURES = HTTPRoute,HTTPRouteQueryParamMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteSchemeRedirect
KIND_KUBE_CONFIG_FOLDER = $${HOME}/.kube/kind
KIND_KUBE_CONFIG=$${HOME}/.kube/kind/config
TAG = latest
BUILD_NKG = true
PREFIX = conformance-test-runner
NKG_DEPLOYMENT_MANIFEST=../deploy/manifests/deployment.yaml
NGINX_IMAGE=$(shell yq '.spec.template.spec.containers[1].image as $$nginx_ver | $$nginx_ver' $(NKG_DEPLOYMENT_MANIFEST))
Expand All @@ -20,20 +19,25 @@ build-test-runner-image: ## Build conformance test runner image

.PHONY: create-kind-cluster
create-kind-cluster: ## Create a kind cluster
kind create cluster --image kindest/node:v1.27.1
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG_FOLDER)/config
$(eval KIND_IMAGE=$(shell grep -m1 'FROM kindest/node' <tests/Dockerfile | awk -F'[ ]' '{print $$2}'))
kind create cluster --image $(KIND_IMAGE)
kind export kubeconfig --kubeconfig $(KIND_KUBE_CONFIG)

.PHONY: preload-nginx-container
preload-nginx-container: ## Preload NGINX container on configured kind cluster
docker pull $(NGINX_IMAGE)
kind load docker-image $(NGINX_IMAGE)

.PHONY: build-and-load-images
build-and-load-images: preload-nginx-container ## Build NKG container and load it and NGINX container on configured kind cluster
ifeq ($(BUILD_NKG),true)
.PHONY: update-nkg-manifest
update-nkg-manifest: ## Update the NKG deployment manifest image name and imagePullPolicy
yq -i 'with(.spec.template.spec.containers[0]; .image = "$(NKG_PREFIX):$(NKG_TAG)" | .imagePullPolicy = "Never")' $(NKG_DEPLOYMENT_MANIFEST)

.PHONY: build-nkg-image
build-nkg-image: update-nkg-manifest ## Build NKG container and load it and NGINX container on configured kind cluster
cd .. && make PREFIX=$(NKG_PREFIX) TAG=$(NKG_TAG) container
endif

.PHONY: load-images
load-images: preload-nginx-container ## Load NKG and NGINX containers on configured kind cluster
kind load docker-image $(NKG_PREFIX):$(NKG_TAG)

.PHONY: prepare-nkg-dependencies
Expand All @@ -47,11 +51,17 @@ prepare-nkg-dependencies: ## Install NKG dependencies on configured kind cluster
kubectl apply -f ../deploy/manifests/gatewayclass.yaml
kubectl apply -f ../deploy/manifests/service/nodeport.yaml

.PHONY: install-nkg-local-build
install-nkg-local-build: build-and-load-images prepare-nkg-dependencies ## Install NKG from local build with provisioner on configured kind cluster
.PHONY: deploy-updated-provisioner
deploy-updated-provisioner: ## Update provisioner manifest and deploy to the configured kind cluster
yq '(select(di != 3))' provisioner/provisioner.yaml | kubectl apply -f -
yq '(select(.spec.template.spec.containers[].image) | .spec.template.spec.containers[].image="$(NKG_PREFIX):$(NKG_TAG)" | .spec.template.spec.containers[].imagePullPolicy = "Never")' provisioner/provisioner.yaml | kubectl apply -f -

.PHONY: install-nkg-local-build
install-nkg-local-build: build-nkg-image load-images prepare-nkg-dependencies deploy-updated-provisioner ## Install NKG from local build with provisioner on configured kind cluster

.PHONY: install-nkg-local-build
install-nkg-local-no-build: load-images prepare-nkg-dependencies deploy-updated-provisioner ## Install NKG from local build with provisioner on configured kind cluster but do not build the NKG image

.PHONY: install-nkg-edge
install-nkg-edge: preload-nginx-container prepare-nkg-dependencies ## Install NKG with provisioner from edge on configured kind cluster
kubectl apply -f provisioner/provisioner.yaml
Expand Down
22 changes: 13 additions & 9 deletions conformance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ List available commands:
```bash
$ make

build-and-load-images Build NKG container and load it and NGINX container on configured kind cluster
build-nkg-image Build NKG container and load it and NGINX container on configured kind cluster
build-test-runner-image Build conformance test runner image
cleanup-conformance-tests Clean up conformance tests fixtures
create-kind-cluster Create a kind cluster
delete-kind-cluster Delete kind cluster
deploy-updated-provisioner Update provisioner manifest and deploy to the configured kind cluster
help Display this help
install-nkg-edge Install NKG with provisioner from edge on configured kind cluster
install-nkg-local-build Install NKG from local build with provisioner on configured kind cluster
install-nkg-local-no-build Install NKG from local build with provisioner on configured kind cluster but do not build the NKG image
load-images Load NKG and NGINX containers on configured kind cluster
preload-nginx-container Preload NGINX container on configured kind cluster
prepare-nkg-dependencies Install NKG dependencies on configured kind cluster
run-conformance-tests Run conformance tests
undo-image-update Undo the NKG image name and tag in deployment manifest
uninstall-nkg Uninstall NKG on configured kind cluster
update-nkg-manifest Update the NKG deployment manifest image name and imagePullPolicy
```

**Note:** The following variables are configurable when running the below `make` commands:
Expand All @@ -35,10 +39,9 @@ uninstall-nkg Uninstall NKG on configured kind cluster
| ------------- | ------------- | ------------- |
| TAG | latest | The tag for the conformance test image |
| PREFIX | conformance-test-runner | The prefix for the conformance test image |
| BUILD_NKG | true | Flag to indicate if the local NKG image needs to be built |
| NKG_TAG | edge | The tag for the locally built NKG image |
| NKG_PREFIX | nginx-kubernetes-gateway | The prefix for the locally built NKG image |
| KIND_KUBE_CONFIG_FOLDER | ~/.kube/kind | The location of the kubeconfig folder |
| KIND_KUBE_CONFIG | ~/.kube/kind/config | The location of the kubeconfig |
| GATEWAY_CLASS | nginx | The gateway class that should be used for the tests |
| SUPPORTED_FEATURES | HTTPRoute,HTTPRouteQueryParamMatching, HTTPRouteMethodMatching,HTTPRoutePortRedirect, HTTPRouteSchemeRedirect | The supported features that should be tested by the conformance tests. Ensure the list is comma separated with no spaces. |
| EXEMPT_FEATURES | ReferenceGrant | The features that should not be tested by the conformance tests |
Expand All @@ -56,8 +59,11 @@ $ make create-kind-cluster
```bash
$ make install-nkg-local-build
```

**Note:** You can optionally skip the actual *build* step by setting the BUILD_NKG flag to "false". However, if choosing
#### *Option 2* Install Nginx Kubernetes Gateway from local already built image to configured kind cluster
```bash
$ make install-nkg-local-no-build
```
**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 All @@ -71,10 +77,8 @@ this option, the following step *must* be completed manually *before* the build
..
.
```

#### *Option 2* Install Nginx Kubernetes Gateway from edge to configured kind cluster
Instead of the above command, you can skip the build NKG image step and prepare the environment to instead
use the `edge` image
#### *Option 3* Install Nginx Kubernetes Gateway from edge to configured kind cluster
You can also skip the build NKG image step and prepare the environment to instead use the `edge` image

```bash
$ make install-nkg-edge
Expand Down
2 changes: 2 additions & 0 deletions conformance/tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# syntax=docker/dockerfile:1.5
# this is here so we can grab the latest version of kind and have dependabot keep it up to date
FROM kindest/node:v1.27.3

FROM golang:1.20

Expand Down
128 changes: 64 additions & 64 deletions deploy/manifests/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,71 +16,71 @@ spec:
shareProcessNamespace: true
serviceAccountName: nginx-gateway
volumes:
- name: nginx
emptyDir: { }
- name: nginx-conf
configMap:
name: nginx-conf
- name: var-lib-nginx
emptyDir: { }
- name: njs-modules
configMap:
name: njs-modules
initContainers:
- image: busybox:1.36
name: set-permissions
command: [ 'sh', '-c', 'rm -r /etc/nginx/conf.d /etc/nginx/secrets; mkdir /etc/nginx/conf.d /etc/nginx/secrets && chown 1001:0 /etc/nginx/conf.d /etc/nginx/secrets' ]
volumeMounts:
- name: nginx
mountPath: /etc/nginx
containers:
- image: ghcr.io/nginxinc/nginx-kubernetes-gateway:edge
imagePullPolicy: Always
name: nginx-gateway
volumeMounts:
- name: nginx
mountPath: /etc/nginx
securityContext:
runAsUser: 1001
capabilities:
drop:
- ALL
add:
- KILL
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
args:
- static-mode
- --gateway-ctlr-name=k8s-gateway.nginx.org/nginx-gateway-controller
- --gatewayclass=nginx
- image: nginx:1.25
imagePullPolicy: Always
name: nginx
ports:
- name: http
containerPort: 80
- name: https
containerPort: 443
volumeMounts:
- name: nginx
mountPath: /etc/nginx
emptyDir: {}
- name: nginx-conf
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
configMap:
name: nginx-conf
- name: var-lib-nginx
mountPath: /var/lib/nginx
emptyDir: {}
- name: njs-modules
mountPath: /usr/lib/nginx/modules/njs
securityContext:
capabilities:
drop:
- ALL
add:
- CHOWN
- NET_BIND_SERVICE
- SETGID
- SETUID
- DAC_OVERRIDE
configMap:
name: njs-modules
initContainers:
- image: busybox:1.36
name: set-permissions
command: ['sh', '-c', 'rm -r /etc/nginx/conf.d /etc/nginx/secrets; mkdir /etc/nginx/conf.d /etc/nginx/secrets && chown 1001:0 /etc/nginx/conf.d /etc/nginx/secrets']
volumeMounts:
- name: nginx
mountPath: /etc/nginx
containers:
- image: nginx-kubernetes-gateway:edge
imagePullPolicy: Never
name: nginx-gateway
volumeMounts:
- name: nginx
mountPath: /etc/nginx
securityContext:
runAsUser: 1001
capabilities:
drop:
- ALL
add:
- KILL
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
args:
- static-mode
- --gateway-ctlr-name=k8s-gateway.nginx.org/nginx-gateway-controller
- --gatewayclass=nginx
- image: nginx:1.25
imagePullPolicy: Always
name: nginx
ports:
- name: http
containerPort: 80
- name: https
containerPort: 443
volumeMounts:
- name: nginx
mountPath: /etc/nginx
- name: nginx-conf
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
- name: var-lib-nginx
mountPath: /var/lib/nginx
- name: njs-modules
mountPath: /usr/lib/nginx/modules/njs
securityContext:
capabilities:
drop:
- ALL
add:
- CHOWN
- NET_BIND_SERVICE
- SETGID
- SETUID
- DAC_OVERRIDE

0 comments on commit 3606730

Please sign in to comment.