Skip to content

Commit 3606730

Browse files
committed
Reconfigure make targets and define kubernetes version only once
1 parent c726876 commit 3606730

File tree

6 files changed

+105
-87
lines changed

6 files changed

+105
-87
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ jobs:
177177
run: |
178178
nkg_prefix=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 1)
179179
nkg_tag=$(echo ${{ steps.meta.outputs.tags }} | cut -d ":" -f 2)
180-
yq -i "with(.spec.template.spec.containers[0]; .image = \"${nkg_prefix}:${nkg_tag}\" | .imagePullPolicy = \"Never\")" deploy/manifests/deployment.yaml
180+
make update-nkg-manifest NKG_PREFIX=${nkg_prefix} NKG_TAG=${nkg_tag}
181+
working-directory: ./conformance
181182

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

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

219220
- name: Run conformance tests

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ deps: ## Add missing and remove unused modules, verify deps and download them to
4646

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

5253
.PHONY: delete-kind-cluster

conformance/Makefile

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ NKG_TAG = edge
22
NKG_PREFIX = nginx-kubernetes-gateway
33
GATEWAY_CLASS = nginx
44
SUPPORTED_FEATURES = HTTPRoute,HTTPRouteQueryParamMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteSchemeRedirect
5-
KIND_KUBE_CONFIG_FOLDER = $${HOME}/.kube/kind
5+
KIND_KUBE_CONFIG=$${HOME}/.kube/kind/config
66
TAG = latest
7-
BUILD_NKG = true
87
PREFIX = conformance-test-runner
98
NKG_DEPLOYMENT_MANIFEST=../deploy/manifests/deployment.yaml
109
NGINX_IMAGE=$(shell yq '.spec.template.spec.containers[1].image as $$nginx_ver | $$nginx_ver' $(NKG_DEPLOYMENT_MANIFEST))
@@ -20,20 +19,25 @@ build-test-runner-image: ## Build conformance test runner image
2019

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

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

31-
.PHONY: build-and-load-images
32-
build-and-load-images: preload-nginx-container ## Build NKG container and load it and NGINX container on configured kind cluster
33-
ifeq ($(BUILD_NKG),true)
31+
.PHONY: update-nkg-manifest
32+
update-nkg-manifest: ## Update the NKG deployment manifest image name and imagePullPolicy
3433
yq -i 'with(.spec.template.spec.containers[0]; .image = "$(NKG_PREFIX):$(NKG_TAG)" | .imagePullPolicy = "Never")' $(NKG_DEPLOYMENT_MANIFEST)
34+
35+
.PHONY: build-nkg-image
36+
build-nkg-image: update-nkg-manifest ## Build NKG container and load it and NGINX container on configured kind cluster
3537
cd .. && make PREFIX=$(NKG_PREFIX) TAG=$(NKG_TAG) container
36-
endif
38+
39+
.PHONY: load-images
40+
load-images: preload-nginx-container ## Load NKG and NGINX containers on configured kind cluster
3741
kind load docker-image $(NKG_PREFIX):$(NKG_TAG)
3842

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

50-
.PHONY: install-nkg-local-build
51-
install-nkg-local-build: build-and-load-images prepare-nkg-dependencies ## Install NKG from local build with provisioner on configured kind cluster
54+
.PHONY: deploy-updated-provisioner
55+
deploy-updated-provisioner: ## Update provisioner manifest and deploy to the configured kind cluster
5256
yq '(select(di != 3))' provisioner/provisioner.yaml | kubectl apply -f -
5357
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 -
5458

59+
.PHONY: install-nkg-local-build
60+
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
61+
62+
.PHONY: install-nkg-local-build
63+
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
64+
5565
.PHONY: install-nkg-edge
5666
install-nkg-edge: preload-nginx-container prepare-nkg-dependencies ## Install NKG with provisioner from edge on configured kind cluster
5767
kubectl apply -f provisioner/provisioner.yaml

conformance/README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@ List available commands:
1414
```bash
1515
$ make
1616

17-
build-and-load-images Build NKG container and load it and NGINX container on configured kind cluster
17+
build-nkg-image Build NKG container and load it and NGINX container on configured kind cluster
1818
build-test-runner-image Build conformance test runner image
1919
cleanup-conformance-tests Clean up conformance tests fixtures
2020
create-kind-cluster Create a kind cluster
2121
delete-kind-cluster Delete kind cluster
22+
deploy-updated-provisioner Update provisioner manifest and deploy to the configured kind cluster
2223
help Display this help
2324
install-nkg-edge Install NKG with provisioner from edge on configured kind cluster
2425
install-nkg-local-build Install NKG from local build with provisioner on configured kind cluster
26+
install-nkg-local-no-build Install NKG from local build with provisioner on configured kind cluster but do not build the NKG image
27+
load-images Load NKG and NGINX containers on configured kind cluster
2528
preload-nginx-container Preload NGINX container on configured kind cluster
2629
prepare-nkg-dependencies Install NKG dependencies on configured kind cluster
2730
run-conformance-tests Run conformance tests
2831
undo-image-update Undo the NKG image name and tag in deployment manifest
2932
uninstall-nkg Uninstall NKG on configured kind cluster
33+
update-nkg-manifest Update the NKG deployment manifest image name and imagePullPolicy
3034
```
3135

3236
**Note:** The following variables are configurable when running the below `make` commands:
@@ -35,10 +39,9 @@ uninstall-nkg Uninstall NKG on configured kind cluster
3539
| ------------- | ------------- | ------------- |
3640
| TAG | latest | The tag for the conformance test image |
3741
| PREFIX | conformance-test-runner | The prefix for the conformance test image |
38-
| BUILD_NKG | true | Flag to indicate if the local NKG image needs to be built |
3942
| NKG_TAG | edge | The tag for the locally built NKG image |
4043
| NKG_PREFIX | nginx-kubernetes-gateway | The prefix for the locally built NKG image |
41-
| KIND_KUBE_CONFIG_FOLDER | ~/.kube/kind | The location of the kubeconfig folder |
44+
| KIND_KUBE_CONFIG | ~/.kube/kind/config | The location of the kubeconfig |
4245
| GATEWAY_CLASS | nginx | The gateway class that should be used for the tests |
4346
| 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. |
4447
| EXEMPT_FEATURES | ReferenceGrant | The features that should not be tested by the conformance tests |
@@ -56,8 +59,11 @@ $ make create-kind-cluster
5659
```bash
5760
$ make install-nkg-local-build
5861
```
59-
60-
**Note:** You can optionally skip the actual *build* step by setting the BUILD_NKG flag to "false". However, if choosing
62+
#### *Option 2* Install Nginx Kubernetes Gateway from local already built image to configured kind cluster
63+
```bash
64+
$ make install-nkg-local-no-build
65+
```
66+
**Note:** You can optionally skip the actual *build* step. However, if choosing
6167
this option, the following step *must* be completed manually *before* the build step:
6268
* Set NKG_PREFIX=<nkg_repo_name> NKG_TAG=<nkg_image_tag> to preferred values.
6369
* Navigate to `deploy/manifests` and update values in `deployment.yaml` as specified in below code-block.
@@ -71,10 +77,8 @@ this option, the following step *must* be completed manually *before* the build
7177
..
7278
.
7379
```
74-
75-
#### *Option 2* Install Nginx Kubernetes Gateway from edge to configured kind cluster
76-
Instead of the above command, you can skip the build NKG image step and prepare the environment to instead
77-
use the `edge` image
80+
#### *Option 3* Install Nginx Kubernetes Gateway from edge to configured kind cluster
81+
You can also skip the build NKG image step and prepare the environment to instead use the `edge` image
7882

7983
```bash
8084
$ make install-nkg-edge

conformance/tests/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# syntax=docker/dockerfile:1.5
2+
# this is here so we can grab the latest version of kind and have dependabot keep it up to date
3+
FROM kindest/node:v1.27.3
24

35
FROM golang:1.20
46

deploy/manifests/deployment.yaml

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,71 +16,71 @@ spec:
1616
shareProcessNamespace: true
1717
serviceAccountName: nginx-gateway
1818
volumes:
19-
- name: nginx
20-
emptyDir: { }
21-
- name: nginx-conf
22-
configMap:
23-
name: nginx-conf
24-
- name: var-lib-nginx
25-
emptyDir: { }
26-
- name: njs-modules
27-
configMap:
28-
name: njs-modules
29-
initContainers:
30-
- image: busybox:1.36
31-
name: set-permissions
32-
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' ]
33-
volumeMounts:
34-
- name: nginx
35-
mountPath: /etc/nginx
36-
containers:
37-
- image: ghcr.io/nginxinc/nginx-kubernetes-gateway:edge
38-
imagePullPolicy: Always
39-
name: nginx-gateway
40-
volumeMounts:
4119
- name: nginx
42-
mountPath: /etc/nginx
43-
securityContext:
44-
runAsUser: 1001
45-
capabilities:
46-
drop:
47-
- ALL
48-
add:
49-
- KILL
50-
env:
51-
- name: POD_IP
52-
valueFrom:
53-
fieldRef:
54-
fieldPath: status.podIP
55-
args:
56-
- static-mode
57-
- --gateway-ctlr-name=k8s-gateway.nginx.org/nginx-gateway-controller
58-
- --gatewayclass=nginx
59-
- image: nginx:1.25
60-
imagePullPolicy: Always
61-
name: nginx
62-
ports:
63-
- name: http
64-
containerPort: 80
65-
- name: https
66-
containerPort: 443
67-
volumeMounts:
68-
- name: nginx
69-
mountPath: /etc/nginx
20+
emptyDir: {}
7021
- name: nginx-conf
71-
mountPath: /etc/nginx/nginx.conf
72-
subPath: nginx.conf
22+
configMap:
23+
name: nginx-conf
7324
- name: var-lib-nginx
74-
mountPath: /var/lib/nginx
25+
emptyDir: {}
7526
- name: njs-modules
76-
mountPath: /usr/lib/nginx/modules/njs
77-
securityContext:
78-
capabilities:
79-
drop:
80-
- ALL
81-
add:
82-
- CHOWN
83-
- NET_BIND_SERVICE
84-
- SETGID
85-
- SETUID
86-
- DAC_OVERRIDE
27+
configMap:
28+
name: njs-modules
29+
initContainers:
30+
- image: busybox:1.36
31+
name: set-permissions
32+
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']
33+
volumeMounts:
34+
- name: nginx
35+
mountPath: /etc/nginx
36+
containers:
37+
- image: nginx-kubernetes-gateway:edge
38+
imagePullPolicy: Never
39+
name: nginx-gateway
40+
volumeMounts:
41+
- name: nginx
42+
mountPath: /etc/nginx
43+
securityContext:
44+
runAsUser: 1001
45+
capabilities:
46+
drop:
47+
- ALL
48+
add:
49+
- KILL
50+
env:
51+
- name: POD_IP
52+
valueFrom:
53+
fieldRef:
54+
fieldPath: status.podIP
55+
args:
56+
- static-mode
57+
- --gateway-ctlr-name=k8s-gateway.nginx.org/nginx-gateway-controller
58+
- --gatewayclass=nginx
59+
- image: nginx:1.25
60+
imagePullPolicy: Always
61+
name: nginx
62+
ports:
63+
- name: http
64+
containerPort: 80
65+
- name: https
66+
containerPort: 443
67+
volumeMounts:
68+
- name: nginx
69+
mountPath: /etc/nginx
70+
- name: nginx-conf
71+
mountPath: /etc/nginx/nginx.conf
72+
subPath: nginx.conf
73+
- name: var-lib-nginx
74+
mountPath: /var/lib/nginx
75+
- name: njs-modules
76+
mountPath: /usr/lib/nginx/modules/njs
77+
securityContext:
78+
capabilities:
79+
drop:
80+
- ALL
81+
add:
82+
- CHOWN
83+
- NET_BIND_SERVICE
84+
- SETGID
85+
- SETUID
86+
- DAC_OVERRIDE

0 commit comments

Comments
 (0)