diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 94afa0c346..f0809b9209 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -149,8 +149,8 @@ jobs: sbom: true provenance: mode=max build-args: | - NJS_DIR=internal/mode/static/nginx/modules/src - NGINX_CONF_DIR=internal/mode/static/nginx/conf + NJS_DIR=internal/controller/nginx/modules/src + NGINX_CONF_DIR=internal/controller/nginx/conf BUILD_AGENT=gha secrets: | ${{ contains(inputs.image, 'plus') && format('"nginx-repo.crt={0}"', secrets.NGINX_CRT) || '' }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 791722162d..304a9841fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -119,7 +119,7 @@ jobs: node-version-file: .nvmrc - name: Run tests - run: npm --prefix ${{ github.workspace }}/internal/mode/static/nginx/modules install-ci-test + run: npm --prefix ${{ github.workspace }}/internal/controller/nginx/modules install-ci-test - name: Upload coverage reports to Codecov uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3 diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml index bdf5d24acf..14693e45c1 100644 --- a/.github/workflows/conformance.yml +++ b/.github/workflows/conformance.yml @@ -106,8 +106,8 @@ jobs: cache-from: type=gha,scope=${{ inputs.image }} pull: true build-args: | - NJS_DIR=internal/mode/static/nginx/modules/src - NGINX_CONF_DIR=internal/mode/static/nginx/conf + NJS_DIR=internal/controller/nginx/modules/src + NGINX_CONF_DIR=internal/controller/nginx/conf BUILD_AGENT=gha - name: Update Go Modules diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index 148a36fedb..10e06eafd7 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -100,8 +100,8 @@ jobs: cache-from: type=gha,scope=${{ inputs.image }} pull: true build-args: | - NJS_DIR=internal/mode/static/nginx/modules/src - NGINX_CONF_DIR=internal/mode/static/nginx/conf + NJS_DIR=internal/controller/nginx/modules/src + NGINX_CONF_DIR=internal/controller/nginx/conf BUILD_AGENT=gha - name: Setup license file for plus diff --git a/.github/workflows/helm.yml b/.github/workflows/helm.yml index 23f9527054..58560c6ba4 100644 --- a/.github/workflows/helm.yml +++ b/.github/workflows/helm.yml @@ -80,8 +80,8 @@ jobs: cache-from: type=gha,scope=${{ inputs.image }} pull: true build-args: | - NJS_DIR=internal/mode/static/nginx/modules/src - NGINX_CONF_DIR=internal/mode/static/nginx/conf + NJS_DIR=internal/controller/nginx/modules/src + NGINX_CONF_DIR=internal/controller/nginx/conf BUILD_AGENT=gha - name: Install cloud-provider-kind diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ecc6521ce9..62340b956f 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -58,8 +58,8 @@ jobs: id: prettier-run uses: rutajdash/prettier-cli-action@d42c4325a3b344f3bd4be482bc34de521998d557 # v1.0.2 with: - config_path: ${{ github.workspace }}/internal/mode/static/nginx/modules/.prettierrc - file_pattern: ${{ github.workspace }}/internal/mode/static/nginx/modules/**/*.js + config_path: ${{ github.workspace }}/internal/controller/nginx/modules/.prettierrc + file_pattern: ${{ github.workspace }}/internal/controller/nginx/modules/**/*.js prettier_version: 3.3.3 # renovate: datasource=npm depName=prettier - name: Prettier Output diff --git a/.gitignore b/.gitignore index 40bb4be096..2bb6e3a4db 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,7 @@ tests/**/*.csv node_modules/ # JS test coverage -internal/mode/static/nginx/modules/coverage +internal/controller/nginx/modules/coverage # MacOS Finder .DS_Store diff --git a/.gitleaksignore b/.gitleaksignore index 5b2f473b18..cb0f6ae1eb 100644 --- a/.gitleaksignore +++ b/.gitleaksignore @@ -3,4 +3,4 @@ 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 -internal/mode/static/state/graph/config_maps_test.go:private-key:35 +internal/controller/state/graph/config_maps_test.go:private-key:35 diff --git a/Makefile b/Makefile index d30488d359..e932564e1f 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ VERSION = edge SELF_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) CHART_DIR = $(SELF_DIR)charts/nginx-gateway-fabric -NGINX_CONF_DIR = internal/mode/static/nginx/conf -NJS_DIR = internal/mode/static/nginx/modules/src +NGINX_CONF_DIR = internal/controller/nginx/conf +NJS_DIR = internal/controller/nginx/modules/src KIND_CONFIG_FILE = $(SELF_DIR)config/cluster/kind-cluster.yaml NGINX_DOCKER_BUILD_PLUS_ARGS = --secret id=nginx-repo.crt,src=$(SELF_DIR)nginx-repo.crt --secret id=nginx-repo.key,src=$(SELF_DIR)nginx-repo.key BUILD_AGENT = local @@ -202,7 +202,7 @@ unit-test: ## Run unit tests for the go code .PHONY: njs-unit-test njs-unit-test: ## Run unit tests for the njs httpmatches module docker run --rm -w /modules \ - -v $(CURDIR)/internal/mode/static/nginx/modules:/modules/ \ + -v $(CURDIR)/internal/controller/nginx/modules:/modules/ \ node:${NODE_VERSION} \ /bin/bash -c "npm ci && npm test && npm run clean" diff --git a/cmd/gateway/commands.go b/cmd/gateway/commands.go index be076a76da..a5b60b5085 100644 --- a/cmd/gateway/commands.go +++ b/cmd/gateway/commands.go @@ -20,11 +20,11 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log" ctlrZap "sigs.k8s.io/controller-runtime/pkg/log/zap" + "github.com/nginx/nginx-gateway-fabric/internal/controller" + "github.com/nginx/nginx-gateway-fabric/internal/controller/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/licensing" + ngxConfig "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config" "github.com/nginx/nginx-gateway-fabric/internal/framework/file" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/licensing" - ngxConfig "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config" ) // These flags are shared by multiple commands. @@ -259,7 +259,7 @@ func createControllerCommand() *cobra.Command { NGINXSCCName: nginxSCCName.value, } - if err := static.StartManager(conf); err != nil { + if err := controller.StartManager(conf); err != nil { return fmt.Errorf("failed to start control loop: %w", err) } diff --git a/cmd/gateway/commands_test.go b/cmd/gateway/commands_test.go index 8db899f1cb..1f87dcb682 100644 --- a/cmd/gateway/commands_test.go +++ b/cmd/gateway/commands_test.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/config" ) type flagTestCase struct { diff --git a/cmd/gateway/initialize.go b/cmd/gateway/initialize.go index 516d2e95f7..c9cc63f1f9 100644 --- a/cmd/gateway/initialize.go +++ b/cmd/gateway/initialize.go @@ -9,9 +9,9 @@ import ( "github.com/go-logr/logr" + "github.com/nginx/nginx-gateway-fabric/internal/controller/licensing" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config" "github.com/nginx/nginx-gateway-fabric/internal/framework/file" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/licensing" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config" ) const ( diff --git a/cmd/gateway/initialize_test.go b/cmd/gateway/initialize_test.go index 04999b6cad..16e271a294 100644 --- a/cmd/gateway/initialize_test.go +++ b/cmd/gateway/initialize_test.go @@ -11,12 +11,12 @@ import ( "github.com/go-logr/logr" . "github.com/onsi/gomega" + "github.com/nginx/nginx-gateway-fabric/internal/controller/licensing/licensingfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/configfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/framework/file" "github.com/nginx/nginx-gateway-fabric/internal/framework/file/filefakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/licensing/licensingfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/configfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" ) func TestInitialize_OSS(t *testing.T) { diff --git a/internal/mode/static/config/config.go b/internal/controller/config/config.go similarity index 100% rename from internal/mode/static/config/config.go rename to internal/controller/config/config.go diff --git a/internal/mode/static/config_updater.go b/internal/controller/config_updater.go similarity index 99% rename from internal/mode/static/config_updater.go rename to internal/controller/config_updater.go index 368f55c81a..2266ef0e7a 100644 --- a/internal/mode/static/config_updater.go +++ b/internal/controller/config_updater.go @@ -1,4 +1,4 @@ -package static +package controller import ( "encoding/json" diff --git a/internal/mode/static/config_updater_test.go b/internal/controller/config_updater_test.go similarity index 95% rename from internal/mode/static/config_updater_test.go rename to internal/controller/config_updater_test.go index 440f7dde22..7ab1f942fb 100644 --- a/internal/mode/static/config_updater_test.go +++ b/internal/controller/config_updater_test.go @@ -1,4 +1,4 @@ -package static +package controller import ( "errors" @@ -11,8 +11,8 @@ import ( "k8s.io/client-go/tools/record" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" + "github.com/nginx/nginx-gateway-fabric/internal/controller/controllerfakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/staticfakes" ) func TestUpdateControlPlane(t *testing.T) { @@ -75,7 +75,7 @@ func TestUpdateControlPlane(t *testing.T) { t.Parallel() g := NewWithT(t) - fakeLogSetter := &staticfakes.FakeLogLevelSetter{ + fakeLogSetter := &controllerfakes.FakeLogLevelSetter{ SetLevelStub: func(_ string) error { return test.setLevelErr }, diff --git a/internal/mode/static/static_suite_test.go b/internal/controller/controller_suite_test.go similarity index 57% rename from internal/mode/static/static_suite_test.go rename to internal/controller/controller_suite_test.go index 0d47b11d5b..3daa3212cc 100644 --- a/internal/mode/static/static_suite_test.go +++ b/internal/controller/controller_suite_test.go @@ -1,4 +1,4 @@ -package static_test +package controller_test import ( "testing" @@ -7,8 +7,8 @@ import ( . "github.com/onsi/gomega" ) -func TestStatic(t *testing.T) { +func TestController(t *testing.T) { t.Parallel() RegisterFailHandler(Fail) - RunSpecs(t, "Static Suite") + RunSpecs(t, "Controller Suite") } diff --git a/internal/mode/static/staticfakes/fake_log_level_setter.go b/internal/controller/controllerfakes/fake_log_level_setter.go similarity index 99% rename from internal/mode/static/staticfakes/fake_log_level_setter.go rename to internal/controller/controllerfakes/fake_log_level_setter.go index 154257ed5d..e607fa4773 100644 --- a/internal/mode/static/staticfakes/fake_log_level_setter.go +++ b/internal/controller/controllerfakes/fake_log_level_setter.go @@ -1,5 +1,5 @@ // Code generated by counterfeiter. DO NOT EDIT. -package staticfakes +package controllerfakes import ( "sync" diff --git a/internal/controller/doc.go b/internal/controller/doc.go new file mode 100644 index 0000000000..d94e9cbe4f --- /dev/null +++ b/internal/controller/doc.go @@ -0,0 +1,4 @@ +/* +Package controller contains all the packages that relate to the controller implementation of NGF. +*/ +package controller diff --git a/internal/mode/static/handler.go b/internal/controller/handler.go similarity index 94% rename from internal/mode/static/handler.go rename to internal/controller/handler.go index 2e2fe6e9c2..e668b3f311 100644 --- a/internal/mode/static/handler.go +++ b/internal/controller/handler.go @@ -1,4 +1,4 @@ -package static +package controller import ( "context" @@ -18,20 +18,19 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" + ngfConfig "github.com/nginx/nginx-gateway-fabric/internal/controller/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/licensing" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent" + ngxConfig "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/provisioner" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller" "github.com/nginx/nginx-gateway-fabric/internal/framework/events" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - frameworkStatus "github.com/nginx/nginx-gateway-fabric/internal/framework/status" - ngfConfig "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/licensing" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent" - ngxConfig "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/provisioner" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/status" ) type handlerMetricsCollector interface { @@ -48,7 +47,7 @@ type eventHandlerConfig struct { // metricsCollector collects metrics for this controller. metricsCollector handlerMetricsCollector // statusUpdater updates statuses on Kubernetes resources. - statusUpdater frameworkStatus.GroupUpdater + statusUpdater status.GroupUpdater // processor is the state ChangeProcessor. processor state.ChangeProcessor // serviceResolver resolves Services to Endpoints. @@ -351,7 +350,7 @@ func (h *eventHandlerImpl) updateStatuses(ctx context.Context, gr *graph.Graph, ) reqs := make( - []frameworkStatus.UpdateRequest, + []status.UpdateRequest, 0, len(gcReqs)+len(routeReqs)+len(polReqs)+len(ngfPolReqs)+len(snippetsFilterReqs), ) @@ -445,7 +444,7 @@ func (h *eventHandlerImpl) updateControlPlaneAndSetStatus( cpUpdateRes.Error = err } - var reqs []frameworkStatus.UpdateRequest + var reqs []status.UpdateRequest req := status.PrepareNginxGatewayStatus(cfg, metav1.Now(), cpUpdateRes) if req != nil { diff --git a/internal/mode/static/handler_test.go b/internal/controller/handler_test.go similarity index 95% rename from internal/mode/static/handler_test.go rename to internal/controller/handler_test.go index 59ed8d8d2a..021584350c 100644 --- a/internal/mode/static/handler_test.go +++ b/internal/controller/handler_test.go @@ -1,4 +1,4 @@ -package static +package controller import ( "context" @@ -20,22 +20,22 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" + "github.com/nginx/nginx-gateway-fabric/internal/controller/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/licensing/licensingfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/metrics/collectors" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/agentfakes" + agentgrpcfakes "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/grpcfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/configfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/provisioner/provisionerfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/statefakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status/statusfakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller" "github.com/nginx/nginx-gateway-fabric/internal/framework/events" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/framework/status/statusfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/licensing/licensingfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/metrics/collectors" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/agentfakes" - agentgrpcfakes "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/grpcfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/configfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/provisioner/provisionerfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/statefakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/status" ) var _ = Describe("eventHandler", func() { diff --git a/internal/mode/static/health.go b/internal/controller/health.go similarity index 98% rename from internal/mode/static/health.go rename to internal/controller/health.go index a0fe4e9b59..7e2848e463 100644 --- a/internal/mode/static/health.go +++ b/internal/controller/health.go @@ -1,4 +1,4 @@ -package static +package controller import ( "errors" diff --git a/internal/mode/static/health_test.go b/internal/controller/health_test.go similarity index 94% rename from internal/mode/static/health_test.go rename to internal/controller/health_test.go index 7246283ed9..d2fbbba60a 100644 --- a/internal/mode/static/health_test.go +++ b/internal/controller/health_test.go @@ -1,4 +1,4 @@ -package static +package controller import ( "testing" diff --git a/internal/mode/static/licensing/collector.go b/internal/controller/licensing/collector.go similarity index 92% rename from internal/mode/static/licensing/collector.go rename to internal/controller/licensing/collector.go index 0babb3bd6a..564e807f46 100644 --- a/internal/mode/static/licensing/collector.go +++ b/internal/controller/licensing/collector.go @@ -7,8 +7,8 @@ import ( "github.com/go-logr/logr" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/telemetry" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/telemetry" ) //go:generate go tool counterfeiter -generate diff --git a/internal/mode/static/licensing/collector_suite_test.go b/internal/controller/licensing/collector_suite_test.go similarity index 100% rename from internal/mode/static/licensing/collector_suite_test.go rename to internal/controller/licensing/collector_suite_test.go diff --git a/internal/mode/static/licensing/collector_test.go b/internal/controller/licensing/collector_test.go similarity index 92% rename from internal/mode/static/licensing/collector_test.go rename to internal/controller/licensing/collector_test.go index 21753a5cfe..114e088d09 100644 --- a/internal/mode/static/licensing/collector_test.go +++ b/internal/controller/licensing/collector_test.go @@ -9,9 +9,9 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client/fake" + "github.com/nginx/nginx-gateway-fabric/internal/controller/licensing" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/licensing" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" ) var _ = Describe("DeploymentContextCollector", func() { diff --git a/internal/mode/static/licensing/licensingfakes/fake_collector.go b/internal/controller/licensing/licensingfakes/fake_collector.go similarity index 95% rename from internal/mode/static/licensing/licensingfakes/fake_collector.go rename to internal/controller/licensing/licensingfakes/fake_collector.go index 8491b5b5a8..cadd444c1f 100644 --- a/internal/mode/static/licensing/licensingfakes/fake_collector.go +++ b/internal/controller/licensing/licensingfakes/fake_collector.go @@ -5,8 +5,8 @@ import ( "context" "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/licensing" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/licensing" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" ) type FakeCollector struct { diff --git a/internal/mode/static/log_level_setters.go b/internal/controller/log_level_setters.go similarity index 95% rename from internal/mode/static/log_level_setters.go rename to internal/controller/log_level_setters.go index 765cb80e0f..a5fc74e268 100644 --- a/internal/mode/static/log_level_setters.go +++ b/internal/controller/log_level_setters.go @@ -1,4 +1,4 @@ -package static +package controller import ( "errors" @@ -7,6 +7,8 @@ import ( "go.uber.org/zap/zapcore" ) +//go:generate go tool counterfeiter -generate + //counterfeiter:generate . logLevelSetter // logLevelSetter defines an interface for setting the logging level of a logger. diff --git a/internal/mode/static/log_level_setters_test.go b/internal/controller/log_level_setters_test.go similarity index 84% rename from internal/mode/static/log_level_setters_test.go rename to internal/controller/log_level_setters_test.go index 844b5a8f91..cd1ee7e8b2 100644 --- a/internal/mode/static/log_level_setters_test.go +++ b/internal/controller/log_level_setters_test.go @@ -1,4 +1,4 @@ -package static +package controller import ( "errors" @@ -7,16 +7,16 @@ import ( . "github.com/onsi/gomega" "go.uber.org/zap" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/staticfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/controllerfakes" ) func TestMultiLogLevelSetter_SetLevel(t *testing.T) { t.Parallel() g := NewWithT(t) - logr1 := &staticfakes.FakeLogLevelSetter{} - logr2 := &staticfakes.FakeLogLevelSetter{} - logr3 := &staticfakes.FakeLogLevelSetter{} + logr1 := &controllerfakes.FakeLogLevelSetter{} + logr2 := &controllerfakes.FakeLogLevelSetter{} + logr3 := &controllerfakes.FakeLogLevelSetter{} multiSetter := newMultiLogLevelSetter(logr1, logr2, logr3) g.Expect(multiSetter.SetLevel("test")).To(Succeed()) diff --git a/internal/mode/static/manager.go b/internal/controller/manager.go similarity index 92% rename from internal/mode/static/manager.go rename to internal/controller/manager.go index 1af84ebe23..f7bc0a68e5 100644 --- a/internal/mode/static/manager.go +++ b/internal/controller/manager.go @@ -1,4 +1,4 @@ -package static +package controller import ( "context" @@ -38,35 +38,33 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/licensing" + "github.com/nginx/nginx-gateway-fabric/internal/controller/metrics/collectors" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent" + agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc" + ngxcfg "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/clientsettings" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/observability" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/upstreamsettings" + ngxvalidation "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/validation" + "github.com/nginx/nginx-gateway-fabric/internal/controller/provisioner" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status" + "github.com/nginx/nginx-gateway-fabric/internal/controller/telemetry" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller/filter" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller/index" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller/predicate" "github.com/nginx/nginx-gateway-fabric/internal/framework/events" - "github.com/nginx/nginx-gateway-fabric/internal/framework/gatewayclass" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" "github.com/nginx/nginx-gateway-fabric/internal/framework/runnables" - frameworkStatus "github.com/nginx/nginx-gateway-fabric/internal/framework/status" ngftypes "github.com/nginx/nginx-gateway-fabric/internal/framework/types" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/licensing" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/metrics/collectors" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent" - agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc" - ngxcfg "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/clientsettings" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/observability" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/upstreamsettings" - ngxvalidation "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/validation" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/provisioner" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/status" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/telemetry" ) const ( @@ -152,18 +150,18 @@ func StartManager(cfg config.Config) error { handlerCollector = collectors.NewControllerCollector(constLabels) handlerCollector, ok := handlerCollector.(prometheus.Collector) if !ok { - return fmt.Errorf("handlerCollector is not a prometheus.Collector: %w", frameworkStatus.ErrFailedAssert) + return fmt.Errorf("handlerCollector is not a prometheus.Collector: %w", status.ErrFailedAssert) } metrics.Registry.MustRegister(handlerCollector) } - statusUpdater := frameworkStatus.NewUpdater( + statusUpdater := status.NewUpdater( mgr.GetClient(), cfg.Logger.WithName("statusUpdater"), ) - groupStatusUpdater := frameworkStatus.NewLeaderAwareGroupUpdater(statusUpdater) + groupStatusUpdater := status.NewLeaderAwareGroupUpdater(statusUpdater) deployCtxCollector := licensing.NewDeploymentContextCollector(licensing.DeploymentContextCollectorConfig{ K8sClientReader: mgr.GetAPIReader(), PodUID: cfg.GatewayPodConfig.UID, @@ -475,7 +473,7 @@ func registerControllers( options: []controller.Option{ controller.WithOnlyMetadata(), controller.WithK8sPredicate( - predicate.AnnotationPredicate{Annotation: gatewayclass.BundleVersionAnnotation}, + predicate.AnnotationPredicate{Annotation: graph.BundleVersionAnnotation}, ), }, }, diff --git a/internal/mode/static/manager_test.go b/internal/controller/manager_test.go similarity index 98% rename from internal/mode/static/manager_test.go rename to internal/controller/manager_test.go index 9a9f0768b7..75aecfe04a 100644 --- a/internal/mode/static/manager_test.go +++ b/internal/controller/manager_test.go @@ -1,4 +1,4 @@ -package static +package controller import ( "testing" @@ -21,8 +21,8 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" ) func TestPrepareFirstEventBatchPreparerArgs(t *testing.T) { diff --git a/internal/mode/static/metrics/collectors/controller.go b/internal/controller/metrics/collectors/controller.go similarity index 96% rename from internal/mode/static/metrics/collectors/controller.go rename to internal/controller/metrics/collectors/controller.go index 3a5db0cb18..ea0eaa81a8 100644 --- a/internal/mode/static/metrics/collectors/controller.go +++ b/internal/controller/metrics/collectors/controller.go @@ -5,7 +5,7 @@ import ( "github.com/prometheus/client_golang/prometheus" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/metrics" + "github.com/nginx/nginx-gateway-fabric/internal/controller/metrics" ) // ControllerCollector collects metrics for the NGF controller. diff --git a/internal/mode/static/metrics/metrics.go b/internal/controller/metrics/metrics.go similarity index 100% rename from internal/mode/static/metrics/metrics.go rename to internal/controller/metrics/metrics.go diff --git a/internal/mode/static/nginx/agent/action.go b/internal/controller/nginx/agent/action.go similarity index 100% rename from internal/mode/static/nginx/agent/action.go rename to internal/controller/nginx/agent/action.go diff --git a/internal/mode/static/nginx/agent/action_test.go b/internal/controller/nginx/agent/action_test.go similarity index 100% rename from internal/mode/static/nginx/agent/action_test.go rename to internal/controller/nginx/agent/action_test.go diff --git a/internal/mode/static/nginx/agent/agent.go b/internal/controller/nginx/agent/agent.go similarity index 94% rename from internal/mode/static/nginx/agent/agent.go rename to internal/controller/nginx/agent/agent.go index dbe49deb0c..ea0dba3ae8 100644 --- a/internal/mode/static/nginx/agent/agent.go +++ b/internal/controller/nginx/agent/agent.go @@ -13,11 +13,11 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/broadcast" - agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/status" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/broadcast" + agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status" ) const retryUpstreamTimeout = 5 * time.Second diff --git a/internal/mode/static/nginx/agent/agent_test.go b/internal/controller/nginx/agent/agent_test.go similarity index 96% rename from internal/mode/static/nginx/agent/agent_test.go rename to internal/controller/nginx/agent/agent_test.go index b0147d4d96..5bc6bb77c6 100644 --- a/internal/mode/static/nginx/agent/agent_test.go +++ b/internal/controller/nginx/agent/agent_test.go @@ -11,10 +11,10 @@ import ( "google.golang.org/protobuf/types/known/structpb" "sigs.k8s.io/controller-runtime/pkg/client/fake" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/broadcast/broadcastfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/status" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/broadcast/broadcastfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status" ) func TestUpdateConfig(t *testing.T) { diff --git a/internal/mode/static/nginx/agent/agentfakes/fake_deployment_storer.go b/internal/controller/nginx/agent/agentfakes/fake_deployment_storer.go similarity index 98% rename from internal/mode/static/nginx/agent/agentfakes/fake_deployment_storer.go rename to internal/controller/nginx/agent/agentfakes/fake_deployment_storer.go index af87b10a8e..19d4f434a5 100644 --- a/internal/mode/static/nginx/agent/agentfakes/fake_deployment_storer.go +++ b/internal/controller/nginx/agent/agentfakes/fake_deployment_storer.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent" "k8s.io/apimachinery/pkg/types" ) diff --git a/internal/mode/static/nginx/agent/agentfakes/fake_nginx_updater.go b/internal/controller/nginx/agent/agentfakes/fake_nginx_updater.go similarity index 96% rename from internal/mode/static/nginx/agent/agentfakes/fake_nginx_updater.go rename to internal/controller/nginx/agent/agentfakes/fake_nginx_updater.go index f69009ce04..c1afc0ba96 100644 --- a/internal/mode/static/nginx/agent/agentfakes/fake_nginx_updater.go +++ b/internal/controller/nginx/agent/agentfakes/fake_nginx_updater.go @@ -4,8 +4,8 @@ package agentfakes import ( "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" ) type FakeNginxUpdater struct { diff --git a/internal/mode/static/nginx/agent/broadcast/broadcast.go b/internal/controller/nginx/agent/broadcast/broadcast.go similarity index 100% rename from internal/mode/static/nginx/agent/broadcast/broadcast.go rename to internal/controller/nginx/agent/broadcast/broadcast.go diff --git a/internal/mode/static/nginx/agent/broadcast/broadcast_test.go b/internal/controller/nginx/agent/broadcast/broadcast_test.go similarity index 96% rename from internal/mode/static/nginx/agent/broadcast/broadcast_test.go rename to internal/controller/nginx/agent/broadcast/broadcast_test.go index 950293c4e1..5a20622671 100644 --- a/internal/mode/static/nginx/agent/broadcast/broadcast_test.go +++ b/internal/controller/nginx/agent/broadcast/broadcast_test.go @@ -6,7 +6,7 @@ import ( . "github.com/onsi/gomega" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/broadcast" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/broadcast" ) func TestSubscribe(t *testing.T) { diff --git a/internal/mode/static/nginx/agent/broadcast/broadcastfakes/fake_broadcaster.go b/internal/controller/nginx/agent/broadcast/broadcastfakes/fake_broadcaster.go similarity index 98% rename from internal/mode/static/nginx/agent/broadcast/broadcastfakes/fake_broadcaster.go rename to internal/controller/nginx/agent/broadcast/broadcastfakes/fake_broadcaster.go index 0d820ef98a..e82946a2d3 100644 --- a/internal/mode/static/nginx/agent/broadcast/broadcastfakes/fake_broadcaster.go +++ b/internal/controller/nginx/agent/broadcast/broadcastfakes/fake_broadcaster.go @@ -4,7 +4,7 @@ package broadcastfakes import ( "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/broadcast" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/broadcast" ) type FakeBroadcaster struct { diff --git a/internal/mode/static/nginx/agent/broadcast/doc.go b/internal/controller/nginx/agent/broadcast/doc.go similarity index 100% rename from internal/mode/static/nginx/agent/broadcast/doc.go rename to internal/controller/nginx/agent/broadcast/doc.go diff --git a/internal/mode/static/nginx/agent/command.go b/internal/controller/nginx/agent/command.go similarity index 97% rename from internal/mode/static/nginx/agent/command.go rename to internal/controller/nginx/agent/command.go index ab269a5b95..41df07a055 100644 --- a/internal/mode/static/nginx/agent/command.go +++ b/internal/controller/nginx/agent/command.go @@ -22,11 +22,11 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/broadcast" - agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc" - grpcContext "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/context" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/messenger" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/status" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/broadcast" + agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc" + grpcContext "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/context" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/messenger" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status" ) const connectionWaitTimeout = 30 * time.Second diff --git a/internal/mode/static/nginx/agent/command_test.go b/internal/controller/nginx/agent/command_test.go similarity index 97% rename from internal/mode/static/nginx/agent/command_test.go rename to internal/controller/nginx/agent/command_test.go index 3a4775c82d..c23bbf02ae 100644 --- a/internal/mode/static/nginx/agent/command_test.go +++ b/internal/controller/nginx/agent/command_test.go @@ -19,13 +19,13 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/broadcast" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/broadcast/broadcastfakes" - agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc" - grpcContext "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/context" - agentgrpcfakes "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/grpcfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/messenger/messengerfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/status" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/broadcast" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/broadcast/broadcastfakes" + agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc" + grpcContext "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/context" + agentgrpcfakes "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/grpcfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/messenger/messengerfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status" ) type mockSubscribeServer struct { diff --git a/internal/mode/static/nginx/agent/deployment.go b/internal/controller/nginx/agent/deployment.go similarity index 98% rename from internal/mode/static/nginx/agent/deployment.go rename to internal/controller/nginx/agent/deployment.go index 3aa8d80b6b..1160bfab20 100644 --- a/internal/mode/static/nginx/agent/deployment.go +++ b/internal/controller/nginx/agent/deployment.go @@ -10,8 +10,8 @@ import ( filesHelper "github.com/nginx/agent/v3/pkg/files" "k8s.io/apimachinery/pkg/types" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/broadcast" - agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/broadcast" + agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc" ) // ignoreFiles is a list of static or base files that live in the diff --git a/internal/mode/static/nginx/agent/deployment_test.go b/internal/controller/nginx/agent/deployment_test.go similarity index 94% rename from internal/mode/static/nginx/agent/deployment_test.go rename to internal/controller/nginx/agent/deployment_test.go index 57d9510588..e6f54614ae 100644 --- a/internal/mode/static/nginx/agent/deployment_test.go +++ b/internal/controller/nginx/agent/deployment_test.go @@ -9,9 +9,9 @@ import ( . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/types" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/broadcast" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/broadcast/broadcastfakes" - agentgrpcfakes "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/grpcfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/broadcast" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/broadcast/broadcastfakes" + agentgrpcfakes "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/grpcfakes" ) func TestNewDeployment(t *testing.T) { diff --git a/internal/mode/static/nginx/agent/doc.go b/internal/controller/nginx/agent/doc.go similarity index 100% rename from internal/mode/static/nginx/agent/doc.go rename to internal/controller/nginx/agent/doc.go diff --git a/internal/mode/static/nginx/agent/file.go b/internal/controller/nginx/agent/file.go similarity index 96% rename from internal/mode/static/nginx/agent/file.go rename to internal/controller/nginx/agent/file.go index 17fac0a9ed..be9852487f 100644 --- a/internal/mode/static/nginx/agent/file.go +++ b/internal/controller/nginx/agent/file.go @@ -12,8 +12,8 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc" - grpcContext "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/context" + agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc" + grpcContext "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/context" ) const defaultChunkSize uint32 = 2097152 // 2MB diff --git a/internal/mode/static/nginx/agent/file_test.go b/internal/controller/nginx/agent/file_test.go similarity index 97% rename from internal/mode/static/nginx/agent/file_test.go rename to internal/controller/nginx/agent/file_test.go index 22f8f4d964..fcd893302d 100644 --- a/internal/mode/static/nginx/agent/file_test.go +++ b/internal/controller/nginx/agent/file_test.go @@ -12,9 +12,9 @@ import ( "google.golang.org/grpc/status" "k8s.io/apimachinery/pkg/types" - agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc" - grpcContext "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/context" - agentgrpcfakes "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/grpcfakes" + agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc" + grpcContext "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/context" + agentgrpcfakes "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/grpcfakes" ) type mockServerStreamingServer struct { diff --git a/internal/mode/static/nginx/agent/grpc/connections.go b/internal/controller/nginx/agent/grpc/connections.go similarity index 100% rename from internal/mode/static/nginx/agent/grpc/connections.go rename to internal/controller/nginx/agent/grpc/connections.go diff --git a/internal/mode/static/nginx/agent/grpc/connections_test.go b/internal/controller/nginx/agent/grpc/connections_test.go similarity index 96% rename from internal/mode/static/nginx/agent/grpc/connections_test.go rename to internal/controller/nginx/agent/grpc/connections_test.go index c9d7b3cdc3..f503cf2e37 100644 --- a/internal/mode/static/nginx/agent/grpc/connections_test.go +++ b/internal/controller/nginx/agent/grpc/connections_test.go @@ -6,7 +6,7 @@ import ( . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/types" - agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc" + agentgrpc "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc" ) func TestGetConnection(t *testing.T) { diff --git a/internal/mode/static/nginx/agent/grpc/context/context.go b/internal/controller/nginx/agent/grpc/context/context.go similarity index 100% rename from internal/mode/static/nginx/agent/grpc/context/context.go rename to internal/controller/nginx/agent/grpc/context/context.go diff --git a/internal/mode/static/nginx/agent/grpc/context/context_test.go b/internal/controller/nginx/agent/grpc/context/context_test.go similarity index 86% rename from internal/mode/static/nginx/agent/grpc/context/context_test.go rename to internal/controller/nginx/agent/grpc/context/context_test.go index 57acf9152f..195479a021 100644 --- a/internal/mode/static/nginx/agent/grpc/context/context_test.go +++ b/internal/controller/nginx/agent/grpc/context/context_test.go @@ -6,7 +6,7 @@ import ( . "github.com/onsi/gomega" - grpcContext "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/context" + grpcContext "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/context" ) func TestGrpcInfoInContext(t *testing.T) { diff --git a/internal/mode/static/nginx/agent/grpc/context/doc.go b/internal/controller/nginx/agent/grpc/context/doc.go similarity index 100% rename from internal/mode/static/nginx/agent/grpc/context/doc.go rename to internal/controller/nginx/agent/grpc/context/doc.go diff --git a/internal/mode/static/nginx/agent/grpc/doc.go b/internal/controller/nginx/agent/grpc/doc.go similarity index 100% rename from internal/mode/static/nginx/agent/grpc/doc.go rename to internal/controller/nginx/agent/grpc/doc.go diff --git a/internal/mode/static/nginx/agent/grpc/filewatcher/doc.go b/internal/controller/nginx/agent/grpc/filewatcher/doc.go similarity index 100% rename from internal/mode/static/nginx/agent/grpc/filewatcher/doc.go rename to internal/controller/nginx/agent/grpc/filewatcher/doc.go diff --git a/internal/mode/static/nginx/agent/grpc/filewatcher/filewatcher.go b/internal/controller/nginx/agent/grpc/filewatcher/filewatcher.go similarity index 100% rename from internal/mode/static/nginx/agent/grpc/filewatcher/filewatcher.go rename to internal/controller/nginx/agent/grpc/filewatcher/filewatcher.go diff --git a/internal/mode/static/nginx/agent/grpc/filewatcher/filewatcher_test.go b/internal/controller/nginx/agent/grpc/filewatcher/filewatcher_test.go similarity index 100% rename from internal/mode/static/nginx/agent/grpc/filewatcher/filewatcher_test.go rename to internal/controller/nginx/agent/grpc/filewatcher/filewatcher_test.go diff --git a/internal/mode/static/nginx/agent/grpc/grpc.go b/internal/controller/nginx/agent/grpc/grpc.go similarity index 95% rename from internal/mode/static/nginx/agent/grpc/grpc.go rename to internal/controller/nginx/agent/grpc/grpc.go index f995756584..73db59334e 100644 --- a/internal/mode/static/nginx/agent/grpc/grpc.go +++ b/internal/controller/nginx/agent/grpc/grpc.go @@ -19,8 +19,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/manager" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/filewatcher" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/interceptor" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/filewatcher" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/interceptor" ) const ( diff --git a/internal/mode/static/nginx/agent/grpc/grpcfakes/fake_connections_tracker.go b/internal/controller/nginx/agent/grpc/grpcfakes/fake_connections_tracker.go similarity index 98% rename from internal/mode/static/nginx/agent/grpc/grpcfakes/fake_connections_tracker.go rename to internal/controller/nginx/agent/grpc/grpcfakes/fake_connections_tracker.go index 8ae97043cd..cdebb13b5d 100644 --- a/internal/mode/static/nginx/agent/grpc/grpcfakes/fake_connections_tracker.go +++ b/internal/controller/nginx/agent/grpc/grpcfakes/fake_connections_tracker.go @@ -4,7 +4,7 @@ package grpcfakes import ( "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc" ) type FakeConnectionsTracker struct { diff --git a/internal/mode/static/nginx/agent/grpc/interceptor/doc.go b/internal/controller/nginx/agent/grpc/interceptor/doc.go similarity index 100% rename from internal/mode/static/nginx/agent/grpc/interceptor/doc.go rename to internal/controller/nginx/agent/grpc/interceptor/doc.go diff --git a/internal/mode/static/nginx/agent/grpc/interceptor/interceptor.go b/internal/controller/nginx/agent/grpc/interceptor/interceptor.go similarity index 98% rename from internal/mode/static/nginx/agent/grpc/interceptor/interceptor.go rename to internal/controller/nginx/agent/grpc/interceptor/interceptor.go index 87517c5875..634b1502c0 100644 --- a/internal/mode/static/nginx/agent/grpc/interceptor/interceptor.go +++ b/internal/controller/nginx/agent/grpc/interceptor/interceptor.go @@ -18,8 +18,8 @@ import ( "k8s.io/apimachinery/pkg/fields" "sigs.k8s.io/controller-runtime/pkg/client" + grpcContext "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/context" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller" - grpcContext "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/context" ) const ( diff --git a/internal/mode/static/nginx/agent/grpc/interceptor/interceptor_test.go b/internal/controller/nginx/agent/grpc/interceptor/interceptor_test.go similarity index 100% rename from internal/mode/static/nginx/agent/grpc/interceptor/interceptor_test.go rename to internal/controller/nginx/agent/grpc/interceptor/interceptor_test.go diff --git a/internal/mode/static/nginx/agent/grpc/messenger/doc.go b/internal/controller/nginx/agent/grpc/messenger/doc.go similarity index 100% rename from internal/mode/static/nginx/agent/grpc/messenger/doc.go rename to internal/controller/nginx/agent/grpc/messenger/doc.go diff --git a/internal/mode/static/nginx/agent/grpc/messenger/messenger.go b/internal/controller/nginx/agent/grpc/messenger/messenger.go similarity index 100% rename from internal/mode/static/nginx/agent/grpc/messenger/messenger.go rename to internal/controller/nginx/agent/grpc/messenger/messenger.go diff --git a/internal/mode/static/nginx/agent/grpc/messenger/messenger_test.go b/internal/controller/nginx/agent/grpc/messenger/messenger_test.go similarity index 96% rename from internal/mode/static/nginx/agent/grpc/messenger/messenger_test.go rename to internal/controller/nginx/agent/grpc/messenger/messenger_test.go index 275f2ed875..f7e5cc6962 100644 --- a/internal/mode/static/nginx/agent/grpc/messenger/messenger_test.go +++ b/internal/controller/nginx/agent/grpc/messenger/messenger_test.go @@ -9,7 +9,7 @@ import ( . "github.com/onsi/gomega" "google.golang.org/grpc" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/messenger" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/messenger" ) type mockServer struct { diff --git a/internal/mode/static/nginx/agent/grpc/messenger/messengerfakes/fake_messenger.go b/internal/controller/nginx/agent/grpc/messenger/messengerfakes/fake_messenger.go similarity index 98% rename from internal/mode/static/nginx/agent/grpc/messenger/messengerfakes/fake_messenger.go rename to internal/controller/nginx/agent/grpc/messenger/messengerfakes/fake_messenger.go index 6b6a97bef9..66384c83d8 100644 --- a/internal/mode/static/nginx/agent/grpc/messenger/messengerfakes/fake_messenger.go +++ b/internal/controller/nginx/agent/grpc/messenger/messengerfakes/fake_messenger.go @@ -6,7 +6,7 @@ import ( "sync" v1 "github.com/nginx/agent/v3/api/grpc/mpi/v1" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/grpc/messenger" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/grpc/messenger" ) type FakeMessenger struct { diff --git a/internal/mode/static/nginx/conf/grpc-error-locations.conf b/internal/controller/nginx/conf/grpc-error-locations.conf similarity index 100% rename from internal/mode/static/nginx/conf/grpc-error-locations.conf rename to internal/controller/nginx/conf/grpc-error-locations.conf diff --git a/internal/mode/static/nginx/conf/grpc-error-pages.conf b/internal/controller/nginx/conf/grpc-error-pages.conf similarity index 100% rename from internal/mode/static/nginx/conf/grpc-error-pages.conf rename to internal/controller/nginx/conf/grpc-error-pages.conf diff --git a/internal/mode/static/nginx/conf/nginx-plus.conf b/internal/controller/nginx/conf/nginx-plus.conf similarity index 100% rename from internal/mode/static/nginx/conf/nginx-plus.conf rename to internal/controller/nginx/conf/nginx-plus.conf diff --git a/internal/mode/static/nginx/conf/nginx.conf b/internal/controller/nginx/conf/nginx.conf similarity index 100% rename from internal/mode/static/nginx/conf/nginx.conf rename to internal/controller/nginx/conf/nginx.conf diff --git a/internal/mode/static/nginx/config/base_http_config.go b/internal/controller/nginx/config/base_http_config.go similarity index 83% rename from internal/mode/static/nginx/config/base_http_config.go rename to internal/controller/nginx/config/base_http_config.go index 65552b3192..f808e86b3e 100644 --- a/internal/mode/static/nginx/config/base_http_config.go +++ b/internal/controller/nginx/config/base_http_config.go @@ -3,9 +3,9 @@ package config import ( gotemplate "text/template" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/shared" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/shared" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" ) var baseHTTPTemplate = gotemplate.Must(gotemplate.New("baseHttp").Parse(baseHTTPTemplateText)) diff --git a/internal/mode/static/nginx/config/base_http_config_template.go b/internal/controller/nginx/config/base_http_config_template.go similarity index 100% rename from internal/mode/static/nginx/config/base_http_config_template.go rename to internal/controller/nginx/config/base_http_config_template.go diff --git a/internal/mode/static/nginx/config/base_http_config_test.go b/internal/controller/nginx/config/base_http_config_test.go similarity index 96% rename from internal/mode/static/nginx/config/base_http_config_test.go rename to internal/controller/nginx/config/base_http_config_test.go index 040802af99..31cc7aff52 100644 --- a/internal/mode/static/nginx/config/base_http_config_test.go +++ b/internal/controller/nginx/config/base_http_config_test.go @@ -7,7 +7,7 @@ import ( . "github.com/onsi/gomega" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" ) func TestExecuteBaseHttp_HTTP2(t *testing.T) { diff --git a/internal/mode/static/nginx/config/configfakes/fake_generator.go b/internal/controller/nginx/config/configfakes/fake_generator.go similarity index 96% rename from internal/mode/static/nginx/config/configfakes/fake_generator.go rename to internal/controller/nginx/config/configfakes/fake_generator.go index 0dc5ac408f..f8a3bd4467 100644 --- a/internal/mode/static/nginx/config/configfakes/fake_generator.go +++ b/internal/controller/nginx/config/configfakes/fake_generator.go @@ -4,9 +4,9 @@ package configfakes import ( "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" ) type FakeGenerator struct { diff --git a/internal/mode/static/nginx/config/generator.go b/internal/controller/nginx/config/generator.go similarity index 91% rename from internal/mode/static/nginx/config/generator.go rename to internal/controller/nginx/config/generator.go index 6b40b6ac06..992db73067 100644 --- a/internal/mode/static/nginx/config/generator.go +++ b/internal/controller/nginx/config/generator.go @@ -9,15 +9,15 @@ import ( pb "github.com/nginx/agent/v3/api/grpc/mpi/v1" filesHelper "github.com/nginx/agent/v3/pkg/files" + ngfConfig "github.com/nginx/nginx-gateway-fabric/internal/controller/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/clientsettings" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/observability" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/upstreamsettings" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/framework/file" - ngfConfig "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/clientsettings" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/observability" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/upstreamsettings" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" ) //go:generate go tool counterfeiter -generate diff --git a/internal/mode/static/nginx/config/generator_test.go b/internal/controller/nginx/config/generator_test.go similarity index 95% rename from internal/mode/static/nginx/config/generator_test.go rename to internal/controller/nginx/config/generator_test.go index 51b73361c7..d7b935caee 100644 --- a/internal/mode/static/nginx/config/generator_test.go +++ b/internal/controller/nginx/config/generator_test.go @@ -10,14 +10,14 @@ import ( . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/types" + ngfConfig "github.com/nginx/nginx-gateway-fabric/internal/controller/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver" "github.com/nginx/nginx-gateway-fabric/internal/framework/file" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - ngfConfig "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver" ) func TestGenerate(t *testing.T) { diff --git a/internal/mode/static/nginx/config/http/config.go b/internal/controller/nginx/config/http/config.go similarity index 97% rename from internal/mode/static/nginx/config/http/config.go rename to internal/controller/nginx/config/http/config.go index d79fe708e9..f1ae092fc0 100644 --- a/internal/mode/static/nginx/config/http/config.go +++ b/internal/controller/nginx/config/http/config.go @@ -1,7 +1,7 @@ package http import ( - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/shared" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/shared" ) const ( diff --git a/internal/mode/static/nginx/config/includes.go b/internal/controller/nginx/config/includes.go similarity index 93% rename from internal/mode/static/nginx/config/includes.go rename to internal/controller/nginx/config/includes.go index 729c100d9c..0bcd2f8ce2 100644 --- a/internal/mode/static/nginx/config/includes.go +++ b/internal/controller/nginx/config/includes.go @@ -1,10 +1,10 @@ package config import ( - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/shared" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/shared" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" ) // createIncludeExecuteResultsFromServers creates a list of executeResults -- or NGINX config files -- from all diff --git a/internal/mode/static/nginx/config/includes_test.go b/internal/controller/nginx/config/includes_test.go similarity index 97% rename from internal/mode/static/nginx/config/includes_test.go rename to internal/controller/nginx/config/includes_test.go index 40e6f292bc..b5a33de5cf 100644 --- a/internal/mode/static/nginx/config/includes_test.go +++ b/internal/controller/nginx/config/includes_test.go @@ -5,10 +5,10 @@ import ( . "github.com/onsi/gomega" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/shared" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/shared" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" ) func TestCreateIncludeExecuteResultsFromServers(t *testing.T) { diff --git a/internal/mode/static/nginx/config/main_config.go b/internal/controller/nginx/config/main_config.go similarity index 92% rename from internal/mode/static/nginx/config/main_config.go rename to internal/controller/nginx/config/main_config.go index f6710bc587..142dc9ce41 100644 --- a/internal/mode/static/nginx/config/main_config.go +++ b/internal/controller/nginx/config/main_config.go @@ -6,12 +6,12 @@ import ( pb "github.com/nginx/agent/v3/api/grpc/mpi/v1" filesHelper "github.com/nginx/agent/v3/pkg/files" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/shared" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" "github.com/nginx/nginx-gateway-fabric/internal/framework/file" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/shared" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" ) var ( diff --git a/internal/mode/static/nginx/config/main_config_template.go b/internal/controller/nginx/config/main_config_template.go similarity index 100% rename from internal/mode/static/nginx/config/main_config_template.go rename to internal/controller/nginx/config/main_config_template.go diff --git a/internal/mode/static/nginx/config/main_config_test.go b/internal/controller/nginx/config/main_config_test.go similarity index 97% rename from internal/mode/static/nginx/config/main_config_test.go rename to internal/controller/nginx/config/main_config_test.go index 476614c016..5c3f6dcfdf 100644 --- a/internal/mode/static/nginx/config/main_config_test.go +++ b/internal/controller/nginx/config/main_config_test.go @@ -6,7 +6,7 @@ import ( . "github.com/onsi/gomega" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" ) func TestExecuteMainConfig_Telemetry(t *testing.T) { diff --git a/internal/mode/static/nginx/config/maps.go b/internal/controller/nginx/config/maps.go similarity index 96% rename from internal/mode/static/nginx/config/maps.go rename to internal/controller/nginx/config/maps.go index 78f81c9e37..93d06995d5 100644 --- a/internal/mode/static/nginx/config/maps.go +++ b/internal/controller/nginx/config/maps.go @@ -4,9 +4,9 @@ import ( "strings" gotemplate "text/template" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/shared" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/shared" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" ) var mapsTemplate = gotemplate.Must(gotemplate.New("maps").Parse(mapsTemplateText)) diff --git a/internal/mode/static/nginx/config/maps_template.go b/internal/controller/nginx/config/maps_template.go similarity index 100% rename from internal/mode/static/nginx/config/maps_template.go rename to internal/controller/nginx/config/maps_template.go diff --git a/internal/mode/static/nginx/config/maps_test.go b/internal/controller/nginx/config/maps_test.go similarity index 97% rename from internal/mode/static/nginx/config/maps_test.go rename to internal/controller/nginx/config/maps_test.go index f1207715ff..bfa1fd9b57 100644 --- a/internal/mode/static/nginx/config/maps_test.go +++ b/internal/controller/nginx/config/maps_test.go @@ -6,9 +6,9 @@ import ( . "github.com/onsi/gomega" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/shared" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/shared" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver" ) func TestExecuteMaps(t *testing.T) { diff --git a/internal/mode/static/nginx/config/plus_api.go b/internal/controller/nginx/config/plus_api.go similarity index 89% rename from internal/mode/static/nginx/config/plus_api.go rename to internal/controller/nginx/config/plus_api.go index d4988bb838..4d37bf52bc 100644 --- a/internal/mode/static/nginx/config/plus_api.go +++ b/internal/controller/nginx/config/plus_api.go @@ -3,8 +3,8 @@ package config import ( gotemplate "text/template" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" ) var plusAPITemplate = gotemplate.Must(gotemplate.New("plusAPI").Parse(plusAPITemplateText)) diff --git a/internal/mode/static/nginx/config/plus_api_template.go b/internal/controller/nginx/config/plus_api_template.go similarity index 100% rename from internal/mode/static/nginx/config/plus_api_template.go rename to internal/controller/nginx/config/plus_api_template.go diff --git a/internal/mode/static/nginx/config/plus_api_test.go b/internal/controller/nginx/config/plus_api_test.go similarity index 93% rename from internal/mode/static/nginx/config/plus_api_test.go rename to internal/controller/nginx/config/plus_api_test.go index f664143402..66dbb592f7 100644 --- a/internal/mode/static/nginx/config/plus_api_test.go +++ b/internal/controller/nginx/config/plus_api_test.go @@ -6,7 +6,7 @@ import ( . "github.com/onsi/gomega" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" ) func TestExecutePlusAPI(t *testing.T) { diff --git a/internal/mode/static/nginx/config/policies/clientsettings/generator.go b/internal/controller/nginx/config/policies/clientsettings/generator.go similarity index 93% rename from internal/mode/static/nginx/config/policies/clientsettings/generator.go rename to internal/controller/nginx/config/policies/clientsettings/generator.go index 8ab6ea10d8..79bcd61fe8 100644 --- a/internal/mode/static/nginx/config/policies/clientsettings/generator.go +++ b/internal/controller/nginx/config/policies/clientsettings/generator.go @@ -5,9 +5,9 @@ import ( "text/template" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" ) var tmpl = template.Must(template.New("client settings policy").Parse(clientSettingsTemplate)) diff --git a/internal/mode/static/nginx/config/policies/clientsettings/generator_test.go b/internal/controller/nginx/config/policies/clientsettings/generator_test.go similarity index 95% rename from internal/mode/static/nginx/config/policies/clientsettings/generator_test.go rename to internal/controller/nginx/config/policies/clientsettings/generator_test.go index e3370a4a57..f07a4f1ae6 100644 --- a/internal/mode/static/nginx/config/policies/clientsettings/generator_test.go +++ b/internal/controller/nginx/config/policies/clientsettings/generator_test.go @@ -7,10 +7,10 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/clientsettings" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/clientsettings" ) func TestGenerate(t *testing.T) { diff --git a/internal/mode/static/nginx/config/policies/clientsettings/validator.go b/internal/controller/nginx/config/policies/clientsettings/validator.go similarity index 91% rename from internal/mode/static/nginx/config/policies/clientsettings/validator.go rename to internal/controller/nginx/config/policies/clientsettings/validator.go index 7c450b2379..e0bcaa849b 100644 --- a/internal/mode/static/nginx/config/policies/clientsettings/validator.go +++ b/internal/controller/nginx/config/policies/clientsettings/validator.go @@ -5,12 +5,11 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" ) // Validator validates a ClientSettingsPolicy. @@ -33,11 +32,11 @@ func (v *Validator) Validate(policy policies.Policy) []conditions.Condition { supportedGroups := []gatewayv1.Group{gatewayv1.GroupName} if err := policies.ValidateTargetRef(csp.Spec.TargetRef, targetRefPath, supportedGroups, supportedKinds); err != nil { - return []conditions.Condition{staticConds.NewPolicyInvalid(err.Error())} + return []conditions.Condition{conditions.NewPolicyInvalid(err.Error())} } if err := v.validateSettings(csp.Spec); err != nil { - return []conditions.Condition{staticConds.NewPolicyInvalid(err.Error())} + return []conditions.Condition{conditions.NewPolicyInvalid(err.Error())} } return nil diff --git a/internal/mode/static/nginx/config/policies/clientsettings/validator_test.go b/internal/controller/nginx/config/policies/clientsettings/validator_test.go similarity index 91% rename from internal/mode/static/nginx/config/policies/clientsettings/validator_test.go rename to internal/controller/nginx/config/policies/clientsettings/validator_test.go index 88b99ba292..4a8a5348e7 100644 --- a/internal/mode/static/nginx/config/policies/clientsettings/validator_test.go +++ b/internal/controller/nginx/config/policies/clientsettings/validator_test.go @@ -9,13 +9,12 @@ import ( "sigs.k8s.io/gateway-api/apis/v1alpha2" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/clientsettings" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/policiesfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/validation" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/clientsettings" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/policiesfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/validation" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) type policyModFunc func(policy *ngfAPI.ClientSettingsPolicy) *ngfAPI.ClientSettingsPolicy @@ -66,7 +65,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("spec.targetRef.group: Unsupported value: \"Unsupported\": " + + conditions.NewPolicyInvalid("spec.targetRef.group: Unsupported value: \"Unsupported\": " + "supported values: \"gateway.networking.k8s.io\""), }, }, @@ -77,7 +76,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("spec.targetRef.kind: Unsupported value: \"Unsupported\": " + + conditions.NewPolicyInvalid("spec.targetRef.kind: Unsupported value: \"Unsupported\": " + "supported values: \"Gateway\", \"HTTPRoute\", \"GRPCRoute\""), }, }, @@ -88,7 +87,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("spec.body.maxSize: Invalid value: \"invalid\": ^\\d{1,4}(k|m|g)?$ " + + conditions.NewPolicyInvalid("spec.body.maxSize: Invalid value: \"invalid\": ^\\d{1,4}(k|m|g)?$ " + "(e.g. '1024', or '8k', or '20m', or '1g', regex used for validation is 'must contain a number. " + "May be followed by 'k', 'm', or 'g', otherwise bytes are assumed')"), }, @@ -103,7 +102,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid( + conditions.NewPolicyInvalid( "[spec.body.timeout: Invalid value: \"invalid\": ^[0-9]{1,4}(ms|s|m|h)? " + "(e.g. '5ms', or '10s', or '500m', or '1000h', regex used for validation is " + "'must contain an, at most, four digit number followed by 'ms', 's', 'm', or 'h''), " + @@ -125,7 +124,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("spec.keepAlive.timeout: Invalid value: \"null\": " + + conditions.NewPolicyInvalid("spec.keepAlive.timeout: Invalid value: \"null\": " + "server timeout must be set if header timeout is set"), }, }, diff --git a/internal/mode/static/nginx/config/policies/generator.go b/internal/controller/nginx/config/policies/generator.go similarity index 97% rename from internal/mode/static/nginx/config/policies/generator.go rename to internal/controller/nginx/config/policies/generator.go index 642aaf181f..e3b2c27419 100644 --- a/internal/mode/static/nginx/config/policies/generator.go +++ b/internal/controller/nginx/config/policies/generator.go @@ -1,7 +1,7 @@ package policies import ( - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" ) // Generator defines an interface for a policy to implement its appropriate generator functions. diff --git a/internal/mode/static/nginx/config/policies/generator_test.go b/internal/controller/nginx/config/policies/generator_test.go similarity index 91% rename from internal/mode/static/nginx/config/policies/generator_test.go rename to internal/controller/nginx/config/policies/generator_test.go index 62dcf4d3b2..9f24e84661 100644 --- a/internal/mode/static/nginx/config/policies/generator_test.go +++ b/internal/controller/nginx/config/policies/generator_test.go @@ -4,9 +4,9 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/policiesfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/policiesfakes" ) var _ = Describe("Policy Generator", func() { diff --git a/internal/mode/static/nginx/config/policies/observability/generator.go b/internal/controller/nginx/config/policies/observability/generator.go similarity index 95% rename from internal/mode/static/nginx/config/policies/observability/generator.go rename to internal/controller/nginx/config/policies/observability/generator.go index dc09e2d8e3..625bd35d71 100644 --- a/internal/mode/static/nginx/config/policies/observability/generator.go +++ b/internal/controller/nginx/config/policies/observability/generator.go @@ -5,10 +5,10 @@ import ( "text/template" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" ) var ( diff --git a/internal/mode/static/nginx/config/policies/observability/generator_test.go b/internal/controller/nginx/config/policies/observability/generator_test.go similarity index 96% rename from internal/mode/static/nginx/config/policies/observability/generator_test.go rename to internal/controller/nginx/config/policies/observability/generator_test.go index 85785d8e09..dc68039ab9 100644 --- a/internal/mode/static/nginx/config/policies/observability/generator_test.go +++ b/internal/controller/nginx/config/policies/observability/generator_test.go @@ -8,11 +8,11 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/observability" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/observability" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" ) func TestGenerate(t *testing.T) { diff --git a/internal/mode/static/nginx/config/policies/observability/validator.go b/internal/controller/nginx/config/policies/observability/validator.go similarity index 86% rename from internal/mode/static/nginx/config/policies/observability/validator.go rename to internal/controller/nginx/config/policies/observability/validator.go index 798b3099c1..4f2b4daacf 100644 --- a/internal/mode/static/nginx/config/policies/observability/validator.go +++ b/internal/controller/nginx/config/policies/observability/validator.go @@ -5,12 +5,11 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" ) // Validator validates an ObservabilityPolicy. @@ -34,12 +33,12 @@ func (v *Validator) Validate(policy policies.Policy) []conditions.Condition { for _, ref := range obs.Spec.TargetRefs { if err := policies.ValidateTargetRef(ref, targetRefPath, supportedGroups, supportedKinds); err != nil { - return []conditions.Condition{staticConds.NewPolicyInvalid(err.Error())} + return []conditions.Condition{conditions.NewPolicyInvalid(err.Error())} } } if err := v.validateSettings(obs.Spec); err != nil { - return []conditions.Condition{staticConds.NewPolicyInvalid(err.Error())} + return []conditions.Condition{conditions.NewPolicyInvalid(err.Error())} } return nil @@ -52,13 +51,13 @@ func (v *Validator) ValidateGlobalSettings( ) []conditions.Condition { if globalSettings == nil { return []conditions.Condition{ - staticConds.NewPolicyNotAcceptedNginxProxyNotSet(staticConds.PolicyMessageNginxProxyInvalid), + conditions.NewPolicyNotAcceptedNginxProxyNotSet(conditions.PolicyMessageNginxProxyInvalid), } } if !globalSettings.TelemetryEnabled { return []conditions.Condition{ - staticConds.NewPolicyNotAcceptedNginxProxyNotSet(staticConds.PolicyMessageTelemetryNotEnabled), + conditions.NewPolicyNotAcceptedNginxProxyNotSet(conditions.PolicyMessageTelemetryNotEnabled), } } diff --git a/internal/mode/static/nginx/config/policies/observability/validator_test.go b/internal/controller/nginx/config/policies/observability/validator_test.go similarity index 84% rename from internal/mode/static/nginx/config/policies/observability/validator_test.go rename to internal/controller/nginx/config/policies/observability/validator_test.go index 9736320545..2a9ba07d84 100644 --- a/internal/mode/static/nginx/config/policies/observability/validator_test.go +++ b/internal/controller/nginx/config/policies/observability/validator_test.go @@ -10,14 +10,13 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/observability" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/policiesfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/validation" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/observability" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/policiesfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/validation" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) type policyModFunc func(policy *ngfAPIv1alpha2.ObservabilityPolicy) *ngfAPIv1alpha2.ObservabilityPolicy @@ -67,7 +66,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("spec.targetRefs.group: Unsupported value: \"Unsupported\": " + + conditions.NewPolicyInvalid("spec.targetRefs.group: Unsupported value: \"Unsupported\": " + "supported values: \"gateway.networking.k8s.io\""), }, }, @@ -78,7 +77,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("spec.targetRefs.kind: Unsupported value: \"Unsupported\": " + + conditions.NewPolicyInvalid("spec.targetRefs.kind: Unsupported value: \"Unsupported\": " + "supported values: \"HTTPRoute\", \"GRPCRoute\""), }, }, @@ -89,7 +88,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("spec.tracing.strategy: Unsupported value: \"invalid\": " + + conditions.NewPolicyInvalid("spec.tracing.strategy: Unsupported value: \"invalid\": " + "supported values: \"ratio\", \"parent\""), }, }, @@ -100,7 +99,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("spec.tracing.context: Unsupported value: \"invalid\": " + + conditions.NewPolicyInvalid("spec.tracing.context: Unsupported value: \"invalid\": " + "supported values: \"extract\", \"inject\", \"propagate\", \"ignore\""), }, }, @@ -111,7 +110,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("spec.tracing.spanName: Invalid value: \"invalid$$$\": " + + conditions.NewPolicyInvalid("spec.tracing.spanName: Invalid value: \"invalid$$$\": " + "a valid value must have all '\"' escaped and must not contain any '$' or end with an " + "unescaped '\\' (regex used for validation is '([^\"$\\\\]|\\\\[^$])*')"), }, @@ -123,7 +122,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("spec.tracing.spanAttributes.key: Invalid value: \"invalid$$$\": " + + conditions.NewPolicyInvalid("spec.tracing.spanAttributes.key: Invalid value: \"invalid$$$\": " + "a valid value must have all '\"' escaped and must not contain any '$' or end with an " + "unescaped '\\' (regex used for validation is '([^\"$\\\\]|\\\\[^$])*')"), }, @@ -135,7 +134,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("spec.tracing.spanAttributes.value: Invalid value: \"invalid$$$\": " + + conditions.NewPolicyInvalid("spec.tracing.spanAttributes.value: Invalid value: \"invalid$$$\": " + "a valid value must have all '\"' escaped and must not contain any '$' or end with an " + "unescaped '\\' (regex used for validation is '([^\"$\\\\]|\\\\[^$])*')"), }, @@ -184,14 +183,14 @@ func TestValidator_ValidateGlobalSettings(t *testing.T) { { name: "global settings are nil", expConditions: []conditions.Condition{ - staticConds.NewPolicyNotAcceptedNginxProxyNotSet(staticConds.PolicyMessageNginxProxyInvalid), + conditions.NewPolicyNotAcceptedNginxProxyNotSet(conditions.PolicyMessageNginxProxyInvalid), }, }, { name: "telemetry is not enabled", globalSettings: &policies.GlobalSettings{TelemetryEnabled: false}, expConditions: []conditions.Condition{ - staticConds.NewPolicyNotAcceptedNginxProxyNotSet(staticConds.PolicyMessageTelemetryNotEnabled), + conditions.NewPolicyNotAcceptedNginxProxyNotSet(conditions.PolicyMessageTelemetryNotEnabled), }, }, { diff --git a/internal/mode/static/nginx/config/policies/policies_suite_test.go b/internal/controller/nginx/config/policies/policies_suite_test.go similarity index 100% rename from internal/mode/static/nginx/config/policies/policies_suite_test.go rename to internal/controller/nginx/config/policies/policies_suite_test.go diff --git a/internal/mode/static/nginx/config/policies/policiesfakes/fake_generator.go b/internal/controller/nginx/config/policies/policiesfakes/fake_generator.go similarity index 98% rename from internal/mode/static/nginx/config/policies/policiesfakes/fake_generator.go rename to internal/controller/nginx/config/policies/policiesfakes/fake_generator.go index c826eceeeb..2cf4bedae5 100644 --- a/internal/mode/static/nginx/config/policies/policiesfakes/fake_generator.go +++ b/internal/controller/nginx/config/policies/policiesfakes/fake_generator.go @@ -4,8 +4,8 @@ package policiesfakes import ( "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" ) type FakeGenerator struct { diff --git a/internal/mode/static/nginx/config/policies/policiesfakes/fake_object_kind.go b/internal/controller/nginx/config/policies/policiesfakes/fake_object_kind.go similarity index 100% rename from internal/mode/static/nginx/config/policies/policiesfakes/fake_object_kind.go rename to internal/controller/nginx/config/policies/policiesfakes/fake_object_kind.go diff --git a/internal/mode/static/nginx/config/policies/policiesfakes/fake_policy.go b/internal/controller/nginx/config/policies/policiesfakes/fake_policy.go similarity index 99% rename from internal/mode/static/nginx/config/policies/policiesfakes/fake_policy.go rename to internal/controller/nginx/config/policies/policiesfakes/fake_policy.go index e47ee41dd7..582cd8b19b 100644 --- a/internal/mode/static/nginx/config/policies/policiesfakes/fake_policy.go +++ b/internal/controller/nginx/config/policies/policiesfakes/fake_policy.go @@ -4,7 +4,7 @@ package policiesfakes import ( "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/internal/mode/static/nginx/config/policies/policiesfakes/fake_validator.go b/internal/controller/nginx/config/policies/policiesfakes/fake_validator.go similarity index 98% rename from internal/mode/static/nginx/config/policies/policiesfakes/fake_validator.go rename to internal/controller/nginx/config/policies/policiesfakes/fake_validator.go index 598c982837..d228a7e44c 100644 --- a/internal/mode/static/nginx/config/policies/policiesfakes/fake_validator.go +++ b/internal/controller/nginx/config/policies/policiesfakes/fake_validator.go @@ -4,8 +4,8 @@ package policiesfakes import ( "sync" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" ) type FakeValidator struct { diff --git a/internal/mode/static/nginx/config/policies/policy.go b/internal/controller/nginx/config/policies/policy.go similarity index 100% rename from internal/mode/static/nginx/config/policies/policy.go rename to internal/controller/nginx/config/policies/policy.go diff --git a/internal/mode/static/nginx/config/policies/upstreamsettings/processor.go b/internal/controller/nginx/config/policies/upstreamsettings/processor.go similarity index 91% rename from internal/mode/static/nginx/config/policies/upstreamsettings/processor.go rename to internal/controller/nginx/config/policies/upstreamsettings/processor.go index 6072820aca..61d69924e5 100644 --- a/internal/mode/static/nginx/config/policies/upstreamsettings/processor.go +++ b/internal/controller/nginx/config/policies/upstreamsettings/processor.go @@ -2,8 +2,8 @@ package upstreamsettings import ( ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" ) // Processor processes UpstreamSettingsPolicies. diff --git a/internal/mode/static/nginx/config/policies/upstreamsettings/processor_test.go b/internal/controller/nginx/config/policies/upstreamsettings/processor_test.go similarity index 98% rename from internal/mode/static/nginx/config/policies/upstreamsettings/processor_test.go rename to internal/controller/nginx/config/policies/upstreamsettings/processor_test.go index 80ca82b7b6..2b568ae7cf 100644 --- a/internal/mode/static/nginx/config/policies/upstreamsettings/processor_test.go +++ b/internal/controller/nginx/config/policies/upstreamsettings/processor_test.go @@ -8,9 +8,9 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" ) func TestProcess(t *testing.T) { diff --git a/internal/mode/static/nginx/config/policies/upstreamsettings/validator.go b/internal/controller/nginx/config/policies/upstreamsettings/validator.go similarity index 89% rename from internal/mode/static/nginx/config/policies/upstreamsettings/validator.go rename to internal/controller/nginx/config/policies/upstreamsettings/validator.go index aaabcbebc9..f490135448 100644 --- a/internal/mode/static/nginx/config/policies/upstreamsettings/validator.go +++ b/internal/controller/nginx/config/policies/upstreamsettings/validator.go @@ -5,12 +5,11 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" ) // Validator validates an UpstreamSettingsPolicy. @@ -35,12 +34,12 @@ func (v Validator) Validate(policy policies.Policy) []conditions.Condition { for i, ref := range usp.Spec.TargetRefs { indexedPath := targetRefsPath.Index(i) if err := policies.ValidateTargetRef(ref, indexedPath, supportedGroups, supportedKinds); err != nil { - return []conditions.Condition{staticConds.NewPolicyInvalid(err.Error())} + return []conditions.Condition{conditions.NewPolicyInvalid(err.Error())} } } if err := v.validateSettings(usp.Spec); err != nil { - return []conditions.Condition{staticConds.NewPolicyInvalid(err.Error())} + return []conditions.Condition{conditions.NewPolicyInvalid(err.Error())} } return nil diff --git a/internal/mode/static/nginx/config/policies/upstreamsettings/validator_test.go b/internal/controller/nginx/config/policies/upstreamsettings/validator_test.go similarity index 90% rename from internal/mode/static/nginx/config/policies/upstreamsettings/validator_test.go rename to internal/controller/nginx/config/policies/upstreamsettings/validator_test.go index 85699ea297..c8ba95d75b 100644 --- a/internal/mode/static/nginx/config/policies/upstreamsettings/validator_test.go +++ b/internal/controller/nginx/config/policies/upstreamsettings/validator_test.go @@ -8,13 +8,12 @@ import ( "sigs.k8s.io/gateway-api/apis/v1alpha2" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/policiesfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/upstreamsettings" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/validation" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/policiesfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/upstreamsettings" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/validation" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) type policyModFunc func(policy *ngfAPI.UpstreamSettingsPolicy) *ngfAPI.UpstreamSettingsPolicy @@ -68,7 +67,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("spec.targetRefs[1].group: Unsupported value: \"Unsupported\": " + + conditions.NewPolicyInvalid("spec.targetRefs[1].group: Unsupported value: \"Unsupported\": " + "supported values: \"\", \"core\""), }, }, @@ -85,7 +84,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("spec.targetRefs[1].kind: Unsupported value: \"Unsupported\": " + + conditions.NewPolicyInvalid("spec.targetRefs[1].kind: Unsupported value: \"Unsupported\": " + "supported values: \"Service\""), }, }, @@ -96,7 +95,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("spec.zoneSize: Invalid value: \"invalid\": ^\\d{1,4}(k|m|g)?$ " + + conditions.NewPolicyInvalid("spec.zoneSize: Invalid value: \"invalid\": ^\\d{1,4}(k|m|g)?$ " + "(e.g. '1024', or '8k', or '20m', or '1g', regex used for validation is 'must contain a number. " + "May be followed by 'k', 'm', or 'g', otherwise bytes are assumed')"), }, @@ -109,7 +108,7 @@ func TestValidator_Validate(t *testing.T) { return p }), expConditions: []conditions.Condition{ - staticConds.NewPolicyInvalid( + conditions.NewPolicyInvalid( "[spec.keepAlive.time: Invalid value: \"invalid\": ^[0-9]{1,4}(ms|s|m|h)? " + "(e.g. '5ms', or '10s', or '500m', or '1000h', regex used for validation is " + "'must contain an, at most, four digit number followed by 'ms', 's', 'm', or 'h''), " + diff --git a/internal/mode/static/nginx/config/policies/validator.go b/internal/controller/nginx/config/policies/validator.go similarity index 97% rename from internal/mode/static/nginx/config/policies/validator.go rename to internal/controller/nginx/config/policies/validator.go index e618eeea17..d7597e67b9 100644 --- a/internal/mode/static/nginx/config/policies/validator.go +++ b/internal/controller/nginx/config/policies/validator.go @@ -7,7 +7,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" ) diff --git a/internal/mode/static/nginx/config/policies/validator_test.go b/internal/controller/nginx/config/policies/validator_test.go similarity index 83% rename from internal/mode/static/nginx/config/policies/validator_test.go rename to internal/controller/nginx/config/policies/validator_test.go index 6787d5360b..d32df91666 100644 --- a/internal/mode/static/nginx/config/policies/validator_test.go +++ b/internal/controller/nginx/config/policies/validator_test.go @@ -6,10 +6,9 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" - policies "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - policiesfakes "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/policiesfakes" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" + policies "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + policiesfakes "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/policiesfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" ) var _ = Describe("Policy CompositeValidator", func() { @@ -50,10 +49,10 @@ var _ = Describe("Policy CompositeValidator", func() { policies.ManagerConfig{ Validator: &policiesfakes.FakeValidator{ ValidateStub: func(_ policies.Policy) []conditions.Condition { - return []conditions.Condition{staticConds.NewPolicyInvalid("apple error")} + return []conditions.Condition{conditions.NewPolicyInvalid("apple error")} }, ValidateGlobalSettingsStub: func(_ policies.Policy, _ *policies.GlobalSettings) []conditions.Condition { - return []conditions.Condition{staticConds.NewPolicyInvalid("apple global settings error")} + return []conditions.Condition{conditions.NewPolicyInvalid("apple global settings error")} }, ConflictsStub: func(_ policies.Policy, _ policies.Policy) bool { return true }, }, @@ -62,10 +61,10 @@ var _ = Describe("Policy CompositeValidator", func() { policies.ManagerConfig{ Validator: &policiesfakes.FakeValidator{ ValidateStub: func(_ policies.Policy) []conditions.Condition { - return []conditions.Condition{staticConds.NewPolicyInvalid("orange error")} + return []conditions.Condition{conditions.NewPolicyInvalid("orange error")} }, ValidateGlobalSettingsStub: func(_ policies.Policy, _ *policies.GlobalSettings) []conditions.Condition { - return []conditions.Condition{staticConds.NewPolicyInvalid("orange global settings error")} + return []conditions.Condition{conditions.NewPolicyInvalid("orange global settings error")} }, ConflictsStub: func(_ policies.Policy, _ policies.Policy) bool { return false }, }, diff --git a/internal/mode/static/nginx/config/servers.go b/internal/controller/nginx/config/servers.go similarity index 98% rename from internal/mode/static/nginx/config/servers.go rename to internal/controller/nginx/config/servers.go index d4f8d9b14f..629237f8c9 100644 --- a/internal/mode/static/nginx/config/servers.go +++ b/internal/controller/nginx/config/servers.go @@ -9,11 +9,11 @@ import ( "strings" gotemplate "text/template" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/shared" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/shared" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" ) var serversTemplate = gotemplate.Must(gotemplate.New("servers").Parse(serversTemplateText)) diff --git a/internal/mode/static/nginx/config/servers_template.go b/internal/controller/nginx/config/servers_template.go similarity index 100% rename from internal/mode/static/nginx/config/servers_template.go rename to internal/controller/nginx/config/servers_template.go diff --git a/internal/mode/static/nginx/config/servers_test.go b/internal/controller/nginx/config/servers_test.go similarity index 99% rename from internal/mode/static/nginx/config/servers_test.go rename to internal/controller/nginx/config/servers_test.go index 70991ecb54..b29550eb8a 100644 --- a/internal/mode/static/nginx/config/servers_test.go +++ b/internal/controller/nginx/config/servers_test.go @@ -10,12 +10,12 @@ import ( "github.com/onsi/gomega/format" "k8s.io/apimachinery/pkg/types" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/policiesfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/shared" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/policiesfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/shared" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" ) var ( diff --git a/internal/mode/static/nginx/config/shared/config.go b/internal/controller/nginx/config/shared/config.go similarity index 100% rename from internal/mode/static/nginx/config/shared/config.go rename to internal/controller/nginx/config/shared/config.go diff --git a/internal/mode/static/nginx/config/sockets.go b/internal/controller/nginx/config/sockets.go similarity index 100% rename from internal/mode/static/nginx/config/sockets.go rename to internal/controller/nginx/config/sockets.go diff --git a/internal/mode/static/nginx/config/sockets_test.go b/internal/controller/nginx/config/sockets_test.go similarity index 100% rename from internal/mode/static/nginx/config/sockets_test.go rename to internal/controller/nginx/config/sockets_test.go diff --git a/internal/mode/static/nginx/config/split_clients.go b/internal/controller/nginx/config/split_clients.go similarity index 95% rename from internal/mode/static/nginx/config/split_clients.go rename to internal/controller/nginx/config/split_clients.go index 0e8250e80e..502859d029 100644 --- a/internal/mode/static/nginx/config/split_clients.go +++ b/internal/controller/nginx/config/split_clients.go @@ -5,9 +5,9 @@ import ( "math" gotemplate "text/template" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" ) var splitClientsTemplate = gotemplate.Must(gotemplate.New("split_clients").Parse(splitClientsTemplateText)) diff --git a/internal/mode/static/nginx/config/split_clients_template.go b/internal/controller/nginx/config/split_clients_template.go similarity index 100% rename from internal/mode/static/nginx/config/split_clients_template.go rename to internal/controller/nginx/config/split_clients_template.go diff --git a/internal/mode/static/nginx/config/split_clients_test.go b/internal/controller/nginx/config/split_clients_test.go similarity index 98% rename from internal/mode/static/nginx/config/split_clients_test.go rename to internal/controller/nginx/config/split_clients_test.go index edc44e7b79..b5ff62a349 100644 --- a/internal/mode/static/nginx/config/split_clients_test.go +++ b/internal/controller/nginx/config/split_clients_test.go @@ -6,8 +6,8 @@ import ( . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/types" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" ) func TestExecuteSplitClients(t *testing.T) { diff --git a/internal/mode/static/nginx/config/stream/config.go b/internal/controller/nginx/config/stream/config.go similarity index 89% rename from internal/mode/static/nginx/config/stream/config.go rename to internal/controller/nginx/config/stream/config.go index 00b93d1ec0..2f9ce82e1c 100644 --- a/internal/mode/static/nginx/config/stream/config.go +++ b/internal/controller/nginx/config/stream/config.go @@ -1,6 +1,6 @@ package stream -import "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/shared" +import "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/shared" // Server holds all configuration for a stream server. type Server struct { diff --git a/internal/mode/static/nginx/config/stream_servers.go b/internal/controller/nginx/config/stream_servers.go similarity index 91% rename from internal/mode/static/nginx/config/stream_servers.go rename to internal/controller/nginx/config/stream_servers.go index fa84ab4e4e..61f7027ba4 100644 --- a/internal/mode/static/nginx/config/stream_servers.go +++ b/internal/controller/nginx/config/stream_servers.go @@ -4,10 +4,10 @@ import ( "fmt" gotemplate "text/template" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/shared" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/stream" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/shared" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/stream" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" ) var streamServersTemplate = gotemplate.Must(gotemplate.New("streamServers").Parse(streamServersTemplateText)) diff --git a/internal/mode/static/nginx/config/stream_servers_template.go b/internal/controller/nginx/config/stream_servers_template.go similarity index 100% rename from internal/mode/static/nginx/config/stream_servers_template.go rename to internal/controller/nginx/config/stream_servers_template.go diff --git a/internal/mode/static/nginx/config/stream_servers_test.go b/internal/controller/nginx/config/stream_servers_test.go similarity index 97% rename from internal/mode/static/nginx/config/stream_servers_test.go rename to internal/controller/nginx/config/stream_servers_test.go index 93b85b364f..4ceb264d36 100644 --- a/internal/mode/static/nginx/config/stream_servers_test.go +++ b/internal/controller/nginx/config/stream_servers_test.go @@ -7,9 +7,9 @@ import ( . "github.com/onsi/gomega" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/stream" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/stream" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver" ) func TestExecuteStreamServers(t *testing.T) { diff --git a/internal/mode/static/nginx/config/telemetry.go b/internal/controller/nginx/config/telemetry.go similarity index 86% rename from internal/mode/static/nginx/config/telemetry.go rename to internal/controller/nginx/config/telemetry.go index 9fcfd7c2bf..9cd19b52ec 100644 --- a/internal/mode/static/nginx/config/telemetry.go +++ b/internal/controller/nginx/config/telemetry.go @@ -3,8 +3,8 @@ package config import ( gotemplate "text/template" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" ) var otelTemplate = gotemplate.Must(gotemplate.New("otel").Parse(otelTemplateText)) diff --git a/internal/mode/static/nginx/config/telemetry_template.go b/internal/controller/nginx/config/telemetry_template.go similarity index 100% rename from internal/mode/static/nginx/config/telemetry_template.go rename to internal/controller/nginx/config/telemetry_template.go diff --git a/internal/mode/static/nginx/config/telemetry_test.go b/internal/controller/nginx/config/telemetry_test.go similarity index 94% rename from internal/mode/static/nginx/config/telemetry_test.go rename to internal/controller/nginx/config/telemetry_test.go index 456adc8a94..6338ad15c1 100644 --- a/internal/mode/static/nginx/config/telemetry_test.go +++ b/internal/controller/nginx/config/telemetry_test.go @@ -6,7 +6,7 @@ import ( . "github.com/onsi/gomega" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" ) func TestExecuteTelemetry(t *testing.T) { diff --git a/internal/mode/static/nginx/config/upstreams.go b/internal/controller/nginx/config/upstreams.go similarity index 93% rename from internal/mode/static/nginx/config/upstreams.go rename to internal/controller/nginx/config/upstreams.go index a5ee3286d1..ead41886bd 100644 --- a/internal/mode/static/nginx/config/upstreams.go +++ b/internal/controller/nginx/config/upstreams.go @@ -4,11 +4,11 @@ import ( "fmt" gotemplate "text/template" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/upstreamsettings" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/stream" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/upstreamsettings" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/stream" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" ) var ( diff --git a/internal/mode/static/nginx/config/upstreams_template.go b/internal/controller/nginx/config/upstreams_template.go similarity index 100% rename from internal/mode/static/nginx/config/upstreams_template.go rename to internal/controller/nginx/config/upstreams_template.go diff --git a/internal/mode/static/nginx/config/upstreams_test.go b/internal/controller/nginx/config/upstreams_test.go similarity index 97% rename from internal/mode/static/nginx/config/upstreams_test.go rename to internal/controller/nginx/config/upstreams_test.go index 2bec7c13e6..5b522f6fe3 100644 --- a/internal/mode/static/nginx/config/upstreams_test.go +++ b/internal/controller/nginx/config/upstreams_test.go @@ -7,13 +7,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/upstreamsettings" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/stream" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/upstreamsettings" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/stream" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver" ) func TestExecuteUpstreams(t *testing.T) { diff --git a/internal/mode/static/nginx/config/validation/common.go b/internal/controller/nginx/config/validation/common.go similarity index 100% rename from internal/mode/static/nginx/config/validation/common.go rename to internal/controller/nginx/config/validation/common.go diff --git a/internal/mode/static/nginx/config/validation/common_test.go b/internal/controller/nginx/config/validation/common_test.go similarity index 100% rename from internal/mode/static/nginx/config/validation/common_test.go rename to internal/controller/nginx/config/validation/common_test.go diff --git a/internal/mode/static/nginx/config/validation/doc.go b/internal/controller/nginx/config/validation/doc.go similarity index 100% rename from internal/mode/static/nginx/config/validation/doc.go rename to internal/controller/nginx/config/validation/doc.go diff --git a/internal/mode/static/nginx/config/validation/framework.go b/internal/controller/nginx/config/validation/framework.go similarity index 100% rename from internal/mode/static/nginx/config/validation/framework.go rename to internal/controller/nginx/config/validation/framework.go diff --git a/internal/mode/static/nginx/config/validation/framework_test.go b/internal/controller/nginx/config/validation/framework_test.go similarity index 100% rename from internal/mode/static/nginx/config/validation/framework_test.go rename to internal/controller/nginx/config/validation/framework_test.go diff --git a/internal/mode/static/nginx/config/validation/generic.go b/internal/controller/nginx/config/validation/generic.go similarity index 100% rename from internal/mode/static/nginx/config/validation/generic.go rename to internal/controller/nginx/config/validation/generic.go diff --git a/internal/mode/static/nginx/config/validation/generic_test.go b/internal/controller/nginx/config/validation/generic_test.go similarity index 100% rename from internal/mode/static/nginx/config/validation/generic_test.go rename to internal/controller/nginx/config/validation/generic_test.go diff --git a/internal/mode/static/nginx/config/validation/http_filters.go b/internal/controller/nginx/config/validation/http_filters.go similarity index 100% rename from internal/mode/static/nginx/config/validation/http_filters.go rename to internal/controller/nginx/config/validation/http_filters.go diff --git a/internal/mode/static/nginx/config/validation/http_filters_test.go b/internal/controller/nginx/config/validation/http_filters_test.go similarity index 100% rename from internal/mode/static/nginx/config/validation/http_filters_test.go rename to internal/controller/nginx/config/validation/http_filters_test.go diff --git a/internal/mode/static/nginx/config/validation/http_njs_match.go b/internal/controller/nginx/config/validation/http_njs_match.go similarity index 97% rename from internal/mode/static/nginx/config/validation/http_njs_match.go rename to internal/controller/nginx/config/validation/http_njs_match.go index b492d7c79c..2c1a2b0ce0 100644 --- a/internal/mode/static/nginx/config/validation/http_njs_match.go +++ b/internal/controller/nginx/config/validation/http_njs_match.go @@ -7,7 +7,7 @@ import ( k8svalidation "k8s.io/apimachinery/pkg/util/validation" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config" ) // HTTPNJSMatchValidator validates values used for matching a request. diff --git a/internal/mode/static/nginx/config/validation/http_njs_match_test.go b/internal/controller/nginx/config/validation/http_njs_match_test.go similarity index 100% rename from internal/mode/static/nginx/config/validation/http_njs_match_test.go rename to internal/controller/nginx/config/validation/http_njs_match_test.go diff --git a/internal/mode/static/nginx/config/validation/http_validator.go b/internal/controller/nginx/config/validation/http_validator.go similarity index 88% rename from internal/mode/static/nginx/config/validation/http_validator.go rename to internal/controller/nginx/config/validation/http_validator.go index a17cfdaa00..1d1bc84e44 100644 --- a/internal/mode/static/nginx/config/validation/http_validator.go +++ b/internal/controller/nginx/config/validation/http_validator.go @@ -1,7 +1,7 @@ package validation import ( - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" ) // HTTPValidator validates values that will propagate into the NGINX configuration http context. diff --git a/internal/mode/static/nginx/config/variable_names.go b/internal/controller/nginx/config/variable_names.go similarity index 100% rename from internal/mode/static/nginx/config/variable_names.go rename to internal/controller/nginx/config/variable_names.go diff --git a/internal/mode/static/nginx/config/variable_names_test.go b/internal/controller/nginx/config/variable_names_test.go similarity index 100% rename from internal/mode/static/nginx/config/variable_names_test.go rename to internal/controller/nginx/config/variable_names_test.go diff --git a/internal/mode/static/nginx/modules/.prettierrc b/internal/controller/nginx/modules/.prettierrc similarity index 100% rename from internal/mode/static/nginx/modules/.prettierrc rename to internal/controller/nginx/modules/.prettierrc diff --git a/internal/mode/static/nginx/modules/README.md b/internal/controller/nginx/modules/README.md similarity index 100% rename from internal/mode/static/nginx/modules/README.md rename to internal/controller/nginx/modules/README.md diff --git a/internal/mode/static/nginx/modules/package-lock.json b/internal/controller/nginx/modules/package-lock.json similarity index 100% rename from internal/mode/static/nginx/modules/package-lock.json rename to internal/controller/nginx/modules/package-lock.json diff --git a/internal/mode/static/nginx/modules/package.json b/internal/controller/nginx/modules/package.json similarity index 100% rename from internal/mode/static/nginx/modules/package.json rename to internal/controller/nginx/modules/package.json diff --git a/internal/mode/static/nginx/modules/src/httpmatches.js b/internal/controller/nginx/modules/src/httpmatches.js similarity index 100% rename from internal/mode/static/nginx/modules/src/httpmatches.js rename to internal/controller/nginx/modules/src/httpmatches.js diff --git a/internal/mode/static/nginx/modules/test/httpmatches.test.js b/internal/controller/nginx/modules/test/httpmatches.test.js similarity index 100% rename from internal/mode/static/nginx/modules/test/httpmatches.test.js rename to internal/controller/nginx/modules/test/httpmatches.test.js diff --git a/internal/mode/static/nginx/modules/test/vitest.config.ts b/internal/controller/nginx/modules/test/vitest.config.ts similarity index 100% rename from internal/mode/static/nginx/modules/test/vitest.config.ts rename to internal/controller/nginx/modules/test/vitest.config.ts diff --git a/internal/mode/static/provisioner/doc.go b/internal/controller/provisioner/doc.go similarity index 100% rename from internal/mode/static/provisioner/doc.go rename to internal/controller/provisioner/doc.go diff --git a/internal/mode/static/provisioner/eventloop.go b/internal/controller/provisioner/eventloop.go similarity index 98% rename from internal/mode/static/provisioner/eventloop.go rename to internal/controller/provisioner/eventloop.go index a3f61e3bad..7b85a47780 100644 --- a/internal/mode/static/provisioner/eventloop.go +++ b/internal/controller/provisioner/eventloop.go @@ -15,11 +15,11 @@ import ( k8spredicate "sigs.k8s.io/controller-runtime/pkg/predicate" gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" + "github.com/nginx/nginx-gateway-fabric/internal/controller/config" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller/predicate" "github.com/nginx/nginx-gateway-fabric/internal/framework/events" ngftypes "github.com/nginx/nginx-gateway-fabric/internal/framework/types" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" ) func newEventLoop( diff --git a/internal/mode/static/provisioner/handler.go b/internal/controller/provisioner/handler.go similarity index 99% rename from internal/mode/static/provisioner/handler.go rename to internal/controller/provisioner/handler.go index 832b1eebad..c5f3f2f4a9 100644 --- a/internal/mode/static/provisioner/handler.go +++ b/internal/controller/provisioner/handler.go @@ -17,9 +17,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller" "github.com/nginx/nginx-gateway-fabric/internal/framework/events" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/status" ) // eventHandler ensures each Gateway for the specific GatewayClass has a corresponding Deployment diff --git a/internal/mode/static/provisioner/handler_test.go b/internal/controller/provisioner/handler_test.go similarity index 98% rename from internal/mode/static/provisioner/handler_test.go rename to internal/controller/provisioner/handler_test.go index 1f44a27de0..4a14008a41 100644 --- a/internal/mode/static/provisioner/handler_test.go +++ b/internal/controller/provisioner/handler_test.go @@ -13,10 +13,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller" "github.com/nginx/nginx-gateway-fabric/internal/framework/events" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/status" ) func TestHandleEventBatch_Upsert(t *testing.T) { diff --git a/internal/mode/static/provisioner/objects.go b/internal/controller/provisioner/objects.go similarity index 99% rename from internal/mode/static/provisioner/objects.go rename to internal/controller/provisioner/objects.go index 2565557b85..e4afe5b194 100644 --- a/internal/mode/static/provisioner/objects.go +++ b/internal/controller/provisioner/objects.go @@ -19,10 +19,10 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" ) const ( diff --git a/internal/mode/static/provisioner/objects_test.go b/internal/controller/provisioner/objects_test.go similarity index 99% rename from internal/mode/static/provisioner/objects_test.go rename to internal/controller/provisioner/objects_test.go index f652e56b4d..061efc7c47 100644 --- a/internal/mode/static/provisioner/objects_test.go +++ b/internal/controller/provisioner/objects_test.go @@ -17,10 +17,10 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" ) func TestBuildNginxResourceObjects(t *testing.T) { diff --git a/internal/mode/static/provisioner/openshift/openshift.go b/internal/controller/provisioner/openshift/openshift.go similarity index 100% rename from internal/mode/static/provisioner/openshift/openshift.go rename to internal/controller/provisioner/openshift/openshift.go diff --git a/internal/mode/static/provisioner/openshift/openshiftfakes/fake_apichecker.go b/internal/controller/provisioner/openshift/openshiftfakes/fake_apichecker.go similarity index 97% rename from internal/mode/static/provisioner/openshift/openshiftfakes/fake_apichecker.go rename to internal/controller/provisioner/openshift/openshiftfakes/fake_apichecker.go index d1e108544d..6954af4a23 100644 --- a/internal/mode/static/provisioner/openshift/openshiftfakes/fake_apichecker.go +++ b/internal/controller/provisioner/openshift/openshiftfakes/fake_apichecker.go @@ -4,7 +4,7 @@ package openshiftfakes import ( "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/provisioner/openshift" + "github.com/nginx/nginx-gateway-fabric/internal/controller/provisioner/openshift" "k8s.io/client-go/rest" ) diff --git a/internal/mode/static/provisioner/provisioner.go b/internal/controller/provisioner/provisioner.go similarity index 97% rename from internal/mode/static/provisioner/provisioner.go rename to internal/controller/provisioner/provisioner.go index 8d9a44eef9..6c60cf1384 100644 --- a/internal/mode/static/provisioner/provisioner.go +++ b/internal/controller/provisioner/provisioner.go @@ -23,13 +23,13 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" + "github.com/nginx/nginx-gateway-fabric/internal/controller/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent" + "github.com/nginx/nginx-gateway-fabric/internal/controller/provisioner/openshift" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller" "github.com/nginx/nginx-gateway-fabric/internal/framework/events" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/provisioner/openshift" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/status" ) //go:generate go tool counterfeiter -generate diff --git a/internal/mode/static/provisioner/provisioner_test.go b/internal/controller/provisioner/provisioner_test.go similarity index 98% rename from internal/mode/static/provisioner/provisioner_test.go rename to internal/controller/provisioner/provisioner_test.go index 4339417c26..9102a8193f 100644 --- a/internal/mode/static/provisioner/provisioner_test.go +++ b/internal/controller/provisioner/provisioner_test.go @@ -20,12 +20,12 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent/agentfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/provisioner/openshift/openshiftfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent/agentfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/provisioner/openshift/openshiftfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" ) const ( diff --git a/internal/mode/static/provisioner/provisionerfakes/fake_provisioner.go b/internal/controller/provisioner/provisionerfakes/fake_provisioner.go similarity index 95% rename from internal/mode/static/provisioner/provisionerfakes/fake_provisioner.go rename to internal/controller/provisioner/provisionerfakes/fake_provisioner.go index b4359a1ceb..55c19c8717 100644 --- a/internal/mode/static/provisioner/provisionerfakes/fake_provisioner.go +++ b/internal/controller/provisioner/provisionerfakes/fake_provisioner.go @@ -5,8 +5,8 @@ import ( "context" "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/provisioner" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/provisioner" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" ) type FakeProvisioner struct { diff --git a/internal/mode/static/provisioner/setter.go b/internal/controller/provisioner/setter.go similarity index 100% rename from internal/mode/static/provisioner/setter.go rename to internal/controller/provisioner/setter.go diff --git a/internal/mode/static/provisioner/store.go b/internal/controller/provisioner/store.go similarity index 99% rename from internal/mode/static/provisioner/store.go rename to internal/controller/provisioner/store.go index 8b43a25ee8..d089a38f9b 100644 --- a/internal/mode/static/provisioner/store.go +++ b/internal/controller/provisioner/store.go @@ -13,7 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" ) // NginxResources are all of the NGINX resources deployed in relation to a Gateway. diff --git a/internal/mode/static/provisioner/store_test.go b/internal/controller/provisioner/store_test.go similarity index 99% rename from internal/mode/static/provisioner/store_test.go rename to internal/controller/provisioner/store_test.go index 41ede10652..a7ed469e98 100644 --- a/internal/mode/static/provisioner/store_test.go +++ b/internal/controller/provisioner/store_test.go @@ -14,9 +14,9 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" ) func TestNewStore(t *testing.T) { diff --git a/internal/mode/static/provisioner/templates.go b/internal/controller/provisioner/templates.go similarity index 100% rename from internal/mode/static/provisioner/templates.go rename to internal/controller/provisioner/templates.go diff --git a/internal/mode/static/sort/doc.go b/internal/controller/sort/doc.go similarity index 100% rename from internal/mode/static/sort/doc.go rename to internal/controller/sort/doc.go diff --git a/internal/mode/static/sort/sort.go b/internal/controller/sort/sort.go similarity index 100% rename from internal/mode/static/sort/sort.go rename to internal/controller/sort/sort.go diff --git a/internal/mode/static/sort/sort_test.go b/internal/controller/sort/sort_test.go similarity index 100% rename from internal/mode/static/sort/sort_test.go rename to internal/controller/sort/sort_test.go diff --git a/internal/mode/static/state/change_processor.go b/internal/controller/state/change_processor.go similarity index 96% rename from internal/mode/static/state/change_processor.go rename to internal/controller/state/change_processor.go index 1d136383b8..a3b43979c5 100644 --- a/internal/mode/static/state/change_processor.go +++ b/internal/controller/state/change_processor.go @@ -18,12 +18,11 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/gatewayclass" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" ngftypes "github.com/nginx/nginx-gateway-fabric/internal/framework/types" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" ) //go:generate go tool counterfeiter -generate @@ -185,7 +184,7 @@ func NewChangeProcessorImpl(cfg ChangeProcessorConfig) *ChangeProcessorImpl { { gvk: cfg.MustExtractGVK(&apiext.CustomResourceDefinition{}), store: newObjectStoreMapAdapter(clusterStore.CRDMetadata), - predicate: annotationChangedPredicate{annotation: gatewayclass.BundleVersionAnnotation}, + predicate: annotationChangedPredicate{annotation: graph.BundleVersionAnnotation}, }, { gvk: cfg.MustExtractGVK(&ngfAPIv1alpha2.NginxProxy{}), diff --git a/internal/mode/static/state/change_processor_test.go b/internal/controller/state/change_processor_test.go similarity index 98% rename from internal/mode/static/state/change_processor_test.go rename to internal/controller/state/change_processor_test.go index 4797710fa3..ca5979324a 100644 --- a/internal/mode/static/state/change_processor_test.go +++ b/internal/controller/state/change_processor_test.go @@ -21,17 +21,15 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation/validationfakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller/index" - "github.com/nginx/nginx-gateway-fabric/internal/framework/gatewayclass" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" ngftypes "github.com/nginx/nginx-gateway-fabric/internal/framework/types" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation/validationfakes" ) const ( @@ -668,13 +666,13 @@ var _ = Describe("ChangeProcessor", func() { ObjectMeta: metav1.ObjectMeta{ Name: "gatewayclasses.gateway.networking.k8s.io", Annotations: map[string]string{ - gatewayclass.BundleVersionAnnotation: gatewayclass.SupportedVersion, + graph.BundleVersionAnnotation: graph.SupportedVersion, }, }, } gatewayAPICRDUpdated = gatewayAPICRD.DeepCopy() - gatewayAPICRDUpdated.Annotations[gatewayclass.BundleVersionAnnotation] = "v1.99.0" + gatewayAPICRDUpdated.Annotations[graph.BundleVersionAnnotation] = "v1.99.0" }) BeforeEach(func() { expRouteHR1 = &graph.L7Route{ @@ -739,7 +737,7 @@ var _ = Describe("ChangeProcessor", func() { Valid: true, Attachable: true, Conditions: []conditions.Condition{ - staticConds.NewRouteBackendRefRefBackendNotFound( + conditions.NewRouteBackendRefRefBackendNotFound( "spec.rules[0].backendRefs[0].name: Not found: \"service\"", ), }, @@ -807,7 +805,7 @@ var _ = Describe("ChangeProcessor", func() { Valid: true, Attachable: true, Conditions: []conditions.Condition{ - staticConds.NewRouteBackendRefRefBackendNotFound( + conditions.NewRouteBackendRefRefBackendNotFound( "spec.rules[0].backendRefs[0].name: Not found: \"service\"", ), }, @@ -875,7 +873,7 @@ var _ = Describe("ChangeProcessor", func() { Valid: true, Attachable: true, Conditions: []conditions.Condition{ - staticConds.NewRouteBackendRefRefBackendNotFound( + conditions.NewRouteBackendRefRefBackendNotFound( "spec.rules[0].backendRefs[0].name: Not found: \"grpc-service\"", ), }, @@ -943,7 +941,7 @@ var _ = Describe("ChangeProcessor", func() { Valid: true, Attachable: true, Conditions: []conditions.Condition{ - staticConds.NewRouteBackendRefRefBackendNotFound( + conditions.NewRouteBackendRefRefBackendNotFound( "spec.rules[0].backendRefs[0].name: Not found: \"grpc-service\"", ), }, @@ -979,7 +977,7 @@ var _ = Describe("ChangeProcessor", func() { Valid: true, Attachable: true, Conditions: []conditions.Condition{ - staticConds.NewRouteBackendRefRefBackendNotFound( + conditions.NewRouteBackendRefRefBackendNotFound( "spec.rules[0].backendRefs[0].name: Not found: \"tls-service\"", ), }, @@ -1015,7 +1013,7 @@ var _ = Describe("ChangeProcessor", func() { Valid: true, Attachable: true, Conditions: []conditions.Condition{ - staticConds.NewRouteBackendRefRefBackendNotFound( + conditions.NewRouteBackendRefRefBackendNotFound( "spec.rules[0].backendRefs[0].name: Not found: \"tls-service\"", ), }, @@ -1278,27 +1276,27 @@ var _ = Describe("ChangeProcessor", func() { expGraph.GatewayClass = nil gw := expGraph.Gateways[types.NamespacedName{Namespace: "test", Name: "gateway-1"}] - gw.Conditions = staticConds.NewGatewayInvalid("GatewayClass doesn't exist") + gw.Conditions = conditions.NewGatewayInvalid("GatewayClass doesn't exist") gw.Valid = false gw.Listeners = nil // no ref grant exists yet for the routes expGraph.Routes[httpRouteKey1].Conditions = []conditions.Condition{ - staticConds.NewRouteBackendRefRefNotPermitted( + conditions.NewRouteBackendRefRefNotPermitted( "spec.rules[0].backendRefs[0].namespace: Forbidden: " + "Backend ref to Service service-ns/service not permitted by any ReferenceGrant", ), } expGraph.Routes[grpcRouteKey1].Conditions = []conditions.Condition{ - staticConds.NewRouteBackendRefRefNotPermitted( + conditions.NewRouteBackendRefRefNotPermitted( "spec.rules[0].backendRefs[0].namespace: Forbidden: Backend ref to Service " + "grpc-service-ns/grpc-service not permitted by any ReferenceGrant", ), } expGraph.L4Routes[trKey1].Conditions = []conditions.Condition{ - staticConds.NewRouteBackendRefRefNotPermitted( + conditions.NewRouteBackendRefRefNotPermitted( "spec.rules[0].backendRefs[0].namespace: Forbidden: Backend ref to Service " + "tls-service-ns/tls-service not permitted by any ReferenceGrant", ), @@ -1307,23 +1305,23 @@ var _ = Describe("ChangeProcessor", func() { // gateway class does not exist so routes cannot attach expGraph.Routes[httpRouteKey1].ParentRefs[0].Attachment = &graph.ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedConditions: []conditions.Condition{staticConds.NewRouteNoMatchingParent()}, + FailedConditions: []conditions.Condition{conditions.NewRouteNoMatchingParent()}, } expGraph.Routes[httpRouteKey1].ParentRefs[1].Attachment = &graph.ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedConditions: []conditions.Condition{staticConds.NewRouteNoMatchingParent()}, + FailedConditions: []conditions.Condition{conditions.NewRouteNoMatchingParent()}, } expGraph.Routes[grpcRouteKey1].ParentRefs[0].Attachment = &graph.ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedConditions: []conditions.Condition{staticConds.NewRouteNoMatchingParent()}, + FailedConditions: []conditions.Condition{conditions.NewRouteNoMatchingParent()}, } expGraph.Routes[grpcRouteKey1].ParentRefs[1].Attachment = &graph.ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedConditions: []conditions.Condition{staticConds.NewRouteNoMatchingParent()}, + FailedConditions: []conditions.Condition{conditions.NewRouteNoMatchingParent()}, } expGraph.L4Routes[trKey1].ParentRefs[0].Attachment = &graph.ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedConditions: []conditions.Condition{staticConds.NewRouteNoMatchingParent()}, + FailedConditions: []conditions.Condition{conditions.NewRouteNoMatchingParent()}, } expGraph.ReferencedSecrets = nil @@ -1348,7 +1346,7 @@ var _ = Describe("ChangeProcessor", func() { listener443 := getListenerByName(gw, httpsListenerName) listener443.Valid = false listener443.ResolvedSecret = nil - listener443.Conditions = staticConds.NewListenerRefNotPermitted( + listener443.Conditions = conditions.NewListenerRefNotPermitted( "Certificate ref to secret cert-ns/different-ns-tls-secret not permitted by any ReferenceGrant", ) @@ -1382,29 +1380,29 @@ var _ = Describe("ChangeProcessor", func() { // no ref grant exists yet for hr1 expGraph.Routes[httpRouteKey1].Conditions = []conditions.Condition{ - staticConds.NewRouteBackendRefRefNotPermitted( + conditions.NewRouteBackendRefRefNotPermitted( "spec.rules[0].backendRefs[0].namespace: Forbidden: Backend ref to Service " + "service-ns/service not permitted by any ReferenceGrant", ), - staticConds.NewRouteInvalidListener(), + conditions.NewRouteInvalidListener(), } expGraph.Routes[httpRouteKey1].ParentRefs[0].Attachment = expAttachment80 expGraph.Routes[httpRouteKey1].ParentRefs[1].Attachment = expAttachment443 // no ref grant exists yet for gr1 expGraph.Routes[grpcRouteKey1].Conditions = []conditions.Condition{ - staticConds.NewRouteBackendRefRefNotPermitted( + conditions.NewRouteBackendRefRefNotPermitted( "spec.rules[0].backendRefs[0].namespace: Forbidden: Backend ref to Service " + "grpc-service-ns/grpc-service not permitted by any ReferenceGrant", ), - staticConds.NewRouteInvalidListener(), + conditions.NewRouteInvalidListener(), } expGraph.Routes[grpcRouteKey1].ParentRefs[0].Attachment = expAttachment80 expGraph.Routes[grpcRouteKey1].ParentRefs[1].Attachment = expAttachment443 // no ref grant exists yet for tr1 expGraph.L4Routes[trKey1].Conditions = []conditions.Condition{ - staticConds.NewRouteBackendRefRefNotPermitted( + conditions.NewRouteBackendRefRefNotPermitted( "spec.rules[0].backendRefs[0].namespace: Forbidden: Backend ref to Service " + "tls-service-ns/tls-service not permitted by any ReferenceGrant", ), @@ -1426,7 +1424,7 @@ var _ = Describe("ChangeProcessor", func() { // no ref grant exists yet for hr1 expGraph.Routes[httpRouteKey1].Conditions = []conditions.Condition{ - staticConds.NewRouteBackendRefRefNotPermitted( + conditions.NewRouteBackendRefRefNotPermitted( "spec.rules[0].backendRefs[0].namespace: Forbidden: Backend ref to Service " + "service-ns/service not permitted by any ReferenceGrant", ), @@ -1434,7 +1432,7 @@ var _ = Describe("ChangeProcessor", func() { // no ref grant exists yet for gr1 expGraph.Routes[grpcRouteKey1].Conditions = []conditions.Condition{ - staticConds.NewRouteBackendRefRefNotPermitted( + conditions.NewRouteBackendRefRefNotPermitted( "spec.rules[0].backendRefs[0].namespace: Forbidden: Backend ref to Service " + "grpc-service-ns/grpc-service not permitted by any ReferenceGrant", ), @@ -1442,7 +1440,7 @@ var _ = Describe("ChangeProcessor", func() { // no ref grant exists yet for tr1 expGraph.L4Routes[trKey1].Conditions = []conditions.Condition{ - staticConds.NewRouteBackendRefRefNotPermitted( + conditions.NewRouteBackendRefRefNotPermitted( "spec.rules[0].backendRefs[0].namespace: Forbidden: Backend ref to Service " + "tls-service-ns/tls-service not permitted by any ReferenceGrant", ), @@ -1474,7 +1472,7 @@ var _ = Describe("ChangeProcessor", func() { // no ref grant exists yet for gr1 expGraph.Routes[grpcRouteKey1].Conditions = []conditions.Condition{ - staticConds.NewRouteBackendRefRefNotPermitted( + conditions.NewRouteBackendRefRefNotPermitted( "spec.rules[0].backendRefs[0].namespace: Forbidden: Backend ref to Service " + "grpc-service-ns/grpc-service not permitted by any ReferenceGrant", ), @@ -1484,7 +1482,7 @@ var _ = Describe("ChangeProcessor", func() { // no ref grant exists yet for tr1 expGraph.L4Routes[trKey1].Conditions = []conditions.Condition{ - staticConds.NewRouteBackendRefRefNotPermitted( + conditions.NewRouteBackendRefRefNotPermitted( "spec.rules[0].backendRefs[0].namespace: Forbidden: Backend ref to Service " + "tls-service-ns/tls-service not permitted by any ReferenceGrant", ), @@ -1513,7 +1511,7 @@ var _ = Describe("ChangeProcessor", func() { // no ref grant exists yet for tr1 expGraph.L4Routes[trKey1].Conditions = []conditions.Condition{ - staticConds.NewRouteBackendRefRefNotPermitted( + conditions.NewRouteBackendRefRefNotPermitted( "spec.rules[0].backendRefs[0].namespace: Forbidden: Backend ref to Service " + "tls-service-ns/tls-service not permitted by any ReferenceGrant", ), @@ -1558,7 +1556,7 @@ var _ = Describe("ChangeProcessor", func() { } expGraph.GatewayClass.Conditions = conditions.NewGatewayClassSupportedVersionBestEffort( - gatewayclass.SupportedVersion, + graph.SupportedVersion, ) processAndValidateGraph(expGraph) @@ -1576,7 +1574,7 @@ var _ = Describe("ChangeProcessor", func() { } expGraph.GatewayClass.Conditions = conditions.NewGatewayClassSupportedVersionBestEffort( - gatewayclass.SupportedVersion, + graph.SupportedVersion, ) graphCfg := processor.Process() @@ -2255,7 +2253,7 @@ var _ = Describe("ChangeProcessor", func() { }, }, }, - Conditions: staticConds.NewGatewayInvalid("GatewayClass doesn't exist"), + Conditions: conditions.NewGatewayInvalid("GatewayClass doesn't exist"), DeploymentName: types.NamespacedName{ Namespace: "test", Name: "gateway-2-test-class", diff --git a/internal/mode/static/state/changed_predicate.go b/internal/controller/state/changed_predicate.go similarity index 100% rename from internal/mode/static/state/changed_predicate.go rename to internal/controller/state/changed_predicate.go diff --git a/internal/mode/static/state/changed_predicate_test.go b/internal/controller/state/changed_predicate_test.go similarity index 100% rename from internal/mode/static/state/changed_predicate_test.go rename to internal/controller/state/changed_predicate_test.go diff --git a/internal/mode/static/state/conditions/conditions.go b/internal/controller/state/conditions/conditions.go similarity index 74% rename from internal/mode/static/state/conditions/conditions.go rename to internal/controller/state/conditions/conditions.go index e864e12103..b9ec5f10cf 100644 --- a/internal/mode/static/state/conditions/conditions.go +++ b/internal/controller/state/conditions/conditions.go @@ -8,10 +8,18 @@ import ( "sigs.k8s.io/gateway-api/apis/v1alpha2" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" ) const ( + // GatewayClassReasonGatewayClassConflict indicates there are multiple GatewayClass resources + // that reference this controller, and we ignored the resource in question and picked the + // GatewayClass that is referenced in the command-line argument. + // This reason is used with GatewayClassConditionAccepted (false). + GatewayClassReasonGatewayClassConflict v1.GatewayClassConditionReason = "GatewayClassConflict" + + // GatewayClassMessageGatewayClassConflict is a message that describes GatewayClassReasonGatewayClassConflict. + GatewayClassMessageGatewayClassConflict = "The resource is ignored due to a conflicting GatewayClass resource" + // ListenerReasonUnsupportedValue is used with the "Accepted" condition when a value of a field in a Listener // is invalid or not supported. ListenerReasonUnsupportedValue v1.ListenerConditionReason = "UnsupportedValue" @@ -115,9 +123,143 @@ const ( GatewayReasonParamsRefInvalid v1.GatewayConditionReason = "ParametersRefInvalid" ) +// Condition defines a condition to be reported in the status of resources. +type Condition struct { + Type string + Status metav1.ConditionStatus + Reason string + Message string +} + +// DeduplicateConditions removes duplicate conditions based on the condition type. +// The last condition wins. The order of conditions is preserved. +func DeduplicateConditions(conds []Condition) []Condition { + type elem struct { + cond Condition + reverseIdx int + } + + uniqueElems := make(map[string]elem) + + idx := 0 + for i := len(conds) - 1; i >= 0; i-- { + if _, exist := uniqueElems[conds[i].Type]; exist { + continue + } + + uniqueElems[conds[i].Type] = elem{ + cond: conds[i], + reverseIdx: idx, + } + idx++ + } + + result := make([]Condition, len(uniqueElems)) + + for _, el := range uniqueElems { + result[len(result)-el.reverseIdx-1] = el.cond + } + + return result +} + +// ConvertConditions converts conditions to Kubernetes API conditions. +func ConvertConditions( + conds []Condition, + observedGeneration int64, + transitionTime metav1.Time, +) []metav1.Condition { + apiConds := make([]metav1.Condition, len(conds)) + + for i := range conds { + apiConds[i] = metav1.Condition{ + Type: conds[i].Type, + Status: conds[i].Status, + ObservedGeneration: observedGeneration, + LastTransitionTime: transitionTime, + Reason: conds[i].Reason, + Message: conds[i].Message, + } + } + + return apiConds +} + +// NewDefaultGatewayClassConditions returns Conditions that indicate that the GatewayClass is accepted and that the +// Gateway API CRD versions are supported. +func NewDefaultGatewayClassConditions() []Condition { + return []Condition{ + { + Type: string(v1.GatewayClassConditionStatusAccepted), + Status: metav1.ConditionTrue, + Reason: string(v1.GatewayClassReasonAccepted), + Message: "GatewayClass is accepted", + }, + { + Type: string(v1.GatewayClassConditionStatusSupportedVersion), + Status: metav1.ConditionTrue, + Reason: string(v1.GatewayClassReasonSupportedVersion), + Message: "Gateway API CRD versions are supported", + }, + } +} + +// NewGatewayClassSupportedVersionBestEffort returns a Condition that indicates that the GatewayClass is accepted, +// but the Gateway API CRD versions are not supported. This means NGF will attempt to generate configuration, +// but it does not guarantee support. +func NewGatewayClassSupportedVersionBestEffort(recommendedVersion string) []Condition { + return []Condition{ + { + Type: string(v1.GatewayClassConditionStatusSupportedVersion), + Status: metav1.ConditionFalse, + Reason: string(v1.GatewayClassReasonUnsupportedVersion), + Message: fmt.Sprintf( + "Gateway API CRD versions are not recommended. Recommended version is %s", + recommendedVersion, + ), + }, + } +} + +// NewGatewayClassUnsupportedVersion returns Conditions that indicate that the GatewayClass is not accepted because +// the Gateway API CRD versions are not supported. NGF will not generate configuration in this case. +func NewGatewayClassUnsupportedVersion(recommendedVersion string) []Condition { + return []Condition{ + { + Type: string(v1.GatewayClassConditionStatusAccepted), + Status: metav1.ConditionFalse, + Reason: string(v1.GatewayClassReasonUnsupportedVersion), + Message: fmt.Sprintf( + "Gateway API CRD versions are not supported. Please install version %s", + recommendedVersion, + ), + }, + { + Type: string(v1.GatewayClassConditionStatusSupportedVersion), + Status: metav1.ConditionFalse, + Reason: string(v1.GatewayClassReasonUnsupportedVersion), + Message: fmt.Sprintf( + "Gateway API CRD versions are not supported. Please install version %s", + recommendedVersion, + ), + }, + } +} + +// NewGatewayClassConflict returns a Condition that indicates that the GatewayClass is not accepted +// due to a conflict with another GatewayClass. +func NewGatewayClassConflict() Condition { + return Condition{ + Type: string(v1.GatewayClassConditionStatusAccepted), + Status: metav1.ConditionFalse, + Reason: string(GatewayClassReasonGatewayClassConflict), + Message: GatewayClassMessageGatewayClassConflict, + } +} + // NewDefaultRouteConditions returns the default conditions that must be present in the status of a Route. -func NewDefaultRouteConditions() []conditions.Condition { - return []conditions.Condition{ +func NewDefaultRouteConditions() []Condition { + return []Condition{ NewRouteAccepted(), NewRouteResolvedRefs(), } @@ -125,8 +267,8 @@ func NewDefaultRouteConditions() []conditions.Condition { // NewRouteNotAllowedByListeners returns a Condition that indicates that the Route is not allowed by // any listener. -func NewRouteNotAllowedByListeners() conditions.Condition { - return conditions.Condition{ +func NewRouteNotAllowedByListeners() Condition { + return Condition{ Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(v1.RouteReasonNotAllowedByListeners), @@ -136,8 +278,8 @@ func NewRouteNotAllowedByListeners() conditions.Condition { // NewRouteNoMatchingListenerHostname returns a Condition that indicates that the hostname of the listener // does not match the hostnames of the Route. -func NewRouteNoMatchingListenerHostname() conditions.Condition { - return conditions.Condition{ +func NewRouteNoMatchingListenerHostname() Condition { + return Condition{ Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(v1.RouteReasonNoMatchingListenerHostname), @@ -146,8 +288,8 @@ func NewRouteNoMatchingListenerHostname() conditions.Condition { } // NewRouteAccepted returns a Condition that indicates that the Route is accepted. -func NewRouteAccepted() conditions.Condition { - return conditions.Condition{ +func NewRouteAccepted() Condition { + return Condition{ Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionTrue, Reason: string(v1.RouteReasonAccepted), @@ -156,8 +298,8 @@ func NewRouteAccepted() conditions.Condition { } // NewRouteUnsupportedValue returns a Condition that indicates that the Route includes an unsupported value. -func NewRouteUnsupportedValue(msg string) conditions.Condition { - return conditions.Condition{ +func NewRouteUnsupportedValue(msg string) Condition { + return Condition{ Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(v1.RouteReasonUnsupportedValue), @@ -171,8 +313,8 @@ func NewRouteUnsupportedValue(msg string) conditions.Condition { // // nolint:lll // The message must start with "Dropped Rules(s)" according to the Gateway API spec // See https://github.com/kubernetes-sigs/gateway-api/blob/37d81593e5a965ed76582dbc1a2f56bbd57c0622/apis/v1/shared_types.go#L408-L413 -func NewRoutePartiallyInvalid(msg string) conditions.Condition { - return conditions.Condition{ +func NewRoutePartiallyInvalid(msg string) Condition { + return Condition{ Type: string(v1.RouteConditionPartiallyInvalid), Status: metav1.ConditionTrue, Reason: string(v1.RouteReasonUnsupportedValue), @@ -182,8 +324,8 @@ func NewRoutePartiallyInvalid(msg string) conditions.Condition { // NewRouteInvalidListener returns a Condition that indicates that the Route is not accepted because of an // invalid listener. -func NewRouteInvalidListener() conditions.Condition { - return conditions.Condition{ +func NewRouteInvalidListener() Condition { + return Condition{ Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(RouteReasonInvalidListener), @@ -193,8 +335,8 @@ func NewRouteInvalidListener() conditions.Condition { // NewRouteHostnameConflict returns a Condition that indicates that the Route is not accepted because of a // conflicting hostname on the same port. -func NewRouteHostnameConflict() conditions.Condition { - return conditions.Condition{ +func NewRouteHostnameConflict() Condition { + return Condition{ Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(RouteReasonHostnameConflict), @@ -203,8 +345,8 @@ func NewRouteHostnameConflict() conditions.Condition { } // NewRouteResolvedRefs returns a Condition that indicates that all the references on the Route are resolved. -func NewRouteResolvedRefs() conditions.Condition { - return conditions.Condition{ +func NewRouteResolvedRefs() Condition { + return Condition{ Type: string(v1.RouteConditionResolvedRefs), Status: metav1.ConditionTrue, Reason: string(v1.RouteReasonResolvedRefs), @@ -214,8 +356,8 @@ func NewRouteResolvedRefs() conditions.Condition { // NewRouteBackendRefInvalidKind returns a Condition that indicates that the Route has a backendRef with an // invalid kind. -func NewRouteBackendRefInvalidKind(msg string) conditions.Condition { - return conditions.Condition{ +func NewRouteBackendRefInvalidKind(msg string) Condition { + return Condition{ Type: string(v1.RouteConditionResolvedRefs), Status: metav1.ConditionFalse, Reason: string(v1.RouteReasonInvalidKind), @@ -225,8 +367,8 @@ func NewRouteBackendRefInvalidKind(msg string) conditions.Condition { // NewRouteBackendRefRefNotPermitted returns a Condition that indicates that the Route has a backendRef that // is not permitted. -func NewRouteBackendRefRefNotPermitted(msg string) conditions.Condition { - return conditions.Condition{ +func NewRouteBackendRefRefNotPermitted(msg string) Condition { + return Condition{ Type: string(v1.RouteConditionResolvedRefs), Status: metav1.ConditionFalse, Reason: string(v1.RouteReasonRefNotPermitted), @@ -236,8 +378,8 @@ func NewRouteBackendRefRefNotPermitted(msg string) conditions.Condition { // NewRouteBackendRefRefBackendNotFound returns a Condition that indicates that the Route has a backendRef that // points to non-existing backend. -func NewRouteBackendRefRefBackendNotFound(msg string) conditions.Condition { - return conditions.Condition{ +func NewRouteBackendRefRefBackendNotFound(msg string) Condition { + return Condition{ Type: string(v1.RouteConditionResolvedRefs), Status: metav1.ConditionFalse, Reason: string(v1.RouteReasonBackendNotFound), @@ -247,8 +389,8 @@ func NewRouteBackendRefRefBackendNotFound(msg string) conditions.Condition { // NewRouteBackendRefUnsupportedValue returns a Condition that indicates that the Route has a backendRef with // an unsupported value. -func NewRouteBackendRefUnsupportedValue(msg string) conditions.Condition { - return conditions.Condition{ +func NewRouteBackendRefUnsupportedValue(msg string) Condition { + return Condition{ Type: string(v1.RouteConditionResolvedRefs), Status: metav1.ConditionFalse, Reason: string(RouteReasonBackendRefUnsupportedValue), @@ -258,8 +400,8 @@ func NewRouteBackendRefUnsupportedValue(msg string) conditions.Condition { // NewRouteInvalidGateway returns a Condition that indicates that the Route is not Accepted because the Gateway it // references is invalid. -func NewRouteInvalidGateway() conditions.Condition { - return conditions.Condition{ +func NewRouteInvalidGateway() Condition { + return Condition{ Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(RouteReasonInvalidGateway), @@ -269,8 +411,8 @@ func NewRouteInvalidGateway() conditions.Condition { // NewRouteNoMatchingParent returns a Condition that indicates that the Route is not Accepted because // it specifies a Port and/or SectionName that does not match any Listeners in the Gateway. -func NewRouteNoMatchingParent() conditions.Condition { - return conditions.Condition{ +func NewRouteNoMatchingParent() Condition { + return Condition{ Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(v1.RouteReasonNoMatchingParent), @@ -280,8 +422,8 @@ func NewRouteNoMatchingParent() conditions.Condition { // NewRouteUnsupportedConfiguration returns a Condition that indicates that the Route is not Accepted because // it is incompatible with the Gateway's configuration. -func NewRouteUnsupportedConfiguration(msg string) conditions.Condition { - return conditions.Condition{ +func NewRouteUnsupportedConfiguration(msg string) Condition { + return Condition{ Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(RouteReasonUnsupportedConfiguration), @@ -291,8 +433,8 @@ func NewRouteUnsupportedConfiguration(msg string) conditions.Condition { // NewRouteGatewayNotProgrammed returns a Condition that indicates that the Gateway it references is not programmed, // which does not guarantee that the Route has been configured. -func NewRouteGatewayNotProgrammed(msg string) conditions.Condition { - return conditions.Condition{ +func NewRouteGatewayNotProgrammed(msg string) Condition { + return Condition{ Type: string(v1.RouteConditionAccepted), Status: metav1.ConditionFalse, Reason: string(RouteReasonGatewayNotProgrammed), @@ -302,8 +444,8 @@ func NewRouteGatewayNotProgrammed(msg string) conditions.Condition { // NewRouteInvalidIPFamily returns a Condition that indicates that the Service associated with the Route // is not configured with the same IP family as the NGINX server. -func NewRouteInvalidIPFamily(msg string) conditions.Condition { - return conditions.Condition{ +func NewRouteInvalidIPFamily(msg string) Condition { + return Condition{ Type: string(v1.RouteConditionResolvedRefs), Status: metav1.ConditionFalse, Reason: string(RouteReasonInvalidIPFamily), @@ -313,8 +455,8 @@ func NewRouteInvalidIPFamily(msg string) conditions.Condition { // NewRouteResolvedRefsInvalidFilter returns a Condition that indicates that the Route has a filter that // cannot be resolved or is invalid. -func NewRouteResolvedRefsInvalidFilter(msg string) conditions.Condition { - return conditions.Condition{ +func NewRouteResolvedRefsInvalidFilter(msg string) Condition { + return Condition{ Type: string(v1.RouteConditionResolvedRefs), Status: metav1.ConditionFalse, Reason: string(RouteReasonInvalidFilter), @@ -323,8 +465,8 @@ func NewRouteResolvedRefsInvalidFilter(msg string) conditions.Condition { } // NewDefaultListenerConditions returns the default Conditions that must be present in the status of a Listener. -func NewDefaultListenerConditions() []conditions.Condition { - return []conditions.Condition{ +func NewDefaultListenerConditions() []Condition { + return []Condition{ NewListenerAccepted(), NewListenerProgrammed(), NewListenerResolvedRefs(), @@ -333,8 +475,8 @@ func NewDefaultListenerConditions() []conditions.Condition { } // NewListenerAccepted returns a Condition that indicates that the Listener is accepted. -func NewListenerAccepted() conditions.Condition { - return conditions.Condition{ +func NewListenerAccepted() Condition { + return Condition{ Type: string(v1.ListenerConditionAccepted), Status: metav1.ConditionTrue, Reason: string(v1.ListenerReasonAccepted), @@ -343,8 +485,8 @@ func NewListenerAccepted() conditions.Condition { } // NewListenerProgrammed returns a Condition that indicates the Listener is programmed. -func NewListenerProgrammed() conditions.Condition { - return conditions.Condition{ +func NewListenerProgrammed() Condition { + return Condition{ Type: string(v1.ListenerConditionProgrammed), Status: metav1.ConditionTrue, Reason: string(v1.ListenerReasonProgrammed), @@ -353,8 +495,8 @@ func NewListenerProgrammed() conditions.Condition { } // NewListenerResolvedRefs returns a Condition that indicates that all references in a Listener are resolved. -func NewListenerResolvedRefs() conditions.Condition { - return conditions.Condition{ +func NewListenerResolvedRefs() Condition { + return Condition{ Type: string(v1.ListenerConditionResolvedRefs), Status: metav1.ConditionTrue, Reason: string(v1.ListenerReasonResolvedRefs), @@ -363,8 +505,8 @@ func NewListenerResolvedRefs() conditions.Condition { } // NewListenerNoConflicts returns a Condition that indicates that there are no conflicts in a Listener. -func NewListenerNoConflicts() conditions.Condition { - return conditions.Condition{ +func NewListenerNoConflicts() Condition { + return Condition{ Type: string(v1.ListenerConditionConflicted), Status: metav1.ConditionFalse, Reason: string(v1.ListenerReasonNoConflicts), @@ -374,8 +516,8 @@ func NewListenerNoConflicts() conditions.Condition { // NewListenerNotProgrammedInvalid returns a Condition that indicates the Listener is not programmed because it is // semantically or syntactically invalid. The provided message contains the details of why the Listener is invalid. -func NewListenerNotProgrammedInvalid(msg string) conditions.Condition { - return conditions.Condition{ +func NewListenerNotProgrammedInvalid(msg string) Condition { + return Condition{ Type: string(v1.ListenerConditionProgrammed), Status: metav1.ConditionFalse, Reason: string(v1.ListenerReasonInvalid), @@ -385,8 +527,8 @@ func NewListenerNotProgrammedInvalid(msg string) conditions.Condition { // NewListenerUnsupportedValue returns Conditions that indicate that a field of a Listener has an unsupported value. // Unsupported means that the value is not supported by the implementation or invalid. -func NewListenerUnsupportedValue(msg string) []conditions.Condition { - return []conditions.Condition{ +func NewListenerUnsupportedValue(msg string) []Condition { + return []Condition{ { Type: string(v1.ListenerConditionAccepted), Status: metav1.ConditionFalse, @@ -398,8 +540,8 @@ func NewListenerUnsupportedValue(msg string) []conditions.Condition { } // NewListenerInvalidCertificateRef returns Conditions that indicate that a CertificateRef of a Listener is invalid. -func NewListenerInvalidCertificateRef(msg string) []conditions.Condition { - return []conditions.Condition{ +func NewListenerInvalidCertificateRef(msg string) []Condition { + return []Condition{ { Type: string(v1.ListenerConditionAccepted), Status: metav1.ConditionFalse, @@ -418,8 +560,8 @@ func NewListenerInvalidCertificateRef(msg string) []conditions.Condition { // NewListenerInvalidRouteKinds returns Conditions that indicate that an invalid or unsupported Route kind is // specified by the Listener. -func NewListenerInvalidRouteKinds(msg string) []conditions.Condition { - return []conditions.Condition{ +func NewListenerInvalidRouteKinds(msg string) []Condition { + return []Condition{ { Type: string(v1.ListenerReasonResolvedRefs), Status: metav1.ConditionFalse, @@ -432,8 +574,8 @@ func NewListenerInvalidRouteKinds(msg string) []conditions.Condition { // NewListenerProtocolConflict returns Conditions that indicate multiple Listeners are specified with the same // Listener port number, but have conflicting protocol specifications. -func NewListenerProtocolConflict(msg string) []conditions.Condition { - return []conditions.Condition{ +func NewListenerProtocolConflict(msg string) []Condition { + return []Condition{ { Type: string(v1.ListenerConditionAccepted), Status: metav1.ConditionFalse, @@ -452,8 +594,8 @@ func NewListenerProtocolConflict(msg string) []conditions.Condition { // NewListenerHostnameConflict returns Conditions that indicate multiple Listeners are specified with the same // Listener port, but are HTTPS and TLS and have overlapping hostnames. -func NewListenerHostnameConflict(msg string) []conditions.Condition { - return []conditions.Condition{ +func NewListenerHostnameConflict(msg string) []Condition { + return []Condition{ { Type: string(v1.ListenerConditionAccepted), Status: metav1.ConditionFalse, @@ -471,8 +613,8 @@ func NewListenerHostnameConflict(msg string) []conditions.Condition { } // NewListenerUnsupportedProtocol returns Conditions that indicate that the protocol of a Listener is unsupported. -func NewListenerUnsupportedProtocol(msg string) []conditions.Condition { - return []conditions.Condition{ +func NewListenerUnsupportedProtocol(msg string) []Condition { + return []Condition{ { Type: string(v1.ListenerConditionAccepted), Status: metav1.ConditionFalse, @@ -485,8 +627,8 @@ func NewListenerUnsupportedProtocol(msg string) []conditions.Condition { // NewListenerRefNotPermitted returns Conditions that indicates that the Listener references a TLS secret that is not // permitted by a ReferenceGrant. -func NewListenerRefNotPermitted(msg string) []conditions.Condition { - return []conditions.Condition{ +func NewListenerRefNotPermitted(msg string) []Condition { + return []Condition{ { Type: string(v1.ListenerConditionAccepted), Status: metav1.ConditionFalse, @@ -505,8 +647,8 @@ func NewListenerRefNotPermitted(msg string) []conditions.Condition { // NewGatewayClassResolvedRefs returns a Condition that indicates that the parametersRef // on the GatewayClass is resolved. -func NewGatewayClassResolvedRefs() conditions.Condition { - return conditions.Condition{ +func NewGatewayClassResolvedRefs() Condition { + return Condition{ Type: string(GatewayClassResolvedRefs), Status: metav1.ConditionTrue, Reason: string(GatewayClassReasonResolvedRefs), @@ -516,8 +658,8 @@ func NewGatewayClassResolvedRefs() conditions.Condition { // NewGatewayClassRefNotFound returns a Condition that indicates that the parametersRef // on the GatewayClass could not be resolved. -func NewGatewayClassRefNotFound() conditions.Condition { - return conditions.Condition{ +func NewGatewayClassRefNotFound() Condition { + return Condition{ Type: string(GatewayClassResolvedRefs), Status: metav1.ConditionFalse, Reason: string(GatewayClassReasonParamsRefNotFound), @@ -527,8 +669,8 @@ func NewGatewayClassRefNotFound() conditions.Condition { // NewGatewayClassRefInvalid returns a Condition that indicates that the parametersRef // on the GatewayClass could not be resolved because the resource it references is invalid. -func NewGatewayClassRefInvalid(msg string) conditions.Condition { - return conditions.Condition{ +func NewGatewayClassRefInvalid(msg string) Condition { + return Condition{ Type: string(GatewayClassResolvedRefs), Status: metav1.ConditionFalse, Reason: string(GatewayClassReasonParamsRefInvalid), @@ -539,8 +681,8 @@ func NewGatewayClassRefInvalid(msg string) conditions.Condition { // NewGatewayClassInvalidParameters returns a Condition that indicates that the GatewayClass has invalid parameters. // We are allowing Accepted to still be true to prevent nullifying the entire config tree if a parametersRef // is updated to something invalid. -func NewGatewayClassInvalidParameters(msg string) conditions.Condition { - return conditions.Condition{ +func NewGatewayClassInvalidParameters(msg string) Condition { + return Condition{ Type: string(v1.GatewayClassConditionStatusAccepted), Status: metav1.ConditionTrue, Reason: string(v1.GatewayClassReasonInvalidParameters), @@ -549,16 +691,16 @@ func NewGatewayClassInvalidParameters(msg string) conditions.Condition { } // NewDefaultGatewayConditions returns the default Conditions that must be present in the status of a Gateway. -func NewDefaultGatewayConditions() []conditions.Condition { - return []conditions.Condition{ +func NewDefaultGatewayConditions() []Condition { + return []Condition{ NewGatewayAccepted(), NewGatewayProgrammed(), } } // NewGatewayAccepted returns a Condition that indicates the Gateway is accepted. -func NewGatewayAccepted() conditions.Condition { - return conditions.Condition{ +func NewGatewayAccepted() Condition { + return Condition{ Type: string(v1.GatewayConditionAccepted), Status: metav1.ConditionTrue, Reason: string(v1.GatewayReasonAccepted), @@ -568,8 +710,8 @@ func NewGatewayAccepted() conditions.Condition { // NewGatewayAcceptedListenersNotValid returns a Condition that indicates the Gateway is accepted, // but has at least one listener that is invalid. -func NewGatewayAcceptedListenersNotValid() conditions.Condition { - return conditions.Condition{ +func NewGatewayAcceptedListenersNotValid() Condition { + return Condition{ Type: string(v1.GatewayConditionAccepted), Status: metav1.ConditionTrue, Reason: string(v1.GatewayReasonListenersNotValid), @@ -579,9 +721,9 @@ func NewGatewayAcceptedListenersNotValid() conditions.Condition { // NewGatewayNotAcceptedListenersNotValid returns Conditions that indicate the Gateway is not accepted, // because all listeners are invalid. -func NewGatewayNotAcceptedListenersNotValid() []conditions.Condition { +func NewGatewayNotAcceptedListenersNotValid() []Condition { msg := "Gateway has no valid listeners" - return []conditions.Condition{ + return []Condition{ { Type: string(v1.GatewayConditionAccepted), Status: metav1.ConditionFalse, @@ -594,8 +736,8 @@ func NewGatewayNotAcceptedListenersNotValid() []conditions.Condition { // NewGatewayInvalid returns Conditions that indicate the Gateway is not accepted and programmed because it is // semantically or syntactically invalid. The provided message contains the details of why the Gateway is invalid. -func NewGatewayInvalid(msg string) []conditions.Condition { - return []conditions.Condition{ +func NewGatewayInvalid(msg string) []Condition { + return []Condition{ { Type: string(v1.GatewayConditionAccepted), Status: metav1.ConditionFalse, @@ -608,8 +750,8 @@ func NewGatewayInvalid(msg string) []conditions.Condition { // NewGatewayUnsupportedValue returns Conditions that indicate that a field of the Gateway has an unsupported value. // Unsupported means that the value is not supported by the implementation or invalid. -func NewGatewayUnsupportedValue(msg string) []conditions.Condition { - return []conditions.Condition{ +func NewGatewayUnsupportedValue(msg string) []Condition { + return []Condition{ { Type: string(v1.GatewayConditionAccepted), Status: metav1.ConditionFalse, @@ -626,8 +768,8 @@ func NewGatewayUnsupportedValue(msg string) []conditions.Condition { } // NewGatewayProgrammed returns a Condition that indicates the Gateway is programmed. -func NewGatewayProgrammed() conditions.Condition { - return conditions.Condition{ +func NewGatewayProgrammed() Condition { + return Condition{ Type: string(v1.GatewayConditionProgrammed), Status: metav1.ConditionTrue, Reason: string(v1.GatewayReasonProgrammed), @@ -638,8 +780,8 @@ func NewGatewayProgrammed() conditions.Condition { // NewGatewayNotProgrammedInvalid returns a Condition that indicates the Gateway is not programmed // because it is semantically or syntactically invalid. The provided message contains the details of // why the Gateway is invalid. -func NewGatewayNotProgrammedInvalid(msg string) conditions.Condition { - return conditions.Condition{ +func NewGatewayNotProgrammedInvalid(msg string) Condition { + return Condition{ Type: string(v1.GatewayConditionProgrammed), Status: metav1.ConditionFalse, Reason: string(v1.GatewayReasonInvalid), @@ -648,8 +790,8 @@ func NewGatewayNotProgrammedInvalid(msg string) conditions.Condition { } // NewNginxGatewayValid returns a Condition that indicates that the NginxGateway config is valid. -func NewNginxGatewayValid() conditions.Condition { - return conditions.Condition{ +func NewNginxGatewayValid() Condition { + return Condition{ Type: string(ngfAPI.NginxGatewayConditionValid), Status: metav1.ConditionTrue, Reason: string(ngfAPI.NginxGatewayReasonValid), @@ -658,8 +800,8 @@ func NewNginxGatewayValid() conditions.Condition { } // NewNginxGatewayInvalid returns a Condition that indicates that the NginxGateway config is invalid. -func NewNginxGatewayInvalid(msg string) conditions.Condition { - return conditions.Condition{ +func NewNginxGatewayInvalid(msg string) Condition { + return Condition{ Type: string(ngfAPI.NginxGatewayConditionValid), Status: metav1.ConditionFalse, Reason: string(ngfAPI.NginxGatewayReasonInvalid), @@ -669,8 +811,8 @@ func NewNginxGatewayInvalid(msg string) conditions.Condition { // NewGatewayResolvedRefs returns a Condition that indicates that the parametersRef // on the Gateway is resolved. -func NewGatewayResolvedRefs() conditions.Condition { - return conditions.Condition{ +func NewGatewayResolvedRefs() Condition { + return Condition{ Type: string(GatewayResolvedRefs), Status: metav1.ConditionTrue, Reason: string(GatewayReasonResolvedRefs), @@ -680,8 +822,8 @@ func NewGatewayResolvedRefs() conditions.Condition { // NewGatewayRefNotFound returns a Condition that indicates that the parametersRef // on the Gateway could not be resolved. -func NewGatewayRefNotFound() conditions.Condition { - return conditions.Condition{ +func NewGatewayRefNotFound() Condition { + return Condition{ Type: string(GatewayResolvedRefs), Status: metav1.ConditionFalse, Reason: string(GatewayReasonParamsRefNotFound), @@ -691,8 +833,8 @@ func NewGatewayRefNotFound() conditions.Condition { // NewGatewayRefInvalid returns a Condition that indicates that the parametersRef // on the Gateway could not be resolved because the referenced resource is invalid. -func NewGatewayRefInvalid(msg string) conditions.Condition { - return conditions.Condition{ +func NewGatewayRefInvalid(msg string) Condition { + return Condition{ Type: string(GatewayResolvedRefs), Status: metav1.ConditionFalse, Reason: string(GatewayReasonParamsRefInvalid), @@ -703,8 +845,8 @@ func NewGatewayRefInvalid(msg string) conditions.Condition { // NewGatewayInvalidParameters returns a Condition that indicates that the Gateway has invalid parameters. // We are allowing Accepted to still be true to prevent nullifying the entire Gateway config if a parametersRef // is updated to something invalid. -func NewGatewayInvalidParameters(msg string) conditions.Condition { - return conditions.Condition{ +func NewGatewayInvalidParameters(msg string) Condition { + return Condition{ Type: string(v1.GatewayConditionAccepted), Status: metav1.ConditionTrue, Reason: string(v1.GatewayReasonInvalidParameters), @@ -713,8 +855,8 @@ func NewGatewayInvalidParameters(msg string) conditions.Condition { } // NewPolicyAccepted returns a Condition that indicates that the Policy is accepted. -func NewPolicyAccepted() conditions.Condition { - return conditions.Condition{ +func NewPolicyAccepted() Condition { + return Condition{ Type: string(v1alpha2.PolicyConditionAccepted), Status: metav1.ConditionTrue, Reason: string(v1alpha2.PolicyReasonAccepted), @@ -724,8 +866,8 @@ func NewPolicyAccepted() conditions.Condition { // NewPolicyInvalid returns a Condition that indicates that the Policy is not accepted because it is semantically or // syntactically invalid. -func NewPolicyInvalid(msg string) conditions.Condition { - return conditions.Condition{ +func NewPolicyInvalid(msg string) Condition { + return Condition{ Type: string(v1alpha2.PolicyConditionAccepted), Status: metav1.ConditionFalse, Reason: string(v1alpha2.PolicyReasonInvalid), @@ -735,8 +877,8 @@ func NewPolicyInvalid(msg string) conditions.Condition { // NewPolicyConflicted returns a Condition that indicates that the Policy is not accepted because it conflicts with // another Policy and a merge is not possible. -func NewPolicyConflicted(msg string) conditions.Condition { - return conditions.Condition{ +func NewPolicyConflicted(msg string) Condition { + return Condition{ Type: string(v1alpha2.PolicyConditionAccepted), Status: metav1.ConditionFalse, Reason: string(v1alpha2.PolicyReasonConflicted), @@ -746,8 +888,8 @@ func NewPolicyConflicted(msg string) conditions.Condition { // NewPolicyTargetNotFound returns a Condition that indicates that the Policy is not accepted because the target // resource does not exist or can not be attached to. -func NewPolicyTargetNotFound(msg string) conditions.Condition { - return conditions.Condition{ +func NewPolicyTargetNotFound(msg string) Condition { + return Condition{ Type: string(v1alpha2.PolicyConditionAccepted), Status: metav1.ConditionFalse, Reason: string(v1alpha2.PolicyReasonTargetNotFound), @@ -757,8 +899,8 @@ func NewPolicyTargetNotFound(msg string) conditions.Condition { // NewPolicyNotAcceptedTargetConflict returns a Condition that indicates that the Policy is not accepted // because the target resource has a conflict with another resource when attempting to apply this policy. -func NewPolicyNotAcceptedTargetConflict(msg string) conditions.Condition { - return conditions.Condition{ +func NewPolicyNotAcceptedTargetConflict(msg string) Condition { + return Condition{ Type: string(v1alpha2.PolicyConditionAccepted), Status: metav1.ConditionFalse, Reason: string(PolicyReasonTargetConflict), @@ -768,8 +910,8 @@ func NewPolicyNotAcceptedTargetConflict(msg string) conditions.Condition { // NewPolicyNotAcceptedNginxProxyNotSet returns a Condition that indicates that the Policy is not accepted // because it relies on the NginxProxy configuration which is missing or invalid. -func NewPolicyNotAcceptedNginxProxyNotSet(msg string) conditions.Condition { - return conditions.Condition{ +func NewPolicyNotAcceptedNginxProxyNotSet(msg string) Condition { + return Condition{ Type: string(v1alpha2.PolicyConditionAccepted), Status: metav1.ConditionFalse, Reason: string(PolicyReasonNginxProxyConfigNotSet), @@ -779,8 +921,8 @@ func NewPolicyNotAcceptedNginxProxyNotSet(msg string) conditions.Condition { // NewSnippetsFilterInvalid returns a Condition that indicates that the SnippetsFilter is not accepted because it is // syntactically or semantically invalid. -func NewSnippetsFilterInvalid(msg string) conditions.Condition { - return conditions.Condition{ +func NewSnippetsFilterInvalid(msg string) Condition { + return Condition{ Type: string(ngfAPI.SnippetsFilterConditionTypeAccepted), Status: metav1.ConditionFalse, Reason: string(ngfAPI.SnippetsFilterConditionReasonInvalid), @@ -790,8 +932,8 @@ func NewSnippetsFilterInvalid(msg string) conditions.Condition { // NewSnippetsFilterAccepted returns a Condition that indicates that the SnippetsFilter is accepted because it is // valid. -func NewSnippetsFilterAccepted() conditions.Condition { - return conditions.Condition{ +func NewSnippetsFilterAccepted() Condition { + return Condition{ Type: string(ngfAPI.SnippetsFilterConditionTypeAccepted), Status: metav1.ConditionTrue, Reason: string(ngfAPI.SnippetsFilterConditionReasonAccepted), diff --git a/internal/framework/conditions/conditions_test.go b/internal/controller/state/conditions/conditions_test.go similarity index 100% rename from internal/framework/conditions/conditions_test.go rename to internal/controller/state/conditions/conditions_test.go diff --git a/internal/mode/static/state/dataplane/configuration.go b/internal/controller/state/dataplane/configuration.go similarity index 99% rename from internal/mode/static/state/dataplane/configuration.go rename to internal/controller/state/dataplane/configuration.go index e0de92d14d..6bded6cebb 100644 --- a/internal/mode/static/state/dataplane/configuration.go +++ b/internal/controller/state/dataplane/configuration.go @@ -15,10 +15,10 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver" ) const ( diff --git a/internal/mode/static/state/dataplane/configuration_test.go b/internal/controller/state/dataplane/configuration_test.go similarity index 99% rename from internal/mode/static/state/dataplane/configuration_test.go rename to internal/controller/state/dataplane/configuration_test.go index 78e4869c59..95a4806e5a 100644 --- a/internal/mode/static/state/dataplane/configuration_test.go +++ b/internal/controller/state/dataplane/configuration_test.go @@ -21,14 +21,14 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/policiesfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver/resolverfakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/policiesfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver/resolverfakes" ) func getNormalBackendRef() graph.BackendRef { diff --git a/internal/mode/static/state/dataplane/convert.go b/internal/controller/state/dataplane/convert.go similarity index 96% rename from internal/mode/static/state/dataplane/convert.go rename to internal/controller/state/dataplane/convert.go index b1b1a4c635..0ab57bf0e9 100644 --- a/internal/mode/static/state/dataplane/convert.go +++ b/internal/controller/state/dataplane/convert.go @@ -7,9 +7,9 @@ import ( v1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/mirror" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/mirror" ) func convertMatch(m v1.HTTPRouteMatch) Match { diff --git a/internal/mode/static/state/dataplane/convert_test.go b/internal/controller/state/dataplane/convert_test.go similarity index 100% rename from internal/mode/static/state/dataplane/convert_test.go rename to internal/controller/state/dataplane/convert_test.go diff --git a/internal/mode/static/state/dataplane/doc.go b/internal/controller/state/dataplane/doc.go similarity index 100% rename from internal/mode/static/state/dataplane/doc.go rename to internal/controller/state/dataplane/doc.go diff --git a/internal/mode/static/state/dataplane/sort.go b/internal/controller/state/dataplane/sort.go similarity index 97% rename from internal/mode/static/state/dataplane/sort.go rename to internal/controller/state/dataplane/sort.go index b663c6144f..baad2e800d 100644 --- a/internal/mode/static/state/dataplane/sort.go +++ b/internal/controller/state/dataplane/sort.go @@ -3,7 +3,7 @@ package dataplane import ( "sort" - ngfsort "github.com/nginx/nginx-gateway-fabric/internal/mode/static/sort" + ngfsort "github.com/nginx/nginx-gateway-fabric/internal/controller/sort" ) func sortMatchRules(matchRules []MatchRule) { diff --git a/internal/mode/static/state/dataplane/sort_test.go b/internal/controller/state/dataplane/sort_test.go similarity index 100% rename from internal/mode/static/state/dataplane/sort_test.go rename to internal/controller/state/dataplane/sort_test.go diff --git a/internal/mode/static/state/dataplane/types.go b/internal/controller/state/dataplane/types.go similarity index 98% rename from internal/mode/static/state/dataplane/types.go rename to internal/controller/state/dataplane/types.go index 975edb4c33..5f4d3c2d9b 100644 --- a/internal/mode/static/state/dataplane/types.go +++ b/internal/controller/state/dataplane/types.go @@ -6,9 +6,9 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver" ) // PathType is the type of the path in a PathRule. diff --git a/internal/mode/static/state/graph/backend_refs.go b/internal/controller/state/graph/backend_refs.go similarity index 92% rename from internal/mode/static/state/graph/backend_refs.go rename to internal/controller/state/graph/backend_refs.go index cf9339cc7a..8f01340b59 100644 --- a/internal/mode/static/state/graph/backend_refs.go +++ b/internal/controller/state/graph/backend_refs.go @@ -12,10 +12,9 @@ import ( "sigs.k8s.io/gateway-api/apis/v1alpha3" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/sort" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/sort" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) // BackendRef is an internal representation of a backendRef in an HTTP/GRPC/TLSRoute. @@ -171,14 +170,14 @@ func createBackendRef( InvalidForGateways: make(map[types.NamespacedName]conditions.Condition), } - return backendRef, []conditions.Condition{staticConds.NewRouteBackendRefRefBackendNotFound(err.Error())} + return backendRef, []conditions.Condition{conditions.NewRouteBackendRefRefBackendNotFound(err.Error())} } var conds []conditions.Condition invalidForGateways := make(map[types.NamespacedName]conditions.Condition) for _, parentRef := range route.ParentRefs { if err := verifyIPFamily(parentRef.Gateway.EffectiveNginxProxy, svcIPFamily); err != nil { - invalidForGateways[parentRef.Gateway.NamespacedName] = staticConds.NewRouteInvalidIPFamily(err.Error()) + invalidForGateways[parentRef.Gateway.NamespacedName] = conditions.NewRouteInvalidIPFamily(err.Error()) } } @@ -198,7 +197,7 @@ func createBackendRef( InvalidForGateways: invalidForGateways, } - return backendRef, append(conds, staticConds.NewRouteBackendRefUnsupportedValue(err.Error())) + return backendRef, append(conds, conditions.NewRouteBackendRefUnsupportedValue(err.Error())) } backendRef := BackendRef{ @@ -251,7 +250,7 @@ func validateBackendTLSPolicyMatchingAllBackends(backendRefs []BackendRef) *cond } if mismatch { msg := "Backend TLS policies do not match for all backends" - return helpers.GetPointer(staticConds.NewRouteBackendRefUnsupportedValue(msg)) + return helpers.GetPointer(conditions.NewRouteBackendRefUnsupportedValue(msg)) } return nil } @@ -290,7 +289,7 @@ func findBackendTLSPolicyForService( if !beTLSPolicy.Valid { err = fmt.Errorf("the backend TLS policy is invalid: %s", beTLSPolicy.Conditions[0].Message) } else { - beTLSPolicy.Conditions = append(beTLSPolicy.Conditions, staticConds.NewPolicyAccepted()) + beTLSPolicy.Conditions = append(beTLSPolicy.Conditions, conditions.NewPolicyAccepted()) } } @@ -361,7 +360,7 @@ func validateRouteBackendRef( // Because all errors cause the same condition but different reasons, we return as soon as we find an error if len(ref.Filters) > 0 { valErr := field.TooMany(path.Child("filters"), len(ref.Filters), 0) - return false, staticConds.NewRouteBackendRefUnsupportedValue(valErr.Error()) + return false, conditions.NewRouteBackendRefUnsupportedValue(valErr.Error()) } return validateBackendRef(ref.BackendRef, routeNs, refGrantResolver, path) @@ -377,12 +376,12 @@ func validateBackendRef( if ref.Group != nil && (*ref.Group != "core" && *ref.Group != "") { valErr := field.NotSupported(path.Child("group"), *ref.Group, []string{"core", ""}) - return false, staticConds.NewRouteBackendRefInvalidKind(valErr.Error()) + return false, conditions.NewRouteBackendRefInvalidKind(valErr.Error()) } if ref.Kind != nil && *ref.Kind != "Service" { valErr := field.NotSupported(path.Child("kind"), *ref.Kind, []string{"Service"}) - return false, staticConds.NewRouteBackendRefInvalidKind(valErr.Error()) + return false, conditions.NewRouteBackendRefInvalidKind(valErr.Error()) } // no need to validate ref.Name @@ -394,13 +393,13 @@ func validateBackendRef( msg := fmt.Sprintf("Backend ref to Service %s not permitted by any ReferenceGrant", refNsName) valErr := field.Forbidden(path.Child("namespace"), msg) - return false, staticConds.NewRouteBackendRefRefNotPermitted(valErr.Error()) + return false, conditions.NewRouteBackendRefRefNotPermitted(valErr.Error()) } } if ref.Port == nil { valErr := field.Required(path.Child("port"), "port cannot be nil") - return false, staticConds.NewRouteBackendRefUnsupportedValue(valErr.Error()) + return false, conditions.NewRouteBackendRefUnsupportedValue(valErr.Error()) } // any value of port is OK @@ -408,7 +407,7 @@ func validateBackendRef( if ref.Weight != nil { if err := validateWeight(*ref.Weight); err != nil { valErr := field.Invalid(path.Child("weight"), *ref.Weight, err.Error()) - return false, staticConds.NewRouteBackendRefUnsupportedValue(valErr.Error()) + return false, conditions.NewRouteBackendRefUnsupportedValue(valErr.Error()) } } diff --git a/internal/mode/static/state/graph/backend_refs_test.go b/internal/controller/state/graph/backend_refs_test.go similarity index 96% rename from internal/mode/static/state/graph/backend_refs_test.go rename to internal/controller/state/graph/backend_refs_test.go index 543973758a..cb42f45daa 100644 --- a/internal/mode/static/state/graph/backend_refs_test.go +++ b/internal/controller/state/graph/backend_refs_test.go @@ -15,9 +15,8 @@ import ( "sigs.k8s.io/gateway-api/apis/v1alpha3" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) func getNormalRef() gatewayv1.BackendRef { @@ -65,7 +64,7 @@ func TestValidateRouteBackendRef(t *testing.T) { }, }, expectedValid: false, - expectedCondition: staticConds.NewRouteBackendRefUnsupportedValue( + expectedCondition: conditions.NewRouteBackendRefUnsupportedValue( "test.filters: Too many: 1: must have at most 0 items", ), }, @@ -78,7 +77,7 @@ func TestValidateRouteBackendRef(t *testing.T) { }), }, expectedValid: false, - expectedCondition: staticConds.NewRouteBackendRefInvalidKind( + expectedCondition: conditions.NewRouteBackendRefInvalidKind( `test.kind: Unsupported value: "NotService": supported values: "Service"`, ), }, @@ -151,7 +150,7 @@ func TestValidateBackendRef(t *testing.T) { }), refGrantResolver: alwaysTrueRefGrantResolver, expectedValid: false, - expectedCondition: staticConds.NewRouteBackendRefInvalidKind( + expectedCondition: conditions.NewRouteBackendRefInvalidKind( `test.group: Unsupported value: "invalid": supported values: "core", ""`, ), }, @@ -163,7 +162,7 @@ func TestValidateBackendRef(t *testing.T) { }), refGrantResolver: alwaysTrueRefGrantResolver, expectedValid: false, - expectedCondition: staticConds.NewRouteBackendRefInvalidKind( + expectedCondition: conditions.NewRouteBackendRefInvalidKind( `test.kind: Unsupported value: "NotService": supported values: "Service"`, ), }, @@ -175,7 +174,7 @@ func TestValidateBackendRef(t *testing.T) { }), refGrantResolver: alwaysFalseRefGrantResolver, expectedValid: false, - expectedCondition: staticConds.NewRouteBackendRefRefNotPermitted( + expectedCondition: conditions.NewRouteBackendRefRefNotPermitted( "test.namespace: Forbidden: Backend ref to Service invalid/service1 not permitted by any ReferenceGrant", ), }, @@ -187,7 +186,7 @@ func TestValidateBackendRef(t *testing.T) { }), refGrantResolver: alwaysTrueRefGrantResolver, expectedValid: false, - expectedCondition: staticConds.NewRouteBackendRefUnsupportedValue( + expectedCondition: conditions.NewRouteBackendRefUnsupportedValue( "test.weight: Invalid value: -1: must be in the range [0, 1000000]", ), }, @@ -199,7 +198,7 @@ func TestValidateBackendRef(t *testing.T) { }), refGrantResolver: alwaysTrueRefGrantResolver, expectedValid: false, - expectedCondition: staticConds.NewRouteBackendRefUnsupportedValue( + expectedCondition: conditions.NewRouteBackendRefUnsupportedValue( "test.port: Required value: port cannot be nil", ), }, @@ -685,7 +684,7 @@ func TestAddBackendRefsToRules(t *testing.T) { }, }, expectedConditions: []conditions.Condition{ - staticConds.NewRouteBackendRefInvalidKind( + conditions.NewRouteBackendRefInvalidKind( `spec.rules[0].backendRefs[0].kind: Unsupported value: "NotService": supported values: "Service"`, ), }, @@ -716,7 +715,7 @@ func TestAddBackendRefsToRules(t *testing.T) { }, }, expectedConditions: []conditions.Condition{ - staticConds.NewRouteBackendRefUnsupportedValue( + conditions.NewRouteBackendRefUnsupportedValue( `Backend TLS policies do not match for all backends`, ), }, @@ -827,7 +826,7 @@ func TestCreateBackend(t *testing.T) { }, Valid: false, Conditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("unsupported value"), + conditions.NewPolicyInvalid("unsupported value"), }, } @@ -888,7 +887,7 @@ func TestCreateBackend(t *testing.T) { }, expectedServicePortReference: "", expectedConditions: []conditions.Condition{ - staticConds.NewRouteBackendRefUnsupportedValue( + conditions.NewRouteBackendRefUnsupportedValue( "test.weight: Invalid value: -1: must be in the range [0, 1000000]", ), }, @@ -910,7 +909,7 @@ func TestCreateBackend(t *testing.T) { }, expectedServicePortReference: "", expectedConditions: []conditions.Condition{ - staticConds.NewRouteBackendRefInvalidKind( + conditions.NewRouteBackendRefInvalidKind( `test.kind: Unsupported value: "NotService": supported values: "Service"`, ), }, @@ -934,7 +933,7 @@ func TestCreateBackend(t *testing.T) { }, expectedServicePortReference: "", expectedConditions: []conditions.Condition{ - staticConds.NewRouteBackendRefRefBackendNotFound(`test.name: Not found: "not-exist"`), + conditions.NewRouteBackendRefRefBackendNotFound(`test.name: Not found: "not-exist"`), }, name: "service doesn't exist", }, @@ -948,7 +947,7 @@ func TestCreateBackend(t *testing.T) { Weight: 5, Valid: true, InvalidForGateways: map[types.NamespacedName]conditions.Condition{ - {Namespace: "test", Name: "gateway"}: staticConds.NewRouteInvalidIPFamily( + {Namespace: "test", Name: "gateway"}: conditions.NewRouteInvalidIPFamily( `service configured with IPv4 family but NginxProxy is configured with IPv6`, ), }, @@ -993,7 +992,7 @@ func TestCreateBackend(t *testing.T) { }, expectedServicePortReference: "", expectedConditions: []conditions.Condition{ - staticConds.NewRouteBackendRefUnsupportedValue( + conditions.NewRouteBackendRefUnsupportedValue( "the backend TLS policy is invalid: unsupported value", ), }, @@ -1213,12 +1212,12 @@ func TestValidateBackendTLSPolicyMatchingAllBackends(t *testing.T) { { name: "not matching policies", backendRefs: backendRefsWithNotMatchingPolicies, - expectedCondition: helpers.GetPointer(staticConds.NewRouteBackendRefUnsupportedValue(msg)), + expectedCondition: helpers.GetPointer(conditions.NewRouteBackendRefUnsupportedValue(msg)), }, { name: "only one policy", backendRefs: backendRefsOnePolicy, - expectedCondition: helpers.GetPointer(staticConds.NewRouteBackendRefUnsupportedValue(msg)), + expectedCondition: helpers.GetPointer(conditions.NewRouteBackendRefUnsupportedValue(msg)), }, } diff --git a/internal/mode/static/state/graph/backend_tls_policy.go b/internal/controller/state/graph/backend_tls_policy.go similarity index 92% rename from internal/mode/static/state/graph/backend_tls_policy.go rename to internal/controller/state/graph/backend_tls_policy.go index 67563eefe5..2d8155c7e9 100644 --- a/internal/mode/static/state/graph/backend_tls_policy.go +++ b/internal/controller/state/graph/backend_tls_policy.go @@ -9,9 +9,8 @@ import ( v1 "sigs.k8s.io/gateway-api/apis/v1" "sigs.k8s.io/gateway-api/apis/v1alpha3" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) type BackendTLSPolicy struct { @@ -82,7 +81,7 @@ func validateBackendTLSPolicy( if err := validateBackendTLSHostname(backendTLSPolicy); err != nil { valid = false - conds = append(conds, staticConds.NewPolicyInvalid(fmt.Sprintf("invalid hostname: %s", err.Error()))) + conds = append(conds, conditions.NewPolicyInvalid(fmt.Sprintf("invalid hostname: %s", err.Error()))) } caCertRefs := backendTLSPolicy.Spec.Validation.CACertificateRefs @@ -91,25 +90,25 @@ func validateBackendTLSPolicy( case len(caCertRefs) > 0 && wellKnownCerts != nil: valid = false msg := "CACertificateRefs and WellKnownCACertificates are mutually exclusive" - conds = append(conds, staticConds.NewPolicyInvalid(msg)) + conds = append(conds, conditions.NewPolicyInvalid(msg)) case len(caCertRefs) > 0: if err := validateBackendTLSCACertRef(backendTLSPolicy, configMapResolver, secretResolver); err != nil { valid = false - conds = append(conds, staticConds.NewPolicyInvalid( + conds = append(conds, conditions.NewPolicyInvalid( fmt.Sprintf("invalid CACertificateRef: %s", err.Error()))) } case wellKnownCerts != nil: if err := validateBackendTLSWellKnownCACerts(backendTLSPolicy); err != nil { valid = false - conds = append(conds, staticConds.NewPolicyInvalid( + conds = append(conds, conditions.NewPolicyInvalid( fmt.Sprintf("invalid WellKnownCACertificates: %s", err.Error()))) } default: valid = false - conds = append(conds, staticConds.NewPolicyInvalid("CACertRefs and WellKnownCACerts are both nil")) + conds = append(conds, conditions.NewPolicyInvalid("CACertRefs and WellKnownCACerts are both nil")) } return valid, ignored, conds } diff --git a/internal/mode/static/state/graph/backend_tls_policy_test.go b/internal/controller/state/graph/backend_tls_policy_test.go similarity index 100% rename from internal/mode/static/state/graph/backend_tls_policy_test.go rename to internal/controller/state/graph/backend_tls_policy_test.go diff --git a/internal/mode/static/state/graph/certificate_bundle.go b/internal/controller/state/graph/certificate_bundle.go similarity index 100% rename from internal/mode/static/state/graph/certificate_bundle.go rename to internal/controller/state/graph/certificate_bundle.go diff --git a/internal/mode/static/state/graph/certificate_bundle_test.go b/internal/controller/state/graph/certificate_bundle_test.go similarity index 100% rename from internal/mode/static/state/graph/certificate_bundle_test.go rename to internal/controller/state/graph/certificate_bundle_test.go diff --git a/internal/mode/static/state/graph/common_filter.go b/internal/controller/state/graph/common_filter.go similarity index 99% rename from internal/mode/static/state/graph/common_filter.go rename to internal/controller/state/graph/common_filter.go index c67d233cda..41266d42c2 100644 --- a/internal/mode/static/state/graph/common_filter.go +++ b/internal/controller/state/graph/common_filter.go @@ -8,7 +8,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" v1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" ) // RouteRuleFilters holds the Filters for a RouteRule. diff --git a/internal/mode/static/state/graph/common_filter_test.go b/internal/controller/state/graph/common_filter_test.go similarity index 99% rename from internal/mode/static/state/graph/common_filter_test.go rename to internal/controller/state/graph/common_filter_test.go index f365a2cde0..0e31a4cbb1 100644 --- a/internal/mode/static/state/graph/common_filter_test.go +++ b/internal/controller/state/graph/common_filter_test.go @@ -9,8 +9,8 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation/validationfakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation/validationfakes" ) func TestValidateFilter(t *testing.T) { diff --git a/internal/mode/static/state/graph/configmaps.go b/internal/controller/state/graph/configmaps.go similarity index 100% rename from internal/mode/static/state/graph/configmaps.go rename to internal/controller/state/graph/configmaps.go diff --git a/internal/mode/static/state/graph/configmaps_test.go b/internal/controller/state/graph/configmaps_test.go similarity index 100% rename from internal/mode/static/state/graph/configmaps_test.go rename to internal/controller/state/graph/configmaps_test.go diff --git a/internal/mode/static/state/graph/doc.go b/internal/controller/state/graph/doc.go similarity index 100% rename from internal/mode/static/state/graph/doc.go rename to internal/controller/state/graph/doc.go diff --git a/internal/mode/static/state/graph/extension_ref_filter.go b/internal/controller/state/graph/extension_ref_filter.go similarity index 100% rename from internal/mode/static/state/graph/extension_ref_filter.go rename to internal/controller/state/graph/extension_ref_filter.go diff --git a/internal/mode/static/state/graph/extension_ref_filter_test.go b/internal/controller/state/graph/extension_ref_filter_test.go similarity index 100% rename from internal/mode/static/state/graph/extension_ref_filter_test.go rename to internal/controller/state/graph/extension_ref_filter_test.go diff --git a/internal/mode/static/state/graph/gateway.go b/internal/controller/state/graph/gateway.go similarity index 86% rename from internal/mode/static/state/graph/gateway.go rename to internal/controller/state/graph/gateway.go index 3ff21ce44f..ba174db032 100644 --- a/internal/mode/static/state/graph/gateway.go +++ b/internal/controller/state/graph/gateway.go @@ -5,11 +5,10 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" v1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) // Gateway represents a Gateway resource. @@ -136,8 +135,8 @@ func validateGatewayParametersRef(npCfg *NginxProxy, ref v1.LocalParametersRefer err := field.NotSupported(path.Child("kind"), string(ref.Kind), []string{kinds.NginxProxy}) conds = append( conds, - staticConds.NewGatewayRefInvalid(err.Error()), - staticConds.NewGatewayInvalidParameters(err.Error()), + conditions.NewGatewayRefInvalid(err.Error()), + conditions.NewGatewayInvalidParameters(err.Error()), ) return conds @@ -146,8 +145,8 @@ func validateGatewayParametersRef(npCfg *NginxProxy, ref v1.LocalParametersRefer if npCfg == nil { conds = append( conds, - staticConds.NewGatewayRefNotFound(), - staticConds.NewGatewayInvalidParameters( + conditions.NewGatewayRefNotFound(), + conditions.NewGatewayInvalidParameters( field.NotFound(path.Child("name"), ref.Name).Error(), ), ) @@ -159,14 +158,14 @@ func validateGatewayParametersRef(npCfg *NginxProxy, ref v1.LocalParametersRefer msg := npCfg.ErrMsgs.ToAggregate().Error() conds = append( conds, - staticConds.NewGatewayRefInvalid(msg), - staticConds.NewGatewayInvalidParameters(msg), + conditions.NewGatewayRefInvalid(msg), + conditions.NewGatewayInvalidParameters(msg), ) return conds } - conds = append(conds, staticConds.NewGatewayResolvedRefs()) + conds = append(conds, conditions.NewGatewayResolvedRefs()) return conds } @@ -174,16 +173,16 @@ func validateGateway(gw *v1.Gateway, gc *GatewayClass, npCfg *NginxProxy) ([]con var conds []conditions.Condition if gc == nil { - conds = append(conds, staticConds.NewGatewayInvalid("GatewayClass doesn't exist")...) + conds = append(conds, conditions.NewGatewayInvalid("GatewayClass doesn't exist")...) } else if !gc.Valid { - conds = append(conds, staticConds.NewGatewayInvalid("GatewayClass is invalid")...) + conds = append(conds, conditions.NewGatewayInvalid("GatewayClass is invalid")...) } if len(gw.Spec.Addresses) > 0 { path := field.NewPath("spec", "addresses") valErr := field.Forbidden(path, "addresses are not supported") - conds = append(conds, staticConds.NewGatewayUnsupportedValue(valErr.Error())...) + conds = append(conds, conditions.NewGatewayUnsupportedValue(valErr.Error())...) } // we evaluate validity before validating parametersRef because an invalid parametersRef/NginxProxy does not diff --git a/internal/mode/static/state/graph/gateway_listener.go b/internal/controller/state/graph/gateway_listener.go similarity index 89% rename from internal/mode/static/state/graph/gateway_listener.go rename to internal/controller/state/graph/gateway_listener.go index 5bf46bd502..1536503392 100644 --- a/internal/mode/static/state/graph/gateway_listener.go +++ b/internal/controller/state/graph/gateway_listener.go @@ -12,10 +12,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" v1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) // Listener represents a Listener of the Gateway resource. @@ -100,7 +99,7 @@ func newListenerConfiguratorFactory( listener.Protocol, []string{string(v1.HTTPProtocolType), string(v1.HTTPSProtocolType), string(v1.TLSProtocolType)}, ) - return staticConds.NewListenerUnsupportedProtocol(valErr.Error()), false /* not attachable */ + return conditions.NewListenerUnsupportedProtocol(valErr.Error()), false /* not attachable */ }, }, }, @@ -191,7 +190,7 @@ func (c *listenerConfigurator) configure(listener v1.Listener, gwNSName types.Na allowedRouteSelector, err = metav1.LabelSelectorAsSelector(selector) if err != nil { msg := fmt.Sprintf("invalid label selector: %s", err.Error()) - conds = append(conds, staticConds.NewListenerUnsupportedValue(msg)...) + conds = append(conds, conditions.NewListenerUnsupportedValue(msg)...) valid = false } } @@ -242,7 +241,7 @@ func validateListenerHostname(listener v1.Listener) (conds []conditions.Conditio if err := validateHostname(h); err != nil { path := field.NewPath("hostname") valErr := field.Invalid(path, listener.Hostname, err.Error()) - return staticConds.NewListenerUnsupportedValue(valErr.Error()), false + return conditions.NewListenerUnsupportedValue(valErr.Error()), false } return nil, true } @@ -293,7 +292,7 @@ func getAndValidateListenerSupportedKinds(listener v1.Listener) ( group = string(*kind.Group) } msg := fmt.Sprintf("Unsupported route kind for protocol %s \"%s/%s\"", listener.Protocol, group, kind.Kind) - conds = append(conds, staticConds.NewListenerInvalidRouteKinds(msg)...) + conds = append(conds, conditions.NewListenerInvalidRouteKinds(msg)...) continue } supportedKinds = append(supportedKinds, kind) @@ -321,7 +320,7 @@ func validateListenerLabelSelector(listener v1.Listener) (conds []conditions.Con *listener.AllowedRoutes.Namespaces.From == v1.NamespacesFromSelector && listener.AllowedRoutes.Namespaces.Selector == nil { msg := "Listener's AllowedRoutes Selector must be set when From is set to type Selector" - return staticConds.NewListenerUnsupportedValue(msg), false + return conditions.NewListenerUnsupportedValue(msg), false } return nil, true @@ -332,13 +331,13 @@ func createHTTPListenerValidator(protectedPorts ProtectedPorts) listenerValidato if err := validateListenerPort(listener.Port, protectedPorts); err != nil { path := field.NewPath("port") valErr := field.Invalid(path, listener.Port, err.Error()) - conds = append(conds, staticConds.NewListenerUnsupportedValue(valErr.Error())...) + conds = append(conds, conditions.NewListenerUnsupportedValue(valErr.Error())...) } if listener.TLS != nil { path := field.NewPath("tls") valErr := field.Forbidden(path, "tls is not supported for HTTP listener") - conds = append(conds, staticConds.NewListenerUnsupportedValue(valErr.Error())...) + conds = append(conds, conditions.NewListenerUnsupportedValue(valErr.Error())...) } return conds, true @@ -361,11 +360,11 @@ func validateTLSFieldOnTLSListener(listener v1.Listener) (conds []conditions.Con tlspath := field.NewPath("TLS") if listener.TLS == nil { valErr := field.Required(tlspath, "tls must be defined for TLS listener") - return staticConds.NewListenerUnsupportedValue(valErr.Error()), false + return conditions.NewListenerUnsupportedValue(valErr.Error()), false } if listener.TLS.Mode == nil || *listener.TLS.Mode != v1.TLSModePassthrough { valErr := field.Required(tlspath.Child("Mode"), "Mode must be passthrough for TLS listener") - return staticConds.NewListenerUnsupportedValue(valErr.Error()), false + return conditions.NewListenerUnsupportedValue(valErr.Error()), false } return nil, true } @@ -375,12 +374,12 @@ func createHTTPSListenerValidator(protectedPorts ProtectedPorts) listenerValidat if err := validateListenerPort(listener.Port, protectedPorts); err != nil { path := field.NewPath("port") valErr := field.Invalid(path, listener.Port, err.Error()) - conds = append(conds, staticConds.NewListenerUnsupportedValue(valErr.Error())...) + conds = append(conds, conditions.NewListenerUnsupportedValue(valErr.Error())...) } if listener.TLS == nil { valErr := field.Required(field.NewPath("TLS"), "tls must be defined for HTTPS listener") - conds = append(conds, staticConds.NewListenerUnsupportedValue(valErr.Error())...) + conds = append(conds, conditions.NewListenerUnsupportedValue(valErr.Error())...) return conds, true } @@ -392,19 +391,19 @@ func createHTTPSListenerValidator(protectedPorts ProtectedPorts) listenerValidat *listener.TLS.Mode, []string{string(v1.TLSModeTerminate)}, ) - conds = append(conds, staticConds.NewListenerUnsupportedValue(valErr.Error())...) + conds = append(conds, conditions.NewListenerUnsupportedValue(valErr.Error())...) } if len(listener.TLS.Options) > 0 { path := tlsPath.Child("options") valErr := field.Forbidden(path, "options are not supported") - conds = append(conds, staticConds.NewListenerUnsupportedValue(valErr.Error())...) + conds = append(conds, conditions.NewListenerUnsupportedValue(valErr.Error())...) } if len(listener.TLS.CertificateRefs) == 0 { msg := "certificateRefs must be defined for TLS mode terminate" valErr := field.Required(tlsPath.Child("certificateRefs"), msg) - conds = append(conds, staticConds.NewListenerInvalidCertificateRef(valErr.Error())...) + conds = append(conds, conditions.NewListenerInvalidCertificateRef(valErr.Error())...) return conds, true } @@ -415,20 +414,20 @@ func createHTTPSListenerValidator(protectedPorts ProtectedPorts) listenerValidat if certRef.Kind != nil && *certRef.Kind != "Secret" { path := certRefPath.Child("kind") valErr := field.NotSupported(path, *certRef.Kind, []string{"Secret"}) - conds = append(conds, staticConds.NewListenerInvalidCertificateRef(valErr.Error())...) + conds = append(conds, conditions.NewListenerInvalidCertificateRef(valErr.Error())...) } // for Kind Secret, certRef.Group must be nil or empty if certRef.Group != nil && *certRef.Group != "" { path := certRefPath.Child("group") valErr := field.NotSupported(path, *certRef.Group, []string{""}) - conds = append(conds, staticConds.NewListenerInvalidCertificateRef(valErr.Error())...) + conds = append(conds, conditions.NewListenerInvalidCertificateRef(valErr.Error())...) } if l := len(listener.TLS.CertificateRefs); l > 1 { path := tlsPath.Child("certificateRefs") valErr := field.TooMany(path, l, 1) - conds = append(conds, staticConds.NewListenerUnsupportedValue(valErr.Error())...) + conds = append(conds, conditions.NewListenerUnsupportedValue(valErr.Error())...) } return conds, true @@ -462,7 +461,7 @@ func createPortConflictResolver() listenerConflictResolver { if conflictedPorts[port] { l.Valid = false - conflictedConds := staticConds.NewListenerProtocolConflict(fmt.Sprintf(format, port)) + conflictedConds := conditions.NewListenerProtocolConflict(fmt.Sprintf(format, port)) l.Conditions = append(l.Conditions, conflictedConds...) return } @@ -483,11 +482,11 @@ func createPortConflictResolver() listenerConflictResolver { conflictedPorts[port] = true for _, listener := range listenersByPort[port] { listener.Valid = false - conflictedConds := staticConds.NewListenerProtocolConflict(fmt.Sprintf(format, port)) + conflictedConds := conditions.NewListenerProtocolConflict(fmt.Sprintf(format, port)) listener.Conditions = append(listener.Conditions, conflictedConds...) } l.Valid = false - conflictedConds := staticConds.NewListenerProtocolConflict(fmt.Sprintf(format, port)) + conflictedConds := conditions.NewListenerProtocolConflict(fmt.Sprintf(format, port)) l.Conditions = append(l.Conditions, conflictedConds...) } else { foundConflict := false @@ -495,7 +494,7 @@ func createPortConflictResolver() listenerConflictResolver { if listener.Source.Protocol != l.Source.Protocol && haveOverlap(l.Source.Hostname, listener.Source.Hostname) { listener.Valid = false - conflictedConds := staticConds.NewListenerHostnameConflict(fmt.Sprintf(formatHostname, port)) + conflictedConds := conditions.NewListenerHostnameConflict(fmt.Sprintf(formatHostname, port)) listener.Conditions = append(listener.Conditions, conflictedConds...) foundConflict = true } @@ -503,7 +502,7 @@ func createPortConflictResolver() listenerConflictResolver { if foundConflict { l.Valid = false - conflictedConds := staticConds.NewListenerHostnameConflict(fmt.Sprintf(formatHostname, port)) + conflictedConds := conditions.NewListenerHostnameConflict(fmt.Sprintf(formatHostname, port)) l.Conditions = append(l.Conditions, conflictedConds...) } } @@ -534,7 +533,7 @@ func createExternalReferencesForTLSSecretsResolver( if !refGrantResolver.refAllowed(toSecret(certRefNsName), fromGateway(gwNs)) { msg := fmt.Sprintf("Certificate ref to secret %s not permitted by any ReferenceGrant", certRefNsName) - l.Conditions = append(l.Conditions, staticConds.NewListenerRefNotPermitted(msg)...) + l.Conditions = append(l.Conditions, conditions.NewListenerRefNotPermitted(msg)...) l.Valid = false return } @@ -545,7 +544,7 @@ func createExternalReferencesForTLSSecretsResolver( // field.NotFound could be better, but it doesn't allow us to set the error message. valErr := field.Invalid(path, certRefNsName, err.Error()) - l.Conditions = append(l.Conditions, staticConds.NewListenerInvalidCertificateRef(valErr.Error())...) + l.Conditions = append(l.Conditions, conditions.NewListenerInvalidCertificateRef(valErr.Error())...) l.Valid = false } else { l.ResolvedSecret = &certRefNsName diff --git a/internal/mode/static/state/graph/gateway_listener_test.go b/internal/controller/state/graph/gateway_listener_test.go similarity index 92% rename from internal/mode/static/state/graph/gateway_listener_test.go rename to internal/controller/state/graph/gateway_listener_test.go index cdcb8b22d2..4d0d83def1 100644 --- a/internal/mode/static/state/graph/gateway_listener_test.go +++ b/internal/controller/state/graph/gateway_listener_test.go @@ -8,10 +8,9 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) func TestValidateHTTPListener(t *testing.T) { @@ -34,7 +33,7 @@ func TestValidateHTTPListener(t *testing.T) { l: v1.Listener{ Port: 0, }, - expected: staticConds.NewListenerUnsupportedValue(`port: Invalid value: 0: port must be between 1-65535`), + expected: conditions.NewListenerUnsupportedValue(`port: Invalid value: 0: port must be between 1-65535`), name: "invalid port", }, { @@ -45,14 +44,14 @@ func TestValidateHTTPListener(t *testing.T) { }, Name: "http-listener", }, - expected: staticConds.NewListenerUnsupportedValue(`tls: Forbidden: tls is not supported for HTTP listener`), + expected: conditions.NewListenerUnsupportedValue(`tls: Forbidden: tls is not supported for HTTP listener`), name: "invalid HTTP listener with TLS", }, { l: v1.Listener{ Port: 9113, }, - expected: staticConds.NewListenerUnsupportedValue( + expected: conditions.NewListenerUnsupportedValue( `port: Invalid value: 9113: port is already in use as MetricsPort`, ), name: "invalid protected port", @@ -123,7 +122,7 @@ func TestValidateHTTPSListener(t *testing.T) { CertificateRefs: []v1.SecretObjectReference{validSecretRef}, }, }, - expected: staticConds.NewListenerUnsupportedValue(`port: Invalid value: 0: port must be between 1-65535`), + expected: conditions.NewListenerUnsupportedValue(`port: Invalid value: 0: port must be between 1-65535`), name: "invalid port", }, { @@ -134,7 +133,7 @@ func TestValidateHTTPSListener(t *testing.T) { CertificateRefs: []v1.SecretObjectReference{validSecretRef}, }, }, - expected: staticConds.NewListenerUnsupportedValue( + expected: conditions.NewListenerUnsupportedValue( `port: Invalid value: 9113: port is already in use as MetricsPort`, ), name: "invalid protected port", @@ -148,7 +147,7 @@ func TestValidateHTTPSListener(t *testing.T) { Options: map[v1.AnnotationKey]v1.AnnotationValue{"key": "val"}, }, }, - expected: staticConds.NewListenerUnsupportedValue("tls.options: Forbidden: options are not supported"), + expected: conditions.NewListenerUnsupportedValue("tls.options: Forbidden: options are not supported"), name: "invalid options", }, { @@ -159,7 +158,7 @@ func TestValidateHTTPSListener(t *testing.T) { CertificateRefs: []v1.SecretObjectReference{validSecretRef}, }, }, - expected: staticConds.NewListenerUnsupportedValue( + expected: conditions.NewListenerUnsupportedValue( `tls.mode: Unsupported value: "Passthrough": supported values: "Terminate"`, ), name: "invalid tls mode", @@ -169,7 +168,7 @@ func TestValidateHTTPSListener(t *testing.T) { Port: 443, TLS: nil, }, - expected: staticConds.NewListenerUnsupportedValue( + expected: conditions.NewListenerUnsupportedValue( `TLS: Required value: tls must be defined for HTTPS listener`, ), name: "nil tls", @@ -182,7 +181,7 @@ func TestValidateHTTPSListener(t *testing.T) { CertificateRefs: []v1.SecretObjectReference{invalidSecretRefGroup}, }, }, - expected: staticConds.NewListenerInvalidCertificateRef( + expected: conditions.NewListenerInvalidCertificateRef( `tls.certificateRefs[0].group: Unsupported value: "some-group": supported values: ""`, ), name: "invalid cert ref group", @@ -195,7 +194,7 @@ func TestValidateHTTPSListener(t *testing.T) { CertificateRefs: []v1.SecretObjectReference{}, }, }, - expected: staticConds.NewListenerInvalidCertificateRef( + expected: conditions.NewListenerInvalidCertificateRef( `tls.certificateRefs: Required value: certificateRefs must be defined for TLS mode terminate`, ), name: "zero cert refs", @@ -208,7 +207,7 @@ func TestValidateHTTPSListener(t *testing.T) { CertificateRefs: []v1.SecretObjectReference{invalidSecretRefKind}, }, }, - expected: staticConds.NewListenerInvalidCertificateRef( + expected: conditions.NewListenerInvalidCertificateRef( `tls.certificateRefs[0].kind: Unsupported value: "ConfigMap": supported values: "Secret"`, ), name: "invalid cert ref kind", @@ -221,7 +220,7 @@ func TestValidateHTTPSListener(t *testing.T) { CertificateRefs: []v1.SecretObjectReference{validSecretRef, validSecretRef}, }, }, - expected: staticConds.NewListenerUnsupportedValue( + expected: conditions.NewListenerUnsupportedValue( "tls.certificateRefs: Too many: 2: must have at most 1 items", ), name: "too many cert refs", @@ -599,7 +598,7 @@ func TestValidateTLSFieldOnTLSListener(t *testing.T) { }{ { listener: v1.Listener{}, - expectedCond: staticConds.NewListenerUnsupportedValue( + expectedCond: conditions.NewListenerUnsupportedValue( "TLS: Required value: tls must be defined for TLS listener", ), expectValid: false, @@ -607,7 +606,7 @@ func TestValidateTLSFieldOnTLSListener(t *testing.T) { }, { listener: v1.Listener{TLS: nil}, - expectedCond: staticConds.NewListenerUnsupportedValue( + expectedCond: conditions.NewListenerUnsupportedValue( "TLS: Required value: tls must be defined for TLS listener", ), expectValid: false, @@ -615,7 +614,7 @@ func TestValidateTLSFieldOnTLSListener(t *testing.T) { }, { listener: v1.Listener{TLS: &v1.GatewayTLSConfig{Mode: helpers.GetPointer(v1.TLSModeTerminate)}}, - expectedCond: staticConds.NewListenerUnsupportedValue( + expectedCond: conditions.NewListenerUnsupportedValue( "TLS.Mode: Required value: Mode must be passthrough for TLS listener", ), expectValid: false, diff --git a/internal/mode/static/state/graph/gateway_test.go b/internal/controller/state/graph/gateway_test.go similarity index 94% rename from internal/mode/static/state/graph/gateway_test.go rename to internal/controller/state/graph/gateway_test.go index 63bd96e753..26dbd375ed 100644 --- a/internal/mode/static/state/graph/gateway_test.go +++ b/internal/controller/state/graph/gateway_test.go @@ -14,11 +14,10 @@ import ( "sigs.k8s.io/gateway-api/apis/v1beta1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) func TestProcessGateways(t *testing.T) { @@ -601,7 +600,7 @@ func TestBuildGateway(t *testing.T) { Port: helpers.GetPointer(int32(90)), }, }, - Conditions: []conditions.Condition{staticConds.NewGatewayResolvedRefs()}, + Conditions: []conditions.Condition{conditions.NewGatewayResolvedRefs()}, }, }, name: "valid http listener with valid NginxProxy; GatewayClass has no NginxProxy", @@ -647,7 +646,7 @@ func TestBuildGateway(t *testing.T) { Port: helpers.GetPointer(int32(90)), }, }, - Conditions: []conditions.Condition{staticConds.NewGatewayResolvedRefs()}, + Conditions: []conditions.Condition{conditions.NewGatewayResolvedRefs()}, }, }, name: "valid http listener with valid NginxProxy; GatewayClass has valid NginxProxy too", @@ -695,7 +694,7 @@ func TestBuildGateway(t *testing.T) { Source: crossNamespaceSecretListener, Valid: false, Attachable: true, - Conditions: staticConds.NewListenerRefNotPermitted( + Conditions: conditions.NewListenerRefNotPermitted( `Certificate ref to secret diff-ns/secret not permitted by any ReferenceGrant`, ), Routes: map[RouteKey]*L7Route{}, @@ -725,7 +724,7 @@ func TestBuildGateway(t *testing.T) { Source: listenerInvalidSelector, Valid: false, Attachable: true, - Conditions: staticConds.NewListenerUnsupportedValue( + Conditions: conditions.NewListenerUnsupportedValue( `invalid label selector: "invalid" is not a valid label selector operator`, ), Routes: map[RouteKey]*L7Route{}, @@ -757,7 +756,7 @@ func TestBuildGateway(t *testing.T) { Source: invalidProtocolListener, Valid: false, Attachable: false, - Conditions: staticConds.NewListenerUnsupportedProtocol( + Conditions: conditions.NewListenerUnsupportedProtocol( `protocol: Unsupported value: "TCP": supported values: "HTTP", "HTTPS", "TLS"`, ), Routes: map[RouteKey]*L7Route{}, @@ -795,7 +794,7 @@ func TestBuildGateway(t *testing.T) { Source: invalidPortListener, Valid: false, Attachable: true, - Conditions: staticConds.NewListenerUnsupportedValue( + Conditions: conditions.NewListenerUnsupportedValue( `port: Invalid value: 0: port must be between 1-65535`, ), Routes: map[RouteKey]*L7Route{}, @@ -808,7 +807,7 @@ func TestBuildGateway(t *testing.T) { Source: invalidHTTPSPortListener, Valid: false, Attachable: true, - Conditions: staticConds.NewListenerUnsupportedValue( + Conditions: conditions.NewListenerUnsupportedValue( `port: Invalid value: 65536: port must be between 1-65535`, ), Routes: map[RouteKey]*L7Route{}, @@ -821,7 +820,7 @@ func TestBuildGateway(t *testing.T) { Source: invalidProtectedPortListener, Valid: false, Attachable: true, - Conditions: staticConds.NewListenerUnsupportedValue( + Conditions: conditions.NewListenerUnsupportedValue( `port: Invalid value: 9113: port is already in use as MetricsPort`, ), SupportedKinds: supportedKindsForListeners, @@ -852,7 +851,7 @@ func TestBuildGateway(t *testing.T) { GatewayName: client.ObjectKeyFromObject(getLastCreatedGateway()), Source: invalidHostnameListener, Valid: false, - Conditions: staticConds.NewListenerUnsupportedValue(invalidHostnameMsg), + Conditions: conditions.NewListenerUnsupportedValue(invalidHostnameMsg), Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{}, SupportedKinds: supportedKindsForListeners, @@ -862,7 +861,7 @@ func TestBuildGateway(t *testing.T) { GatewayName: client.ObjectKeyFromObject(getLastCreatedGateway()), Source: invalidHTTPSHostnameListener, Valid: false, - Conditions: staticConds.NewListenerUnsupportedValue(invalidHostnameMsg), + Conditions: conditions.NewListenerUnsupportedValue(invalidHostnameMsg), Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{}, SupportedKinds: supportedKindsForListeners, @@ -892,7 +891,7 @@ func TestBuildGateway(t *testing.T) { Attachable: true, Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{}, - Conditions: staticConds.NewListenerInvalidCertificateRef( + Conditions: conditions.NewListenerInvalidCertificateRef( `tls.certificateRefs[0]: Invalid value: test/does-not-exist: secret does not exist`, ), SupportedKinds: supportedKindsForListeners, @@ -1049,7 +1048,7 @@ func TestBuildGateway(t *testing.T) { Attachable: true, Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{}, - Conditions: staticConds.NewListenerProtocolConflict(conflict80PortMsg), + Conditions: conditions.NewListenerProtocolConflict(conflict80PortMsg), SupportedKinds: supportedKindsForListeners, }, { @@ -1060,7 +1059,7 @@ func TestBuildGateway(t *testing.T) { Attachable: true, Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{}, - Conditions: staticConds.NewListenerProtocolConflict(conflict80PortMsg), + Conditions: conditions.NewListenerProtocolConflict(conflict80PortMsg), SupportedKinds: supportedKindsForListeners, }, { @@ -1071,7 +1070,7 @@ func TestBuildGateway(t *testing.T) { Attachable: true, Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{}, - Conditions: staticConds.NewListenerProtocolConflict(conflict443PortMsg), + Conditions: conditions.NewListenerProtocolConflict(conflict443PortMsg), SupportedKinds: supportedKindsForListeners, }, { @@ -1082,7 +1081,7 @@ func TestBuildGateway(t *testing.T) { Attachable: true, Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{}, - Conditions: staticConds.NewListenerProtocolConflict(conflict80PortMsg), + Conditions: conditions.NewListenerProtocolConflict(conflict80PortMsg), ResolvedSecret: helpers.GetPointer(client.ObjectKeyFromObject(secretSameNs)), SupportedKinds: supportedKindsForListeners, }, @@ -1094,7 +1093,7 @@ func TestBuildGateway(t *testing.T) { Attachable: true, Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{}, - Conditions: staticConds.NewListenerProtocolConflict(conflict443PortMsg), + Conditions: conditions.NewListenerProtocolConflict(conflict443PortMsg), ResolvedSecret: helpers.GetPointer(client.ObjectKeyFromObject(secretSameNs)), SupportedKinds: supportedKindsForListeners, }, @@ -1106,7 +1105,7 @@ func TestBuildGateway(t *testing.T) { Attachable: true, Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{}, - Conditions: staticConds.NewListenerProtocolConflict(conflict443PortMsg), + Conditions: conditions.NewListenerProtocolConflict(conflict443PortMsg), ResolvedSecret: helpers.GetPointer(client.ObjectKeyFromObject(secretSameNs)), SupportedKinds: supportedKindsForListeners, }, @@ -1137,7 +1136,7 @@ func TestBuildGateway(t *testing.T) { Name: controller.CreateNginxResourceName("gateway1", gcName), }, Valid: false, - Conditions: staticConds.NewGatewayUnsupportedValue("spec." + + Conditions: conditions.NewGatewayUnsupportedValue("spec." + "addresses: Forbidden: addresses are not supported", ), }, @@ -1162,7 +1161,7 @@ func TestBuildGateway(t *testing.T) { Name: controller.CreateNginxResourceName("gateway1", gcName), }, Valid: false, - Conditions: staticConds.NewGatewayInvalid("GatewayClass is invalid"), + Conditions: conditions.NewGatewayInvalid("GatewayClass is invalid"), }, }, name: "invalid gatewayclass", @@ -1180,7 +1179,7 @@ func TestBuildGateway(t *testing.T) { Name: controller.CreateNginxResourceName("gateway1", gcName), }, Valid: false, - Conditions: staticConds.NewGatewayInvalid("GatewayClass doesn't exist"), + Conditions: conditions.NewGatewayInvalid("GatewayClass doesn't exist"), }, }, name: "nil gatewayclass", @@ -1207,7 +1206,7 @@ func TestBuildGateway(t *testing.T) { Attachable: true, Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{}, - Conditions: staticConds.NewListenerProtocolConflict(conflict443PortMsg), + Conditions: conditions.NewListenerProtocolConflict(conflict443PortMsg), SupportedKinds: []v1.RouteGroupKind{ {Kind: kinds.TLSRoute, Group: helpers.GetPointer[v1.Group](v1.GroupName)}, }, @@ -1220,7 +1219,7 @@ func TestBuildGateway(t *testing.T) { Attachable: true, Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{}, - Conditions: staticConds.NewListenerProtocolConflict(conflict443PortMsg), + Conditions: conditions.NewListenerProtocolConflict(conflict443PortMsg), SupportedKinds: supportedKindsForListeners, }, }, @@ -1250,7 +1249,7 @@ func TestBuildGateway(t *testing.T) { Attachable: true, Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{}, - Conditions: staticConds.NewListenerHostnameConflict(conflict443HostnameMsg), + Conditions: conditions.NewListenerHostnameConflict(conflict443HostnameMsg), SupportedKinds: []v1.RouteGroupKind{ {Kind: kinds.TLSRoute, Group: helpers.GetPointer[v1.Group](v1.GroupName)}, }, @@ -1264,7 +1263,7 @@ func TestBuildGateway(t *testing.T) { ResolvedSecret: helpers.GetPointer(client.ObjectKeyFromObject(secretSameNs)), Routes: map[RouteKey]*L7Route{}, L4Routes: map[L4RouteKey]*L4Route{}, - Conditions: staticConds.NewListenerHostnameConflict(conflict443HostnameMsg), + Conditions: conditions.NewListenerHostnameConflict(conflict443HostnameMsg), SupportedKinds: supportedKindsForListeners, }, }, @@ -1344,11 +1343,11 @@ func TestBuildGateway(t *testing.T) { }, Valid: true, // invalid parametersRef does not invalidate Gateway. Conditions: []conditions.Condition{ - staticConds.NewGatewayRefInvalid( + conditions.NewGatewayRefInvalid( "spec.infrastructure.parametersRef.kind: Unsupported value: \"Invalid\": " + "supported values: \"NginxProxy\"", ), - staticConds.NewGatewayInvalidParameters( + conditions.NewGatewayInvalidParameters( "spec.infrastructure.parametersRef.kind: Unsupported value: \"Invalid\": " + "supported values: \"NginxProxy\"", ), @@ -1387,8 +1386,8 @@ func TestBuildGateway(t *testing.T) { }, Valid: true, // invalid parametersRef does not invalidate Gateway. Conditions: []conditions.Condition{ - staticConds.NewGatewayRefNotFound(), - staticConds.NewGatewayInvalidParameters( + conditions.NewGatewayRefNotFound(), + conditions.NewGatewayInvalidParameters( "spec.infrastructure.parametersRef.name: Not found: \"does-not-exist\"", ), }, @@ -1433,8 +1432,8 @@ func TestBuildGateway(t *testing.T) { Valid: false, }, Conditions: []conditions.Condition{ - staticConds.NewGatewayRefInvalid("somePath: Required value: someField"), - staticConds.NewGatewayInvalidParameters("somePath: Required value: someField"), + conditions.NewGatewayRefInvalid("somePath: Required value: someField"), + conditions.NewGatewayInvalidParameters("somePath: Required value: someField"), }, }, }, @@ -1464,9 +1463,9 @@ func TestBuildGateway(t *testing.T) { Valid: false, }, Conditions: append( - staticConds.NewGatewayInvalid("GatewayClass is invalid"), - staticConds.NewGatewayRefInvalid("somePath: Required value: someField"), - staticConds.NewGatewayInvalidParameters("somePath: Required value: someField"), + conditions.NewGatewayInvalid("GatewayClass is invalid"), + conditions.NewGatewayRefInvalid("somePath: Required value: someField"), + conditions.NewGatewayInvalidParameters("somePath: Required value: someField"), ), }, }, @@ -1515,11 +1514,11 @@ func TestValidateGatewayParametersRef(t *testing.T) { Kind: "wrong-kind", }, expConds: []conditions.Condition{ - staticConds.NewGatewayRefInvalid( + conditions.NewGatewayRefInvalid( "spec.infrastructure.parametersRef.kind: Unsupported value: \"wrong-kind\": " + "supported values: \"NginxProxy\"", ), - staticConds.NewGatewayInvalidParameters( + conditions.NewGatewayInvalidParameters( "spec.infrastructure.parametersRef.kind: Unsupported value: \"wrong-kind\": " + "supported values: \"NginxProxy\"", ), @@ -1533,8 +1532,8 @@ func TestValidateGatewayParametersRef(t *testing.T) { Name: "np", }, expConds: []conditions.Condition{ - staticConds.NewGatewayRefNotFound(), - staticConds.NewGatewayInvalidParameters("spec.infrastructure.parametersRef.name: Not found: \"np\""), + conditions.NewGatewayRefNotFound(), + conditions.NewGatewayInvalidParameters("spec.infrastructure.parametersRef.name: Not found: \"np\""), }, }, { @@ -1552,8 +1551,8 @@ func TestValidateGatewayParametersRef(t *testing.T) { Name: "np", }, expConds: []conditions.Condition{ - staticConds.NewGatewayRefInvalid("somePath: Required value: someField"), - staticConds.NewGatewayInvalidParameters("somePath: Required value: someField"), + conditions.NewGatewayRefInvalid("somePath: Required value: someField"), + conditions.NewGatewayInvalidParameters("somePath: Required value: someField"), }, }, { @@ -1568,7 +1567,7 @@ func TestValidateGatewayParametersRef(t *testing.T) { Name: "np", }, expConds: []conditions.Condition{ - staticConds.NewGatewayResolvedRefs(), + conditions.NewGatewayResolvedRefs(), }, }, } diff --git a/internal/mode/static/state/graph/gatewayclass.go b/internal/controller/state/graph/gatewayclass.go similarity index 61% rename from internal/mode/static/state/graph/gatewayclass.go rename to internal/controller/state/graph/gatewayclass.go index db5e3dff77..b464825a2e 100644 --- a/internal/mode/static/state/graph/gatewayclass.go +++ b/internal/controller/state/graph/gatewayclass.go @@ -1,18 +1,35 @@ package graph import ( + "strings" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/validation/field" "sigs.k8s.io/controller-runtime/pkg/client" v1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/framework/gatewayclass" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) +const ( + // BundleVersionAnnotation is the annotation on Gateway API CRDs that contains the installed version. + BundleVersionAnnotation = "gateway.networking.k8s.io/bundle-version" + // SupportedVersion is the supported version of the Gateway API CRDs. + SupportedVersion = "v1.3.0" +) + +var gatewayCRDs = map[string]apiVersion{ + "gatewayclasses.gateway.networking.k8s.io": {}, + "gateways.gateway.networking.k8s.io": {}, + "httproutes.gateway.networking.k8s.io": {}, + "referencegrants.gateway.networking.k8s.io": {}, + "backendtlspolicies.gateway.networking.k8s.io": {}, + "grpcroutes.gateway.networking.k8s.io": {}, + "tlsroutes.gateway.networking.k8s.io": {}, +} + // GatewayClass represents the GatewayClass resource. type GatewayClass struct { // Source is the source resource. @@ -115,8 +132,8 @@ func validateGatewayClassParametersRef(path *field.Path, ref v1.ParametersRefere if len(errs) > 0 { msg := errs.ToAggregate().Error() return []conditions.Condition{ - staticConds.NewGatewayClassRefInvalid(msg), - staticConds.NewGatewayClassInvalidParameters(msg), + conditions.NewGatewayClassRefInvalid(msg), + conditions.NewGatewayClassInvalidParameters(msg), } } @@ -130,7 +147,7 @@ func validateGatewayClass( ) ([]conditions.Condition, bool) { var conds []conditions.Condition - supportedVersionConds, versionsValid := gatewayclass.ValidateCRDVersions(crdVersions) + supportedVersionConds, versionsValid := validateCRDVersions(crdVersions) conds = append(conds, supportedVersionConds...) if gc.Spec.ParametersRef == nil { @@ -149,8 +166,8 @@ func validateGatewayClass( if npCfg == nil { conds = append( conds, - staticConds.NewGatewayClassRefNotFound(), - staticConds.NewGatewayClassInvalidParameters( + conditions.NewGatewayClassRefNotFound(), + conditions.NewGatewayClassInvalidParameters( field.NotFound(path.Child("name"), gc.Spec.ParametersRef.Name).Error(), ), ) @@ -161,15 +178,74 @@ func validateGatewayClass( msg := npCfg.ErrMsgs.ToAggregate().Error() conds = append( conds, - staticConds.NewGatewayClassRefInvalid(msg), - staticConds.NewGatewayClassInvalidParameters(msg), + conditions.NewGatewayClassRefInvalid(msg), + conditions.NewGatewayClassInvalidParameters(msg), ) return conds, versionsValid } - return append(conds, staticConds.NewGatewayClassResolvedRefs()), versionsValid + return append(conds, conditions.NewGatewayClassResolvedRefs()), versionsValid } var supportedParamKinds = map[string]struct{}{ kinds.NginxProxy: {}, } + +type apiVersion struct { + major string + minor string +} + +func validateCRDVersions( + crdMetadata map[types.NamespacedName]*metav1.PartialObjectMetadata, +) (conds []conditions.Condition, valid bool) { + installedAPIVersions := getBundleVersions(crdMetadata) + supportedAPIVersion := parseVersionString(SupportedVersion) + + var unsupported, bestEffort bool + + for _, version := range installedAPIVersions { + if version.major != supportedAPIVersion.major { + unsupported = true + } else if version.minor != supportedAPIVersion.minor { + bestEffort = true + } + } + + if unsupported { + return conditions.NewGatewayClassUnsupportedVersion(SupportedVersion), false + } + + if bestEffort { + return conditions.NewGatewayClassSupportedVersionBestEffort(SupportedVersion), true + } + + return nil, true +} + +func parseVersionString(version string) apiVersion { + versionBits := strings.Split(version, ".") + if len(versionBits) != 3 { + return apiVersion{} + } + + major, _ := strings.CutPrefix(versionBits[0], "v") + + return apiVersion{ + major: major, + minor: versionBits[1], + } +} + +func getBundleVersions(crdMetadata map[types.NamespacedName]*metav1.PartialObjectMetadata) []apiVersion { + versions := make([]apiVersion, 0, len(gatewayCRDs)) + + for nsname, md := range crdMetadata { + if _, ok := gatewayCRDs[nsname.Name]; ok { + bundleVersion := md.Annotations[BundleVersionAnnotation] + versions = append(versions, parseVersionString(bundleVersion)) + } + } + + return versions +} diff --git a/internal/mode/static/state/graph/gatewayclass_test.go b/internal/controller/state/graph/gatewayclass_test.go similarity index 61% rename from internal/mode/static/state/graph/gatewayclass_test.go rename to internal/controller/state/graph/gatewayclass_test.go index 3d26b6b1fd..131bc51ea9 100644 --- a/internal/mode/static/state/graph/gatewayclass_test.go +++ b/internal/controller/state/graph/gatewayclass_test.go @@ -1,6 +1,7 @@ package graph import ( + "strings" "testing" . "github.com/onsi/gomega" @@ -11,11 +12,9 @@ import ( v1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/framework/gatewayclass" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) func TestProcessGatewayClasses(t *testing.T) { @@ -166,7 +165,7 @@ func TestBuildGatewayClass(t *testing.T) { {Name: "gateways.gateway.networking.k8s.io"}: { ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - gatewayclass.BundleVersionAnnotation: gatewayclass.SupportedVersion, + BundleVersionAnnotation: SupportedVersion, }, }, }, @@ -176,7 +175,7 @@ func TestBuildGatewayClass(t *testing.T) { {Name: "gateways.gateway.networking.k8s.io"}: { ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - gatewayclass.BundleVersionAnnotation: "v99.0.0", + BundleVersionAnnotation: "v99.0.0", }, }, }, @@ -214,7 +213,7 @@ func TestBuildGatewayClass(t *testing.T) { expected: &GatewayClass{ Source: gcWithParams, Valid: true, - Conditions: []conditions.Condition{staticConds.NewGatewayClassResolvedRefs()}, + Conditions: []conditions.Condition{conditions.NewGatewayClassResolvedRefs()}, NginxProxy: &NginxProxy{ Valid: true, Source: np, @@ -228,10 +227,10 @@ func TestBuildGatewayClass(t *testing.T) { Source: gcWithParamsNoNamespace, Valid: true, Conditions: []conditions.Condition{ - staticConds.NewGatewayClassRefInvalid( + conditions.NewGatewayClassRefInvalid( "spec.parametersRef.namespace: Required value: ParametersRef must specify Namespace", ), - staticConds.NewGatewayClassInvalidParameters( + conditions.NewGatewayClassInvalidParameters( "spec.parametersRef.namespace: Required value: ParametersRef must specify Namespace", ), }, @@ -244,10 +243,10 @@ func TestBuildGatewayClass(t *testing.T) { Source: gcWithInvalidKind, Valid: true, Conditions: []conditions.Condition{ - staticConds.NewGatewayClassRefInvalid( + conditions.NewGatewayClassRefInvalid( "spec.parametersRef.kind: Unsupported value: \"Invalid\": supported values: \"NginxProxy\"", ), - staticConds.NewGatewayClassInvalidParameters( + conditions.NewGatewayClassInvalidParameters( "spec.parametersRef.kind: Unsupported value: \"Invalid\": supported values: \"NginxProxy\"", ), }, @@ -260,8 +259,8 @@ func TestBuildGatewayClass(t *testing.T) { Source: gcWithParams, Valid: true, Conditions: []conditions.Condition{ - staticConds.NewGatewayClassRefNotFound(), - staticConds.NewGatewayClassInvalidParameters( + conditions.NewGatewayClassRefNotFound(), + conditions.NewGatewayClassInvalidParameters( "spec.parametersRef.name: Not found: \"nginx-proxy\"", ), }, @@ -291,11 +290,11 @@ func TestBuildGatewayClass(t *testing.T) { Source: gcWithParams, Valid: true, Conditions: []conditions.Condition{ - staticConds.NewGatewayClassRefInvalid( + conditions.NewGatewayClassRefInvalid( "[spec.telemetry.serviceName: Invalid value: \"my-svc\": error" + ", spec.telemetry.exporter.endpoint: Invalid value: \"my-endpoint\": error]", ), - staticConds.NewGatewayClassInvalidParameters( + conditions.NewGatewayClassInvalidParameters( "[spec.telemetry.serviceName: Invalid value: \"my-svc\": error" + ", spec.telemetry.exporter.endpoint: Invalid value: \"my-endpoint\": error]", ), @@ -324,7 +323,7 @@ func TestBuildGatewayClass(t *testing.T) { expected: &GatewayClass{ Source: validGC, Valid: false, - Conditions: conditions.NewGatewayClassUnsupportedVersion(gatewayclass.SupportedVersion), + Conditions: conditions.NewGatewayClassUnsupportedVersion(SupportedVersion), }, name: "invalid gatewayclass; unsupported version", }, @@ -340,3 +339,116 @@ func TestBuildGatewayClass(t *testing.T) { }) } } + +func TestValidateCRDVersions(t *testing.T) { + t.Parallel() + createCRDMetadata := func(version string) *metav1.PartialObjectMetadata { + return &metav1.PartialObjectMetadata{ + ObjectMeta: metav1.ObjectMeta{ + Annotations: map[string]string{ + BundleVersionAnnotation: version, + }, + }, + } + } + + // Adding patch version to SupportedVersion to try and avoid having to update these tests with every release. + fields := strings.Split(SupportedVersion, ".") + fields[2] = "99" + + validVersionWithPatch := createCRDMetadata(strings.Join(fields, ".")) + bestEffortVersion := createCRDMetadata("v1.99.99") + unsupportedVersion := createCRDMetadata("v99.0.0") + + tests := []struct { + crds map[types.NamespacedName]*metav1.PartialObjectMetadata + name string + expConds []conditions.Condition + valid bool + }{ + { + name: "valid; all supported versions", + crds: map[types.NamespacedName]*metav1.PartialObjectMetadata{ + {Name: "gatewayclasses.gateway.networking.k8s.io"}: validVersionWithPatch, + {Name: "gateways.gateway.networking.k8s.io"}: validVersionWithPatch, + {Name: "httproutes.gateway.networking.k8s.io"}: validVersionWithPatch, + {Name: "referencegrants.gateway.networking.k8s.io"}: validVersionWithPatch, + {Name: "some.other.crd"}: unsupportedVersion, /* should ignore */ + }, + valid: true, + expConds: nil, + }, + { + name: "valid; only one Gateway API CRD exists but it's a supported version", + crds: map[types.NamespacedName]*metav1.PartialObjectMetadata{ + {Name: "gatewayclasses.gateway.networking.k8s.io"}: validVersionWithPatch, + {Name: "some.other.crd"}: unsupportedVersion, /* should ignore */ + }, + valid: true, + expConds: nil, + }, + { + name: "valid; all best effort (supported major version)", + crds: map[types.NamespacedName]*metav1.PartialObjectMetadata{ + {Name: "gatewayclasses.gateway.networking.k8s.io"}: bestEffortVersion, + {Name: "gateways.gateway.networking.k8s.io"}: bestEffortVersion, + {Name: "httproutes.gateway.networking.k8s.io"}: bestEffortVersion, + {Name: "referencegrants.gateway.networking.k8s.io"}: bestEffortVersion, + }, + valid: true, + expConds: conditions.NewGatewayClassSupportedVersionBestEffort(SupportedVersion), + }, + { + name: "valid; mix of supported and best effort versions", + crds: map[types.NamespacedName]*metav1.PartialObjectMetadata{ + {Name: "gatewayclasses.gateway.networking.k8s.io"}: validVersionWithPatch, + {Name: "gateways.gateway.networking.k8s.io"}: bestEffortVersion, + {Name: "httproutes.gateway.networking.k8s.io"}: validVersionWithPatch, + {Name: "referencegrants.gateway.networking.k8s.io"}: validVersionWithPatch, + }, + valid: true, + expConds: conditions.NewGatewayClassSupportedVersionBestEffort(SupportedVersion), + }, + { + name: "invalid; all unsupported versions", + crds: map[types.NamespacedName]*metav1.PartialObjectMetadata{ + {Name: "gatewayclasses.gateway.networking.k8s.io"}: unsupportedVersion, + {Name: "gateways.gateway.networking.k8s.io"}: unsupportedVersion, + {Name: "httproutes.gateway.networking.k8s.io"}: unsupportedVersion, + {Name: "referencegrants.gateway.networking.k8s.io"}: unsupportedVersion, + }, + valid: false, + expConds: conditions.NewGatewayClassUnsupportedVersion(SupportedVersion), + }, + { + name: "invalid; mix unsupported and best effort versions", + crds: map[types.NamespacedName]*metav1.PartialObjectMetadata{ + {Name: "gatewayclasses.gateway.networking.k8s.io"}: unsupportedVersion, + {Name: "gateways.gateway.networking.k8s.io"}: bestEffortVersion, + {Name: "httproutes.gateway.networking.k8s.io"}: unsupportedVersion, + {Name: "referencegrants.gateway.networking.k8s.io"}: bestEffortVersion, + }, + valid: false, + expConds: conditions.NewGatewayClassUnsupportedVersion(SupportedVersion), + }, + { + name: "invalid; bad version string", + crds: map[types.NamespacedName]*metav1.PartialObjectMetadata{ + {Name: "gatewayclasses.gateway.networking.k8s.io"}: createCRDMetadata("v"), + }, + valid: false, + expConds: conditions.NewGatewayClassUnsupportedVersion(SupportedVersion), + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + t.Parallel() + g := NewWithT(t) + + conds, valid := validateCRDVersions(test.crds) + g.Expect(valid).To(Equal(test.valid)) + g.Expect(conds).To(Equal(test.expConds)) + }) + } +} diff --git a/internal/mode/static/state/graph/graph.go b/internal/controller/state/graph/graph.go similarity index 98% rename from internal/mode/static/state/graph/graph.go rename to internal/controller/state/graph/graph.go index 61d39fb44c..12017112e0 100644 --- a/internal/mode/static/state/graph/graph.go +++ b/internal/controller/state/graph/graph.go @@ -15,11 +15,11 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller/index" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" ngftypes "github.com/nginx/nginx-gateway-fabric/internal/framework/types" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" ) // ClusterState includes cluster resources necessary to build the Graph. diff --git a/internal/mode/static/state/graph/graph_test.go b/internal/controller/state/graph/graph_test.go similarity index 98% rename from internal/mode/static/state/graph/graph_test.go rename to internal/controller/state/graph/graph_test.go index 0fdeecaeb3..9006e5bd46 100644 --- a/internal/mode/static/state/graph/graph_test.go +++ b/internal/controller/state/graph/graph_test.go @@ -19,15 +19,14 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/policiesfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation/validationfakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller/index" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/policiesfakes" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation/validationfakes" ) func TestBuildGraph(t *testing.T) { @@ -50,9 +49,9 @@ func TestBuildGraph(t *testing.T) { } btpAcceptedConds := []conditions.Condition{ - staticConds.NewPolicyAccepted(), - staticConds.NewPolicyAccepted(), - staticConds.NewPolicyAccepted(), + conditions.NewPolicyAccepted(), + conditions.NewPolicyAccepted(), + conditions.NewPolicyAccepted(), } btp := BackendTLSPolicy{ @@ -824,7 +823,7 @@ func TestBuildGraph(t *testing.T) { Attachment: &ParentRefAttachmentStatus{ Attached: false, AcceptedHostnames: map[string][]string{}, - FailedConditions: []conditions.Condition{staticConds.NewRouteHostnameConflict()}, + FailedConditions: []conditions.Condition{conditions.NewRouteHostnameConflict()}, }, }, }, @@ -918,7 +917,7 @@ func TestBuildGraph(t *testing.T) { GatewayClass: &GatewayClass{ Source: gc, Valid: true, - Conditions: []conditions.Condition{staticConds.NewGatewayClassResolvedRefs()}, + Conditions: []conditions.Condition{conditions.NewGatewayClassResolvedRefs()}, NginxProxy: &NginxProxy{ Source: npGlobal, Valid: true, @@ -1001,7 +1000,7 @@ func TestBuildGraph(t *testing.T) { ErrorLevel: helpers.GetPointer(ngfAPIv1alpha2.NginxLogLevelError), }, }, - Conditions: []conditions.Condition{staticConds.NewGatewayResolvedRefs()}, + Conditions: []conditions.Condition{conditions.NewGatewayResolvedRefs()}, DeploymentName: types.NamespacedName{ Namespace: "test", Name: "gateway-1-my-class", @@ -1077,7 +1076,7 @@ func TestBuildGraph(t *testing.T) { }, IPFamily: helpers.GetPointer(ngfAPIv1alpha2.IPv6), }, - Conditions: []conditions.Condition{staticConds.NewGatewayResolvedRefs()}, + Conditions: []conditions.Condition{conditions.NewGatewayResolvedRefs()}, DeploymentName: types.NamespacedName{ Namespace: "test", Name: "gateway-2-my-class", diff --git a/internal/mode/static/state/graph/grpcroute.go b/internal/controller/state/graph/grpcroute.go similarity index 94% rename from internal/mode/static/state/graph/grpcroute.go rename to internal/controller/state/graph/grpcroute.go index f114a130ee..51976006b4 100644 --- a/internal/mode/static/state/graph/grpcroute.go +++ b/internal/controller/state/graph/grpcroute.go @@ -8,12 +8,11 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" v1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/mirror" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/mirror" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" ) func buildGRPCRoute( @@ -44,7 +43,7 @@ func buildGRPCRoute( field.NewPath("spec").Child("hostnames"), ); err != nil { r.Valid = false - r.Conditions = append(r.Conditions, staticConds.NewRouteUnsupportedValue(err.Error())) + r.Conditions = append(r.Conditions, conditions.NewRouteUnsupportedValue(err.Error())) return r } @@ -258,10 +257,10 @@ func processGRPCRouteRules( msg := allRulesErrors.invalid.ToAggregate().Error() if atLeastOneValid { - conds = append(conds, staticConds.NewRoutePartiallyInvalid(msg)) + conds = append(conds, conditions.NewRoutePartiallyInvalid(msg)) } else { msg = "All rules are invalid: " + msg - conds = append(conds, staticConds.NewRouteUnsupportedValue(msg)) + conds = append(conds, conditions.NewRouteUnsupportedValue(msg)) valid = false } } @@ -269,7 +268,7 @@ func processGRPCRouteRules( // resolve errors do not invalidate routes if len(allRulesErrors.resolve) > 0 { msg := allRulesErrors.resolve.ToAggregate().Error() - conds = append(conds, staticConds.NewRouteResolvedRefsInvalidFilter(msg)) + conds = append(conds, conditions.NewRouteResolvedRefsInvalidFilter(msg)) } return rules, valid, conds diff --git a/internal/mode/static/state/graph/grpcroute_test.go b/internal/controller/state/graph/grpcroute_test.go similarity index 97% rename from internal/mode/static/state/graph/grpcroute_test.go rename to internal/controller/state/graph/grpcroute_test.go index 255a201186..5c9da4c5c6 100644 --- a/internal/mode/static/state/graph/grpcroute_test.go +++ b/internal/controller/state/graph/grpcroute_test.go @@ -11,12 +11,11 @@ import ( v1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/mirror" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation/validationfakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/mirror" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation/validationfakes" ) func createGRPCMethodMatch(serviceName, methodName, methodType string) v1.GRPCRouteRule { @@ -646,7 +645,7 @@ func TestBuildGRPCRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( `All rules are invalid: ` + `[spec.rules[0].matches[0].method.type: Unsupported value: "": supported values: "Exact",` + ` spec.rules[0].matches[0].method.service: Required value: service is required,` + @@ -690,7 +689,7 @@ func TestBuildGRPCRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( `All rules are invalid: ` + `[spec.rules[0].matches[0].method.service: Invalid value: "service{}": invalid path value,` + ` spec.rules[0].matches[0].method.method: Invalid value: "method{}": invalid path value]`, @@ -738,7 +737,7 @@ func TestBuildGRPCRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRoutePartiallyInvalid( + conditions.NewRoutePartiallyInvalid( `spec.rules[1].matches[0].headers[0].type: Unsupported value: "": supported values: "Exact", "RegularExpression"`, ), }, @@ -784,7 +783,7 @@ func TestBuildGRPCRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( `All rules are invalid: spec.rules[0].matches[0].headers[0].type: ` + `Unsupported value: "": supported values: "Exact", "RegularExpression"`, ), @@ -822,7 +821,7 @@ func TestBuildGRPCRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( `All rules are invalid: spec.rules[0].matches[0].headers[0].type: ` + `Required value: cannot be empty`, ), @@ -860,7 +859,7 @@ func TestBuildGRPCRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( `All rules are invalid: spec.rules[0].matches[0].method.type: Required value: cannot be empty`, ), }, @@ -897,7 +896,7 @@ func TestBuildGRPCRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( `All rules are invalid: spec.rules[0].filters[0].type: Unsupported value: ` + `"InvalidFilter": supported values: "ResponseHeaderModifier", ` + `"RequestHeaderModifier", "RequestMirror", "ExtensionRef"`, @@ -942,7 +941,7 @@ func TestBuildGRPCRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( `spec.hostnames[0]: Invalid value: "": cannot be empty string`, ), }, @@ -965,7 +964,7 @@ func TestBuildGRPCRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( "All rules are invalid: spec.rules[0].filters[0].extensionRef: " + "Unsupported value: \"wrong\": supported values: \"gateway.nginx.org\"", ), @@ -1003,7 +1002,7 @@ func TestBuildGRPCRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteResolvedRefsInvalidFilter( + conditions.NewRouteResolvedRefsInvalidFilter( "spec.rules[0].filters[0].extensionRef: Not found: " + "v1.LocalObjectReference{Group:\"gateway.nginx.org\", Kind:\"SnippetsFilter\", " + "Name:\"does-not-exist\"}", @@ -1042,11 +1041,11 @@ func TestBuildGRPCRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( "All rules are invalid: spec.rules[0].filters[1].extensionRef: " + "Unsupported value: \"wrong\": supported values: \"gateway.nginx.org\"", ), - staticConds.NewRouteResolvedRefsInvalidFilter( + conditions.NewRouteResolvedRefsInvalidFilter( "spec.rules[0].filters[0].extensionRef: Not found: " + "v1.LocalObjectReference{Group:\"gateway.nginx.org\", Kind:\"SnippetsFilter\", " + "Name:\"does-not-exist\"}", diff --git a/internal/mode/static/state/graph/httproute.go b/internal/controller/state/graph/httproute.go similarity index 94% rename from internal/mode/static/state/graph/httproute.go rename to internal/controller/state/graph/httproute.go index 408d742dd5..8838e11e17 100644 --- a/internal/mode/static/state/graph/httproute.go +++ b/internal/controller/state/graph/httproute.go @@ -8,12 +8,11 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" v1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/mirror" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/mirror" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" ) var ( @@ -50,7 +49,7 @@ func buildHTTPRoute( field.NewPath("spec").Child("hostnames"), ); err != nil { r.Valid = false - r.Conditions = append(r.Conditions, staticConds.NewRouteUnsupportedValue(err.Error())) + r.Conditions = append(r.Conditions, conditions.NewRouteUnsupportedValue(err.Error())) return r } @@ -265,10 +264,10 @@ func processHTTPRouteRules( msg := allRulesErrors.invalid.ToAggregate().Error() if atLeastOneValid { - conds = append(conds, staticConds.NewRoutePartiallyInvalid(msg)) + conds = append(conds, conditions.NewRoutePartiallyInvalid(msg)) } else { msg = "All rules are invalid: " + msg - conds = append(conds, staticConds.NewRouteUnsupportedValue(msg)) + conds = append(conds, conditions.NewRouteUnsupportedValue(msg)) valid = false } } @@ -276,7 +275,7 @@ func processHTTPRouteRules( // resolve errors do not invalidate routes if len(allRulesErrors.resolve) > 0 { msg := allRulesErrors.resolve.ToAggregate().Error() - conds = append(conds, staticConds.NewRouteResolvedRefsInvalidFilter(msg)) + conds = append(conds, conditions.NewRouteResolvedRefsInvalidFilter(msg)) } return rules, valid, conds diff --git a/internal/mode/static/state/graph/httproute_test.go b/internal/controller/state/graph/httproute_test.go similarity index 98% rename from internal/mode/static/state/graph/httproute_test.go rename to internal/controller/state/graph/httproute_test.go index ee0d2dac27..03d4ca2820 100644 --- a/internal/mode/static/state/graph/httproute_test.go +++ b/internal/controller/state/graph/httproute_test.go @@ -12,12 +12,11 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/mirror" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation/validationfakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/mirror" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation/validationfakes" ) const ( @@ -427,7 +426,7 @@ func TestBuildHTTPRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( `All rules are invalid: spec.rules[0].matches[0].path.type: Required value: path type cannot be nil`, ), }, @@ -473,7 +472,7 @@ func TestBuildHTTPRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( `All rules are invalid: spec.rules[0].matches[0].path.value: Required value: path value cannot be nil`, ), }, @@ -516,7 +515,7 @@ func TestBuildHTTPRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( `spec.hostnames[0]: Invalid value: "": cannot be empty string`, ), }, @@ -539,7 +538,7 @@ func TestBuildHTTPRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( `All rules are invalid: spec.rules[0].matches[0].path.value: Invalid value: "/invalid": invalid path`, ), }, @@ -576,7 +575,7 @@ func TestBuildHTTPRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( `All rules are invalid: spec.rules[0].filters[0].requestRedirect.hostname: ` + `Invalid value: "invalid.example.com": invalid hostname`, ), @@ -614,7 +613,7 @@ func TestBuildHTTPRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRoutePartiallyInvalid( + conditions.NewRoutePartiallyInvalid( `spec.rules[0].matches[0].path.value: Invalid value: "/invalid": invalid path`, ), }, @@ -661,7 +660,7 @@ func TestBuildHTTPRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRoutePartiallyInvalid( + conditions.NewRoutePartiallyInvalid( `[spec.rules[0].matches[0].path.value: Invalid value: "/invalid": invalid path, ` + `spec.rules[1].filters[0].requestRedirect.hostname: Invalid value: ` + `"invalid.example.com": invalid hostname]`, @@ -720,7 +719,7 @@ func TestBuildHTTPRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRoutePartiallyInvalid( + conditions.NewRoutePartiallyInvalid( `spec.rules[1].filters[0].requestRedirect.hostname: Invalid value: ` + `"invalid.example.com": invalid hostname`, ), @@ -809,7 +808,7 @@ func TestBuildHTTPRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( "All rules are invalid: spec.rules[0].filters[0].extensionRef: " + "Unsupported value: \"wrong\": supported values: \"gateway.nginx.org\"", ), @@ -847,7 +846,7 @@ func TestBuildHTTPRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteResolvedRefsInvalidFilter( + conditions.NewRouteResolvedRefsInvalidFilter( "spec.rules[0].filters[0].extensionRef: Not found: " + "v1.LocalObjectReference{Group:\"gateway.nginx.org\", Kind:\"SnippetsFilter\", " + "Name:\"does-not-exist\"}", @@ -886,11 +885,11 @@ func TestBuildHTTPRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( "All rules are invalid: spec.rules[0].filters[0].extensionRef: " + "Unsupported value: \"wrong\": supported values: \"gateway.nginx.org\"", ), - staticConds.NewRouteResolvedRefsInvalidFilter( + conditions.NewRouteResolvedRefsInvalidFilter( "spec.rules[0].filters[1].extensionRef: Not found: " + "v1.LocalObjectReference{Group:\"gateway.nginx.org\", Kind:\"SnippetsFilter\", " + "Name:\"does-not-exist\"}", diff --git a/internal/mode/static/state/graph/multiple_gateways_test.go b/internal/controller/state/graph/multiple_gateways_test.go similarity index 96% rename from internal/mode/static/state/graph/multiple_gateways_test.go rename to internal/controller/state/graph/multiple_gateways_test.go index 497fbd9680..415a5851ab 100644 --- a/internal/mode/static/state/graph/multiple_gateways_test.go +++ b/internal/controller/state/graph/multiple_gateways_test.go @@ -13,12 +13,11 @@ import ( "sigs.k8s.io/gateway-api/apis/v1beta1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation/validationfakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation/validationfakes" ) const ( @@ -244,7 +243,7 @@ func Test_MultipleGateways_WithNginxProxy(t *testing.T) { gateway1withNP := createGateway("gateway-1", testNs, "nginx-proxy-gateway-1", []gatewayv1.Listener{}) gateway3withNP := createGateway("gateway-3", "test2", "nginx-proxy-gateway-3", []gatewayv1.Listener{}) - gcConditions := []conditions.Condition{staticConds.NewGatewayClassResolvedRefs()} + gcConditions := []conditions.Condition{conditions.NewGatewayClassResolvedRefs()} tests := []struct { clusterState ClusterState @@ -601,7 +600,7 @@ func Test_MultipleGateways_WithListeners(t *testing.T) { }, }, expGraph: &Graph{ - GatewayClass: convertedGatewayClass(gatewayClass, *nginxProxyGlobal, staticConds.NewGatewayClassResolvedRefs()), + GatewayClass: convertedGatewayClass(gatewayClass, *nginxProxyGlobal, conditions.NewGatewayClassResolvedRefs()), Gateways: map[types.NamespacedName]*Gateway{ client.ObjectKeyFromObject(gateway1): convertedGateway( gateway1, @@ -617,7 +616,7 @@ func Test_MultipleGateways_WithListeners(t *testing.T) { map[L4RouteKey]*L4Route{}, ), }, - []conditions.Condition{staticConds.NewGatewayClassResolvedRefs()}, + []conditions.Condition{conditions.NewGatewayClassResolvedRefs()}, ), client.ObjectKeyFromObject(gateway2): convertedGateway( gateway2, @@ -633,7 +632,7 @@ func Test_MultipleGateways_WithListeners(t *testing.T) { map[L4RouteKey]*L4Route{}, ), }, - []conditions.Condition{staticConds.NewGatewayClassResolvedRefs()}, + []conditions.Condition{conditions.NewGatewayClassResolvedRefs()}, ), }, Routes: map[RouteKey]*L7Route{}, @@ -674,7 +673,7 @@ func Test_MultipleGateways_WithListeners(t *testing.T) { }, }, expGraph: &Graph{ - GatewayClass: convertedGatewayClass(gatewayClass, *nginxProxyGlobal, staticConds.NewGatewayClassResolvedRefs()), + GatewayClass: convertedGatewayClass(gatewayClass, *nginxProxyGlobal, conditions.NewGatewayClassResolvedRefs()), Gateways: map[types.NamespacedName]*Gateway{ client.ObjectKeyFromObject(gatewayMultipleListeners1): convertedGateway( gatewayMultipleListeners1, @@ -706,7 +705,7 @@ func Test_MultipleGateways_WithListeners(t *testing.T) { map[L4RouteKey]*L4Route{}, ), }, - []conditions.Condition{staticConds.NewGatewayClassResolvedRefs()}, + []conditions.Condition{conditions.NewGatewayClassResolvedRefs()}, ), client.ObjectKeyFromObject(gatewayMultipleListeners2): convertedGateway( gatewayMultipleListeners2, @@ -738,7 +737,7 @@ func Test_MultipleGateways_WithListeners(t *testing.T) { map[L4RouteKey]*L4Route{}, ), }, - []conditions.Condition{staticConds.NewGatewayClassResolvedRefs()}, + []conditions.Condition{conditions.NewGatewayClassResolvedRefs()}, ), client.ObjectKeyFromObject(gatewayMultipleListeners3): convertedGateway( gatewayMultipleListeners3, @@ -770,7 +769,7 @@ func Test_MultipleGateways_WithListeners(t *testing.T) { map[L4RouteKey]*L4Route{}, ), }, - []conditions.Condition{staticConds.NewGatewayClassResolvedRefs()}, + []conditions.Condition{conditions.NewGatewayClassResolvedRefs()}, ), }, Routes: map[RouteKey]*L7Route{}, @@ -809,7 +808,7 @@ func Test_MultipleGateways_WithListeners(t *testing.T) { }, }, expGraph: &Graph{ - GatewayClass: convertedGatewayClass(gatewayClass, *nginxProxyGlobal, staticConds.NewGatewayClassResolvedRefs()), + GatewayClass: convertedGatewayClass(gatewayClass, *nginxProxyGlobal, conditions.NewGatewayClassResolvedRefs()), Gateways: map[types.NamespacedName]*Gateway{ client.ObjectKeyFromObject(gatewayTLSSamePortHostname): convertedGateway( gatewayTLSSamePortHostname, @@ -825,7 +824,7 @@ func Test_MultipleGateways_WithListeners(t *testing.T) { map[L4RouteKey]*L4Route{}, ), }, - []conditions.Condition{staticConds.NewGatewayClassResolvedRefs()}, + []conditions.Condition{conditions.NewGatewayClassResolvedRefs()}, ), client.ObjectKeyFromObject(gatewayHTTPSSamePortHostname): convertedGateway( gatewayHTTPSSamePortHostname, @@ -841,7 +840,7 @@ func Test_MultipleGateways_WithListeners(t *testing.T) { map[L4RouteKey]*L4Route{}, ), }, - []conditions.Condition{staticConds.NewGatewayClassResolvedRefs()}, + []conditions.Condition{conditions.NewGatewayClassResolvedRefs()}, ), }, Routes: map[RouteKey]*L7Route{}, diff --git a/internal/mode/static/state/graph/namespace.go b/internal/controller/state/graph/namespace.go similarity index 100% rename from internal/mode/static/state/graph/namespace.go rename to internal/controller/state/graph/namespace.go diff --git a/internal/mode/static/state/graph/namespace_test.go b/internal/controller/state/graph/namespace_test.go similarity index 100% rename from internal/mode/static/state/graph/namespace_test.go rename to internal/controller/state/graph/namespace_test.go diff --git a/internal/mode/static/state/graph/nginxproxy.go b/internal/controller/state/graph/nginxproxy.go similarity index 99% rename from internal/mode/static/state/graph/nginxproxy.go rename to internal/controller/state/graph/nginxproxy.go index 3b72161233..77c50934ef 100644 --- a/internal/mode/static/state/graph/nginxproxy.go +++ b/internal/controller/state/graph/nginxproxy.go @@ -13,8 +13,8 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" ) // NginxProxy represents the NginxProxy resource. diff --git a/internal/mode/static/state/graph/nginxproxy_test.go b/internal/controller/state/graph/nginxproxy_test.go similarity index 99% rename from internal/mode/static/state/graph/nginxproxy_test.go rename to internal/controller/state/graph/nginxproxy_test.go index 5d99148874..c8713ea116 100644 --- a/internal/mode/static/state/graph/nginxproxy_test.go +++ b/internal/controller/state/graph/nginxproxy_test.go @@ -12,10 +12,10 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation/validationfakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation/validationfakes" ) func createValidValidator() *validationfakes.FakeGenericValidator { diff --git a/internal/mode/static/state/graph/policies.go b/internal/controller/state/graph/policies.go similarity index 93% rename from internal/mode/static/state/graph/policies.go rename to internal/controller/state/graph/policies.go index 50dd3c3601..b5a1251aee 100644 --- a/internal/mode/static/state/graph/policies.go +++ b/internal/controller/state/graph/policies.go @@ -9,12 +9,11 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" v1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + ngfsort "github.com/nginx/nginx-gateway-fabric/internal/controller/sort" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - ngfsort "github.com/nginx/nginx-gateway-fabric/internal/mode/static/sort" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" ) // Policy represents an NGF Policy. @@ -121,7 +120,7 @@ func attachPolicyToService( if !gw.Valid { policy.InvalidForGateways[gwNsName] = struct{}{} - ancestor.Conditions = []conditions.Condition{staticConds.NewPolicyTargetNotFound("Parent Gateway is invalid")} + ancestor.Conditions = []conditions.Condition{conditions.NewPolicyTargetNotFound("Parent Gateway is invalid")} if ancestorsContainsAncestorRef(policy.Ancestors, ancestor.Ancestor) { continue } @@ -159,7 +158,7 @@ func attachPolicyToRoute(policy *Policy, route *L7Route, validator validation.Po } if !route.Valid || !route.Attachable || len(route.ParentRefs) == 0 { - ancestor.Conditions = []conditions.Condition{staticConds.NewPolicyTargetNotFound("TargetRef is invalid")} + ancestor.Conditions = []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is invalid")} policy.Ancestors = append(policy.Ancestors, ancestor) return } @@ -206,14 +205,14 @@ func attachPolicyToGateway( if !exists || (gw != nil && gw.Source == nil) { policy.InvalidForGateways[ref.Nsname] = struct{}{} - ancestor.Conditions = []conditions.Condition{staticConds.NewPolicyTargetNotFound("TargetRef is not found")} + ancestor.Conditions = []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is not found")} policy.Ancestors = append(policy.Ancestors, ancestor) return } if !gw.Valid { policy.InvalidForGateways[ref.Nsname] = struct{}{} - ancestor.Conditions = []conditions.Condition{staticConds.NewPolicyTargetNotFound("TargetRef is invalid")} + ancestor.Conditions = []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is invalid")} policy.Ancestors = append(policy.Ancestors, ancestor) return } @@ -338,7 +337,7 @@ func checkForRouteOverlap(route *L7Route, hostPortPaths map[string]string) *cond conflictingRouteName := fmt.Sprintf("%s/%s", route.Source.GetNamespace(), route.Source.GetName()) msg := fmt.Sprintf("Policy cannot be applied to target %q since another "+ "Route %q shares a hostname:port/path combination with this target", val, conflictingRouteName) - cond := staticConds.NewPolicyNotAcceptedTargetConflict(msg) + cond := conditions.NewPolicyNotAcceptedTargetConflict(msg) return &cond } @@ -429,7 +428,7 @@ func markConflictedPolicies(pols map[PolicyKey]*Policy, validator validation.Pol if validator.Conflicts(policyList[i].Source, policyList[j].Source) { conflicted := policyList[j] conflicted.Valid = false - conflicted.Conditions = append(conflicted.Conditions, staticConds.NewPolicyConflicted( + conflicted.Conditions = append(conflicted.Conditions, conditions.NewPolicyConflicted( fmt.Sprintf( "Conflicts with another %s", conflicted.Source.GetObjectKind().GroupVersionKind().Kind, diff --git a/internal/mode/static/state/graph/policies_test.go b/internal/controller/state/graph/policies_test.go similarity index 96% rename from internal/mode/static/state/graph/policies_test.go rename to internal/controller/state/graph/policies_test.go index 4adda19357..6d477ea809 100644 --- a/internal/mode/static/state/graph/policies_test.go +++ b/internal/controller/state/graph/policies_test.go @@ -12,13 +12,12 @@ import ( "sigs.k8s.io/gateway-api/apis/v1alpha2" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/policiesfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/policiesfakes" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" ) var testNs = "test" @@ -301,7 +300,7 @@ func TestAttachPolicyToRoute(t *testing.T) { ValidateGlobalSettingsStub: func(_ policies.Policy, gs *policies.GlobalSettings) []conditions.Condition { if !gs.TelemetryEnabled { return []conditions.Condition{ - staticConds.NewPolicyNotAcceptedNginxProxyNotSet(staticConds.PolicyMessageTelemetryNotEnabled), + conditions.NewPolicyNotAcceptedNginxProxyNotSet(conditions.PolicyMessageTelemetryNotEnabled), } } return nil @@ -360,7 +359,7 @@ func TestAttachPolicyToRoute(t *testing.T) { expAncestors: []PolicyAncestor{ { Ancestor: createExpAncestor(kinds.HTTPRoute), - Conditions: []conditions.Condition{staticConds.NewPolicyTargetNotFound("TargetRef is invalid")}, + Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is invalid")}, }, }, expAttached: false, @@ -373,7 +372,7 @@ func TestAttachPolicyToRoute(t *testing.T) { expAncestors: []PolicyAncestor{ { Ancestor: createExpAncestor(kinds.HTTPRoute), - Conditions: []conditions.Condition{staticConds.NewPolicyTargetNotFound("TargetRef is invalid")}, + Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is invalid")}, }, }, expAttached: false, @@ -386,7 +385,7 @@ func TestAttachPolicyToRoute(t *testing.T) { expAncestors: []PolicyAncestor{ { Ancestor: createExpAncestor(kinds.HTTPRoute), - Conditions: []conditions.Condition{staticConds.NewPolicyTargetNotFound("TargetRef is invalid")}, + Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is invalid")}, }, }, expAttached: false, @@ -447,7 +446,7 @@ func TestAttachPolicyToRoute(t *testing.T) { { Ancestor: createExpAncestor(kinds.HTTPRoute), Conditions: []conditions.Condition{ - staticConds.NewPolicyNotAcceptedNginxProxyNotSet(staticConds.PolicyMessageTelemetryNotEnabled), + conditions.NewPolicyNotAcceptedNginxProxyNotSet(conditions.PolicyMessageTelemetryNotEnabled), }, }, }, @@ -486,7 +485,7 @@ func TestAttachPolicyToRoute(t *testing.T) { { Ancestor: createExpAncestor(kinds.HTTPRoute), Conditions: []conditions.Condition{ - staticConds.NewPolicyNotAcceptedNginxProxyNotSet(staticConds.PolicyMessageTelemetryNotEnabled), + conditions.NewPolicyNotAcceptedNginxProxyNotSet(conditions.PolicyMessageTelemetryNotEnabled), }, }, }, @@ -596,7 +595,7 @@ func TestAttachPolicyToGateway(t *testing.T) { expAncestors: []PolicyAncestor{ { Ancestor: getGatewayParentRef(gateway2NsName), - Conditions: []conditions.Condition{staticConds.NewPolicyTargetNotFound("TargetRef is not found")}, + Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is not found")}, }, }, expAttached: false, @@ -617,7 +616,7 @@ func TestAttachPolicyToGateway(t *testing.T) { expAncestors: []PolicyAncestor{ { Ancestor: getGatewayParentRef(gatewayNsName), - Conditions: []conditions.Condition{staticConds.NewPolicyTargetNotFound("TargetRef is invalid")}, + Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("TargetRef is invalid")}, }, }, expAttached: false, @@ -771,7 +770,7 @@ func TestAttachPolicyToService(t *testing.T) { expAncestors: []PolicyAncestor{ { Ancestor: getGatewayParentRef(gwNsname), - Conditions: []conditions.Condition{staticConds.NewPolicyTargetNotFound("Parent Gateway is invalid")}, + Conditions: []conditions.Condition{conditions.NewPolicyTargetNotFound("Parent Gateway is invalid")}, }, }, }, @@ -977,7 +976,7 @@ func TestProcessPolicies(t *testing.T) { validator: &policiesfakes.FakeValidator{ ValidateStub: func(policy policies.Policy) []conditions.Condition { if policy.GetName() == "pol1" { - return []conditions.Condition{staticConds.NewPolicyInvalid("invalid error")} + return []conditions.Condition{conditions.NewPolicyInvalid("invalid error")} } return nil @@ -998,7 +997,7 @@ func TestProcessPolicies(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewPolicyInvalid("invalid error"), + conditions.NewPolicyInvalid("invalid error"), }, Ancestors: []PolicyAncestor{}, InvalidForGateways: map[types.NamespacedName]struct{}{}, @@ -1054,7 +1053,7 @@ func TestProcessPolicies(t *testing.T) { }, }, Conditions: []conditions.Condition{ - staticConds.NewPolicyConflicted("Conflicts with another MyPolicy"), + conditions.NewPolicyConflicted("Conflicts with another MyPolicy"), }, Ancestors: []PolicyAncestor{}, InvalidForGateways: map[types.NamespacedName]struct{}{}, @@ -1406,7 +1405,7 @@ func TestMarkConflictedPolicies(t *testing.T) { g.Expect(test.fakeValidator.ConflictsCallCount()).To(BeZero()) } else { g.Expect(test.fakeValidator.ConflictsCallCount()).To(Not(BeZero())) - expConflictCond := staticConds.NewPolicyConflicted("Conflicts with another OrangePolicy") + expConflictCond := conditions.NewPolicyConflicted("Conflicts with another OrangePolicy") for key, policy := range test.policies { if slices.Contains(test.conflictedNames, key.NsName.Name) { diff --git a/internal/mode/static/state/graph/policy_ancestor.go b/internal/controller/state/graph/policy_ancestor.go similarity index 100% rename from internal/mode/static/state/graph/policy_ancestor.go rename to internal/controller/state/graph/policy_ancestor.go diff --git a/internal/mode/static/state/graph/policy_ancestor_test.go b/internal/controller/state/graph/policy_ancestor_test.go similarity index 100% rename from internal/mode/static/state/graph/policy_ancestor_test.go rename to internal/controller/state/graph/policy_ancestor_test.go diff --git a/internal/mode/static/state/graph/reference_grant.go b/internal/controller/state/graph/reference_grant.go similarity index 100% rename from internal/mode/static/state/graph/reference_grant.go rename to internal/controller/state/graph/reference_grant.go diff --git a/internal/mode/static/state/graph/reference_grant_test.go b/internal/controller/state/graph/reference_grant_test.go similarity index 100% rename from internal/mode/static/state/graph/reference_grant_test.go rename to internal/controller/state/graph/reference_grant_test.go diff --git a/internal/mode/static/state/graph/route_common.go b/internal/controller/state/graph/route_common.go similarity index 96% rename from internal/mode/static/state/graph/route_common.go rename to internal/controller/state/graph/route_common.go index e97c552f52..c702f1d46a 100644 --- a/internal/mode/static/state/graph/route_common.go +++ b/internal/controller/state/graph/route_common.go @@ -13,11 +13,10 @@ import ( v1 "sigs.k8s.io/gateway-api/apis/v1" v1alpha "sigs.k8s.io/gateway-api/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + ngfSort "github.com/nginx/nginx-gateway-fabric/internal/controller/sort" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - ngfSort "github.com/nginx/nginx-gateway-fabric/internal/mode/static/sort" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" ) const wildcardHostname = "~^" @@ -515,7 +514,7 @@ func validateParentRef( // Case 1: Attachment is not possible because the specified SectionName does not match any Listeners in the // Gateway. if !listenerExists { - attachment.FailedConditions = append(attachment.FailedConditions, staticConds.NewRouteNoMatchingParent()) + attachment.FailedConditions = append(attachment.FailedConditions, conditions.NewRouteNoMatchingParent()) return attachment, nil } @@ -524,7 +523,7 @@ func validateParentRef( if ref.Port != nil { valErr := field.Forbidden(path.Child("port"), "cannot be set") attachment.FailedConditions = append( - attachment.FailedConditions, staticConds.NewRouteUnsupportedValue(valErr.Error()), + attachment.FailedConditions, conditions.NewRouteUnsupportedValue(valErr.Error()), ) return attachment, attachableListeners } @@ -532,7 +531,7 @@ func validateParentRef( // Case 3: Attachment is not possible because Gateway is invalid if !gw.Valid { - attachment.FailedConditions = append(attachment.FailedConditions, staticConds.NewRouteInvalidGateway()) + attachment.FailedConditions = append(attachment.FailedConditions, conditions.NewRouteInvalidGateway()) return attachment, attachableListeners } @@ -607,7 +606,7 @@ func tryToAttachL4RouteToListeners( portHostnamesMap map[string]struct{}, ) (conditions.Condition, bool) { if len(attachableListeners) == 0 { - return staticConds.NewRouteInvalidListener(), false + return conditions.NewRouteInvalidListener(), false } var ( @@ -645,16 +644,16 @@ func tryToAttachL4RouteToListeners( if !attached { if !allowed { - return staticConds.NewRouteNotAllowedByListeners(), false + return conditions.NewRouteNotAllowedByListeners(), false } if !hostnamesUnique { - return staticConds.NewRouteHostnameConflict(), false + return conditions.NewRouteHostnameConflict(), false } - return staticConds.NewRouteNoMatchingListenerHostname(), false + return conditions.NewRouteNoMatchingListenerHostname(), false } if !attachedToAtLeastOneValidListener { - return staticConds.NewRouteInvalidListener(), true + return conditions.NewRouteInvalidListener(), true } return conditions.Condition{}, true @@ -731,7 +730,7 @@ func bindL7RouteToListeners( if route.RouteType == RouteTypeGRPC && isHTTP2Disabled(gw.EffectiveNginxProxy) { msg := "HTTP2 is disabled - cannot configure GRPCRoutes" attachment.FailedConditions = append( - attachment.FailedConditions, staticConds.NewRouteUnsupportedConfiguration(msg), + attachment.FailedConditions, conditions.NewRouteUnsupportedConfiguration(msg), ) } @@ -793,7 +792,7 @@ func tryToAttachL7RouteToListeners( namespaces map[types.NamespacedName]*apiv1.Namespace, ) (conditions.Condition, bool) { if len(attachableListeners) == 0 { - return staticConds.NewRouteInvalidListener(), false + return conditions.NewRouteInvalidListener(), false } rk := CreateRouteKey(route.Source) @@ -832,13 +831,13 @@ func tryToAttachL7RouteToListeners( if !attached { if !allowed { - return staticConds.NewRouteNotAllowedByListeners(), false + return conditions.NewRouteNotAllowedByListeners(), false } - return staticConds.NewRouteNoMatchingListenerHostname(), false + return conditions.NewRouteNoMatchingListenerHostname(), false } if !attachedToAtLeastOneValidListener { - return staticConds.NewRouteInvalidListener(), true + return conditions.NewRouteInvalidListener(), true } return conditions.Condition{}, true diff --git a/internal/mode/static/state/graph/route_common_test.go b/internal/controller/state/graph/route_common_test.go similarity index 98% rename from internal/mode/static/state/graph/route_common_test.go rename to internal/controller/state/graph/route_common_test.go index dc127bb3b8..8acf8c005b 100644 --- a/internal/mode/static/state/graph/route_common_test.go +++ b/internal/controller/state/graph/route_common_test.go @@ -14,10 +14,9 @@ import ( gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" "sigs.k8s.io/gateway-api/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) func TestBuildSectionNameRefs(t *testing.T) { @@ -670,7 +669,7 @@ func TestBindRouteToListeners(t *testing.T) { SectionName: hrWithEmptySectionName.Spec.ParentRefs[0].SectionName, Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedConditions: []conditions.Condition{staticConds.NewRouteInvalidListener()}, + FailedConditions: []conditions.Condition{conditions.NewRouteInvalidListener()}, AcceptedHostnames: map[string][]string{}, }, }, @@ -697,7 +696,7 @@ func TestBindRouteToListeners(t *testing.T) { Attachment: &ParentRefAttachmentStatus{ Attached: false, FailedConditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( `spec.parentRefs[0].port: Forbidden: cannot be set`, ), }, @@ -727,7 +726,7 @@ func TestBindRouteToListeners(t *testing.T) { SectionName: hrWithNonExistingListener.Spec.ParentRefs[0].SectionName, Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedConditions: []conditions.Condition{staticConds.NewRouteNoMatchingParent()}, + FailedConditions: []conditions.Condition{conditions.NewRouteNoMatchingParent()}, AcceptedHostnames: map[string][]string{}, }, }, @@ -753,7 +752,7 @@ func TestBindRouteToListeners(t *testing.T) { SectionName: hr.Spec.ParentRefs[0].SectionName, Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedConditions: []conditions.Condition{staticConds.NewRouteInvalidListener()}, + FailedConditions: []conditions.Condition{conditions.NewRouteInvalidListener()}, AcceptedHostnames: map[string][]string{}, }, }, @@ -779,7 +778,7 @@ func TestBindRouteToListeners(t *testing.T) { SectionName: hr.Spec.ParentRefs[0].SectionName, Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedConditions: []conditions.Condition{staticConds.NewRouteNoMatchingListenerHostname()}, + FailedConditions: []conditions.Condition{conditions.NewRouteNoMatchingListenerHostname()}, AcceptedHostnames: map[string][]string{}, }, }, @@ -827,7 +826,7 @@ func TestBindRouteToListeners(t *testing.T) { SectionName: hr.Spec.ParentRefs[0].SectionName, Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedConditions: []conditions.Condition{staticConds.NewRouteInvalidGateway()}, + FailedConditions: []conditions.Condition{conditions.NewRouteInvalidGateway()}, AcceptedHostnames: map[string][]string{}, }, }, @@ -872,7 +871,7 @@ func TestBindRouteToListeners(t *testing.T) { } }), }, - expectedConditions: []conditions.Condition{staticConds.NewRouteInvalidListener()}, + expectedConditions: []conditions.Condition{conditions.NewRouteInvalidListener()}, name: "invalid attachable listener", }, { @@ -944,7 +943,7 @@ func TestBindRouteToListeners(t *testing.T) { } }), }, - expectedConditions: []conditions.Condition{staticConds.NewRouteInvalidListener()}, + expectedConditions: []conditions.Condition{conditions.NewRouteInvalidListener()}, name: "invalid attachable listener with invalid attachable route", }, { @@ -971,7 +970,7 @@ func TestBindRouteToListeners(t *testing.T) { SectionName: hr.Spec.ParentRefs[0].SectionName, Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedConditions: []conditions.Condition{staticConds.NewRouteNotAllowedByListeners()}, + FailedConditions: []conditions.Condition{conditions.NewRouteNotAllowedByListeners()}, AcceptedHostnames: map[string][]string{}, }, }, @@ -1060,7 +1059,7 @@ func TestBindRouteToListeners(t *testing.T) { SectionName: hr.Spec.ParentRefs[0].SectionName, Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedConditions: []conditions.Condition{staticConds.NewRouteNotAllowedByListeners()}, + FailedConditions: []conditions.Condition{conditions.NewRouteNotAllowedByListeners()}, AcceptedHostnames: map[string][]string{}, }, }, @@ -1189,7 +1188,7 @@ func TestBindRouteToListeners(t *testing.T) { SectionName: gr.Spec.ParentRefs[0].SectionName, Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedConditions: []conditions.Condition{staticConds.NewRouteNotAllowedByListeners()}, + FailedConditions: []conditions.Condition{conditions.NewRouteNotAllowedByListeners()}, AcceptedHostnames: map[string][]string{}, }, }, @@ -1235,7 +1234,7 @@ func TestBindRouteToListeners(t *testing.T) { Attachment: &ParentRefAttachmentStatus{ Attached: false, FailedConditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedConfiguration( + conditions.NewRouteUnsupportedConfiguration( `HTTP2 is disabled - cannot configure GRPCRoutes`, ), }, @@ -1722,7 +1721,7 @@ func TestBindL4RouteToListeners(t *testing.T) { noMatchingParentAttachment := ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedConditions: []conditions.Condition{staticConds.NewRouteNoMatchingParent()}, + FailedConditions: []conditions.Condition{conditions.NewRouteNoMatchingParent()}, } notAttachableRoute := &L4Route{ @@ -1878,7 +1877,7 @@ func TestBindL4RouteToListeners(t *testing.T) { Attachment: &ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, FailedConditions: []conditions.Condition{ - staticConds.NewRouteUnsupportedValue( + conditions.NewRouteUnsupportedValue( `spec.parentRefs[0].port: Forbidden: cannot be set`, ), }, @@ -1912,7 +1911,7 @@ func TestBindL4RouteToListeners(t *testing.T) { { Attachment: &ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedConditions: []conditions.Condition{staticConds.NewRouteInvalidGateway()}, + FailedConditions: []conditions.Condition{conditions.NewRouteInvalidGateway()}, Attached: false, }, SectionName: tr.Spec.ParentRefs[0].SectionName, @@ -1952,7 +1951,7 @@ func TestBindL4RouteToListeners(t *testing.T) { SectionName: tr.Spec.ParentRefs[0].SectionName, Attachment: &ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedConditions: []conditions.Condition{staticConds.NewRouteNotAllowedByListeners()}, + FailedConditions: []conditions.Condition{conditions.NewRouteNotAllowedByListeners()}, }, }, }, @@ -2003,7 +2002,7 @@ func TestBindL4RouteToListeners(t *testing.T) { createModifiedListener("listener-443", func(l *Listener) { l.Valid = false r := createNormalRoute(gw) - r.Conditions = append(r.Conditions, staticConds.NewRouteInvalidListener()) + r.Conditions = append(r.Conditions, conditions.NewRouteInvalidListener()) r.ParentRefs = []ParentRef{ { Idx: 0, @@ -2025,7 +2024,7 @@ func TestBindL4RouteToListeners(t *testing.T) { } }), }, - expectedConditions: []conditions.Condition{staticConds.NewRouteInvalidListener()}, + expectedConditions: []conditions.Condition{conditions.NewRouteInvalidListener()}, name: "invalid attachable listener", }, { @@ -2050,7 +2049,7 @@ func TestBindL4RouteToListeners(t *testing.T) { SectionName: tr.Spec.ParentRefs[0].SectionName, Attachment: &ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedConditions: []conditions.Condition{staticConds.NewRouteNoMatchingListenerHostname()}, + FailedConditions: []conditions.Condition{conditions.NewRouteNoMatchingListenerHostname()}, }, }, }, @@ -2223,7 +2222,7 @@ func TestBindL4RouteToListeners(t *testing.T) { Gateway: &ParentRefGateway{NamespacedName: client.ObjectKeyFromObject(gw)}, Attachment: &ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedConditions: []conditions.Condition{staticConds.NewRouteNotAllowedByListeners()}, + FailedConditions: []conditions.Condition{conditions.NewRouteNotAllowedByListeners()}, }, SectionName: helpers.GetPointer[gatewayv1.SectionName]("listener-443"), }, @@ -2369,7 +2368,7 @@ func TestTryToAttachL4RouteToListeners_NoAttachableListeners(t *testing.T) { nil, map[string]struct{}{}, ) - g.Expect(cond).To(Equal(staticConds.NewRouteInvalidListener())) + g.Expect(cond).To(Equal(conditions.NewRouteInvalidListener())) g.Expect(attachable).To(BeFalse()) } diff --git a/internal/mode/static/state/graph/secret.go b/internal/controller/state/graph/secret.go similarity index 100% rename from internal/mode/static/state/graph/secret.go rename to internal/controller/state/graph/secret.go diff --git a/internal/mode/static/state/graph/secret_test.go b/internal/controller/state/graph/secret_test.go similarity index 100% rename from internal/mode/static/state/graph/secret_test.go rename to internal/controller/state/graph/secret_test.go diff --git a/internal/mode/static/state/graph/service.go b/internal/controller/state/graph/service.go similarity index 100% rename from internal/mode/static/state/graph/service.go rename to internal/controller/state/graph/service.go diff --git a/internal/mode/static/state/graph/service_test.go b/internal/controller/state/graph/service_test.go similarity index 100% rename from internal/mode/static/state/graph/service_test.go rename to internal/controller/state/graph/service_test.go diff --git a/internal/mode/static/state/graph/snippets_filter.go b/internal/controller/state/graph/snippets_filter.go similarity index 92% rename from internal/mode/static/state/graph/snippets_filter.go rename to internal/controller/state/graph/snippets_filter.go index 3904d34777..e9d7c927d6 100644 --- a/internal/mode/static/state/graph/snippets_filter.go +++ b/internal/controller/state/graph/snippets_filter.go @@ -6,9 +6,8 @@ import ( v1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) // SnippetsFilter represents a ngfAPI.SnippetsFilter. @@ -98,7 +97,7 @@ func validateSnippetsFilter(filter *ngfAPI.SnippetsFilter) *conditions.Condition snippetsPath := field.NewPath("spec.snippets") if len(filter.Spec.Snippets) == 0 { - cond := staticConds.NewSnippetsFilterInvalid( + cond := conditions.NewSnippetsFilterInvalid( field.Required(snippetsPath, "at least one snippet must be provided").Error(), ) return &cond @@ -109,7 +108,7 @@ func validateSnippetsFilter(filter *ngfAPI.SnippetsFilter) *conditions.Condition for i, snippet := range filter.Spec.Snippets { valuePath := snippetsPath.Index(i).Child("value") if snippet.Value == "" { - cond := staticConds.NewSnippetsFilterInvalid( + cond := conditions.NewSnippetsFilterInvalid( field.Required(valuePath, "value cannot be empty").Error(), ) @@ -151,7 +150,7 @@ func validateSnippetsFilter(filter *ngfAPI.SnippetsFilter) *conditions.Condition } if allErrs != nil { - cond := staticConds.NewSnippetsFilterInvalid(allErrs.ToAggregate().Error()) + cond := conditions.NewSnippetsFilterInvalid(allErrs.ToAggregate().Error()) return &cond } diff --git a/internal/mode/static/state/graph/snippets_filter_test.go b/internal/controller/state/graph/snippets_filter_test.go similarity index 95% rename from internal/mode/static/state/graph/snippets_filter_test.go rename to internal/controller/state/graph/snippets_filter_test.go index dd617c409d..a37ec8db99 100644 --- a/internal/mode/static/state/graph/snippets_filter_test.go +++ b/internal/controller/state/graph/snippets_filter_test.go @@ -9,9 +9,8 @@ import ( v1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) func TestProcessSnippetsFilters(t *testing.T) { @@ -102,7 +101,7 @@ func TestProcessSnippetsFilters(t *testing.T) { invalidFilterNsName: { Source: invalidFilter, Conditions: []conditions.Condition{ - staticConds.NewSnippetsFilterInvalid( + conditions.NewSnippetsFilterInvalid( "spec.snippets[1].context: Unsupported value: \"invalid context\": " + "supported values: \"main\", \"http\", \"http.server\", \"http.server.location\"", ), @@ -153,7 +152,7 @@ func TestValidateSnippetsFilter(t *testing.T) { { msg: "empty filter", filter: &ngfAPI.SnippetsFilter{}, - expCond: staticConds.NewSnippetsFilterInvalid( + expCond: conditions.NewSnippetsFilterInvalid( "spec.snippets: Required value: at least one snippet must be provided", ), }, @@ -177,7 +176,7 @@ func TestValidateSnippetsFilter(t *testing.T) { }, }, }, - expCond: staticConds.NewSnippetsFilterInvalid( + expCond: conditions.NewSnippetsFilterInvalid( "spec.snippets[2].context: Unsupported value: \"invalid context\": " + "supported values: \"main\", \"http\", \"http.server\", \"http.server.location\"", ), @@ -202,7 +201,7 @@ func TestValidateSnippetsFilter(t *testing.T) { }, }, }, - expCond: staticConds.NewSnippetsFilterInvalid( + expCond: conditions.NewSnippetsFilterInvalid( "[spec.snippets[1].context: Unsupported value: \"invalid context\": supported values: " + "\"main\", \"http\", \"http.server\", \"http.server.location\", spec.snippets[2].context: " + "Unsupported value: \"\": supported values: \"main\", \"http\", " + @@ -229,7 +228,7 @@ func TestValidateSnippetsFilter(t *testing.T) { }, }, }, - expCond: staticConds.NewSnippetsFilterInvalid( + expCond: conditions.NewSnippetsFilterInvalid( "spec.snippets[2].context: Invalid value: \"main\": only one snippet is allowed per context", ), }, @@ -257,7 +256,7 @@ func TestValidateSnippetsFilter(t *testing.T) { }, }, }, - expCond: staticConds.NewSnippetsFilterInvalid( + expCond: conditions.NewSnippetsFilterInvalid( "[spec.snippets[2].context: Invalid value: \"main\": only one snippet is allowed per context, " + "spec.snippets[3].context: Unsupported value: \"invalid context\": supported values: \"main\", " + "\"http\", \"http.server\", \"http.server.location\"]", @@ -279,7 +278,7 @@ func TestValidateSnippetsFilter(t *testing.T) { }, }, }, - expCond: staticConds.NewSnippetsFilterInvalid( + expCond: conditions.NewSnippetsFilterInvalid( "spec.snippets[1].value: Required value: value cannot be empty", ), }, diff --git a/internal/mode/static/state/graph/tlsroute.go b/internal/controller/state/graph/tlsroute.go similarity index 86% rename from internal/mode/static/state/graph/tlsroute.go rename to internal/controller/state/graph/tlsroute.go index 8e471afad0..2cec3ffb3d 100644 --- a/internal/mode/static/state/graph/tlsroute.go +++ b/internal/controller/state/graph/tlsroute.go @@ -6,8 +6,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" "sigs.k8s.io/gateway-api/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" ) func buildTLSRoute( @@ -37,7 +36,7 @@ func buildTLSRoute( field.NewPath("spec").Child("hostnames"), ); err != nil { r.Valid = false - r.Conditions = append(r.Conditions, staticConds.NewRouteUnsupportedValue(err.Error())) + r.Conditions = append(r.Conditions, conditions.NewRouteUnsupportedValue(err.Error())) return r } @@ -45,7 +44,7 @@ func buildTLSRoute( if len(gtr.Spec.Rules) != 1 || len(gtr.Spec.Rules[0].BackendRefs) != 1 { r.Valid = false - cond := staticConds.NewRouteBackendRefUnsupportedValue( + cond := conditions.NewRouteBackendRefUnsupportedValue( "Must have exactly one Rule and BackendRef", ) r.Conditions = append(r.Conditions, cond) @@ -117,14 +116,14 @@ func validateBackendRefTLSRoute( if err != nil { backendRef.Valid = false - return backendRef, []conditions.Condition{staticConds.NewRouteBackendRefRefBackendNotFound(err.Error())} + return backendRef, []conditions.Condition{conditions.NewRouteBackendRefRefBackendNotFound(err.Error())} } var conds []conditions.Condition for _, parentRef := range parentRefs { if err := verifyIPFamily(parentRef.Gateway.EffectiveNginxProxy, svcIPFamily); err != nil { backendRef.Valid = backendRef.Valid || false - backendRef.InvalidForGateways[parentRef.Gateway.NamespacedName] = staticConds.NewRouteInvalidIPFamily(err.Error()) + backendRef.InvalidForGateways[parentRef.Gateway.NamespacedName] = conditions.NewRouteInvalidIPFamily(err.Error()) } } diff --git a/internal/mode/static/state/graph/tlsroute_test.go b/internal/controller/state/graph/tlsroute_test.go similarity index 94% rename from internal/mode/static/state/graph/tlsroute_test.go rename to internal/controller/state/graph/tlsroute_test.go index 988013a594..aaeb5a3698 100644 --- a/internal/mode/static/state/graph/tlsroute_test.go +++ b/internal/controller/state/graph/tlsroute_test.go @@ -12,9 +12,8 @@ import ( "sigs.k8s.io/gateway-api/apis/v1alpha2" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" ) func createTLSRoute( @@ -317,7 +316,7 @@ func TestBuildTLSRoute(t *testing.T) { expected: &L4Route{ Source: invalidHostnameGtr, ParentRefs: []ParentRef{parentRefGraph}, - Conditions: []conditions.Condition{staticConds.NewRouteUnsupportedValue( + Conditions: []conditions.Condition{conditions.NewRouteUnsupportedValue( "spec.hostnames[0]: Invalid value: \"hi....com\": a lowercase RFC 1" + "123 subdomain must consist of lower case alphanumeric characters" + ", '-' or '.', and must start and end with an alphanumeric charac" + @@ -341,7 +340,7 @@ func TestBuildTLSRoute(t *testing.T) { "app.example.com", }, }, - Conditions: []conditions.Condition{staticConds.NewRouteBackendRefUnsupportedValue( + Conditions: []conditions.Condition{conditions.NewRouteBackendRefUnsupportedValue( "Must have exactly one Rule and BackendRef", )}, Valid: false, @@ -369,7 +368,7 @@ func TestBuildTLSRoute(t *testing.T) { InvalidForGateways: map[types.NamespacedName]conditions.Condition{}, }, }, - Conditions: []conditions.Condition{staticConds.NewRouteBackendRefRefBackendNotFound( + Conditions: []conditions.Condition{conditions.NewRouteBackendRefRefBackendNotFound( "spec.rules[0].backendRefs[0].name: Not found: \"hi\"", )}, Attachable: true, @@ -394,7 +393,7 @@ func TestBuildTLSRoute(t *testing.T) { InvalidForGateways: map[types.NamespacedName]conditions.Condition{}, }, }, - Conditions: []conditions.Condition{staticConds.NewRouteBackendRefInvalidKind( + Conditions: []conditions.Condition{conditions.NewRouteBackendRefInvalidKind( "spec.rules[0].backendRefs[0].group:" + " Unsupported value: \"wrong\": supported values: \"core\", \"\"", )}, @@ -422,7 +421,7 @@ func TestBuildTLSRoute(t *testing.T) { InvalidForGateways: map[types.NamespacedName]conditions.Condition{}, }, }, - Conditions: []conditions.Condition{staticConds.NewRouteBackendRefInvalidKind( + Conditions: []conditions.Condition{conditions.NewRouteBackendRefInvalidKind( "spec.rules[0].backendRefs[0].kind:" + " Unsupported value: \"not service\": supported values: \"Service\"", )}, @@ -450,7 +449,7 @@ func TestBuildTLSRoute(t *testing.T) { InvalidForGateways: map[types.NamespacedName]conditions.Condition{}, }, }, - Conditions: []conditions.Condition{staticConds.NewRouteBackendRefRefNotPermitted( + Conditions: []conditions.Condition{conditions.NewRouteBackendRefRefNotPermitted( "spec.rules[0].backendRefs[0].namespace: Forbidden: Backend ref to Service " + "diff/hi not permitted by any ReferenceGrant", )}, @@ -478,7 +477,7 @@ func TestBuildTLSRoute(t *testing.T) { InvalidForGateways: map[types.NamespacedName]conditions.Condition{}, }, }, - Conditions: []conditions.Condition{staticConds.NewRouteBackendRefUnsupportedValue( + Conditions: []conditions.Condition{conditions.NewRouteBackendRefUnsupportedValue( "spec.rules[0].backendRefs[0].port: Required value: port cannot be nil", )}, Attachable: true, @@ -515,7 +514,7 @@ func TestBuildTLSRoute(t *testing.T) { SvcNsName: svcNsName, ServicePort: apiv1.ServicePort{Port: 80}, InvalidForGateways: map[types.NamespacedName]conditions.Condition{ - {Namespace: "test", Name: "gateway"}: staticConds.NewRouteInvalidIPFamily( + {Namespace: "test", Name: "gateway"}: conditions.NewRouteInvalidIPFamily( "service configured with IPv4 family but NginxProxy is configured with IPv6", ), }, diff --git a/internal/mode/static/state/graph/validation.go b/internal/controller/state/graph/validation.go similarity index 100% rename from internal/mode/static/state/graph/validation.go rename to internal/controller/state/graph/validation.go diff --git a/internal/mode/static/state/graph/validation_test.go b/internal/controller/state/graph/validation_test.go similarity index 100% rename from internal/mode/static/state/graph/validation_test.go rename to internal/controller/state/graph/validation_test.go diff --git a/internal/mode/static/state/mirror/mirror.go b/internal/controller/state/mirror/mirror.go similarity index 94% rename from internal/mode/static/state/mirror/mirror.go rename to internal/controller/state/mirror/mirror.go index 485fe8ccf3..9e66a44a72 100644 --- a/internal/mode/static/state/mirror/mirror.go +++ b/internal/controller/state/mirror/mirror.go @@ -6,7 +6,7 @@ import ( v1 "sigs.k8s.io/gateway-api/apis/v1" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/http" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/http" ) // RouteName builds the name for the internal mirror route, using the user route name, diff --git a/internal/mode/static/state/mirror/mirror_test.go b/internal/controller/state/mirror/mirror_test.go similarity index 100% rename from internal/mode/static/state/mirror/mirror_test.go rename to internal/controller/state/mirror/mirror_test.go diff --git a/internal/mode/static/state/resolver/resolver.go b/internal/controller/state/resolver/resolver.go similarity index 100% rename from internal/mode/static/state/resolver/resolver.go rename to internal/controller/state/resolver/resolver.go diff --git a/internal/mode/static/state/resolver/resolver_test.go b/internal/controller/state/resolver/resolver_test.go similarity index 100% rename from internal/mode/static/state/resolver/resolver_test.go rename to internal/controller/state/resolver/resolver_test.go diff --git a/internal/mode/static/state/resolver/resolverfakes/fake_service_resolver.go b/internal/controller/state/resolver/resolverfakes/fake_service_resolver.go similarity index 98% rename from internal/mode/static/state/resolver/resolverfakes/fake_service_resolver.go rename to internal/controller/state/resolver/resolverfakes/fake_service_resolver.go index a1eadd5d14..6997103288 100644 --- a/internal/mode/static/state/resolver/resolverfakes/fake_service_resolver.go +++ b/internal/controller/state/resolver/resolverfakes/fake_service_resolver.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver" v1 "k8s.io/api/core/v1" v1a "k8s.io/api/discovery/v1" "k8s.io/apimachinery/pkg/types" diff --git a/internal/mode/static/state/resolver/service_resolver_suite_test.go b/internal/controller/state/resolver/service_resolver_suite_test.go similarity index 100% rename from internal/mode/static/state/resolver/service_resolver_suite_test.go rename to internal/controller/state/resolver/service_resolver_suite_test.go diff --git a/internal/mode/static/state/resolver/service_resolver_test.go b/internal/controller/state/resolver/service_resolver_test.go similarity index 98% rename from internal/mode/static/state/resolver/service_resolver_test.go rename to internal/controller/state/resolver/service_resolver_test.go index 7c4f1ec091..ffe85e246d 100644 --- a/internal/mode/static/state/resolver/service_resolver_test.go +++ b/internal/controller/state/resolver/service_resolver_test.go @@ -14,9 +14,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller/index" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver" ) func createSlice( diff --git a/internal/mode/static/state/state_suite_test.go b/internal/controller/state/state_suite_test.go similarity index 100% rename from internal/mode/static/state/state_suite_test.go rename to internal/controller/state/state_suite_test.go diff --git a/internal/mode/static/state/statefakes/fake_change_processor.go b/internal/controller/state/statefakes/fake_change_processor.go similarity index 98% rename from internal/mode/static/state/statefakes/fake_change_processor.go rename to internal/controller/state/statefakes/fake_change_processor.go index c88a31ce01..1b63180ad3 100644 --- a/internal/mode/static/state/statefakes/fake_change_processor.go +++ b/internal/controller/state/statefakes/fake_change_processor.go @@ -4,9 +4,9 @@ package statefakes import ( "sync" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" "github.com/nginx/nginx-gateway-fabric/internal/framework/types" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" typesa "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" ) diff --git a/internal/mode/static/state/store.go b/internal/controller/state/store.go similarity index 98% rename from internal/mode/static/state/store.go rename to internal/controller/state/store.go index 910f257c90..9408efc494 100644 --- a/internal/mode/static/state/store.go +++ b/internal/controller/state/store.go @@ -7,10 +7,10 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" ngftypes "github.com/nginx/nginx-gateway-fabric/internal/framework/types" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" ) // Updater updates the cluster state. diff --git a/internal/mode/static/state/validation/validationfakes/fake_generic_validator.go b/internal/controller/state/validation/validationfakes/fake_generic_validator.go similarity index 99% rename from internal/mode/static/state/validation/validationfakes/fake_generic_validator.go rename to internal/controller/state/validation/validationfakes/fake_generic_validator.go index 44e0da38bb..930bb48e2a 100644 --- a/internal/mode/static/state/validation/validationfakes/fake_generic_validator.go +++ b/internal/controller/state/validation/validationfakes/fake_generic_validator.go @@ -4,7 +4,7 @@ package validationfakes import ( "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" ) type FakeGenericValidator struct { diff --git a/internal/mode/static/state/validation/validationfakes/fake_httpfields_validator.go b/internal/controller/state/validation/validationfakes/fake_httpfields_validator.go similarity index 99% rename from internal/mode/static/state/validation/validationfakes/fake_httpfields_validator.go rename to internal/controller/state/validation/validationfakes/fake_httpfields_validator.go index 71a907acbf..9889ec7582 100644 --- a/internal/mode/static/state/validation/validationfakes/fake_httpfields_validator.go +++ b/internal/controller/state/validation/validationfakes/fake_httpfields_validator.go @@ -4,7 +4,7 @@ package validationfakes import ( "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" ) type FakeHTTPFieldsValidator struct { diff --git a/internal/mode/static/state/validation/validationfakes/fake_policy_validator.go b/internal/controller/state/validation/validationfakes/fake_policy_validator.go similarity index 97% rename from internal/mode/static/state/validation/validationfakes/fake_policy_validator.go rename to internal/controller/state/validation/validationfakes/fake_policy_validator.go index 59883a9fc7..ff7cba94b3 100644 --- a/internal/mode/static/state/validation/validationfakes/fake_policy_validator.go +++ b/internal/controller/state/validation/validationfakes/fake_policy_validator.go @@ -4,9 +4,9 @@ package validationfakes import ( "sync" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/validation" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/validation" ) type FakePolicyValidator struct { diff --git a/internal/mode/static/state/validation/validator.go b/internal/controller/state/validation/validator.go similarity index 96% rename from internal/mode/static/state/validation/validator.go rename to internal/controller/state/validation/validator.go index f012c3c6ec..29ac3809ea 100644 --- a/internal/mode/static/state/validation/validator.go +++ b/internal/controller/state/validation/validator.go @@ -3,8 +3,8 @@ package validation //go:generate go tool counterfeiter -generate import ( - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" ) // Validators include validators for API resources from the perspective of a data-plane. diff --git a/internal/framework/status/conditions.go b/internal/controller/status/conditions.go similarity index 100% rename from internal/framework/status/conditions.go rename to internal/controller/status/conditions.go diff --git a/internal/framework/status/conditions_test.go b/internal/controller/status/conditions_test.go similarity index 100% rename from internal/framework/status/conditions_test.go rename to internal/controller/status/conditions_test.go diff --git a/internal/framework/status/k8s_updater.go b/internal/controller/status/k8s_updater.go similarity index 100% rename from internal/framework/status/k8s_updater.go rename to internal/controller/status/k8s_updater.go diff --git a/internal/framework/status/leader_aware_group_updater.go b/internal/controller/status/leader_aware_group_updater.go similarity index 96% rename from internal/framework/status/leader_aware_group_updater.go rename to internal/controller/status/leader_aware_group_updater.go index 81f8d95cd8..ab1e5db76d 100644 --- a/internal/framework/status/leader_aware_group_updater.go +++ b/internal/controller/status/leader_aware_group_updater.go @@ -9,7 +9,7 @@ import ( // GroupUpdater updates statuses of groups of resources. // // Note: this interface is created so that it that we can create a fake from it and use it -// in mode/static/handler_test.go (to avoid import cycles). +// in controller/handler_test.go (to avoid import cycles). // //counterfeiter:generate . GroupUpdater type GroupUpdater interface { diff --git a/internal/framework/status/leader_aware_group_updater_test.go b/internal/controller/status/leader_aware_group_updater_test.go similarity index 100% rename from internal/framework/status/leader_aware_group_updater_test.go rename to internal/controller/status/leader_aware_group_updater_test.go diff --git a/internal/mode/static/status/prepare_requests.go b/internal/controller/status/prepare_requests.go similarity index 83% rename from internal/mode/static/status/prepare_requests.go rename to internal/controller/status/prepare_requests.go index fc0cfe358a..1da7f8e348 100644 --- a/internal/mode/static/status/prepare_requests.go +++ b/internal/controller/status/prepare_requests.go @@ -11,12 +11,10 @@ import ( "sigs.k8s.io/gateway-api/apis/v1alpha3" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - frameworkStatus "github.com/nginx/nginx-gateway-fabric/internal/framework/status" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" ) // PrepareRouteRequests prepares status UpdateRequests for the given Routes. @@ -26,8 +24,8 @@ func PrepareRouteRequests( transitionTime metav1.Time, nginxReloadRes graph.NginxReloadResult, gatewayCtlrName string, -) []frameworkStatus.UpdateRequest { - reqs := make([]frameworkStatus.UpdateRequest, 0, len(routes)) +) []UpdateRequest { + reqs := make([]UpdateRequest, 0, len(routes)) for routeKey, r := range l4routes { routeStatus := prepareRouteStatus( @@ -43,7 +41,7 @@ func PrepareRouteRequests( RouteStatus: routeStatus, } - req := frameworkStatus.UpdateRequest{ + req := UpdateRequest{ NsName: routeKey.NamespacedName, ResourceType: &v1alpha2.TLSRoute{}, Setter: newTLSRouteStatusSetter(status, gatewayCtlrName), @@ -68,7 +66,7 @@ func PrepareRouteRequests( RouteStatus: routeStatus, } - req := frameworkStatus.UpdateRequest{ + req := UpdateRequest{ NsName: routeKey.NamespacedName, ResourceType: &v1.HTTPRoute{}, Setter: newHTTPRouteStatusSetter(status, gatewayCtlrName), @@ -81,7 +79,7 @@ func PrepareRouteRequests( RouteStatus: routeStatus, } - req := frameworkStatus.UpdateRequest{ + req := UpdateRequest{ NsName: routeKey.NamespacedName, ResourceType: &v1.GRPCRoute{}, Setter: newGRPCRouteStatusSetter(status, gatewayCtlrName), @@ -107,7 +105,7 @@ func prepareRouteStatus( ) v1.RouteStatus { parents := make([]v1.RouteParentStatus, 0, len(parentRefs)) - defaultConds := staticConds.NewDefaultRouteConditions() + defaultConds := conditions.NewDefaultRouteConditions() for _, ref := range parentRefs { failedAttachmentCondCount := 0 @@ -127,7 +125,7 @@ func prepareRouteStatus( if nginxReloadRes.Error != nil { allConds = append( allConds, - staticConds.NewRouteGatewayNotProgrammed(staticConds.RouteMessageFailedNginxReload), + conditions.NewRouteGatewayNotProgrammed(conditions.RouteMessageFailedNginxReload), ) } @@ -155,8 +153,8 @@ func PrepareGatewayClassRequests( gc *graph.GatewayClass, ignoredGwClasses map[types.NamespacedName]*v1.GatewayClass, transitionTime metav1.Time, -) []frameworkStatus.UpdateRequest { - var reqs []frameworkStatus.UpdateRequest +) []UpdateRequest { + var reqs []UpdateRequest if gc != nil { defaultConds := conditions.NewDefaultGatewayClassConditions() @@ -172,7 +170,7 @@ func PrepareGatewayClassRequests( apiConds := conditions.ConvertConditions(conds, gc.Source.Generation, transitionTime) - req := frameworkStatus.UpdateRequest{ + req := UpdateRequest{ NsName: client.ObjectKeyFromObject(gc.Source), ResourceType: &v1.GatewayClass{}, Setter: newGatewayClassStatusSetter(v1.GatewayClassStatus{ @@ -184,7 +182,7 @@ func PrepareGatewayClassRequests( } for nsname, gwClass := range ignoredGwClasses { - req := frameworkStatus.UpdateRequest{ + req := UpdateRequest{ NsName: nsname, ResourceType: &v1.GatewayClass{}, Setter: newGatewayClassStatusSetter(v1.GatewayClassStatus{ @@ -208,8 +206,8 @@ func PrepareGatewayRequests( transitionTime metav1.Time, gwAddresses []v1.GatewayStatusAddress, nginxReloadRes graph.NginxReloadResult, -) []frameworkStatus.UpdateRequest { - reqs := make([]frameworkStatus.UpdateRequest, 0, 1) +) []UpdateRequest { + reqs := make([]UpdateRequest, 0, 1) if gateway != nil { reqs = append(reqs, prepareGatewayRequest(gateway, transitionTime, gwAddresses, nginxReloadRes)) @@ -223,7 +221,7 @@ func prepareGatewayRequest( transitionTime metav1.Time, gwAddresses []v1.GatewayStatusAddress, nginxReloadRes graph.NginxReloadResult, -) frameworkStatus.UpdateRequest { +) UpdateRequest { if !gateway.Valid { conds := conditions.ConvertConditions( conditions.DeduplicateConditions(gateway.Conditions), @@ -231,7 +229,7 @@ func prepareGatewayRequest( transitionTime, ) - return frameworkStatus.UpdateRequest{ + return UpdateRequest{ NsName: client.ObjectKeyFromObject(gateway.Source), ResourceType: &v1.Gateway{}, Setter: newGatewayStatusSetter(v1.GatewayStatus{ @@ -247,17 +245,17 @@ func prepareGatewayRequest( var conds []conditions.Condition if l.Valid { - conds = staticConds.NewDefaultListenerConditions() + conds = conditions.NewDefaultListenerConditions() validListenerCount++ } else { conds = l.Conditions } if nginxReloadRes.Error != nil { - msg := fmt.Sprintf("%s: %s", staticConds.ListenerMessageFailedNginxReload, nginxReloadRes.Error.Error()) + msg := fmt.Sprintf("%s: %s", conditions.ListenerMessageFailedNginxReload, nginxReloadRes.Error.Error()) conds = append( conds, - staticConds.NewListenerNotProgrammedInvalid(msg), + conditions.NewListenerNotProgrammedInvalid(msg), ) } @@ -275,20 +273,20 @@ func prepareGatewayRequest( }) } - gwConds := staticConds.NewDefaultGatewayConditions() + gwConds := conditions.NewDefaultGatewayConditions() gwConds = append(gwConds, gateway.Conditions...) if validListenerCount == 0 { - gwConds = append(gwConds, staticConds.NewGatewayNotAcceptedListenersNotValid()...) + gwConds = append(gwConds, conditions.NewGatewayNotAcceptedListenersNotValid()...) } else if validListenerCount < len(gateway.Listeners) { - gwConds = append(gwConds, staticConds.NewGatewayAcceptedListenersNotValid()) + gwConds = append(gwConds, conditions.NewGatewayAcceptedListenersNotValid()) } if nginxReloadRes.Error != nil { - msg := fmt.Sprintf("%s: %s", staticConds.GatewayMessageFailedNginxReload, nginxReloadRes.Error.Error()) + msg := fmt.Sprintf("%s: %s", conditions.GatewayMessageFailedNginxReload, nginxReloadRes.Error.Error()) gwConds = append( gwConds, - staticConds.NewGatewayNotProgrammedInvalid(msg), + conditions.NewGatewayNotProgrammedInvalid(msg), ) } @@ -298,7 +296,7 @@ func prepareGatewayRequest( transitionTime, ) - return frameworkStatus.UpdateRequest{ + return UpdateRequest{ NsName: client.ObjectKeyFromObject(gateway.Source), ResourceType: &v1.Gateway{}, Setter: newGatewayStatusSetter(v1.GatewayStatus{ @@ -313,8 +311,8 @@ func PrepareNGFPolicyRequests( policies map[graph.PolicyKey]*graph.Policy, transitionTime metav1.Time, gatewayCtlrName string, -) []frameworkStatus.UpdateRequest { - reqs := make([]frameworkStatus.UpdateRequest, 0, len(policies)) +) []UpdateRequest { + reqs := make([]UpdateRequest, 0, len(policies)) for key, pol := range policies { ancestorStatuses := make([]v1alpha2.PolicyAncestorStatus, 0, len(pol.TargetRefs)) @@ -329,7 +327,7 @@ func PrepareNGFPolicyRequests( // The order of conditions matters here. // We add the default condition first, followed by the ancestor conditions, and finally the policy conditions. // DeduplicateConditions will ensure the last condition wins. - allConds = append(allConds, staticConds.NewPolicyAccepted()) + allConds = append(allConds, conditions.NewPolicyAccepted()) allConds = append(allConds, ancestor.Conditions...) allConds = append(allConds, pol.Conditions...) @@ -345,7 +343,7 @@ func PrepareNGFPolicyRequests( status := v1alpha2.PolicyStatus{Ancestors: ancestorStatuses} - reqs = append(reqs, frameworkStatus.UpdateRequest{ + reqs = append(reqs, UpdateRequest{ NsName: key.NsName, ResourceType: pol.Source, Setter: newNGFPolicyStatusSetter(status, gatewayCtlrName), @@ -360,8 +358,8 @@ func PrepareBackendTLSPolicyRequests( policies map[types.NamespacedName]*graph.BackendTLSPolicy, transitionTime metav1.Time, gatewayCtlrName string, -) []frameworkStatus.UpdateRequest { - reqs := make([]frameworkStatus.UpdateRequest, 0, len(policies)) +) []UpdateRequest { + reqs := make([]UpdateRequest, 0, len(policies)) for nsname, pol := range policies { if !pol.IsReferenced || pol.Ignored { @@ -391,7 +389,7 @@ func PrepareBackendTLSPolicyRequests( Ancestors: policyAncestors, } - reqs = append(reqs, frameworkStatus.UpdateRequest{ + reqs = append(reqs, UpdateRequest{ NsName: nsname, ResourceType: &v1alpha3.BackendTLSPolicy{}, Setter: newBackendTLSPolicyStatusSetter(status, gatewayCtlrName), @@ -405,8 +403,8 @@ func PrepareSnippetsFilterRequests( snippetsFilters map[types.NamespacedName]*graph.SnippetsFilter, transitionTime metav1.Time, gatewayCtlrName string, -) []frameworkStatus.UpdateRequest { - reqs := make([]frameworkStatus.UpdateRequest, 0, len(snippetsFilters)) +) []UpdateRequest { + reqs := make([]UpdateRequest, 0, len(snippetsFilters)) for nsname, snippetsFilter := range snippetsFilters { allConds := make([]conditions.Condition, 0, len(snippetsFilter.Conditions)+1) @@ -414,7 +412,7 @@ func PrepareSnippetsFilterRequests( // The order of conditions matters here. // We add the default condition first, followed by the snippetsFilter conditions. // DeduplicateConditions will ensure the last condition wins. - allConds = append(allConds, staticConds.NewSnippetsFilterAccepted()) + allConds = append(allConds, conditions.NewSnippetsFilterAccepted()) allConds = append(allConds, snippetsFilter.Conditions...) conds := conditions.DeduplicateConditions(allConds) @@ -428,7 +426,7 @@ func PrepareSnippetsFilterRequests( }, } - reqs = append(reqs, frameworkStatus.UpdateRequest{ + reqs = append(reqs, UpdateRequest{ NsName: nsname, ResourceType: snippetsFilter.Source, Setter: newSnippetsFilterStatusSetter(status, gatewayCtlrName), @@ -450,7 +448,7 @@ func PrepareNginxGatewayStatus( nginxGateway *ngfAPI.NginxGateway, transitionTime metav1.Time, cpUpdateRes ControlPlaneUpdateResult, -) *frameworkStatus.UpdateRequest { +) *UpdateRequest { if nginxGateway == nil { return nil } @@ -459,13 +457,13 @@ func PrepareNginxGatewayStatus( if cpUpdateRes.Error != nil { msg := "Failed to update control plane configuration" conds = []conditions.Condition{ - staticConds.NewNginxGatewayInvalid(fmt.Sprintf("%s: %v", msg, cpUpdateRes.Error)), + conditions.NewNginxGatewayInvalid(fmt.Sprintf("%s: %v", msg, cpUpdateRes.Error)), } } else { - conds = []conditions.Condition{staticConds.NewNginxGatewayValid()} + conds = []conditions.Condition{conditions.NewNginxGatewayValid()} } - return &frameworkStatus.UpdateRequest{ + return &UpdateRequest{ NsName: client.ObjectKeyFromObject(nginxGateway), ResourceType: &ngfAPI.NginxGateway{}, Setter: newNginxGatewayStatusSetter(ngfAPI.NginxGatewayStatus{ diff --git a/internal/mode/static/status/prepare_requests_test.go b/internal/controller/status/prepare_requests_test.go similarity index 95% rename from internal/mode/static/status/prepare_requests_test.go rename to internal/controller/status/prepare_requests_test.go index fbc5ede98e..81f2929481 100644 --- a/internal/mode/static/status/prepare_requests_test.go +++ b/internal/controller/status/prepare_requests_test.go @@ -20,13 +20,11 @@ import ( "sigs.k8s.io/gateway-api/apis/v1alpha3" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - statusFramework "github.com/nginx/nginx-gateway-fabric/internal/framework/status" ngftypes "github.com/nginx/nginx-gateway-fabric/internal/framework/types" - staticConds "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" ) func createK8sClientFor(resourceType ngftypes.ObjectType) client.Client { @@ -313,7 +311,7 @@ func TestBuildHTTPRouteStatuses(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) } - updater := statusFramework.NewUpdater(k8sClient, logr.Discard()) + updater := NewUpdater(k8sClient, logr.Discard()) reqs := PrepareRouteRequests( map[graph.L4RouteKey]*graph.L4Route{}, @@ -392,7 +390,7 @@ func TestBuildGRPCRouteStatuses(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) } - updater := statusFramework.NewUpdater(k8sClient, logr.Discard()) + updater := NewUpdater(k8sClient, logr.Discard()) reqs := PrepareRouteRequests( map[graph.L4RouteKey]*graph.L4Route{}, @@ -469,7 +467,7 @@ func TestBuildTLSRouteStatuses(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) } - updater := statusFramework.NewUpdater(k8sClient, logr.Discard()) + updater := NewUpdater(k8sClient, logr.Discard()) reqs := PrepareRouteRequests( routes, @@ -555,8 +553,8 @@ func TestBuildRouteStatusesNginxErr(t *testing.T) { Status: metav1.ConditionFalse, ObservedGeneration: 3, LastTransitionTime: transitionTime, - Reason: string(staticConds.RouteReasonGatewayNotProgrammed), - Message: staticConds.RouteMessageFailedNginxReload, + Reason: string(conditions.RouteReasonGatewayNotProgrammed), + Message: conditions.RouteMessageFailedNginxReload, }, }, }, @@ -573,7 +571,7 @@ func TestBuildRouteStatusesNginxErr(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) } - updater := statusFramework.NewUpdater(k8sClient, logr.Discard()) + updater := NewUpdater(k8sClient, logr.Discard()) reqs := PrepareRouteRequests( map[graph.L4RouteKey]*graph.L4Route{}, @@ -707,7 +705,7 @@ func TestBuildGatewayClassStatuses(t *testing.T) { expectedTotalReqs++ } - updater := statusFramework.NewUpdater(k8sClient, logr.Discard()) + updater := NewUpdater(k8sClient, logr.Discard()) reqs := PrepareGatewayClassRequests(test.gc, test.ignoredClasses, transitionTime) @@ -861,7 +859,7 @@ func TestBuildGatewayStatuses(t *testing.T) { { Name: "listener-invalid", Valid: false, - Conditions: staticConds.NewListenerUnsupportedValue("unsupported value"), + Conditions: conditions.NewListenerUnsupportedValue("unsupported value"), }, }, Valid: true, @@ -903,7 +901,7 @@ func TestBuildGatewayStatuses(t *testing.T) { Status: metav1.ConditionFalse, ObservedGeneration: 2, LastTransitionTime: transitionTime, - Reason: string(staticConds.ListenerReasonUnsupportedValue), + Reason: string(conditions.ListenerReasonUnsupportedValue), Message: "unsupported value", }, { @@ -928,12 +926,12 @@ func TestBuildGatewayStatuses(t *testing.T) { { Name: "listener-invalid-1", Valid: false, - Conditions: staticConds.NewListenerUnsupportedProtocol("unsupported protocol"), + Conditions: conditions.NewListenerUnsupportedProtocol("unsupported protocol"), }, { Name: "listener-invalid-2", Valid: false, - Conditions: staticConds.NewListenerUnsupportedValue("unsupported value"), + Conditions: conditions.NewListenerUnsupportedValue("unsupported value"), }, }, Valid: true, @@ -991,7 +989,7 @@ func TestBuildGatewayStatuses(t *testing.T) { Status: metav1.ConditionFalse, ObservedGeneration: 2, LastTransitionTime: transitionTime, - Reason: string(staticConds.ListenerReasonUnsupportedValue), + Reason: string(conditions.ListenerReasonUnsupportedValue), Message: "unsupported value", }, { @@ -1013,7 +1011,7 @@ func TestBuildGatewayStatuses(t *testing.T) { gateway: &graph.Gateway{ Source: createGateway(), Valid: false, - Conditions: staticConds.NewGatewayInvalid("no gateway class"), + Conditions: conditions.NewGatewayInvalid("no gateway class"), }, expected: map[types.NamespacedName]v1.GatewayStatus{ {Namespace: "test", Name: "gateway"}: { @@ -1043,7 +1041,7 @@ func TestBuildGatewayStatuses(t *testing.T) { gateway: &graph.Gateway{ Source: createGateway(), Valid: true, - Conditions: staticConds.NewDefaultGatewayConditions(), + Conditions: conditions.NewDefaultGatewayConditions(), Listeners: []*graph.Listener{ { Name: "listener-valid", @@ -1070,7 +1068,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.GatewayReasonInvalid), - Message: fmt.Sprintf("%s: test error", staticConds.GatewayMessageFailedNginxReload), + Message: fmt.Sprintf("%s: test error", conditions.GatewayMessageFailedNginxReload), }, }, Listeners: []v1.ListenerStatus{ @@ -1108,7 +1106,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, LastTransitionTime: transitionTime, Reason: string(v1.ListenerReasonInvalid), - Message: fmt.Sprintf("%s: test error", staticConds.ListenerMessageFailedNginxReload), + Message: fmt.Sprintf("%s: test error", conditions.ListenerMessageFailedNginxReload), }, }, }, @@ -1130,7 +1128,7 @@ func TestBuildGatewayStatuses(t *testing.T) { }, Valid: true, Conditions: []conditions.Condition{ - staticConds.NewGatewayResolvedRefs(), + conditions.NewGatewayResolvedRefs(), }, }, expected: map[types.NamespacedName]v1.GatewayStatus{ @@ -1154,11 +1152,11 @@ func TestBuildGatewayStatuses(t *testing.T) { Message: "Gateway is programmed", }, { - Type: string(staticConds.GatewayResolvedRefs), + Type: string(conditions.GatewayResolvedRefs), Status: metav1.ConditionTrue, ObservedGeneration: 2, LastTransitionTime: transitionTime, - Reason: string(staticConds.GatewayReasonResolvedRefs), + Reason: string(conditions.GatewayReasonResolvedRefs), Message: "ParametersRef resource is resolved", }, }, @@ -1185,8 +1183,8 @@ func TestBuildGatewayStatuses(t *testing.T) { }, Valid: true, Conditions: []conditions.Condition{ - staticConds.NewGatewayRefNotFound(), - staticConds.NewGatewayInvalidParameters("ParametersRef not found"), + conditions.NewGatewayRefNotFound(), + conditions.NewGatewayInvalidParameters("ParametersRef not found"), }, }, expected: map[types.NamespacedName]v1.GatewayStatus{ @@ -1202,11 +1200,11 @@ func TestBuildGatewayStatuses(t *testing.T) { Message: "Gateway is programmed", }, { - Type: string(staticConds.GatewayResolvedRefs), + Type: string(conditions.GatewayResolvedRefs), Status: metav1.ConditionFalse, ObservedGeneration: 2, LastTransitionTime: transitionTime, - Reason: string(staticConds.GatewayReasonParamsRefNotFound), + Reason: string(conditions.GatewayReasonParamsRefNotFound), Message: "ParametersRef resource could not be found", }, { @@ -1246,7 +1244,7 @@ func TestBuildGatewayStatuses(t *testing.T) { expectedTotalReqs++ } - updater := statusFramework.NewUpdater(k8sClient, logr.Discard()) + updater := NewUpdater(k8sClient, logr.Discard()) reqs := PrepareGatewayRequests( test.gateway, @@ -1302,8 +1300,8 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) { } } - attachedConds := []conditions.Condition{staticConds.NewPolicyAccepted()} - invalidConds := []conditions.Condition{staticConds.NewPolicyInvalid("invalid backendTLSPolicy")} + attachedConds := []conditions.Condition{conditions.NewPolicyAccepted()} + invalidConds := []conditions.Condition{conditions.NewPolicyInvalid("invalid backendTLSPolicy")} validPolicyCfg := policyCfg{ Name: "valid-bt", @@ -1509,7 +1507,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) } - updater := statusFramework.NewUpdater(k8sClient, logr.Discard()) + updater := NewUpdater(k8sClient, logr.Discard()) reqs := PrepareBackendTLSPolicyRequests(test.backendTLSPolicies, transitionTime, gatewayCtlrName) @@ -1603,7 +1601,7 @@ func TestBuildNginxGatewayStatus(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) } - updater := statusFramework.NewUpdater(k8sClient, logr.Discard()) + updater := NewUpdater(k8sClient, logr.Discard()) req := PrepareNginxGatewayStatus(test.nginxGateway, transitionTime, test.cpUpdateResult) @@ -1651,8 +1649,8 @@ func TestBuildNGFPolicyStatuses(t *testing.T) { } } - invalidConds := []conditions.Condition{staticConds.NewPolicyInvalid("invalid")} - targetRefNotFoundConds := []conditions.Condition{staticConds.NewPolicyTargetNotFound("target not found")} + invalidConds := []conditions.Condition{conditions.NewPolicyInvalid("invalid")} + targetRefNotFoundConds := []conditions.Condition{conditions.NewPolicyTargetNotFound("target not found")} validPolicyKey := graph.PolicyKey{ NsName: types.NamespacedName{Namespace: "test", Name: "valid-pol"}, @@ -1897,7 +1895,7 @@ func TestBuildNGFPolicyStatuses(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) } - updater := statusFramework.NewUpdater(k8sClient, logr.Discard()) + updater := NewUpdater(k8sClient, logr.Discard()) reqs := PrepareNGFPolicyRequests(test.policies, transitionTime, gatewayCtlrName) @@ -1947,7 +1945,7 @@ func TestBuildSnippetsFilterStatuses(t *testing.T) { Generation: 1, }, }, - Conditions: []conditions.Condition{staticConds.NewSnippetsFilterInvalid("invalid snippetsFilter")}, + Conditions: []conditions.Condition{conditions.NewSnippetsFilterInvalid("invalid snippetsFilter")}, Valid: false, } @@ -2027,7 +2025,7 @@ func TestBuildSnippetsFilterStatuses(t *testing.T) { g.Expect(err).ToNot(HaveOccurred()) } - updater := statusFramework.NewUpdater(k8sClient, logr.Discard()) + updater := NewUpdater(k8sClient, logr.Discard()) reqs := PrepareSnippetsFilterRequests(test.snippetsFilters, transitionTime, gatewayCtlrName) diff --git a/internal/mode/static/status/queue.go b/internal/controller/status/queue.go similarity index 100% rename from internal/mode/static/status/queue.go rename to internal/controller/status/queue.go diff --git a/internal/mode/static/status/queue_test.go b/internal/controller/status/queue_test.go similarity index 100% rename from internal/mode/static/status/queue_test.go rename to internal/controller/status/queue_test.go diff --git a/internal/mode/static/status/status_setters.go b/internal/controller/status/status_setters.go similarity index 91% rename from internal/mode/static/status/status_setters.go rename to internal/controller/status/status_setters.go index afd3923eea..5f973a5f07 100644 --- a/internal/mode/static/status/status_setters.go +++ b/internal/controller/status/status_setters.go @@ -9,16 +9,15 @@ import ( "sigs.k8s.io/gateway-api/apis/v1alpha3" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - frameworkStatus "github.com/nginx/nginx-gateway-fabric/internal/framework/status" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies" ) -func newNginxGatewayStatusSetter(status ngfAPI.NginxGatewayStatus) frameworkStatus.Setter { +func newNginxGatewayStatusSetter(status ngfAPI.NginxGatewayStatus) Setter { return func(obj client.Object) (wasSet bool) { ng := helpers.MustCastObject[*ngfAPI.NginxGateway](obj) - if frameworkStatus.ConditionsEqual(ng.Status.Conditions, status.Conditions) { + if ConditionsEqual(ng.Status.Conditions, status.Conditions) { return false } @@ -27,7 +26,7 @@ func newNginxGatewayStatusSetter(status ngfAPI.NginxGatewayStatus) frameworkStat } } -func newGatewayStatusSetter(status gatewayv1.GatewayStatus) frameworkStatus.Setter { +func newGatewayStatusSetter(status gatewayv1.GatewayStatus) Setter { return func(obj client.Object) (wasSet bool) { gw := helpers.MustCastObject[*gatewayv1.Gateway](obj) @@ -53,7 +52,7 @@ func gwStatusEqual(prev, cur gatewayv1.GatewayStatus) bool { return false } - if !frameworkStatus.ConditionsEqual(prev.Conditions, cur.Conditions) { + if !ConditionsEqual(prev.Conditions, cur.Conditions) { return false } @@ -66,7 +65,7 @@ func gwStatusEqual(prev, cur gatewayv1.GatewayStatus) bool { return false } - if !frameworkStatus.ConditionsEqual(s1.Conditions, s2.Conditions) { + if !ConditionsEqual(s1.Conditions, s2.Conditions) { return false } @@ -80,7 +79,7 @@ func gwStatusEqual(prev, cur gatewayv1.GatewayStatus) bool { }) } -func newHTTPRouteStatusSetter(status gatewayv1.HTTPRouteStatus, gatewayCtlrName string) frameworkStatus.Setter { +func newHTTPRouteStatusSetter(status gatewayv1.HTTPRouteStatus, gatewayCtlrName string) Setter { return func(object client.Object) (wasSet bool) { hr := helpers.MustCastObject[*gatewayv1.HTTPRoute](object) @@ -101,7 +100,7 @@ func newHTTPRouteStatusSetter(status gatewayv1.HTTPRouteStatus, gatewayCtlrName } } -func newTLSRouteStatusSetter(status v1alpha2.TLSRouteStatus, gatewayCtlrName string) frameworkStatus.Setter { +func newTLSRouteStatusSetter(status v1alpha2.TLSRouteStatus, gatewayCtlrName string) Setter { return func(object client.Object) (wasSet bool) { tr := helpers.MustCastObject[*v1alpha2.TLSRoute](object) @@ -122,7 +121,7 @@ func newTLSRouteStatusSetter(status v1alpha2.TLSRouteStatus, gatewayCtlrName str } } -func newGRPCRouteStatusSetter(status gatewayv1.GRPCRouteStatus, gatewayCtlrName string) frameworkStatus.Setter { +func newGRPCRouteStatusSetter(status gatewayv1.GRPCRouteStatus, gatewayCtlrName string) Setter { return func(object client.Object) (wasSet bool) { gr := helpers.MustCastObject[*gatewayv1.GRPCRoute](object) @@ -196,14 +195,14 @@ func routeParentStatusEqual(p1, p2 gatewayv1.RouteParentStatus) bool { // we ignore the rest of the ParentRef fields because we do not set them - return frameworkStatus.ConditionsEqual(p1.Conditions, p2.Conditions) + return ConditionsEqual(p1.Conditions, p2.Conditions) } -func newGatewayClassStatusSetter(status gatewayv1.GatewayClassStatus) frameworkStatus.Setter { +func newGatewayClassStatusSetter(status gatewayv1.GatewayClassStatus) Setter { return func(obj client.Object) (wasSet bool) { gc := helpers.MustCastObject[*gatewayv1.GatewayClass](obj) - if frameworkStatus.ConditionsEqual(gc.Status.Conditions, status.Conditions) { + if ConditionsEqual(gc.Status.Conditions, status.Conditions) { return false } @@ -215,7 +214,7 @@ func newGatewayClassStatusSetter(status gatewayv1.GatewayClassStatus) frameworkS func newBackendTLSPolicyStatusSetter( status v1alpha2.PolicyStatus, gatewayCtlrName string, -) frameworkStatus.Setter { +) Setter { return func(object client.Object) (wasSet bool) { btp := helpers.MustCastObject[*v1alpha3.BackendTLSPolicy](object) @@ -246,7 +245,7 @@ func newBackendTLSPolicyStatusSetter( func newNGFPolicyStatusSetter( status v1alpha2.PolicyStatus, gatewayCtlrName string, -) frameworkStatus.Setter { +) Setter { return func(object client.Object) (wasSet bool) { policy := helpers.MustCastObject[policies.Policy](object) prevStatus := policy.GetPolicyStatus() @@ -331,13 +330,13 @@ func ancestorStatusEqual(p1, p2 v1alpha2.PolicyAncestorStatus) bool { } // we ignore the rest of the AncestorRef fields because we do not set them - return frameworkStatus.ConditionsEqual(p1.Conditions, p2.Conditions) + return ConditionsEqual(p1.Conditions, p2.Conditions) } func newSnippetsFilterStatusSetter( snippetsFilterStatus ngfAPI.SnippetsFilterStatus, gatewayCtlrName string, -) frameworkStatus.Setter { +) Setter { return func(obj client.Object) (wasSet bool) { sf := helpers.MustCastObject[*ngfAPI.SnippetsFilter](obj) @@ -403,5 +402,5 @@ func snippetsStatusEqual(status1, status2 ngfAPI.ControllerStatus) bool { return false } - return frameworkStatus.ConditionsEqual(status1.Conditions, status2.Conditions) + return ConditionsEqual(status1.Conditions, status2.Conditions) } diff --git a/internal/mode/static/status/status_setters_test.go b/internal/controller/status/status_setters_test.go similarity index 99% rename from internal/mode/static/status/status_setters_test.go rename to internal/controller/status/status_setters_test.go index d9eb316329..145dc48540 100644 --- a/internal/mode/static/status/status_setters_test.go +++ b/internal/controller/status/status_setters_test.go @@ -10,9 +10,9 @@ import ( "sigs.k8s.io/gateway-api/apis/v1alpha3" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/config/policies/policiesfakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/config/policies/policiesfakes" ) func TestNewNginxGatewayStatusSetter(t *testing.T) { diff --git a/internal/framework/status/status_suite_test.go b/internal/controller/status/status_suite_test.go similarity index 100% rename from internal/framework/status/status_suite_test.go rename to internal/controller/status/status_suite_test.go diff --git a/internal/framework/status/statusfakes/fake_group_updater.go b/internal/controller/status/statusfakes/fake_group_updater.go similarity index 97% rename from internal/framework/status/statusfakes/fake_group_updater.go rename to internal/controller/status/statusfakes/fake_group_updater.go index 2b643ff210..2e3097dfbd 100644 --- a/internal/framework/status/statusfakes/fake_group_updater.go +++ b/internal/controller/status/statusfakes/fake_group_updater.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/nginx/nginx-gateway-fabric/internal/framework/status" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status" ) type FakeGroupUpdater struct { diff --git a/internal/framework/status/statusfakes/fake_k8s_updater.go b/internal/controller/status/statusfakes/fake_k8s_updater.go similarity index 97% rename from internal/framework/status/statusfakes/fake_k8s_updater.go rename to internal/controller/status/statusfakes/fake_k8s_updater.go index ee5fdd7137..031b24addd 100644 --- a/internal/framework/status/statusfakes/fake_k8s_updater.go +++ b/internal/controller/status/statusfakes/fake_k8s_updater.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/nginx/nginx-gateway-fabric/internal/framework/status" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status" "sigs.k8s.io/controller-runtime/pkg/client" ) diff --git a/internal/framework/status/updater.go b/internal/controller/status/updater.go similarity index 100% rename from internal/framework/status/updater.go rename to internal/controller/status/updater.go diff --git a/internal/framework/status/updater_retry_test.go b/internal/controller/status/updater_retry_test.go similarity index 94% rename from internal/framework/status/updater_retry_test.go rename to internal/controller/status/updater_retry_test.go index 7768d78ad5..b2a578908f 100644 --- a/internal/framework/status/updater_retry_test.go +++ b/internal/controller/status/updater_retry_test.go @@ -13,9 +13,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" v1 "sigs.k8s.io/gateway-api/apis/v1" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status" + "github.com/nginx/nginx-gateway-fabric/internal/controller/status/statusfakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/controller/controllerfakes" - "github.com/nginx/nginx-gateway-fabric/internal/framework/status" - "github.com/nginx/nginx-gateway-fabric/internal/framework/status/statusfakes" ) func TestNewRetryUpdateFunc(t *testing.T) { diff --git a/internal/framework/status/updater_test.go b/internal/controller/status/updater_test.go similarity index 100% rename from internal/framework/status/updater_test.go rename to internal/controller/status/updater_test.go diff --git a/internal/mode/static/telemetry/collector.go b/internal/controller/telemetry/collector.go similarity index 98% rename from internal/mode/static/telemetry/collector.go rename to internal/controller/telemetry/collector.go index 2752f4cf7c..9655b5ce35 100644 --- a/internal/mode/static/telemetry/collector.go +++ b/internal/controller/telemetry/collector.go @@ -17,10 +17,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" + "github.com/nginx/nginx-gateway-fabric/internal/controller/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" ) //counterfeiter:generate . GraphGetter diff --git a/internal/mode/static/telemetry/collector_test.go b/internal/controller/telemetry/collector_test.go similarity index 98% rename from internal/mode/static/telemetry/collector_test.go rename to internal/controller/telemetry/collector_test.go index c52823b286..105f2da68a 100644 --- a/internal/mode/static/telemetry/collector_test.go +++ b/internal/controller/telemetry/collector_test.go @@ -19,15 +19,15 @@ import ( ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/config" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/resolver" + "github.com/nginx/nginx-gateway-fabric/internal/controller/telemetry" + "github.com/nginx/nginx-gateway-fabric/internal/controller/telemetry/telemetryfakes" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginx/nginx-gateway-fabric/internal/framework/kinds" "github.com/nginx/nginx-gateway-fabric/internal/framework/kubernetes/kubernetesfakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/config" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/resolver" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/telemetry" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/telemetry/telemetryfakes" ) type listCallsFunc = func( diff --git a/internal/mode/static/telemetry/data.avdl b/internal/controller/telemetry/data.avdl similarity index 100% rename from internal/mode/static/telemetry/data.avdl rename to internal/controller/telemetry/data.avdl diff --git a/internal/mode/static/telemetry/data_attributes_generated.go b/internal/controller/telemetry/data_attributes_generated.go similarity index 100% rename from internal/mode/static/telemetry/data_attributes_generated.go rename to internal/controller/telemetry/data_attributes_generated.go diff --git a/internal/mode/static/telemetry/data_test.go b/internal/controller/telemetry/data_test.go similarity index 100% rename from internal/mode/static/telemetry/data_test.go rename to internal/controller/telemetry/data_test.go diff --git a/internal/mode/static/telemetry/doc.go b/internal/controller/telemetry/doc.go similarity index 100% rename from internal/mode/static/telemetry/doc.go rename to internal/controller/telemetry/doc.go diff --git a/internal/mode/static/telemetry/exporter.go b/internal/controller/telemetry/exporter.go similarity index 100% rename from internal/mode/static/telemetry/exporter.go rename to internal/controller/telemetry/exporter.go diff --git a/internal/mode/static/telemetry/exporter_test.go b/internal/controller/telemetry/exporter_test.go similarity index 100% rename from internal/mode/static/telemetry/exporter_test.go rename to internal/controller/telemetry/exporter_test.go diff --git a/internal/mode/static/telemetry/job_worker.go b/internal/controller/telemetry/job_worker.go similarity index 100% rename from internal/mode/static/telemetry/job_worker.go rename to internal/controller/telemetry/job_worker.go diff --git a/internal/mode/static/telemetry/job_worker_test.go b/internal/controller/telemetry/job_worker_test.go similarity index 89% rename from internal/mode/static/telemetry/job_worker_test.go rename to internal/controller/telemetry/job_worker_test.go index 8855fd5d8b..283814d9d3 100644 --- a/internal/mode/static/telemetry/job_worker_test.go +++ b/internal/controller/telemetry/job_worker_test.go @@ -10,8 +10,8 @@ import ( tel "github.com/nginx/telemetry-exporter/pkg/telemetry" . "github.com/onsi/gomega" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/telemetry" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/telemetry/telemetryfakes" + "github.com/nginx/nginx-gateway-fabric/internal/controller/telemetry" + "github.com/nginx/nginx-gateway-fabric/internal/controller/telemetry/telemetryfakes" ) func TestCreateTelemetryJobWorker_Succeeds(t *testing.T) { diff --git a/internal/mode/static/telemetry/ngfresourcecounts_attributes_generated.go b/internal/controller/telemetry/ngfresourcecounts_attributes_generated.go similarity index 100% rename from internal/mode/static/telemetry/ngfresourcecounts_attributes_generated.go rename to internal/controller/telemetry/ngfresourcecounts_attributes_generated.go diff --git a/internal/mode/static/telemetry/platform.go b/internal/controller/telemetry/platform.go similarity index 100% rename from internal/mode/static/telemetry/platform.go rename to internal/controller/telemetry/platform.go diff --git a/internal/mode/static/telemetry/platform_test.go b/internal/controller/telemetry/platform_test.go similarity index 100% rename from internal/mode/static/telemetry/platform_test.go rename to internal/controller/telemetry/platform_test.go diff --git a/internal/mode/static/telemetry/telemetry_suite_test.go b/internal/controller/telemetry/telemetry_suite_test.go similarity index 100% rename from internal/mode/static/telemetry/telemetry_suite_test.go rename to internal/controller/telemetry/telemetry_suite_test.go diff --git a/internal/mode/static/telemetry/telemetryfakes/fake_configuration_getter.go b/internal/controller/telemetry/telemetryfakes/fake_configuration_getter.go similarity index 95% rename from internal/mode/static/telemetry/telemetryfakes/fake_configuration_getter.go rename to internal/controller/telemetry/telemetryfakes/fake_configuration_getter.go index 8650078dc7..d5c44676b1 100644 --- a/internal/mode/static/telemetry/telemetryfakes/fake_configuration_getter.go +++ b/internal/controller/telemetry/telemetryfakes/fake_configuration_getter.go @@ -4,8 +4,8 @@ package telemetryfakes import ( "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/telemetry" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/dataplane" + "github.com/nginx/nginx-gateway-fabric/internal/controller/telemetry" ) type FakeConfigurationGetter struct { diff --git a/internal/mode/static/telemetry/telemetryfakes/fake_data_collector.go b/internal/controller/telemetry/telemetryfakes/fake_data_collector.go similarity index 97% rename from internal/mode/static/telemetry/telemetryfakes/fake_data_collector.go rename to internal/controller/telemetry/telemetryfakes/fake_data_collector.go index 6c820a3a6e..6d83361827 100644 --- a/internal/mode/static/telemetry/telemetryfakes/fake_data_collector.go +++ b/internal/controller/telemetry/telemetryfakes/fake_data_collector.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/telemetry" + "github.com/nginx/nginx-gateway-fabric/internal/controller/telemetry" ) type FakeDataCollector struct { diff --git a/internal/mode/static/telemetry/telemetryfakes/fake_exporter.go b/internal/controller/telemetry/telemetryfakes/fake_exporter.go similarity index 97% rename from internal/mode/static/telemetry/telemetryfakes/fake_exporter.go rename to internal/controller/telemetry/telemetryfakes/fake_exporter.go index f854e50fe6..d78ddc2f4f 100644 --- a/internal/mode/static/telemetry/telemetryfakes/fake_exporter.go +++ b/internal/controller/telemetry/telemetryfakes/fake_exporter.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/telemetry" + "github.com/nginx/nginx-gateway-fabric/internal/controller/telemetry" telemetrya "github.com/nginx/telemetry-exporter/pkg/telemetry" ) diff --git a/internal/mode/static/telemetry/telemetryfakes/fake_graph_getter.go b/internal/controller/telemetry/telemetryfakes/fake_graph_getter.go similarity index 95% rename from internal/mode/static/telemetry/telemetryfakes/fake_graph_getter.go rename to internal/controller/telemetry/telemetryfakes/fake_graph_getter.go index 60b9d6baa5..32735acb60 100644 --- a/internal/mode/static/telemetry/telemetryfakes/fake_graph_getter.go +++ b/internal/controller/telemetry/telemetryfakes/fake_graph_getter.go @@ -4,8 +4,8 @@ package telemetryfakes import ( "sync" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/telemetry" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/graph" + "github.com/nginx/nginx-gateway-fabric/internal/controller/telemetry" ) type FakeGraphGetter struct { diff --git a/internal/framework/conditions/conditions.go b/internal/framework/conditions/conditions.go deleted file mode 100644 index bfdfe2b23e..0000000000 --- a/internal/framework/conditions/conditions.go +++ /dev/null @@ -1,153 +0,0 @@ -package conditions - -import ( - "fmt" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - v1 "sigs.k8s.io/gateway-api/apis/v1" -) - -const ( - // GatewayClassReasonGatewayClassConflict indicates there are multiple GatewayClass resources - // that reference this controller, and we ignored the resource in question and picked the - // GatewayClass that is referenced in the command-line argument. - // This reason is used with GatewayClassConditionAccepted (false). - GatewayClassReasonGatewayClassConflict v1.GatewayClassConditionReason = "GatewayClassConflict" - - // GatewayClassMessageGatewayClassConflict is a message that describes GatewayClassReasonGatewayClassConflict. - GatewayClassMessageGatewayClassConflict = "The resource is ignored due to a conflicting GatewayClass resource" -) - -// Condition defines a condition to be reported in the status of resources. -type Condition struct { - Type string - Status metav1.ConditionStatus - Reason string - Message string -} - -// DeduplicateConditions removes duplicate conditions based on the condition type. -// The last condition wins. The order of conditions is preserved. -func DeduplicateConditions(conds []Condition) []Condition { - type elem struct { - cond Condition - reverseIdx int - } - - uniqueElems := make(map[string]elem) - - idx := 0 - for i := len(conds) - 1; i >= 0; i-- { - if _, exist := uniqueElems[conds[i].Type]; exist { - continue - } - - uniqueElems[conds[i].Type] = elem{ - cond: conds[i], - reverseIdx: idx, - } - idx++ - } - - result := make([]Condition, len(uniqueElems)) - - for _, el := range uniqueElems { - result[len(result)-el.reverseIdx-1] = el.cond - } - - return result -} - -// NewDefaultGatewayClassConditions returns Conditions that indicate that the GatewayClass is accepted and that the -// Gateway API CRD versions are supported. -func NewDefaultGatewayClassConditions() []Condition { - return []Condition{ - { - Type: string(v1.GatewayClassConditionStatusAccepted), - Status: metav1.ConditionTrue, - Reason: string(v1.GatewayClassReasonAccepted), - Message: "GatewayClass is accepted", - }, - { - Type: string(v1.GatewayClassConditionStatusSupportedVersion), - Status: metav1.ConditionTrue, - Reason: string(v1.GatewayClassReasonSupportedVersion), - Message: "Gateway API CRD versions are supported", - }, - } -} - -// NewGatewayClassSupportedVersionBestEffort returns a Condition that indicates that the GatewayClass is accepted, -// but the Gateway API CRD versions are not supported. This means NGF will attempt to generate configuration, -// but it does not guarantee support. -func NewGatewayClassSupportedVersionBestEffort(recommendedVersion string) []Condition { - return []Condition{ - { - Type: string(v1.GatewayClassConditionStatusSupportedVersion), - Status: metav1.ConditionFalse, - Reason: string(v1.GatewayClassReasonUnsupportedVersion), - Message: fmt.Sprintf( - "Gateway API CRD versions are not recommended. Recommended version is %s", - recommendedVersion, - ), - }, - } -} - -// NewGatewayClassUnsupportedVersion returns Conditions that indicate that the GatewayClass is not accepted because -// the Gateway API CRD versions are not supported. NGF will not generate configuration in this case. -func NewGatewayClassUnsupportedVersion(recommendedVersion string) []Condition { - return []Condition{ - { - Type: string(v1.GatewayClassConditionStatusAccepted), - Status: metav1.ConditionFalse, - Reason: string(v1.GatewayClassReasonUnsupportedVersion), - Message: fmt.Sprintf( - "Gateway API CRD versions are not supported. Please install version %s", - recommendedVersion, - ), - }, - { - Type: string(v1.GatewayClassConditionStatusSupportedVersion), - Status: metav1.ConditionFalse, - Reason: string(v1.GatewayClassReasonUnsupportedVersion), - Message: fmt.Sprintf( - "Gateway API CRD versions are not supported. Please install version %s", - recommendedVersion, - ), - }, - } -} - -// NewGatewayClassConflict returns a Condition that indicates that the GatewayClass is not accepted -// due to a conflict with another GatewayClass. -func NewGatewayClassConflict() Condition { - return Condition{ - Type: string(v1.GatewayClassConditionStatusAccepted), - Status: metav1.ConditionFalse, - Reason: string(GatewayClassReasonGatewayClassConflict), - Message: GatewayClassMessageGatewayClassConflict, - } -} - -// ConvertConditions converts conditions to Kubernetes API conditions. -func ConvertConditions( - conds []Condition, - observedGeneration int64, - transitionTime metav1.Time, -) []metav1.Condition { - apiConds := make([]metav1.Condition, len(conds)) - - for i := range conds { - apiConds[i] = metav1.Condition{ - Type: conds[i].Type, - Status: conds[i].Status, - ObservedGeneration: observedGeneration, - LastTransitionTime: transitionTime, - Reason: conds[i].Reason, - Message: conds[i].Message, - } - } - - return apiConds -} diff --git a/internal/framework/doc.go b/internal/framework/doc.go index 221cf07449..1ff2d59f3c 100644 --- a/internal/framework/doc.go +++ b/internal/framework/doc.go @@ -1,4 +1,4 @@ /* -Package framework contains all the packages that are shared by the provisioner and static modes of the project. +Package framework contains general packages for building the controller. */ package framework diff --git a/internal/framework/file/file.go b/internal/framework/file/file.go index 555731ba45..8b090d3fa9 100644 --- a/internal/framework/file/file.go +++ b/internal/framework/file/file.go @@ -6,7 +6,7 @@ import ( "io" "os" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent" ) //go:generate go tool counterfeiter -generate diff --git a/internal/framework/file/file_test.go b/internal/framework/file/file_test.go index c67678bbad..555fdedf5c 100644 --- a/internal/framework/file/file_test.go +++ b/internal/framework/file/file_test.go @@ -9,9 +9,9 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + "github.com/nginx/nginx-gateway-fabric/internal/controller/nginx/agent" "github.com/nginx/nginx-gateway-fabric/internal/framework/file" "github.com/nginx/nginx-gateway-fabric/internal/framework/file/filefakes" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/nginx/agent" ) var _ = Describe("Write files", Ordered, func() { diff --git a/internal/framework/gatewayclass/validate.go b/internal/framework/gatewayclass/validate.go deleted file mode 100644 index 1ec247fcd4..0000000000 --- a/internal/framework/gatewayclass/validate.go +++ /dev/null @@ -1,86 +0,0 @@ -package gatewayclass - -import ( - "strings" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" -) - -const ( - // BundleVersionAnnotation is the annotation on Gateway API CRDs that contains the installed version. - BundleVersionAnnotation = "gateway.networking.k8s.io/bundle-version" - // SupportedVersion is the supported version of the Gateway API CRDs. - SupportedVersion = "v1.3.0" -) - -var gatewayCRDs = map[string]apiVersion{ - "gatewayclasses.gateway.networking.k8s.io": {}, - "gateways.gateway.networking.k8s.io": {}, - "httproutes.gateway.networking.k8s.io": {}, - "referencegrants.gateway.networking.k8s.io": {}, - "backendtlspolicies.gateway.networking.k8s.io": {}, - "grpcroutes.gateway.networking.k8s.io": {}, - "tlsroutes.gateway.networking.k8s.io": {}, -} - -type apiVersion struct { - major string - minor string -} - -func ValidateCRDVersions( - crdMetadata map[types.NamespacedName]*metav1.PartialObjectMetadata, -) (conds []conditions.Condition, valid bool) { - installedAPIVersions := getBundleVersions(crdMetadata) - supportedAPIVersion := parseVersionString(SupportedVersion) - - var unsupported, bestEffort bool - - for _, version := range installedAPIVersions { - if version.major != supportedAPIVersion.major { - unsupported = true - } else if version.minor != supportedAPIVersion.minor { - bestEffort = true - } - } - - if unsupported { - return conditions.NewGatewayClassUnsupportedVersion(SupportedVersion), false - } - - if bestEffort { - return conditions.NewGatewayClassSupportedVersionBestEffort(SupportedVersion), true - } - - return nil, true -} - -func parseVersionString(version string) apiVersion { - versionBits := strings.Split(version, ".") - if len(versionBits) != 3 { - return apiVersion{} - } - - major, _ := strings.CutPrefix(versionBits[0], "v") - - return apiVersion{ - major: major, - minor: versionBits[1], - } -} - -func getBundleVersions(crdMetadata map[types.NamespacedName]*metav1.PartialObjectMetadata) []apiVersion { - versions := make([]apiVersion, 0, len(gatewayCRDs)) - - for nsname, md := range crdMetadata { - if _, ok := gatewayCRDs[nsname.Name]; ok { - bundleVersion := md.Annotations[BundleVersionAnnotation] - versions = append(versions, parseVersionString(bundleVersion)) - } - } - - return versions -} diff --git a/internal/framework/gatewayclass/validate_test.go b/internal/framework/gatewayclass/validate_test.go deleted file mode 100644 index c76f6a883e..0000000000 --- a/internal/framework/gatewayclass/validate_test.go +++ /dev/null @@ -1,126 +0,0 @@ -package gatewayclass_test - -import ( - "strings" - "testing" - - . "github.com/onsi/gomega" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - - "github.com/nginx/nginx-gateway-fabric/internal/framework/conditions" - "github.com/nginx/nginx-gateway-fabric/internal/framework/gatewayclass" -) - -func TestValidateCRDVersions(t *testing.T) { - t.Parallel() - createCRDMetadata := func(version string) *metav1.PartialObjectMetadata { - return &metav1.PartialObjectMetadata{ - ObjectMeta: metav1.ObjectMeta{ - Annotations: map[string]string{ - gatewayclass.BundleVersionAnnotation: version, - }, - }, - } - } - - // Adding patch version to SupportedVersion to try and avoid having to update these tests with every release. - fields := strings.Split(gatewayclass.SupportedVersion, ".") - fields[2] = "99" - - validVersionWithPatch := createCRDMetadata(strings.Join(fields, ".")) - bestEffortVersion := createCRDMetadata("v1.99.99") - unsupportedVersion := createCRDMetadata("v99.0.0") - - tests := []struct { - crds map[types.NamespacedName]*metav1.PartialObjectMetadata - name string - expConds []conditions.Condition - valid bool - }{ - { - name: "valid; all supported versions", - crds: map[types.NamespacedName]*metav1.PartialObjectMetadata{ - {Name: "gatewayclasses.gateway.networking.k8s.io"}: validVersionWithPatch, - {Name: "gateways.gateway.networking.k8s.io"}: validVersionWithPatch, - {Name: "httproutes.gateway.networking.k8s.io"}: validVersionWithPatch, - {Name: "referencegrants.gateway.networking.k8s.io"}: validVersionWithPatch, - {Name: "some.other.crd"}: unsupportedVersion, /* should ignore */ - }, - valid: true, - expConds: nil, - }, - { - name: "valid; only one Gateway API CRD exists but it's a supported version", - crds: map[types.NamespacedName]*metav1.PartialObjectMetadata{ - {Name: "gatewayclasses.gateway.networking.k8s.io"}: validVersionWithPatch, - {Name: "some.other.crd"}: unsupportedVersion, /* should ignore */ - }, - valid: true, - expConds: nil, - }, - { - name: "valid; all best effort (supported major version)", - crds: map[types.NamespacedName]*metav1.PartialObjectMetadata{ - {Name: "gatewayclasses.gateway.networking.k8s.io"}: bestEffortVersion, - {Name: "gateways.gateway.networking.k8s.io"}: bestEffortVersion, - {Name: "httproutes.gateway.networking.k8s.io"}: bestEffortVersion, - {Name: "referencegrants.gateway.networking.k8s.io"}: bestEffortVersion, - }, - valid: true, - expConds: conditions.NewGatewayClassSupportedVersionBestEffort(gatewayclass.SupportedVersion), - }, - { - name: "valid; mix of supported and best effort versions", - crds: map[types.NamespacedName]*metav1.PartialObjectMetadata{ - {Name: "gatewayclasses.gateway.networking.k8s.io"}: validVersionWithPatch, - {Name: "gateways.gateway.networking.k8s.io"}: bestEffortVersion, - {Name: "httproutes.gateway.networking.k8s.io"}: validVersionWithPatch, - {Name: "referencegrants.gateway.networking.k8s.io"}: validVersionWithPatch, - }, - valid: true, - expConds: conditions.NewGatewayClassSupportedVersionBestEffort(gatewayclass.SupportedVersion), - }, - { - name: "invalid; all unsupported versions", - crds: map[types.NamespacedName]*metav1.PartialObjectMetadata{ - {Name: "gatewayclasses.gateway.networking.k8s.io"}: unsupportedVersion, - {Name: "gateways.gateway.networking.k8s.io"}: unsupportedVersion, - {Name: "httproutes.gateway.networking.k8s.io"}: unsupportedVersion, - {Name: "referencegrants.gateway.networking.k8s.io"}: unsupportedVersion, - }, - valid: false, - expConds: conditions.NewGatewayClassUnsupportedVersion(gatewayclass.SupportedVersion), - }, - { - name: "invalid; mix unsupported and best effort versions", - crds: map[types.NamespacedName]*metav1.PartialObjectMetadata{ - {Name: "gatewayclasses.gateway.networking.k8s.io"}: unsupportedVersion, - {Name: "gateways.gateway.networking.k8s.io"}: bestEffortVersion, - {Name: "httproutes.gateway.networking.k8s.io"}: unsupportedVersion, - {Name: "referencegrants.gateway.networking.k8s.io"}: bestEffortVersion, - }, - valid: false, - expConds: conditions.NewGatewayClassUnsupportedVersion(gatewayclass.SupportedVersion), - }, - { - name: "invalid; bad version string", - crds: map[types.NamespacedName]*metav1.PartialObjectMetadata{ - {Name: "gatewayclasses.gateway.networking.k8s.io"}: createCRDMetadata("v"), - }, - valid: false, - expConds: conditions.NewGatewayClassUnsupportedVersion(gatewayclass.SupportedVersion), - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - t.Parallel() - g := NewWithT(t) - - conds, valid := gatewayclass.ValidateCRDVersions(test.crds) - g.Expect(valid).To(Equal(test.valid)) - g.Expect(conds).To(Equal(test.expConds)) - }) - } -} diff --git a/internal/mode/static/doc.go b/internal/mode/static/doc.go deleted file mode 100644 index 3b386ac027..0000000000 --- a/internal/mode/static/doc.go +++ /dev/null @@ -1,5 +0,0 @@ -/* -Package static contains all the packages that relate to the static-mode implementation of NGF. -Static-mode configures NGINX in the scope of a single Gateway resource. -*/ -package static diff --git a/tests/Makefile b/tests/Makefile index 391ddf9771..de6121f188 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -11,7 +11,7 @@ GW_API_PREV_VERSION ?= 1.2.1## Supported Gateway API version from previous NGF r GW_SERVICE_TYPE = NodePort## Service type to use for the gateway NGF_VERSION ?= edge## NGF version to be tested PULL_POLICY = Never## Pull policy for the images -NGINX_CONF_DIR = internal/mode/static/nginx/conf +NGINX_CONF_DIR = internal/controller/nginx/conf SUPPORTED_EXTENDED_FEATURES = HTTPRouteQueryParamMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteSchemeRedirect,HTTPRouteHostRewrite,HTTPRoutePathRewrite,GatewayPort8080,HTTPRouteResponseHeaderModification,HTTPRoutePathRedirect,GatewayHTTPListenerIsolation,GatewayInfrastructurePropagation STANDARD_CONFORMANCE_PROFILES = GATEWAY-HTTP,GATEWAY-GRPC EXPERIMENTAL_CONFORMANCE_PROFILES = GATEWAY-TLS diff --git a/tests/suite/snippets_filter_test.go b/tests/suite/snippets_filter_test.go index de6583d79b..8c2a8ca80b 100644 --- a/tests/suite/snippets_filter_test.go +++ b/tests/suite/snippets_filter_test.go @@ -14,7 +14,7 @@ import ( v1 "sigs.k8s.io/gateway-api/apis/v1" ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/tests/framework" ) diff --git a/tests/suite/tracing_test.go b/tests/suite/tracing_test.go index f56a083426..448205a6ce 100644 --- a/tests/suite/tracing_test.go +++ b/tests/suite/tracing_test.go @@ -19,8 +19,8 @@ import ( ngfAPIv1alpha1 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1" ngfAPIv1alpha2 "github.com/nginx/nginx-gateway-fabric/apis/v1alpha2" + "github.com/nginx/nginx-gateway-fabric/internal/controller/state/conditions" "github.com/nginx/nginx-gateway-fabric/internal/framework/helpers" - "github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/conditions" "github.com/nginx/nginx-gateway-fabric/tests/framework" )