From 21ad367d9a556089789ac767d0a3c0860b4812a3 Mon Sep 17 00:00:00 2001 From: Saylor Berman Date: Thu, 16 Nov 2023 13:58:59 -0700 Subject: [PATCH 1/5] Add test utilities for installing NGF Problem: 1. In order to start running system tests, we need a framework in place. 2. Sometimes when installed, NGF would start before the control plane CRD existed. Solution: 1. Implement a basic framework that installs and uninstalls NGF. 2. Add a polling loop to find the control plane CRD before exiting. --- .github/workflows/conformance.yml | 4 +- conformance/Makefile | 24 ++-- conformance/README.md | 10 +- docs/developer/release-process.md | 2 +- go.mod | 4 +- go.sum | 8 +- internal/mode/static/manager.go | 15 ++- tests/Makefile | 31 +++++ tests/framework/ngf.go | 188 ++++++++++++++++++++++++++++++ tests/system_suite_test.go | 92 +++++++++++++++ 10 files changed, 350 insertions(+), 28 deletions(-) create mode 100644 tests/Makefile create mode 100644 tests/framework/ngf.go create mode 100644 tests/system_suite_test.go diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml index d53ad637dc..919df7e8b8 100644 --- a/.github/workflows/conformance.yml +++ b/.github/workflows/conformance.yml @@ -74,7 +74,7 @@ jobs: run: | ngf_prefix=$(echo ${{ steps.ngf-meta.outputs.tags }} | cut -d ":" -f 1) ngf_tag=$(echo ${{ steps.ngf-meta.outputs.tags }} | cut -d ":" -f 2) - make update-ngf-manifest NGF_PREFIX=${ngf_prefix} NGF_TAG=${ngf_tag} + make update-ngf-manifest PREFIX=${ngf_prefix} TAG=${ngf_tag} working-directory: ./conformance - name: Build binary @@ -146,7 +146,7 @@ jobs: ngf_tag=$(echo ${{ steps.ngf-meta.outputs.tags }} | cut -d ":" -f 2) if [ ${{ github.event_name }} == "schedule" ]; then export GW_API_VERSION=main; fi if [ ${{ startsWith(matrix.k8s-version, '1.23') || startsWith(matrix.k8s-version, '1.24') }} == "true" ]; then export INSTALL_WEBHOOK=true; fi - make install-ngf-local-no-build NGF_PREFIX=${ngf_prefix} NGF_TAG=${ngf_tag} + make install-ngf-local-no-build PREFIX=${ngf_prefix} TAG=${ngf_tag} working-directory: ./conformance - name: Run conformance tests diff --git a/conformance/Makefile b/conformance/Makefile index 47078450f0..9e19179450 100644 --- a/conformance/Makefile +++ b/conformance/Makefile @@ -1,13 +1,13 @@ -NGF_TAG = edge -NGF_PREFIX = nginx-gateway-fabric -NGINX_IMAGE_NAME = $(NGF_PREFIX)/nginx +TAG = edge +PREFIX = nginx-gateway-fabric +NGINX_PREFIX = $(PREFIX)/nginx GW_API_VERSION ?= 1.0.0 GATEWAY_CLASS = nginx SUPPORTED_FEATURES = HTTPRoute,HTTPRouteQueryParamMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteSchemeRedirect,GatewayClassObservedGenerationBump KIND_IMAGE ?= $(shell grep -m1 'FROM kindest/node' Note: If choosing this option, the following step *must* be completed manually *before* you build the image: ```makefile -make update-ngf-manifest NGF_PREFIX= NGF_TAG= +make update-ngf-manifest PREFIX= TAG= ``` #### *Option 3* Install NGINX Gateway Fabric from edge to configured kind cluster diff --git a/docs/developer/release-process.md b/docs/developer/release-process.md index 42ee7cf5ce..ddf8fe90d9 100644 --- a/docs/developer/release-process.md +++ b/docs/developer/release-process.md @@ -34,7 +34,7 @@ To create a new release, follow these steps: 6. Prepare and merge a PR into the release branch to update the repo files for the release: 1. Update the Helm [Chart.yaml](/deploy/helm-chart/Chart.yaml): the `appVersion` to `X.Y.Z`, the icon and source URLs to point at `vX.Y.Z`, and bump the `version`. - 2. Adjust the `VERSION` variable in the [Makefile](/Makefile) and the `NGF_TAG` in the + 2. Adjust the `VERSION` variable in the [Makefile](/Makefile) and the `TAG` in the [conformance tests Makefile](/conformance/Makefile) to `X.Y.Z`. 3. Update the tag of NGF container images used in the Helm [values.yaml](/deploy/helm-chart/values.yaml) file, the [provisioner manifest](/conformance/provisioner/provisioner.yaml), and all docs to `X.Y.Z`. diff --git a/go.mod b/go.mod index f5b4fb4509..6532389af0 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/spf13/cobra v1.8.0 go.uber.org/zap v1.26.0 k8s.io/api v0.28.4 + k8s.io/apiextensions-apiserver v0.28.4 k8s.io/apimachinery v0.28.4 k8s.io/client-go v0.28.4 sigs.k8s.io/controller-runtime v0.16.3 @@ -82,8 +83,7 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/apiextensions-apiserver v0.28.3 // indirect - k8s.io/component-base v0.28.3 // indirect + k8s.io/component-base v0.28.4 // indirect k8s.io/klog/v2 v2.100.1 // indirect k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect diff --git a/go.sum b/go.sum index 16860e25a6..8ca7b3e428 100644 --- a/go.sum +++ b/go.sum @@ -255,14 +255,14 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= k8s.io/api v0.28.4 h1:8ZBrLjwosLl/NYgv1P7EQLqoO8MGQApnbgH8tu3BMzY= k8s.io/api v0.28.4/go.mod h1:axWTGrY88s/5YE+JSt4uUi6NMM+gur1en2REMR7IRj0= -k8s.io/apiextensions-apiserver v0.28.3 h1:Od7DEnhXHnHPZG+W9I97/fSQkVpVPQx2diy+2EtmY08= -k8s.io/apiextensions-apiserver v0.28.3/go.mod h1:NE1XJZ4On0hS11aWWJUTNkmVB03j9LM7gJSisbRt8Lc= +k8s.io/apiextensions-apiserver v0.28.4 h1:AZpKY/7wQ8n+ZYDtNHbAJBb+N4AXXJvyZx6ww6yAJvU= +k8s.io/apiextensions-apiserver v0.28.4/go.mod h1:pgQIZ1U8eJSMQcENew/0ShUTlePcSGFq6dxSxf2mwPM= k8s.io/apimachinery v0.28.4 h1:zOSJe1mc+GxuMnFzD4Z/U1wst50X28ZNsn5bhgIIao8= k8s.io/apimachinery v0.28.4/go.mod h1:wI37ncBvfAoswfq626yPTe6Bz1c22L7uaJ8dho83mgg= k8s.io/client-go v0.28.4 h1:Np5ocjlZcTrkyRJ3+T3PkXDpe4UpatQxj85+xjaD2wY= k8s.io/client-go v0.28.4/go.mod h1:0VDZFpgoZfelyP5Wqu0/r/TRYcLYuJ2U1KEeoaPa1N4= -k8s.io/component-base v0.28.3 h1:rDy68eHKxq/80RiMb2Ld/tbH8uAE75JdCqJyi6lXMzI= -k8s.io/component-base v0.28.3/go.mod h1:fDJ6vpVNSk6cRo5wmDa6eKIG7UlIQkaFmZN2fYgIUD8= +k8s.io/component-base v0.28.4 h1:c/iQLWPdUgI90O+T9TeECg8o7N3YJTiuz2sKxILYcYo= +k8s.io/component-base v0.28.4/go.mod h1:m9hR0uvqXDybiGL2nf/3Lf0MerAfQXzkfWhUY58JUbU= k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/AuzbMm96cd3YHRTU83I780= diff --git a/internal/mode/static/manager.go b/internal/mode/static/manager.go index 3d0c4de05a..bb1d9ae096 100644 --- a/internal/mode/static/manager.go +++ b/internal/mode/static/manager.go @@ -13,6 +13,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" utilruntime "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/tools/record" ctlr "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -376,8 +377,18 @@ func setInitialConfig( defer cancel() var config ngfAPI.NginxGateway - if err := reader.Get(ctx, configName, &config); err != nil { - return err + if err := wait.PollUntilContextCancel( + ctx, + 500*time.Millisecond, + true, /* poll immediately */ + func(ctx context.Context) (bool, error) { + if err := reader.Get(ctx, configName, &config); err != nil { + return false, nil //nolint:nilerr // returning an error cancels the polling + } + return true, nil + }, + ); err != nil { + return fmt.Errorf("NginxGateway %s not found: %w", configName, err) } // status is not updated until the status updater's cache is started and the diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000000..3ed3edf3d0 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,31 @@ +TAG = edge +PREFIX = nginx-gateway-fabric +NGINX_PREFIX = $(PREFIX)/nginx +PULL_POLICY=Never +GW_API_VERSION ?= 1.0.0 +K8S_VERSION ?= latest ## Expected format: 1.24 (major.minor) or latest + +.PHONY: help +help: Makefile ## Display this help + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "; printf "Usage:\n\n make \033[36m\033[0m\n\nTargets:\n\n"}; {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: create-kind-cluster +create-kind-cluster: ## Create a kind cluster + cd .. && make create-kind-cluster + +.PHONY: build-images +build-images: ## Build NGF and nginx images + cd .. && make PREFIX=$(PREFIX) TAG=$(TAG) build-images + +.PHONY: load-images +load-images: ## Load NGF and NGINX images on configured kind cluster + kind load docker-image $(PREFIX):$(TAG) $(NGINX_PREFIX):$(TAG) + +test: ## Run the system tests against your default k8s cluster + go test -v . -args --gateway-api-version=$(GW_API_VERSION) --image-tag=$(TAG) \ + --ngf-image-repo=$(PREFIX) --nginx-image-repo=$(NGINX_PREFIX) --pull-policy=$(PULL_POLICY) \ + --k8s-version=$(K8S_VERSION) + +.PHONY: delete-kind-cluster +delete-kind-cluster: ## Delete kind cluster + kind delete cluster diff --git a/tests/framework/ngf.go b/tests/framework/ngf.go new file mode 100644 index 0000000000..f6182bdfe8 --- /dev/null +++ b/tests/framework/ngf.go @@ -0,0 +1,188 @@ +package framework + +import ( + "context" + "fmt" + "os/exec" + "strings" + "time" + + apps "k8s.io/api/apps/v1" + core "k8s.io/api/core/v1" + apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/wait" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +const gwInstallBasePath = "https://github.com/kubernetes-sigs/gateway-api/releases/download" + +// InstallationConfig contains the configuration for the NGF installation. +type InstallationConfig struct { + ReleaseName string + Namespace string + ChartPath string + NgfImageRepository string + NginxImageRepository string + ImageTag string + ImagePullPolicy string + ServiceType string +} + +// InstallGatewayAPI installs the specified version of the Gateway API resources. +func InstallGatewayAPI( + k8sClient client.Client, + apiVersion, + k8sVersion string, +) ([]byte, error) { + apiPath := fmt.Sprintf("%s/v%s/standard-install.yaml", gwInstallBasePath, apiVersion) + + if output, err := exec.Command("kubectl", "apply", "-f", apiPath).CombinedOutput(); err != nil { + return output, err + } + + if webhookRequired(k8sVersion) { + webhookPath := fmt.Sprintf("%s/v%s/webhook-install.yaml", gwInstallBasePath, apiVersion) + + if output, err := exec.Command("kubectl", "apply", "-f", webhookPath).CombinedOutput(); err != nil { + return output, err + } + + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + if err := wait.PollUntilContextCancel( + ctx, + 500*time.Millisecond, + true, /* poll immediately */ + func(ctx context.Context) (bool, error) { + var deployment apps.Deployment + key := types.NamespacedName{ + Namespace: "gateway-system", + Name: "gateway-api-admission-server", + } + + if err := k8sClient.Get(ctx, key, &deployment); err != nil { + return false, err + } + + if deployment.Status.ReadyReplicas == 1 { + return true, nil + } + + return false, nil + }, + ); err != nil { + return nil, err + } + } + + return nil, nil +} + +// InstallNGF installs NGF. +func InstallNGF(cfg InstallationConfig, extraArgs ...string) ([]byte, error) { + args := []string{ + "install", cfg.ReleaseName, cfg.ChartPath, "--create-namespace", "--namespace", cfg.Namespace, "--wait", + } + + if cfg.NgfImageRepository != "" { + args = append(args, formatValueSet("nginxGateway.image.repository", cfg.NgfImageRepository)...) + if cfg.ImageTag != "" { + args = append(args, formatValueSet("nginxGateway.image.tag", cfg.ImageTag)...) + } + if cfg.ImagePullPolicy != "" { + args = append(args, formatValueSet("nginxGateway.image.pullPolicy", cfg.ImagePullPolicy)...) + } + } + + if cfg.NginxImageRepository != "" { + args = append(args, formatValueSet("nginx.image.repository", cfg.NginxImageRepository)...) + if cfg.ImageTag != "" { + args = append(args, formatValueSet("nginx.image.tag", cfg.ImageTag)...) + } + if cfg.ImagePullPolicy != "" { + args = append(args, formatValueSet("nginx.image.pullPolicy", cfg.ImagePullPolicy)...) + } + } + + if cfg.ServiceType != "" { + args = append(args, formatValueSet("service.type", cfg.ServiceType)...) + } + + fullArgs := append(args, extraArgs...) + + return exec.Command("helm", fullArgs...).CombinedOutput() +} + +// UninstallNGF uninstalls NGF. +func UninstallNGF(cfg InstallationConfig, k8sClient client.Client) ([]byte, error) { + args := []string{ + "uninstall", cfg.ReleaseName, "--namespace", cfg.Namespace, + } + + output, err := exec.Command("helm", args...).CombinedOutput() + if err != nil { + return output, err + } + + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + err = k8sClient.Delete(ctx, &core.Namespace{ObjectMeta: metav1.ObjectMeta{Name: cfg.Namespace}}) + if err != nil && !apierrors.IsNotFound(err) { + return nil, err + } + + var crList apiext.CustomResourceDefinitionList + if err := k8sClient.List(ctx, &crList); err != nil { + return nil, err + } + + for _, cr := range crList.Items { + if strings.Contains(cr.Spec.Group, "gateway.nginx.org") { + cr := cr + if err := k8sClient.Delete(ctx, &cr); err != nil && !apierrors.IsNotFound(err) { + return nil, err + } + } + } + + return nil, nil +} + +// UninstallGatewayAPI uninstalls the specified version of the Gateway API resources. +func UninstallGatewayAPI(apiVersion, k8sVersion string) ([]byte, error) { + apiPath := fmt.Sprintf("%s/v%s/standard-install.yaml", gwInstallBasePath, apiVersion) + + if webhookRequired(k8sVersion) { + webhookPath := fmt.Sprintf("%s/v%s/webhook-install.yaml", gwInstallBasePath, apiVersion) + + if output, err := exec.Command("kubectl", "delete", "-f", webhookPath).CombinedOutput(); err != nil { + return output, err + } + } + + return exec.Command("kubectl", "delete", "-f", apiPath).CombinedOutput() +} + +func formatValueSet(key, value string) []string { + return []string{"--set", fmt.Sprintf("%s=%s", key, value)} +} + +// webookRequired returns true if the k8s version is less than 1.25. +func webhookRequired(k8sVersion string) bool { + // contains the supported versions of K8s that require the gateway webhook + webhookK8sVersions := map[string]struct{}{ + "1.23": {}, + "1.24": {}, + } + + if _, ok := webhookK8sVersions[k8sVersion]; ok { + return ok + } + + return false +} diff --git a/tests/system_suite_test.go b/tests/system_suite_test.go new file mode 100644 index 0000000000..78d1e243c9 --- /dev/null +++ b/tests/system_suite_test.go @@ -0,0 +1,92 @@ +package tests + +import ( + "flag" + "path" + "path/filepath" + "runtime" + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + apps "k8s.io/api/apps/v1" + core "k8s.io/api/core/v1" + apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + k8sRuntime "k8s.io/apimachinery/pkg/runtime" + ctlr "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + + "github.com/nginxinc/nginx-gateway-fabric/tests/framework" +) + +func TestNGF(t *testing.T) { + flag.Parse() + if *gatewayAPIVersion == "" { + panic("Gateway API version must be set") + } + + RegisterFailHandler(Fail) + RunSpecs(t, "NGF System Tests") +} + +var k8sClient client.Client + +var _ = BeforeSuite(func() { + k8sConfig := ctlr.GetConfigOrDie() + scheme := k8sRuntime.NewScheme() + Expect(core.AddToScheme(scheme)).To(Succeed()) + Expect(apps.AddToScheme(scheme)).To(Succeed()) + Expect(apiext.AddToScheme(scheme)).To(Succeed()) + + options := client.Options{ + Scheme: scheme, + } + + var err error + k8sClient, err = client.New(k8sConfig, options) + Expect(err).ToNot(HaveOccurred()) + + _, file, _, _ := runtime.Caller(0) + fileDir := path.Join(path.Dir(file)) + basepath := filepath.Dir(fileDir) + + cfg := framework.InstallationConfig{ + ReleaseName: "ngf-test", + Namespace: "nginx-gateway", + ChartPath: filepath.Join(basepath, "deploy/helm-chart"), + NgfImageRepository: *ngfImageRepository, + NginxImageRepository: *nginxImageRepository, + ImageTag: *imageTag, + ImagePullPolicy: *imagePullPolicy, + ServiceType: "NodePort", + } + + output, err := framework.InstallGatewayAPI(k8sClient, *gatewayAPIVersion, *k8sVersion) + Expect(err).ToNot(HaveOccurred(), string(output)) + + output, err = framework.InstallNGF(cfg) + Expect(err).ToNot(HaveOccurred(), string(output)) +}) + +var _ = AfterSuite(func() { + cfg := framework.InstallationConfig{ + ReleaseName: "ngf-test", + Namespace: "nginx-gateway", + } + + output, err := framework.UninstallNGF(cfg, k8sClient) + Expect(err).ToNot(HaveOccurred(), string(output)) + + output, err = framework.UninstallGatewayAPI(*gatewayAPIVersion, *k8sVersion) + Expect(err).ToNot(HaveOccurred(), string(output)) +}) + +var ( + gatewayAPIVersion = flag.String("gateway-api-version", "", "Version of Gateway API to install") + k8sVersion = flag.String("k8s-version", "latest", "Version of k8s being tested on") + // Configurable NGF installation variables. Helm values will be used as defaults if not specified. + ngfImageRepository = flag.String("ngf-image-repo", "", "Image repo for NGF control plane") + nginxImageRepository = flag.String("nginx-image-repo", "", "Image repo for NGF data plane") + imageTag = flag.String("image-tag", "", "Image tag for NGF images") + imagePullPolicy = flag.String("pull-policy", "", "Image pull policy for NGF images") +) From 334835564125191776ae05ab091bb44ab3bb544f Mon Sep 17 00:00:00 2001 From: Saylor Berman Date: Thu, 16 Nov 2023 16:19:43 -0700 Subject: [PATCH 2/5] Fix unit tests --- Makefile | 2 +- tests/system_suite_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ed7791fcfb..304decea1f 100644 --- a/Makefile +++ b/Makefile @@ -123,7 +123,7 @@ lint: ## Run golangci-lint against code .PHONY: unit-test unit-test: ## Run unit tests for the go code - go test ./... -race -coverprofile cover.out + go test ./... -tags unit -race -coverprofile cover.out go tool cover -html=cover.out -o cover.html .PHONY: njs-unit-test diff --git a/tests/system_suite_test.go b/tests/system_suite_test.go index 78d1e243c9..0a770f0f4f 100644 --- a/tests/system_suite_test.go +++ b/tests/system_suite_test.go @@ -1,3 +1,6 @@ +//go:build !unit +// +build !unit + package tests import ( From 10c726b0c8424f9c93817303d5cf85597b7be1f6 Mon Sep 17 00:00:00 2001 From: Saylor Berman Date: Thu, 16 Nov 2023 16:28:57 -0700 Subject: [PATCH 3/5] Fix conformance --- .github/workflows/conformance.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml index 919df7e8b8..851606a6fd 100644 --- a/.github/workflows/conformance.yml +++ b/.github/workflows/conformance.yml @@ -151,7 +151,7 @@ jobs: - name: Run conformance tests run: | - make run-conformance-tests TAG=${{ github.sha }} VERSION=${{ github.ref_name }} + make run-conformance-tests CONFORMANCE_TAG=${{ github.sha }} VERSION=${{ github.ref_name }} core_result=$(cat conformance-profile.yaml | yq '.profiles[0].core.result') extended_result=$(cat conformance-profile.yaml | yq '.profiles[0].extended.result') if [ "${core_result}" == "failure" ] || [ "${extended_result}" == "failure" ]; then echo "Conformance test failed, see above for details." && exit 2; fi From 4805fc290afe98fc107df0e48f10df6d3439c459 Mon Sep 17 00:00:00 2001 From: Saylor Berman Date: Fri, 17 Nov 2023 14:02:28 -0700 Subject: [PATCH 4/5] code review feedback --- internal/mode/static/manager.go | 7 ++++++- tests/framework/ngf.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/mode/static/manager.go b/internal/mode/static/manager.go index bb1d9ae096..e293291663 100644 --- a/internal/mode/static/manager.go +++ b/internal/mode/static/manager.go @@ -9,6 +9,7 @@ import ( "github.com/prometheus/client_golang/prometheus" apiv1 "k8s.io/api/core/v1" discoveryV1 "k8s.io/api/discovery/v1" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" @@ -377,13 +378,17 @@ func setInitialConfig( defer cancel() var config ngfAPI.NginxGateway + // Polling to wait for CRD to exist if the Deployment is created first. if err := wait.PollUntilContextCancel( ctx, 500*time.Millisecond, true, /* poll immediately */ func(ctx context.Context) (bool, error) { if err := reader.Get(ctx, configName, &config); err != nil { - return false, nil //nolint:nilerr // returning an error cancels the polling + if !apierrors.IsNotFound(err) { + return false, err + } + return false, nil } return true, nil }, diff --git a/tests/framework/ngf.go b/tests/framework/ngf.go index f6182bdfe8..e16cb08923 100644 --- a/tests/framework/ngf.go +++ b/tests/framework/ngf.go @@ -172,7 +172,7 @@ func formatValueSet(key, value string) []string { return []string{"--set", fmt.Sprintf("%s=%s", key, value)} } -// webookRequired returns true if the k8s version is less than 1.25. +// webhookRequired returns true if the k8s version is less than 1.25. func webhookRequired(k8sVersion string) bool { // contains the supported versions of K8s that require the gateway webhook webhookK8sVersions := map[string]struct{}{ From 82e76924dfec5f8aab14aae0e695e4c07e279471 Mon Sep 17 00:00:00 2001 From: Saylor Berman Date: Fri, 17 Nov 2023 15:55:38 -0700 Subject: [PATCH 5/5] Update tests/Makefile Co-authored-by: bjee19 <139261241+bjee19@users.noreply.github.com> --- tests/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile b/tests/Makefile index 3ed3edf3d0..528e8dabc7 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -14,7 +14,7 @@ create-kind-cluster: ## Create a kind cluster cd .. && make create-kind-cluster .PHONY: build-images -build-images: ## Build NGF and nginx images +build-images: ## Build NGF and NGINX images cd .. && make PREFIX=$(PREFIX) TAG=$(TAG) build-images .PHONY: load-images