From d5cdbdc881ff6eae2cde78667add84043330b64b Mon Sep 17 00:00:00 2001 From: Kate Osborn Date: Fri, 7 Jul 2023 15:10:10 -0600 Subject: [PATCH 1/7] Refactor packages --- .gitignore | 2 +- cmd/gateway/commands.go | 8 +- conformance/Makefile | 2 +- docs/installation.md | 2 +- .../conditions/conditions.go | 0 .../conditions/conditions_test.go | 0 internal/{ => framework}/config/config.go | 0 .../controller/controller_suite_test.go | 2 +- .../controllerfakes/fake_field_indexer.go | 0 .../controller/controllerfakes/fake_getter.go | 2 +- .../controllerfakes/fake_manager.go | 0 internal/{ => framework}/controller/doc.go | 0 internal/{ => framework}/controller/fakes.go | 0 internal/{ => framework}/controller/getter.go | 0 .../{ => framework}/controller/reconciler.go | 2 +- .../controller/reconciler_test.go | 6 +- .../{ => framework}/controller/register.go | 2 +- .../controller/register_test.go | 8 +- internal/framework/doc.go | 4 + internal/{ => framework}/events/event.go | 0 .../events/events_suite_test.go} | 0 .../{ => framework}/events/events_test.go | 0 .../events/eventsfakes/fake_event_handler.go | 2 +- .../fake_first_event_batch_preparer.go | 2 +- .../events/eventsfakes/fake_reader.go | 2 +- .../events/first_eventbatch_preparer.go | 0 .../events/first_eventbatch_preparer_test.go | 4 +- internal/framework/events/handler.go | 14 ++ internal/{ => framework}/events/loop.go | 0 internal/{ => framework}/events/loop_test.go | 4 +- internal/{ => framework}/helpers/helpers.go | 0 .../{ => framework}/manager/filter/filter.go | 2 +- .../manager/filter/filter_test.go | 0 .../manager/index/endpointslice.go | 0 .../manager/index/endpointslice_test.go | 0 .../{ => framework}/manager/index/index.go | 0 .../manager/predicate/gatewayclass.go | 0 .../manager/predicate/gatewayclass_test.go | 0 .../manager/predicate/service.go | 0 .../manager/predicate/service_test.go | 0 internal/{ => framework}/status/clock.go | 2 +- internal/{ => framework}/status/conditions.go | 2 +- .../{ => framework}/status/conditions_test.go | 4 +- internal/{ => framework}/status/gateway.go | 0 .../{ => framework}/status/gateway_test.go | 2 +- .../{ => framework}/status/gatewayclass.go | 0 .../status/gatewayclass_test.go | 2 +- internal/{ => framework}/status/httproute.go | 0 .../{ => framework}/status/httproute_test.go | 2 +- .../status/status_suite_test.go} | 0 internal/framework/status/statuses.go | 71 ++++++ .../status/statusfakes/fake_clock.go | 2 +- .../status/statusfakes/fake_updater.go | 2 +- internal/{ => framework}/status/updater.go | 0 .../{ => framework}/status/updater_test.go | 8 +- internal/{ => mode}/provisioner/deployment.go | 0 internal/mode/provisioner/doc.go | 6 + internal/{ => mode}/provisioner/handler.go | 6 +- .../{ => mode}/provisioner/handler_test.go | 10 +- internal/{ => mode}/provisioner/manager.go | 8 +- .../provisioner/provisioner_suite_test.go | 0 internal/{ => mode}/provisioner/store.go | 2 +- internal/mode/static/build_statuses.go | 176 ++++++++++++++ .../static/build_statuses_test.go} | 79 +++--- internal/mode/static/doc.go | 5 + internal/{events => mode/static}/handler.go | 38 ++- .../{events => mode/static}/handler_test.go | 25 +- internal/{manager => mode/static}/manager.go | 36 +-- .../{manager => mode/static}/manager_test.go | 2 +- .../config/configfakes/fake_generator.go | 6 +- .../{ => mode/static}/nginx/config/execute.go | 0 .../static}/nginx/config/execute_test.go | 2 +- .../static}/nginx/config/generator.go | 4 +- .../static}/nginx/config/generator_test.go | 6 +- .../static}/nginx/config/http/config.go | 0 .../{ => mode/static}/nginx/config/maps.go | 4 +- .../static}/nginx/config/maps_template.go | 0 .../static}/nginx/config/maps_test.go | 4 +- .../{ => mode/static}/nginx/config/servers.go | 4 +- .../static}/nginx/config/servers_template.go | 0 .../static}/nginx/config/servers_test.go | 6 +- .../static}/nginx/config/split_clients.go | 4 +- .../nginx/config/split_clients_template.go | 0 .../nginx/config/split_clients_test.go | 4 +- .../static}/nginx/config/upstreams.go | 4 +- .../nginx/config/upstreams_template.go | 0 .../static}/nginx/config/upstreams_test.go | 6 +- .../static}/nginx/config/validation/common.go | 0 .../nginx/config/validation/common_test.go | 0 .../static}/nginx/config/validation/doc.go | 0 .../nginx/config/validation/framework.go | 0 .../nginx/config/validation/framework_test.go | 0 .../nginx/config/validation/http_filters.go | 0 .../config/validation/http_filters_test.go | 0 .../nginx/config/validation/http_njs_match.go | 2 +- .../config/validation/http_njs_match_test.go | 0 .../nginx/config/validation/http_validator.go | 2 +- .../static}/nginx/config/variable_names.go | 0 .../nginx/config/variable_names_test.go | 0 .../static}/nginx/file/file_suite_test.go | 0 .../fake_clear_folders_osfile_manager.go | 2 +- .../nginx/file/filefakes/fake_dir_entry.go | 0 .../nginx/file/filefakes/fake_manager.go | 2 +- .../file/filefakes/fake_osfile_manager.go | 2 +- .../{ => mode/static}/nginx/file/folders.go | 0 .../static}/nginx/file/folders_test.go | 4 +- .../{ => mode/static}/nginx/file/manager.go | 0 .../static}/nginx/file/manager_test.go | 4 +- .../static}/nginx/file/os_filemanager.go | 0 .../static}/nginx/modules/.prettierrc | 0 .../{ => mode/static}/nginx/modules/README.md | 0 .../static}/nginx/modules/package-lock.json | 0 .../static}/nginx/modules/package.json | 0 .../static}/nginx/modules/src/httpmatches.js | 0 .../nginx/modules/test/httpmatches.test.js | 0 .../static}/nginx/runtime/manager.go | 0 .../static}/nginx/runtime/manager_test.go | 0 .../runtime/runtimefakes/fake_manager.go | 2 +- internal/{ => mode/static}/sort/doc.go | 0 internal/{ => mode/static}/sort/sort.go | 0 internal/{ => mode/static}/sort/sort_test.go | 0 .../static}/state/change_processor.go | 6 +- .../static}/state/change_processor_test.go | 18 +- .../static}/state/dataplane/configuration.go | 4 +- .../state/dataplane/configuration_test.go | 8 +- .../{ => mode/static}/state/dataplane/doc.go | 0 .../{ => mode/static}/state/dataplane/sort.go | 2 +- .../static}/state/dataplane/sort_test.go | 2 +- .../static}/state/graph/backend_refs.go | 2 +- .../static}/state/graph/backend_refs_test.go | 4 +- internal/{ => mode/static}/state/graph/doc.go | 0 .../{ => mode/static}/state/graph/gateway.go | 4 +- .../static}/state/graph/gateway_listener.go | 2 +- .../state/graph/gateway_listener_test.go | 4 +- .../static}/state/graph/gateway_test.go | 4 +- .../static}/state/graph/gatewayclass.go | 2 +- .../static}/state/graph/gatewayclass_test.go | 8 +- .../{ => mode/static}/state/graph/graph.go | 2 +- .../static}/state/graph/graph_test.go | 6 +- .../static}/state/graph/httproute.go | 4 +- .../static}/state/graph/httproute_test.go | 6 +- .../static}/state/graph/reference_grant.go | 0 .../state/graph/reference_grant_test.go | 2 +- .../{ => mode/static}/state/graph/secret.go | 0 .../static}/state/graph/secret_test.go | 0 .../static}/state/graph/validation.go | 0 .../static}/state/graph/validation_test.go | 0 .../static}/state/relationship/capturer.go | 4 +- .../state/relationship/capturer_suite_test.go | 0 .../state/relationship/capturer_test.go | 6 +- .../relationshipfakes/fake_capturer.go | 2 +- .../state/relationship/relationships_test.go | 2 +- .../static}/state/resolver/resolver.go | 2 +- .../static}/state/resolver/resolver_test.go | 2 +- .../resolverfakes/fake_service_resolver.go | 2 +- .../resolver/service_resolver_suite_test.go | 0 .../state/resolver/service_resolver_test.go | 6 +- .../static}/state/state_suite_test.go | 0 .../state/statefakes/fake_change_processor.go | 4 +- internal/{ => mode/static}/state/store.go | 2 +- .../fake_httpfields_validator.go | 2 +- .../static}/state/validation/validator.go | 0 internal/mode/static/static_suite_test.go | 13 + internal/status/statuses.go | 229 ------------------ 164 files changed, 528 insertions(+), 472 deletions(-) rename internal/{state => framework}/conditions/conditions.go (100%) rename internal/{state => framework}/conditions/conditions_test.go (100%) rename internal/{ => framework}/config/config.go (100%) rename internal/{ => framework}/controller/controller_suite_test.go (84%) rename internal/{ => framework}/controller/controllerfakes/fake_field_indexer.go (100%) rename internal/{ => framework}/controller/controllerfakes/fake_getter.go (97%) rename internal/{ => framework}/controller/controllerfakes/fake_manager.go (100%) rename internal/{ => framework}/controller/doc.go (100%) rename internal/{ => framework}/controller/fakes.go (100%) rename internal/{ => framework}/controller/getter.go (100%) rename internal/{ => framework}/controller/reconciler.go (97%) rename internal/{ => framework}/controller/reconciler_test.go (96%) rename internal/{ => framework}/controller/register.go (97%) rename internal/{ => framework}/controller/register_test.go (92%) create mode 100644 internal/framework/doc.go rename internal/{ => framework}/events/event.go (100%) rename internal/{events/events_suit_test.go => framework/events/events_suite_test.go} (100%) rename internal/{ => framework}/events/events_test.go (100%) rename internal/{ => framework}/events/eventsfakes/fake_event_handler.go (97%) rename internal/{ => framework}/events/eventsfakes/fake_first_event_batch_preparer.go (97%) rename internal/{ => framework}/events/eventsfakes/fake_reader.go (98%) rename internal/{ => framework}/events/first_eventbatch_preparer.go (100%) rename internal/{ => framework}/events/first_eventbatch_preparer_test.go (96%) create mode 100644 internal/framework/events/handler.go rename internal/{ => framework}/events/loop.go (100%) rename internal/{ => framework}/events/loop_test.go (96%) rename internal/{ => framework}/helpers/helpers.go (100%) rename internal/{ => framework}/manager/filter/filter.go (89%) rename internal/{ => framework}/manager/filter/filter_test.go (100%) rename internal/{ => framework}/manager/index/endpointslice.go (100%) rename internal/{ => framework}/manager/index/endpointslice_test.go (100%) rename internal/{ => framework}/manager/index/index.go (100%) rename internal/{ => framework}/manager/predicate/gatewayclass.go (100%) rename internal/{ => framework}/manager/predicate/gatewayclass_test.go (100%) rename internal/{ => framework}/manager/predicate/service.go (100%) rename internal/{ => framework}/manager/predicate/service_test.go (100%) rename internal/{ => framework}/status/clock.go (90%) rename internal/{ => framework}/status/conditions.go (88%) rename internal/{ => framework}/status/conditions_test.go (90%) rename internal/{ => framework}/status/gateway.go (100%) rename internal/{ => framework}/status/gateway_test.go (94%) rename internal/{ => framework}/status/gatewayclass.go (100%) rename internal/{ => framework}/status/gatewayclass_test.go (89%) rename internal/{ => framework}/status/httproute.go (100%) rename internal/{ => framework}/status/httproute_test.go (96%) rename internal/{status/status_suit_test.go => framework/status/status_suite_test.go} (100%) create mode 100644 internal/framework/status/statuses.go rename internal/{ => framework}/status/statusfakes/fake_clock.go (96%) rename internal/{ => framework}/status/statusfakes/fake_updater.go (96%) rename internal/{ => framework}/status/updater.go (100%) rename internal/{ => framework}/status/updater_test.go (97%) rename internal/{ => mode}/provisioner/deployment.go (100%) create mode 100644 internal/mode/provisioner/doc.go rename internal/{ => mode}/provisioner/handler.go (94%) rename internal/{ => mode}/provisioner/handler_test.go (96%) rename internal/{ => mode}/provisioner/manager.go (91%) rename internal/{ => mode}/provisioner/provisioner_suite_test.go (100%) rename internal/{ => mode}/provisioner/store.go (94%) create mode 100644 internal/mode/static/build_statuses.go rename internal/{status/statuses_test.go => mode/static/build_statuses_test.go} (87%) create mode 100644 internal/mode/static/doc.go rename internal/{events => mode/static}/handler.go (70%) rename internal/{events => mode/static}/handler_test.go (80%) rename internal/{manager => mode/static}/manager.go (83%) rename internal/{manager => mode/static}/manager_test.go (99%) rename internal/{ => mode/static}/nginx/config/configfakes/fake_generator.go (92%) rename internal/{ => mode/static}/nginx/config/execute.go (100%) rename internal/{ => mode/static}/nginx/config/execute_test.go (85%) rename internal/{ => mode/static}/nginx/config/generator.go (95%) rename internal/{ => mode/static}/nginx/config/generator_test.go (89%) rename internal/{ => mode/static}/nginx/config/http/config.go (100%) rename internal/{ => mode/static}/nginx/config/maps.go (91%) rename internal/{ => mode/static}/nginx/config/maps_template.go (100%) rename internal/{ => mode/static}/nginx/config/maps_test.go (95%) rename internal/{ => mode/static}/nginx/config/servers.go (98%) rename internal/{ => mode/static}/nginx/config/servers_template.go (100%) rename internal/{ => mode/static}/nginx/config/servers_test.go (99%) rename internal/{ => mode/static}/nginx/config/split_clients.go (95%) rename internal/{ => mode/static}/nginx/config/split_clients_template.go (100%) rename internal/{ => mode/static}/nginx/config/split_clients_test.go (98%) rename internal/{ => mode/static}/nginx/config/upstreams.go (91%) rename internal/{ => mode/static}/nginx/config/upstreams_template.go (100%) rename internal/{ => mode/static}/nginx/config/upstreams_test.go (93%) rename internal/{ => mode/static}/nginx/config/validation/common.go (100%) rename internal/{ => mode/static}/nginx/config/validation/common_test.go (100%) rename internal/{ => mode/static}/nginx/config/validation/doc.go (100%) rename internal/{ => mode/static}/nginx/config/validation/framework.go (100%) rename internal/{ => mode/static}/nginx/config/validation/framework_test.go (100%) rename internal/{ => mode/static}/nginx/config/validation/http_filters.go (100%) rename internal/{ => mode/static}/nginx/config/validation/http_filters_test.go (100%) rename internal/{ => mode/static}/nginx/config/validation/http_njs_match.go (97%) rename internal/{ => mode/static}/nginx/config/validation/http_njs_match_test.go (100%) rename internal/{ => mode/static}/nginx/config/validation/http_validator.go (85%) rename internal/{ => mode/static}/nginx/config/variable_names.go (100%) rename internal/{ => mode/static}/nginx/config/variable_names_test.go (100%) rename internal/{ => mode/static}/nginx/file/file_suite_test.go (100%) rename internal/{ => mode/static}/nginx/file/filefakes/fake_clear_folders_osfile_manager.go (98%) rename internal/{ => mode/static}/nginx/file/filefakes/fake_dir_entry.go (100%) rename internal/{ => mode/static}/nginx/file/filefakes/fake_manager.go (97%) rename internal/{ => mode/static}/nginx/file/filefakes/fake_osfile_manager.go (99%) rename internal/{ => mode/static}/nginx/file/folders.go (100%) rename internal/{ => mode/static}/nginx/file/folders_test.go (91%) rename internal/{ => mode/static}/nginx/file/manager.go (100%) rename internal/{ => mode/static}/nginx/file/manager_test.go (96%) rename internal/{ => mode/static}/nginx/file/os_filemanager.go (100%) rename internal/{ => mode/static}/nginx/modules/.prettierrc (100%) rename internal/{ => mode/static}/nginx/modules/README.md (100%) rename internal/{ => mode/static}/nginx/modules/package-lock.json (100%) rename internal/{ => mode/static}/nginx/modules/package.json (100%) rename internal/{ => mode/static}/nginx/modules/src/httpmatches.js (100%) rename internal/{ => mode/static}/nginx/modules/test/httpmatches.test.js (100%) rename internal/{ => mode/static}/nginx/runtime/manager.go (100%) rename internal/{ => mode/static}/nginx/runtime/manager_test.go (100%) rename internal/{ => mode/static}/nginx/runtime/runtimefakes/fake_manager.go (97%) rename internal/{ => mode/static}/sort/doc.go (100%) rename internal/{ => mode/static}/sort/sort.go (100%) rename internal/{ => mode/static}/sort/sort_test.go (100%) rename internal/{ => mode/static}/state/change_processor.go (97%) rename internal/{ => mode/static}/state/change_processor_test.go (98%) rename internal/{ => mode/static}/state/dataplane/configuration.go (99%) rename internal/{ => mode/static}/state/dataplane/configuration_test.go (99%) rename internal/{ => mode/static}/state/dataplane/doc.go (100%) rename internal/{ => mode/static}/state/dataplane/sort.go (99%) rename internal/{ => mode/static}/state/dataplane/sort_test.go (98%) rename internal/{ => mode/static}/state/graph/backend_refs.go (98%) rename internal/{ => mode/static}/state/graph/backend_refs_test.go (99%) rename internal/{ => mode/static}/state/graph/doc.go (100%) rename internal/{ => mode/static}/state/graph/gateway.go (97%) rename internal/{ => mode/static}/state/graph/gateway_listener.go (99%) rename internal/{ => mode/static}/state/graph/gateway_listener_test.go (98%) rename internal/{ => mode/static}/state/graph/gateway_test.go (99%) rename internal/{ => mode/static}/state/graph/gatewayclass.go (96%) rename internal/{ => mode/static}/state/graph/gatewayclass_test.go (93%) rename internal/{ => mode/static}/state/graph/graph.go (97%) rename internal/{ => mode/static}/state/graph/graph_test.go (97%) rename internal/{ => mode/static}/state/graph/httproute.go (99%) rename internal/{ => mode/static}/state/graph/httproute_test.go (99%) rename internal/{ => mode/static}/state/graph/reference_grant.go (100%) rename internal/{ => mode/static}/state/graph/reference_grant_test.go (98%) rename internal/{ => mode/static}/state/graph/secret.go (100%) rename internal/{ => mode/static}/state/graph/secret_test.go (100%) rename internal/{ => mode/static}/state/graph/validation.go (100%) rename internal/{ => mode/static}/state/graph/validation_test.go (100%) rename internal/{ => mode/static}/state/relationship/capturer.go (97%) rename internal/{ => mode/static}/state/relationship/capturer_suite_test.go (100%) rename internal/{ => mode/static}/state/relationship/capturer_test.go (98%) rename internal/{ => mode/static}/state/relationship/relationshipfakes/fake_capturer.go (98%) rename internal/{ => mode/static}/state/relationship/relationships_test.go (98%) rename internal/{ => mode/static}/state/resolver/resolver.go (98%) rename internal/{ => mode/static}/state/resolver/resolver_test.go (99%) rename internal/{ => mode/static}/state/resolver/resolverfakes/fake_service_resolver.go (97%) rename internal/{ => mode/static}/state/resolver/service_resolver_suite_test.go (100%) rename internal/{ => mode/static}/state/resolver/service_resolver_test.go (96%) rename internal/{ => mode/static}/state/state_suite_test.go (100%) rename internal/{ => mode/static}/state/statefakes/fake_change_processor.go (97%) rename internal/{ => mode/static}/state/store.go (99%) rename internal/{ => mode/static}/state/validation/validationfakes/fake_httpfields_validator.go (99%) rename internal/{ => mode/static}/state/validation/validator.go (100%) create mode 100644 internal/mode/static/static_suite_test.go delete mode 100644 internal/status/statuses.go diff --git a/.gitignore b/.gitignore index 596e428485..fdea6e239f 100644 --- a/.gitignore +++ b/.gitignore @@ -31,4 +31,4 @@ dist/ node_modules/ # JS test coverage -internal/nginx/modules/coverage +internal/mode/static/nginx/modules/coverage diff --git a/cmd/gateway/commands.go b/cmd/gateway/commands.go index ff6a2c0557..6f8cb66837 100644 --- a/cmd/gateway/commands.go +++ b/cmd/gateway/commands.go @@ -9,9 +9,9 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "sigs.k8s.io/controller-runtime/pkg/log/zap" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/config" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/manager" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/provisioner" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/config" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/provisioner" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static" ) const ( @@ -149,7 +149,7 @@ func createStaticModeCommand() *cobra.Command { UpdateGatewayClassStatus: updateGCStatus, } - if err := manager.Start(conf); err != nil { + if err := static.StartManager(conf); err != nil { return fmt.Errorf("failed to start control loop: %w", err) } diff --git a/conformance/Makefile b/conformance/Makefile index c797171d78..e256a9445d 100644 --- a/conformance/Makefile +++ b/conformance/Makefile @@ -45,7 +45,7 @@ prepare-nkg-dependencies: ## Install NKG dependencies on configured kind cluster kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.7.1/standard-install.yaml kubectl wait --for=condition=available --timeout=60s deployment gateway-api-admission-server -n gateway-system kubectl apply -f ../deploy/manifests/namespace.yaml - kubectl create configmap njs-modules --from-file=../internal/nginx/modules/src/httpmatches.js -n nginx-gateway + kubectl create configmap njs-modules --from-file=../internal/mode/static/nginx/modules/src/httpmatches.js -n nginx-gateway kubectl apply -f ../deploy/manifests/nginx-conf.yaml kubectl apply -f ../deploy/manifests/rbac.yaml kubectl apply -f ../deploy/manifests/gatewayclass.yaml diff --git a/docs/installation.md b/docs/installation.md index ed719329b1..5e32f797bc 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -32,7 +32,7 @@ This guide walks you through how to install NGINX Kubernetes Gateway on a generi 1. Create the njs-modules ConfigMap: ``` - kubectl create configmap njs-modules --from-file=internal/nginx/modules/src/httpmatches.js -n nginx-gateway + kubectl create configmap njs-modules --from-file=internal/mode/static/nginx/modules/src/httpmatches.js -n nginx-gateway ``` 1. Create the ConfigMap with the main NGINX configuration file: diff --git a/internal/state/conditions/conditions.go b/internal/framework/conditions/conditions.go similarity index 100% rename from internal/state/conditions/conditions.go rename to internal/framework/conditions/conditions.go diff --git a/internal/state/conditions/conditions_test.go b/internal/framework/conditions/conditions_test.go similarity index 100% rename from internal/state/conditions/conditions_test.go rename to internal/framework/conditions/conditions_test.go diff --git a/internal/config/config.go b/internal/framework/config/config.go similarity index 100% rename from internal/config/config.go rename to internal/framework/config/config.go diff --git a/internal/controller/controller_suite_test.go b/internal/framework/controller/controller_suite_test.go similarity index 84% rename from internal/controller/controller_suite_test.go rename to internal/framework/controller/controller_suite_test.go index f5b8541edd..2a0ef5ee0e 100644 --- a/internal/controller/controller_suite_test.go +++ b/internal/framework/controller/controller_suite_test.go @@ -9,5 +9,5 @@ import ( func TestControllers(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "Reconciler Suite") + RunSpecs(t, "Controller Suite") } diff --git a/internal/controller/controllerfakes/fake_field_indexer.go b/internal/framework/controller/controllerfakes/fake_field_indexer.go similarity index 100% rename from internal/controller/controllerfakes/fake_field_indexer.go rename to internal/framework/controller/controllerfakes/fake_field_indexer.go diff --git a/internal/controller/controllerfakes/fake_getter.go b/internal/framework/controller/controllerfakes/fake_getter.go similarity index 97% rename from internal/controller/controllerfakes/fake_getter.go rename to internal/framework/controller/controllerfakes/fake_getter.go index 0a7862a666..466622e1e1 100644 --- a/internal/controller/controllerfakes/fake_getter.go +++ b/internal/framework/controller/controllerfakes/fake_getter.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/controller" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" ) diff --git a/internal/controller/controllerfakes/fake_manager.go b/internal/framework/controller/controllerfakes/fake_manager.go similarity index 100% rename from internal/controller/controllerfakes/fake_manager.go rename to internal/framework/controller/controllerfakes/fake_manager.go diff --git a/internal/controller/doc.go b/internal/framework/controller/doc.go similarity index 100% rename from internal/controller/doc.go rename to internal/framework/controller/doc.go diff --git a/internal/controller/fakes.go b/internal/framework/controller/fakes.go similarity index 100% rename from internal/controller/fakes.go rename to internal/framework/controller/fakes.go diff --git a/internal/controller/getter.go b/internal/framework/controller/getter.go similarity index 100% rename from internal/controller/getter.go rename to internal/framework/controller/getter.go diff --git a/internal/controller/reconciler.go b/internal/framework/controller/reconciler.go similarity index 97% rename from internal/controller/reconciler.go rename to internal/framework/controller/reconciler.go index b2a87997ea..5766721c71 100644 --- a/internal/controller/reconciler.go +++ b/internal/framework/controller/reconciler.go @@ -11,7 +11,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" ) // NamespacedNameFilterFunc is a function that returns true if the resource should be processed by the reconciler. diff --git a/internal/controller/reconciler_test.go b/internal/framework/controller/reconciler_test.go similarity index 96% rename from internal/controller/reconciler_test.go rename to internal/framework/controller/reconciler_test.go index 206a99ff52..103abd7a7a 100644 --- a/internal/controller/reconciler_test.go +++ b/internal/framework/controller/reconciler_test.go @@ -14,9 +14,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/controller" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/controller/controllerfakes" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/controllerfakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" ) type getFunc func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error diff --git a/internal/controller/register.go b/internal/framework/controller/register.go similarity index 97% rename from internal/controller/register.go rename to internal/framework/controller/register.go index ac7f04803f..f51d5a515f 100644 --- a/internal/controller/register.go +++ b/internal/framework/controller/register.go @@ -10,7 +10,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/predicate" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/index" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" ) const ( diff --git a/internal/controller/register_test.go b/internal/framework/controller/register_test.go similarity index 92% rename from internal/controller/register_test.go rename to internal/framework/controller/register_test.go index 0a60fef046..e2993a9379 100644 --- a/internal/controller/register_test.go +++ b/internal/framework/controller/register_test.go @@ -16,10 +16,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/controller" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/controller/controllerfakes" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/index" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/predicate" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/controllerfakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/predicate" ) func TestRegister(t *testing.T) { diff --git a/internal/framework/doc.go b/internal/framework/doc.go new file mode 100644 index 0000000000..221cf07449 --- /dev/null +++ b/internal/framework/doc.go @@ -0,0 +1,4 @@ +/* +Package framework contains all the packages that are shared by the provisioner and static modes of the project. +*/ +package framework diff --git a/internal/events/event.go b/internal/framework/events/event.go similarity index 100% rename from internal/events/event.go rename to internal/framework/events/event.go diff --git a/internal/events/events_suit_test.go b/internal/framework/events/events_suite_test.go similarity index 100% rename from internal/events/events_suit_test.go rename to internal/framework/events/events_suite_test.go diff --git a/internal/events/events_test.go b/internal/framework/events/events_test.go similarity index 100% rename from internal/events/events_test.go rename to internal/framework/events/events_test.go diff --git a/internal/events/eventsfakes/fake_event_handler.go b/internal/framework/events/eventsfakes/fake_event_handler.go similarity index 97% rename from internal/events/eventsfakes/fake_event_handler.go rename to internal/framework/events/eventsfakes/fake_event_handler.go index 06a20b3a12..bfb6ab896b 100644 --- a/internal/events/eventsfakes/fake_event_handler.go +++ b/internal/framework/events/eventsfakes/fake_event_handler.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" ) type FakeEventHandler struct { diff --git a/internal/events/eventsfakes/fake_first_event_batch_preparer.go b/internal/framework/events/eventsfakes/fake_first_event_batch_preparer.go similarity index 97% rename from internal/events/eventsfakes/fake_first_event_batch_preparer.go rename to internal/framework/events/eventsfakes/fake_first_event_batch_preparer.go index e35585ddac..874543c64b 100644 --- a/internal/events/eventsfakes/fake_first_event_batch_preparer.go +++ b/internal/framework/events/eventsfakes/fake_first_event_batch_preparer.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" ) type FakeFirstEventBatchPreparer struct { diff --git a/internal/events/eventsfakes/fake_reader.go b/internal/framework/events/eventsfakes/fake_reader.go similarity index 98% rename from internal/events/eventsfakes/fake_reader.go rename to internal/framework/events/eventsfakes/fake_reader.go index f0ff663f0a..1674faf3cc 100644 --- a/internal/events/eventsfakes/fake_reader.go +++ b/internal/framework/events/eventsfakes/fake_reader.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" ) diff --git a/internal/events/first_eventbatch_preparer.go b/internal/framework/events/first_eventbatch_preparer.go similarity index 100% rename from internal/events/first_eventbatch_preparer.go rename to internal/framework/events/first_eventbatch_preparer.go diff --git a/internal/events/first_eventbatch_preparer_test.go b/internal/framework/events/first_eventbatch_preparer_test.go similarity index 96% rename from internal/events/first_eventbatch_preparer_test.go rename to internal/framework/events/first_eventbatch_preparer_test.go index 02b5aa6d37..69972d8105 100644 --- a/internal/events/first_eventbatch_preparer_test.go +++ b/internal/framework/events/first_eventbatch_preparer_test.go @@ -16,8 +16,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events/eventsfakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events/eventsfakes" ) var _ = Describe("FirstEventBatchPreparer", func() { diff --git a/internal/framework/events/handler.go b/internal/framework/events/handler.go new file mode 100644 index 0000000000..8c2cff4133 --- /dev/null +++ b/internal/framework/events/handler.go @@ -0,0 +1,14 @@ +package events + +import ( + "context" +) + +//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . EventHandler + +// EventHandler handles events. +type EventHandler interface { + // HandleEventBatch handles a batch of events. + // EventBatch can include duplicated events. + HandleEventBatch(ctx context.Context, batch EventBatch) +} diff --git a/internal/events/loop.go b/internal/framework/events/loop.go similarity index 100% rename from internal/events/loop.go rename to internal/framework/events/loop.go diff --git a/internal/events/loop_test.go b/internal/framework/events/loop_test.go similarity index 96% rename from internal/events/loop_test.go rename to internal/framework/events/loop_test.go index b6ae87fb9c..5fbdf7277d 100644 --- a/internal/events/loop_test.go +++ b/internal/framework/events/loop_test.go @@ -8,8 +8,8 @@ import ( . "github.com/onsi/gomega" "sigs.k8s.io/controller-runtime/pkg/log/zap" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events/eventsfakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events/eventsfakes" ) var _ = Describe("EventLoop", func() { diff --git a/internal/helpers/helpers.go b/internal/framework/helpers/helpers.go similarity index 100% rename from internal/helpers/helpers.go rename to internal/framework/helpers/helpers.go diff --git a/internal/manager/filter/filter.go b/internal/framework/manager/filter/filter.go similarity index 89% rename from internal/manager/filter/filter.go rename to internal/framework/manager/filter/filter.go index 12002ca17a..86901fd809 100644 --- a/internal/manager/filter/filter.go +++ b/internal/framework/manager/filter/filter.go @@ -5,7 +5,7 @@ import ( "k8s.io/apimachinery/pkg/types" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/controller" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller" ) // CreateSingleResourceFilter creates a filter function that filters out all resources except the one diff --git a/internal/manager/filter/filter_test.go b/internal/framework/manager/filter/filter_test.go similarity index 100% rename from internal/manager/filter/filter_test.go rename to internal/framework/manager/filter/filter_test.go diff --git a/internal/manager/index/endpointslice.go b/internal/framework/manager/index/endpointslice.go similarity index 100% rename from internal/manager/index/endpointslice.go rename to internal/framework/manager/index/endpointslice.go diff --git a/internal/manager/index/endpointslice_test.go b/internal/framework/manager/index/endpointslice_test.go similarity index 100% rename from internal/manager/index/endpointslice_test.go rename to internal/framework/manager/index/endpointslice_test.go diff --git a/internal/manager/index/index.go b/internal/framework/manager/index/index.go similarity index 100% rename from internal/manager/index/index.go rename to internal/framework/manager/index/index.go diff --git a/internal/manager/predicate/gatewayclass.go b/internal/framework/manager/predicate/gatewayclass.go similarity index 100% rename from internal/manager/predicate/gatewayclass.go rename to internal/framework/manager/predicate/gatewayclass.go diff --git a/internal/manager/predicate/gatewayclass_test.go b/internal/framework/manager/predicate/gatewayclass_test.go similarity index 100% rename from internal/manager/predicate/gatewayclass_test.go rename to internal/framework/manager/predicate/gatewayclass_test.go diff --git a/internal/manager/predicate/service.go b/internal/framework/manager/predicate/service.go similarity index 100% rename from internal/manager/predicate/service.go rename to internal/framework/manager/predicate/service.go diff --git a/internal/manager/predicate/service_test.go b/internal/framework/manager/predicate/service_test.go similarity index 100% rename from internal/manager/predicate/service_test.go rename to internal/framework/manager/predicate/service_test.go diff --git a/internal/status/clock.go b/internal/framework/status/clock.go similarity index 90% rename from internal/status/clock.go rename to internal/framework/status/clock.go index 718ba0fddd..67d22daa83 100644 --- a/internal/status/clock.go +++ b/internal/framework/status/clock.go @@ -11,7 +11,7 @@ type Clock interface { Now() metav1.Time } -// Real clock returns the current local time. +// RealClock returns the current local time. type RealClock struct{} // NewRealClock creates a new RealClock. diff --git a/internal/status/conditions.go b/internal/framework/status/conditions.go similarity index 88% rename from internal/status/conditions.go rename to internal/framework/status/conditions.go index c9ce4c21b1..ba958bc63c 100644 --- a/internal/status/conditions.go +++ b/internal/framework/status/conditions.go @@ -3,7 +3,7 @@ package status import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" ) func convertConditions( diff --git a/internal/status/conditions_test.go b/internal/framework/status/conditions_test.go similarity index 90% rename from internal/status/conditions_test.go rename to internal/framework/status/conditions_test.go index 8b52896ffa..de4fd02c22 100644 --- a/internal/status/conditions_test.go +++ b/internal/framework/status/conditions_test.go @@ -7,8 +7,8 @@ import ( . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" ) func CreateTestConditions(condType string) []conditions.Condition { diff --git a/internal/status/gateway.go b/internal/framework/status/gateway.go similarity index 100% rename from internal/status/gateway.go rename to internal/framework/status/gateway.go diff --git a/internal/status/gateway_test.go b/internal/framework/status/gateway_test.go similarity index 94% rename from internal/status/gateway_test.go rename to internal/framework/status/gateway_test.go index a3e6d5a1ff..30f3cbd5df 100644 --- a/internal/status/gateway_test.go +++ b/internal/framework/status/gateway_test.go @@ -8,7 +8,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" ) func TestPrepareGatewayStatus(t *testing.T) { diff --git a/internal/status/gatewayclass.go b/internal/framework/status/gatewayclass.go similarity index 100% rename from internal/status/gatewayclass.go rename to internal/framework/status/gatewayclass.go diff --git a/internal/status/gatewayclass_test.go b/internal/framework/status/gatewayclass_test.go similarity index 89% rename from internal/status/gatewayclass_test.go rename to internal/framework/status/gatewayclass_test.go index c49ce2d747..530d0566d5 100644 --- a/internal/status/gatewayclass_test.go +++ b/internal/framework/status/gatewayclass_test.go @@ -8,7 +8,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" ) func TestPrepareGatewayClassStatus(t *testing.T) { diff --git a/internal/status/httproute.go b/internal/framework/status/httproute.go similarity index 100% rename from internal/status/httproute.go rename to internal/framework/status/httproute.go diff --git a/internal/status/httproute_test.go b/internal/framework/status/httproute_test.go similarity index 96% rename from internal/status/httproute_test.go rename to internal/framework/status/httproute_test.go index e3bcf8b5d2..92a276d946 100644 --- a/internal/status/httproute_test.go +++ b/internal/framework/status/httproute_test.go @@ -9,7 +9,7 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" ) func TestPrepareHTTPRouteStatus(t *testing.T) { diff --git a/internal/status/status_suit_test.go b/internal/framework/status/status_suite_test.go similarity index 100% rename from internal/status/status_suit_test.go rename to internal/framework/status/status_suite_test.go diff --git a/internal/framework/status/statuses.go b/internal/framework/status/statuses.go new file mode 100644 index 0000000000..9def44228f --- /dev/null +++ b/internal/framework/status/statuses.go @@ -0,0 +1,71 @@ +package status + +import ( + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/gateway-api/apis/v1beta1" + + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" +) + +// ListenerStatuses holds the statuses of listeners where the key is the name of a listener in the Gateway resource. +type ListenerStatuses map[string]ListenerStatus + +// HTTPRouteStatuses holds the statuses of HTTPRoutes where the key is the namespaced name of an HTTPRoute. +type HTTPRouteStatuses map[types.NamespacedName]HTTPRouteStatus + +// GatewayStatuses holds the statuses of Gateways where the key is the namespaced name of a Gateway. +type GatewayStatuses map[types.NamespacedName]GatewayStatus + +// GatewayClassStatuses holds the statuses of GatewayClasses where the key is the namespaced name of a GatewayClass. +type GatewayClassStatuses map[types.NamespacedName]GatewayClassStatus + +// Statuses holds the status-related information about Gateway API resources. +type Statuses struct { + GatewayClassStatuses GatewayClassStatuses + GatewayStatuses GatewayStatuses + HTTPRouteStatuses HTTPRouteStatuses +} + +// GatewayStatus holds the status of the winning Gateway resource. +type GatewayStatus struct { + // ListenerStatuses holds the statuses of listeners defined on the Gateway. + ListenerStatuses ListenerStatuses + // Conditions is the list of conditions for this Gateway. + Conditions []conditions.Condition + // ObservedGeneration is the generation of the resource that was processed. + ObservedGeneration int64 +} + +// ListenerStatus holds the status-related information about a listener in the Gateway resource. +type ListenerStatus struct { + // Conditions is the list of conditions for this listener. + Conditions []conditions.Condition + // SupportedKinds is the list of SupportedKinds for this listener. + SupportedKinds []v1beta1.RouteGroupKind + // AttachedRoutes is the number of routes attached to the listener. + AttachedRoutes int32 +} + +// HTTPRouteStatus holds the status-related information about an HTTPRoute resource. +type HTTPRouteStatus struct { + // ParentStatuses holds the statuses for parentRefs of the HTTPRoute. + ParentStatuses []ParentStatus + // ObservedGeneration is the generation of the resource that was processed. + ObservedGeneration int64 +} + +// ParentStatus holds status-related information related to how the HTTPRoute binds to a specific parentRef. +type ParentStatus struct { + // GatewayNsName is the Namespaced name of the Gateway, which the parentRef references. + GatewayNsName types.NamespacedName + // SectionName is the SectionName of the parentRef. + SectionName *v1beta1.SectionName + // Conditions is the list of conditions that are relevant to the parentRef. + Conditions []conditions.Condition +} + +// GatewayClassStatus holds status-related information about the GatewayClass resource. +type GatewayClassStatus struct { + Conditions []conditions.Condition + ObservedGeneration int64 +} diff --git a/internal/status/statusfakes/fake_clock.go b/internal/framework/status/statusfakes/fake_clock.go similarity index 96% rename from internal/status/statusfakes/fake_clock.go rename to internal/framework/status/statusfakes/fake_clock.go index f02f382c08..a1a33166c2 100644 --- a/internal/status/statusfakes/fake_clock.go +++ b/internal/framework/status/statusfakes/fake_clock.go @@ -4,7 +4,7 @@ package statusfakes import ( "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/status" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/internal/status/statusfakes/fake_updater.go b/internal/framework/status/statusfakes/fake_updater.go similarity index 96% rename from internal/status/statusfakes/fake_updater.go rename to internal/framework/status/statusfakes/fake_updater.go index 206db177db..53c2002b02 100644 --- a/internal/status/statusfakes/fake_updater.go +++ b/internal/framework/status/statusfakes/fake_updater.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/status" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" ) type FakeUpdater struct { diff --git a/internal/status/updater.go b/internal/framework/status/updater.go similarity index 100% rename from internal/status/updater.go rename to internal/framework/status/updater.go diff --git a/internal/status/updater_test.go b/internal/framework/status/updater_test.go similarity index 97% rename from internal/status/updater_test.go rename to internal/framework/status/updater_test.go index 4732ff85a9..b242163494 100644 --- a/internal/status/updater_test.go +++ b/internal/framework/status/updater_test.go @@ -14,10 +14,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/status" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/status/statusfakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status/statusfakes" ) var _ = Describe("Updater", func() { diff --git a/internal/provisioner/deployment.go b/internal/mode/provisioner/deployment.go similarity index 100% rename from internal/provisioner/deployment.go rename to internal/mode/provisioner/deployment.go diff --git a/internal/mode/provisioner/doc.go b/internal/mode/provisioner/doc.go new file mode 100644 index 0000000000..689924d87c --- /dev/null +++ b/internal/mode/provisioner/doc.go @@ -0,0 +1,6 @@ +/* +Package provisioner contains all the packages that relate to the provisioner-mode implementation of NKG. +Provisioner-mode implements data plane provisioning for NGINX Kubernetes Gateway (NKG): it creates an NKG static mode +Deployment for each Gateway that belongs to the provisioner GatewayClass. +*/ +package provisioner diff --git a/internal/provisioner/handler.go b/internal/mode/provisioner/handler.go similarity index 94% rename from internal/provisioner/handler.go rename to internal/mode/provisioner/handler.go index 16f7c8a8d7..3e760608eb 100644 --- a/internal/provisioner/handler.go +++ b/internal/mode/provisioner/handler.go @@ -9,9 +9,9 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/status" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" ) // eventHandler ensures each Gateway for the specific GatewayClass has a corresponding Deployment diff --git a/internal/provisioner/handler_test.go b/internal/mode/provisioner/handler_test.go similarity index 96% rename from internal/provisioner/handler_test.go rename to internal/mode/provisioner/handler_test.go index ad47f38735..bf6549f636 100644 --- a/internal/provisioner/handler_test.go +++ b/internal/mode/provisioner/handler_test.go @@ -17,11 +17,11 @@ import ( . "github.com/onsi/gomega" embeddedfiles "github.com/nginxinc/nginx-kubernetes-gateway" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/status" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/status/statusfakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status/statusfakes" ) var _ = Describe("handler", func() { diff --git a/internal/provisioner/manager.go b/internal/mode/provisioner/manager.go similarity index 91% rename from internal/provisioner/manager.go rename to internal/mode/provisioner/manager.go index 0337c7b495..96ad19329b 100644 --- a/internal/provisioner/manager.go +++ b/internal/mode/provisioner/manager.go @@ -14,10 +14,10 @@ import ( gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" embeddedfiles "github.com/nginxinc/nginx-kubernetes-gateway" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/controller" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/predicate" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/status" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/predicate" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" ) // Config is configuration for the provisioner mode. diff --git a/internal/provisioner/provisioner_suite_test.go b/internal/mode/provisioner/provisioner_suite_test.go similarity index 100% rename from internal/provisioner/provisioner_suite_test.go rename to internal/mode/provisioner/provisioner_suite_test.go diff --git a/internal/provisioner/store.go b/internal/mode/provisioner/store.go similarity index 94% rename from internal/provisioner/store.go rename to internal/mode/provisioner/store.go index f13e57b168..c1a861165f 100644 --- a/internal/provisioner/store.go +++ b/internal/mode/provisioner/store.go @@ -7,7 +7,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" ) // store stores the cluster state needed by the provisioner and allows to update it from the events. diff --git a/internal/mode/static/build_statuses.go b/internal/mode/static/build_statuses.go new file mode 100644 index 0000000000..10bc5e1373 --- /dev/null +++ b/internal/mode/static/build_statuses.go @@ -0,0 +1,176 @@ +package static + +import ( + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/gateway-api/apis/v1beta1" + + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/graph" +) + +type nginxReloadResult struct { + error error +} + +// buildStatuses builds status.Statuses from a Graph. +func buildStatuses(graph *graph.Graph, nginxReloadRes nginxReloadResult) status.Statuses { + statuses := status.Statuses{ + HTTPRouteStatuses: make(status.HTTPRouteStatuses), + } + + statuses.GatewayClassStatuses = buildGatewayClassStatuses(graph.GatewayClass, graph.IgnoredGatewayClasses) + + statuses.GatewayStatuses = buildGatewayStatuses(graph.Gateway, graph.IgnoredGateways, nginxReloadRes) + + for nsname, r := range graph.Routes { + parentStatuses := make([]status.ParentStatus, 0, len(r.ParentRefs)) + + defaultConds := conditions.NewDefaultRouteConditions() + + for _, ref := range r.ParentRefs { + failedAttachmentCondCount := 0 + if ref.Attachment != nil && !ref.Attachment.Attached { + failedAttachmentCondCount = 1 + } + allConds := make([]conditions.Condition, 0, len(r.Conditions)+len(defaultConds)+failedAttachmentCondCount) + + // We add defaultConds first, so that any additional conditions will override them, which is + // ensured by DeduplicateConditions. + allConds = append(allConds, defaultConds...) + allConds = append(allConds, r.Conditions...) + if failedAttachmentCondCount == 1 { + allConds = append(allConds, ref.Attachment.FailedCondition) + } + + if nginxReloadRes.error != nil { + allConds = append( + allConds, + conditions.NewRouteGatewayNotProgrammed(conditions.RouteMessageFailedNginxReload), + ) + } + + routeRef := r.Source.Spec.ParentRefs[ref.Idx] + + parentStatuses = append(parentStatuses, status.ParentStatus{ + GatewayNsName: ref.Gateway, + SectionName: routeRef.SectionName, + Conditions: conditions.DeduplicateConditions(allConds), + }) + } + + statuses.HTTPRouteStatuses[nsname] = status.HTTPRouteStatus{ + ObservedGeneration: r.Source.Generation, + ParentStatuses: parentStatuses, + } + } + + return statuses +} + +func buildGatewayClassStatuses( + gc *graph.GatewayClass, + ignoredGwClasses map[types.NamespacedName]*v1beta1.GatewayClass, +) status.GatewayClassStatuses { + statuses := make(status.GatewayClassStatuses) + + if gc != nil { + defaultConds := conditions.NewDefaultGatewayClassConditions() + + conds := make([]conditions.Condition, 0, len(gc.Conditions)+len(defaultConds)) + + // We add default conds first, so that any additional conditions will override them, which is + // ensured by DeduplicateConditions. + conds = append(conds, defaultConds...) + conds = append(conds, gc.Conditions...) + + statuses[client.ObjectKeyFromObject(gc.Source)] = status.GatewayClassStatus{ + Conditions: conditions.DeduplicateConditions(conds), + ObservedGeneration: gc.Source.Generation, + } + } + + for nsname, gwClass := range ignoredGwClasses { + statuses[nsname] = status.GatewayClassStatus{ + Conditions: []conditions.Condition{conditions.NewGatewayClassConflict()}, + ObservedGeneration: gwClass.Generation, + } + } + + return statuses +} + +func buildGatewayStatuses( + gateway *graph.Gateway, + ignoredGateways map[types.NamespacedName]*v1beta1.Gateway, + nginxReloadRes nginxReloadResult, +) status.GatewayStatuses { + statuses := make(status.GatewayStatuses) + + if gateway != nil { + statuses[client.ObjectKeyFromObject(gateway.Source)] = buildGatewayStatus(gateway, nginxReloadRes) + } + + for nsname, gw := range ignoredGateways { + statuses[nsname] = status.GatewayStatus{ + Conditions: conditions.NewGatewayConflict(), + ObservedGeneration: gw.Generation, + } + } + + return statuses +} + +func buildGatewayStatus(gateway *graph.Gateway, nginxReloadRes nginxReloadResult) status.GatewayStatus { + if !gateway.Valid { + return status.GatewayStatus{ + Conditions: conditions.DeduplicateConditions(gateway.Conditions), + ObservedGeneration: gateway.Source.Generation, + } + } + + listenerStatuses := make(map[string]status.ListenerStatus) + + validListenerCount := 0 + for name, l := range gateway.Listeners { + var conds []conditions.Condition + + if l.Valid { + conds = conditions.NewDefaultListenerConditions() + validListenerCount++ + } else { + conds = l.Conditions + } + + if nginxReloadRes.error != nil { + conds = append( + conds, + conditions.NewListenerNotProgrammedInvalid(conditions.ListenerMessageFailedNginxReload), + ) + } + + listenerStatuses[name] = status.ListenerStatus{ + AttachedRoutes: int32(len(l.Routes)), + Conditions: conditions.DeduplicateConditions(conds), + SupportedKinds: l.SupportedKinds, + } + } + + gwConds := conditions.NewDefaultGatewayConditions() + if validListenerCount == 0 { + gwConds = append(gwConds, conditions.NewGatewayNotAcceptedListenersNotValid()...) + } else if validListenerCount < len(gateway.Listeners) { + gwConds = append(gwConds, conditions.NewGatewayAcceptedListenersNotValid()) + } + + if nginxReloadRes.error != nil { + gwConds = append(gwConds, conditions.NewGatewayNotProgrammedInvalid(conditions.GatewayMessageFailedNginxReload)) + } + + return status.GatewayStatus{ + Conditions: conditions.DeduplicateConditions(gwConds), + ListenerStatuses: listenerStatuses, + ObservedGeneration: gateway.Source.Generation, + } +} diff --git a/internal/status/statuses_test.go b/internal/mode/static/build_statuses_test.go similarity index 87% rename from internal/status/statuses_test.go rename to internal/mode/static/build_statuses_test.go index b151658bdf..97b3053fe5 100644 --- a/internal/status/statuses_test.go +++ b/internal/mode/static/build_statuses_test.go @@ -1,4 +1,4 @@ -package status +package static import ( "errors" @@ -10,9 +10,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/graph" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/graph" ) var ( @@ -133,17 +134,17 @@ func TestBuildStatuses(t *testing.T) { Routes: routes, } - expected := Statuses{ - GatewayClassStatuses: GatewayClassStatuses{ + expected := status.Statuses{ + GatewayClassStatuses: status.GatewayClassStatuses{ {Name: ""}: { ObservedGeneration: 1, Conditions: conditions.NewDefaultGatewayClassConditions(), }, }, - GatewayStatuses: GatewayStatuses{ + GatewayStatuses: status.GatewayStatuses{ {Namespace: "test", Name: "gateway"}: { Conditions: conditions.NewDefaultGatewayConditions(), - ListenerStatuses: map[string]ListenerStatus{ + ListenerStatuses: map[string]status.ListenerStatus{ "listener-80-1": { AttachedRoutes: 1, Conditions: conditions.NewDefaultListenerConditions(), @@ -156,10 +157,10 @@ func TestBuildStatuses(t *testing.T) { ObservedGeneration: 1, }, }, - HTTPRouteStatuses: HTTPRouteStatuses{ + HTTPRouteStatuses: status.HTTPRouteStatuses{ {Namespace: "test", Name: "hr-valid"}: { ObservedGeneration: 3, - ParentStatuses: []ParentStatus{ + ParentStatuses: []status.ParentStatus{ { GatewayNsName: client.ObjectKeyFromObject(gw), SectionName: helpers.GetPointer[v1beta1.SectionName]("listener-80-1"), @@ -177,7 +178,7 @@ func TestBuildStatuses(t *testing.T) { }, {Namespace: "test", Name: "hr-invalid"}: { ObservedGeneration: 3, - ParentStatuses: []ParentStatus{ + ParentStatuses: []status.ParentStatus{ { GatewayNsName: client.ObjectKeyFromObject(gw), SectionName: helpers.GetPointer[v1beta1.SectionName]("listener-80-1"), @@ -193,8 +194,8 @@ func TestBuildStatuses(t *testing.T) { g := NewGomegaWithT(t) - var nginxReloadRes NginxReloadResult - result := BuildStatuses(graph, nginxReloadRes) + var nginxReloadRes nginxReloadResult + result := buildStatuses(graph, nginxReloadRes) g.Expect(helpers.Diff(expected, result)).To(BeEmpty()) } @@ -244,15 +245,15 @@ func TestBuildStatusesNginxErr(t *testing.T) { Routes: routes, } - expected := Statuses{ - GatewayClassStatuses: GatewayClassStatuses{}, - GatewayStatuses: GatewayStatuses{ + expected := status.Statuses{ + GatewayClassStatuses: status.GatewayClassStatuses{}, + GatewayStatuses: status.GatewayStatuses{ {Namespace: "test", Name: "gateway"}: { Conditions: []conditions.Condition{ conditions.NewGatewayAccepted(), conditions.NewGatewayNotProgrammedInvalid(conditions.GatewayMessageFailedNginxReload), }, - ListenerStatuses: map[string]ListenerStatus{ + ListenerStatuses: map[string]status.ListenerStatus{ "listener-80-1": { AttachedRoutes: 1, Conditions: []conditions.Condition{ @@ -266,10 +267,10 @@ func TestBuildStatusesNginxErr(t *testing.T) { ObservedGeneration: 2, }, }, - HTTPRouteStatuses: HTTPRouteStatuses{ + HTTPRouteStatuses: status.HTTPRouteStatuses{ {Namespace: "test", Name: "hr-valid"}: { ObservedGeneration: 3, - ParentStatuses: []ParentStatus{ + ParentStatuses: []status.ParentStatus{ { GatewayNsName: client.ObjectKeyFromObject(gw), SectionName: helpers.GetPointer[v1beta1.SectionName]("listener-80-1"), @@ -285,8 +286,8 @@ func TestBuildStatusesNginxErr(t *testing.T) { g := NewGomegaWithT(t) - nginxReloadRes := NginxReloadResult{Error: errors.New("test error")} - result := BuildStatuses(graph, nginxReloadRes) + nginxReloadRes := nginxReloadResult{error: errors.New("test error")} + result := buildStatuses(graph, nginxReloadRes) g.Expect(helpers.Diff(expected, result)).To(BeEmpty()) } @@ -294,12 +295,12 @@ func TestBuildGatewayClassStatuses(t *testing.T) { tests := []struct { gc *graph.GatewayClass ignoredClasses map[types.NamespacedName]*v1beta1.GatewayClass - expected GatewayClassStatuses + expected status.GatewayClassStatuses name string }{ { name: "nil gatewayclass and no ignored gatewayclasses", - expected: GatewayClassStatuses{}, + expected: status.GatewayClassStatuses{}, }, { name: "nil gatewayclass and ignored gatewayclasses", @@ -315,7 +316,7 @@ func TestBuildGatewayClassStatuses(t *testing.T) { }, }, }, - expected: GatewayClassStatuses{ + expected: status.GatewayClassStatuses{ {Name: "ignored-1"}: { Conditions: []conditions.Condition{conditions.NewGatewayClassConflict()}, ObservedGeneration: 1, @@ -336,7 +337,7 @@ func TestBuildGatewayClassStatuses(t *testing.T) { }, }, }, - expected: GatewayClassStatuses{ + expected: status.GatewayClassStatuses{ {Name: "valid-gc"}: { Conditions: conditions.NewDefaultGatewayClassConditions(), ObservedGeneration: 1, @@ -357,15 +358,15 @@ func TestBuildGatewayClassStatuses(t *testing.T) { func TestBuildGatewayStatuses(t *testing.T) { tests := []struct { - nginxReloadRes NginxReloadResult + nginxReloadRes nginxReloadResult gateway *graph.Gateway ignoredGateways map[types.NamespacedName]*v1beta1.Gateway - expected GatewayStatuses + expected status.GatewayStatuses name string }{ { name: "nil gateway and no ignored gateways", - expected: GatewayStatuses{}, + expected: status.GatewayStatuses{}, }, { name: "nil gateway and ignored gateways", @@ -381,7 +382,7 @@ func TestBuildGatewayStatuses(t *testing.T) { }, }, }, - expected: GatewayStatuses{ + expected: status.GatewayStatuses{ {Namespace: "test", Name: "ignored-1"}: { Conditions: conditions.NewGatewayConflict(), ObservedGeneration: 1, @@ -412,10 +413,10 @@ func TestBuildGatewayStatuses(t *testing.T) { }, Valid: true, }, - expected: GatewayStatuses{ + expected: status.GatewayStatuses{ {Namespace: "test", Name: "gateway"}: { Conditions: conditions.NewDefaultGatewayConditions(), - ListenerStatuses: map[string]ListenerStatus{ + ListenerStatuses: map[string]status.ListenerStatus{ "listener-valid-1": { AttachedRoutes: 1, Conditions: conditions.NewDefaultListenerConditions(), @@ -447,13 +448,13 @@ func TestBuildGatewayStatuses(t *testing.T) { }, Valid: true, }, - expected: GatewayStatuses{ + expected: status.GatewayStatuses{ {Namespace: "test", Name: "gateway"}: { Conditions: []conditions.Condition{ conditions.NewGatewayProgrammed(), conditions.NewGatewayAcceptedListenersNotValid(), }, - ListenerStatuses: map[string]ListenerStatus{ + ListenerStatuses: map[string]status.ListenerStatus{ "listener-valid": { AttachedRoutes: 1, Conditions: conditions.NewDefaultListenerConditions(), @@ -482,10 +483,10 @@ func TestBuildGatewayStatuses(t *testing.T) { }, Valid: true, }, - expected: GatewayStatuses{ + expected: status.GatewayStatuses{ {Namespace: "test", Name: "gateway"}: { Conditions: conditions.NewGatewayNotAcceptedListenersNotValid(), - ListenerStatuses: map[string]ListenerStatus{ + ListenerStatuses: map[string]status.ListenerStatus{ "listener-invalid-1": { Conditions: conditions.NewListenerUnsupportedProtocol("unsupported protocol"), }, @@ -504,7 +505,7 @@ func TestBuildGatewayStatuses(t *testing.T) { Valid: false, Conditions: conditions.NewGatewayInvalid("no gateway class"), }, - expected: GatewayStatuses{ + expected: status.GatewayStatuses{ {Namespace: "test", Name: "gateway"}: { Conditions: conditions.NewGatewayInvalid("no gateway class"), ObservedGeneration: 2, @@ -526,13 +527,13 @@ func TestBuildGatewayStatuses(t *testing.T) { }, }, }, - expected: GatewayStatuses{ + expected: status.GatewayStatuses{ {Namespace: "test", Name: "gateway"}: { Conditions: []conditions.Condition{ conditions.NewGatewayAccepted(), conditions.NewGatewayNotProgrammedInvalid(conditions.GatewayMessageFailedNginxReload), }, - ListenerStatuses: map[string]ListenerStatus{ + ListenerStatuses: map[string]status.ListenerStatus{ "listener-valid": { AttachedRoutes: 1, Conditions: []conditions.Condition{ @@ -546,7 +547,7 @@ func TestBuildGatewayStatuses(t *testing.T) { ObservedGeneration: 2, }, }, - nginxReloadRes: NginxReloadResult{Error: errors.New("test error")}, + nginxReloadRes: nginxReloadResult{error: errors.New("test error")}, }, } diff --git a/internal/mode/static/doc.go b/internal/mode/static/doc.go new file mode 100644 index 0000000000..5b4ffcd337 --- /dev/null +++ b/internal/mode/static/doc.go @@ -0,0 +1,5 @@ +/* +Package static contains all the packages that relate to the static-mode implementation of NKG. +Static-mode configures NGINX in the scope of a single Gateway resource +*/ +package static diff --git a/internal/events/handler.go b/internal/mode/static/handler.go similarity index 70% rename from internal/events/handler.go rename to internal/mode/static/handler.go index af07d5c9ed..1376187b0b 100644 --- a/internal/events/handler.go +++ b/internal/mode/static/handler.go @@ -1,4 +1,4 @@ -package events +package static import ( "context" @@ -6,24 +6,16 @@ import ( "github.com/go-logr/logr" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/file" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/runtime" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/dataplane" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/resolver" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/status" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/runtime" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/dataplane" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/resolver" ) -//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . EventHandler - -// EventHandler handle events. -type EventHandler interface { - // HandleEventBatch handles a batch of events. - // EventBatch can include duplicated events. - HandleEventBatch(ctx context.Context, batch EventBatch) -} - // EventHandlerConfig holds configuration parameters for EventHandlerImpl. type EventHandlerConfig struct { // Processor is the state ChangeProcessor. @@ -57,12 +49,12 @@ func NewEventHandlerImpl(cfg EventHandlerConfig) *EventHandlerImpl { } } -func (h *EventHandlerImpl) HandleEventBatch(ctx context.Context, batch EventBatch) { +func (h *EventHandlerImpl) HandleEventBatch(ctx context.Context, batch events.EventBatch) { for _, event := range batch { switch e := event.(type) { - case *UpsertEvent: + case *events.UpsertEvent: h.cfg.Processor.CaptureUpsertChange(e.Resource) - case *DeleteEvent: + case *events.DeleteEvent: h.cfg.Processor.CaptureDeleteChange(e.Type, e.NamespacedName) default: panic(fmt.Errorf("unknown event type %T", e)) @@ -75,16 +67,16 @@ func (h *EventHandlerImpl) HandleEventBatch(ctx context.Context, batch EventBatc return } - var nginxReloadRes status.NginxReloadResult + var nginxReloadRes nginxReloadResult err := h.updateNginx(ctx, dataplane.BuildConfiguration(ctx, graph, h.cfg.ServiceResolver)) if err != nil { h.cfg.Logger.Error(err, "Failed to update NGINX configuration") - nginxReloadRes.Error = err + nginxReloadRes.error = err } else { h.cfg.Logger.Info("NGINX configuration was successfully updated") } - h.cfg.StatusUpdater.Update(ctx, status.BuildStatuses(graph, nginxReloadRes)) + h.cfg.StatusUpdater.Update(ctx, buildStatuses(graph, nginxReloadRes)) } func (h *EventHandlerImpl) updateNginx(ctx context.Context, conf dataplane.Configuration) error { diff --git a/internal/events/handler_test.go b/internal/mode/static/handler_test.go similarity index 80% rename from internal/events/handler_test.go rename to internal/mode/static/handler_test.go index 7c0e309fe2..e868de1a0c 100644 --- a/internal/events/handler_test.go +++ b/internal/mode/static/handler_test.go @@ -1,4 +1,4 @@ -package events_test +package static_test import ( "context" @@ -9,20 +9,21 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config/configfakes" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/file" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/file/filefakes" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/runtime/runtimefakes" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/dataplane" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/graph" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/statefakes" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/status/statusfakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status/statusfakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config/configfakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file/filefakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/runtime/runtimefakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/dataplane" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/graph" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/statefakes" ) var _ = Describe("EventHandler", func() { var ( - handler *events.EventHandlerImpl + handler *static.EventHandlerImpl fakeProcessor *statefakes.FakeChangeProcessor fakeGenerator *configfakes.FakeGenerator fakeNginxFileMgr *filefakes.FakeManager @@ -52,7 +53,7 @@ var _ = Describe("EventHandler", func() { fakeNginxRuntimeMgr = &runtimefakes.FakeManager{} fakeStatusUpdater = &statusfakes.FakeUpdater{} - handler = events.NewEventHandlerImpl(events.EventHandlerConfig{ + handler = static.NewEventHandlerImpl(static.EventHandlerConfig{ Processor: fakeProcessor, Generator: fakeGenerator, Logger: zap.New(), diff --git a/internal/manager/manager.go b/internal/mode/static/manager.go similarity index 83% rename from internal/manager/manager.go rename to internal/mode/static/manager.go index 3454ab26da..c6929580c6 100644 --- a/internal/manager/manager.go +++ b/internal/mode/static/manager.go @@ -1,4 +1,4 @@ -package manager +package static import ( "fmt" @@ -16,21 +16,21 @@ import ( k8spredicate "sigs.k8s.io/controller-runtime/pkg/predicate" gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/config" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/controller" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/events" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/filter" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/index" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/predicate" - ngxcfg "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config" - ngxvalidation "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config/validation" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/file" - ngxruntime "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/runtime" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/relationship" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/resolver" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/validation" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/status" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/config" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/filter" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/predicate" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" + ngxcfg "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config" + ngxvalidation "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config/validation" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file" + ngxruntime "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/runtime" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/relationship" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/resolver" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/validation" ) const ( @@ -46,7 +46,7 @@ func init() { utilruntime.Must(discoveryV1.AddToScheme(scheme)) } -func Start(cfg config.Config) error { +func StartManager(cfg config.Config) error { logger := cfg.Logger options := manager.Options{ @@ -168,7 +168,7 @@ func Start(cfg config.Config) error { UpdateGatewayClassStatus: cfg.UpdateGatewayClassStatus, }) - eventHandler := events.NewEventHandlerImpl(events.EventHandlerConfig{ + eventHandler := NewEventHandlerImpl(EventHandlerConfig{ Processor: processor, ServiceResolver: resolver.NewServiceResolverImpl(mgr.GetClient()), Generator: configGenerator, diff --git a/internal/manager/manager_test.go b/internal/mode/static/manager_test.go similarity index 99% rename from internal/manager/manager_test.go rename to internal/mode/static/manager_test.go index 71554bc5fe..4fbe4c9f5d 100644 --- a/internal/manager/manager_test.go +++ b/internal/mode/static/manager_test.go @@ -1,4 +1,4 @@ -package manager +package static import ( "testing" diff --git a/internal/nginx/config/configfakes/fake_generator.go b/internal/mode/static/nginx/config/configfakes/fake_generator.go similarity index 92% rename from internal/nginx/config/configfakes/fake_generator.go rename to internal/mode/static/nginx/config/configfakes/fake_generator.go index 7628a7978d..4b058a3553 100644 --- a/internal/nginx/config/configfakes/fake_generator.go +++ b/internal/mode/static/nginx/config/configfakes/fake_generator.go @@ -4,9 +4,9 @@ package configfakes import ( "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/file" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/dataplane" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/dataplane" ) type FakeGenerator struct { diff --git a/internal/nginx/config/execute.go b/internal/mode/static/nginx/config/execute.go similarity index 100% rename from internal/nginx/config/execute.go rename to internal/mode/static/nginx/config/execute.go diff --git a/internal/nginx/config/execute_test.go b/internal/mode/static/nginx/config/execute_test.go similarity index 85% rename from internal/nginx/config/execute_test.go rename to internal/mode/static/nginx/config/execute_test.go index 618fa438e0..9b3a4b5f2c 100644 --- a/internal/nginx/config/execute_test.go +++ b/internal/mode/static/nginx/config/execute_test.go @@ -3,7 +3,7 @@ package config import ( "testing" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config/http" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config/http" ) func TestExecute(t *testing.T) { diff --git a/internal/nginx/config/generator.go b/internal/mode/static/nginx/config/generator.go similarity index 95% rename from internal/nginx/config/generator.go rename to internal/mode/static/nginx/config/generator.go index 732c09b72e..1956a03664 100644 --- a/internal/nginx/config/generator.go +++ b/internal/mode/static/nginx/config/generator.go @@ -3,8 +3,8 @@ package config import ( "path/filepath" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/file" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/dataplane" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/dataplane" ) //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . Generator diff --git a/internal/nginx/config/generator_test.go b/internal/mode/static/nginx/config/generator_test.go similarity index 89% rename from internal/nginx/config/generator_test.go rename to internal/mode/static/nginx/config/generator_test.go index cc30a4e779..3d64174dad 100644 --- a/internal/nginx/config/generator_test.go +++ b/internal/mode/static/nginx/config/generator_test.go @@ -6,9 +6,9 @@ import ( . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/types" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/file" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/dataplane" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/dataplane" ) func TestGenerate(t *testing.T) { diff --git a/internal/nginx/config/http/config.go b/internal/mode/static/nginx/config/http/config.go similarity index 100% rename from internal/nginx/config/http/config.go rename to internal/mode/static/nginx/config/http/config.go diff --git a/internal/nginx/config/maps.go b/internal/mode/static/nginx/config/maps.go similarity index 91% rename from internal/nginx/config/maps.go rename to internal/mode/static/nginx/config/maps.go index 4d1aa3a1b1..b5cc695f4f 100644 --- a/internal/nginx/config/maps.go +++ b/internal/mode/static/nginx/config/maps.go @@ -4,8 +4,8 @@ import ( "strings" gotemplate "text/template" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config/http" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/dataplane" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config/http" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/dataplane" ) var mapsTemplate = gotemplate.Must(gotemplate.New("maps").Parse(mapsTemplateText)) diff --git a/internal/nginx/config/maps_template.go b/internal/mode/static/nginx/config/maps_template.go similarity index 100% rename from internal/nginx/config/maps_template.go rename to internal/mode/static/nginx/config/maps_template.go diff --git a/internal/nginx/config/maps_test.go b/internal/mode/static/nginx/config/maps_test.go similarity index 95% rename from internal/nginx/config/maps_test.go rename to internal/mode/static/nginx/config/maps_test.go index 233ff90c60..3e7529655f 100644 --- a/internal/nginx/config/maps_test.go +++ b/internal/mode/static/nginx/config/maps_test.go @@ -6,8 +6,8 @@ import ( . "github.com/onsi/gomega" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config/http" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/dataplane" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config/http" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/dataplane" ) func TestExecuteMaps(t *testing.T) { diff --git a/internal/nginx/config/servers.go b/internal/mode/static/nginx/config/servers.go similarity index 98% rename from internal/nginx/config/servers.go rename to internal/mode/static/nginx/config/servers.go index f2efec53b7..aa604ab1ef 100644 --- a/internal/nginx/config/servers.go +++ b/internal/mode/static/nginx/config/servers.go @@ -8,8 +8,8 @@ import ( "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config/http" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/dataplane" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config/http" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/dataplane" ) var serversTemplate = gotemplate.Must(gotemplate.New("servers").Parse(serversTemplateText)) diff --git a/internal/nginx/config/servers_template.go b/internal/mode/static/nginx/config/servers_template.go similarity index 100% rename from internal/nginx/config/servers_template.go rename to internal/mode/static/nginx/config/servers_template.go diff --git a/internal/nginx/config/servers_test.go b/internal/mode/static/nginx/config/servers_test.go similarity index 99% rename from internal/nginx/config/servers_test.go rename to internal/mode/static/nginx/config/servers_test.go index e0a5d9a818..eb45a9a611 100644 --- a/internal/nginx/config/servers_test.go +++ b/internal/mode/static/nginx/config/servers_test.go @@ -12,9 +12,9 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config/http" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/dataplane" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config/http" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/dataplane" ) func TestExecuteServers(t *testing.T) { diff --git a/internal/nginx/config/split_clients.go b/internal/mode/static/nginx/config/split_clients.go similarity index 95% rename from internal/nginx/config/split_clients.go rename to internal/mode/static/nginx/config/split_clients.go index a77e176f1c..7728c52307 100644 --- a/internal/nginx/config/split_clients.go +++ b/internal/mode/static/nginx/config/split_clients.go @@ -5,8 +5,8 @@ import ( "math" gotemplate "text/template" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config/http" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/dataplane" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config/http" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/dataplane" ) var splitClientsTemplate = gotemplate.Must(gotemplate.New("split_clients").Parse(splitClientsTemplateText)) diff --git a/internal/nginx/config/split_clients_template.go b/internal/mode/static/nginx/config/split_clients_template.go similarity index 100% rename from internal/nginx/config/split_clients_template.go rename to internal/mode/static/nginx/config/split_clients_template.go diff --git a/internal/nginx/config/split_clients_test.go b/internal/mode/static/nginx/config/split_clients_test.go similarity index 98% rename from internal/nginx/config/split_clients_test.go rename to internal/mode/static/nginx/config/split_clients_test.go index ac190448ec..0396c59328 100644 --- a/internal/nginx/config/split_clients_test.go +++ b/internal/mode/static/nginx/config/split_clients_test.go @@ -7,8 +7,8 @@ import ( "github.com/google/go-cmp/cmp" "k8s.io/apimachinery/pkg/types" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config/http" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/dataplane" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config/http" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/dataplane" ) func TestExecuteSplitClients(t *testing.T) { diff --git a/internal/nginx/config/upstreams.go b/internal/mode/static/nginx/config/upstreams.go similarity index 91% rename from internal/nginx/config/upstreams.go rename to internal/mode/static/nginx/config/upstreams.go index 927745ed5a..3410f01c18 100644 --- a/internal/nginx/config/upstreams.go +++ b/internal/mode/static/nginx/config/upstreams.go @@ -4,8 +4,8 @@ import ( "fmt" gotemplate "text/template" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config/http" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/dataplane" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config/http" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/dataplane" ) var upstreamsTemplate = gotemplate.Must(gotemplate.New("upstreams").Parse(upstreamsTemplateText)) diff --git a/internal/nginx/config/upstreams_template.go b/internal/mode/static/nginx/config/upstreams_template.go similarity index 100% rename from internal/nginx/config/upstreams_template.go rename to internal/mode/static/nginx/config/upstreams_template.go diff --git a/internal/nginx/config/upstreams_test.go b/internal/mode/static/nginx/config/upstreams_test.go similarity index 93% rename from internal/nginx/config/upstreams_test.go rename to internal/mode/static/nginx/config/upstreams_test.go index 95cb9bfe65..79cc381f8a 100644 --- a/internal/nginx/config/upstreams_test.go +++ b/internal/mode/static/nginx/config/upstreams_test.go @@ -6,9 +6,9 @@ import ( "github.com/google/go-cmp/cmp" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config/http" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/dataplane" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/resolver" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config/http" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/dataplane" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/resolver" ) func TestExecuteUpstreams(t *testing.T) { diff --git a/internal/nginx/config/validation/common.go b/internal/mode/static/nginx/config/validation/common.go similarity index 100% rename from internal/nginx/config/validation/common.go rename to internal/mode/static/nginx/config/validation/common.go diff --git a/internal/nginx/config/validation/common_test.go b/internal/mode/static/nginx/config/validation/common_test.go similarity index 100% rename from internal/nginx/config/validation/common_test.go rename to internal/mode/static/nginx/config/validation/common_test.go diff --git a/internal/nginx/config/validation/doc.go b/internal/mode/static/nginx/config/validation/doc.go similarity index 100% rename from internal/nginx/config/validation/doc.go rename to internal/mode/static/nginx/config/validation/doc.go diff --git a/internal/nginx/config/validation/framework.go b/internal/mode/static/nginx/config/validation/framework.go similarity index 100% rename from internal/nginx/config/validation/framework.go rename to internal/mode/static/nginx/config/validation/framework.go diff --git a/internal/nginx/config/validation/framework_test.go b/internal/mode/static/nginx/config/validation/framework_test.go similarity index 100% rename from internal/nginx/config/validation/framework_test.go rename to internal/mode/static/nginx/config/validation/framework_test.go diff --git a/internal/nginx/config/validation/http_filters.go b/internal/mode/static/nginx/config/validation/http_filters.go similarity index 100% rename from internal/nginx/config/validation/http_filters.go rename to internal/mode/static/nginx/config/validation/http_filters.go diff --git a/internal/nginx/config/validation/http_filters_test.go b/internal/mode/static/nginx/config/validation/http_filters_test.go similarity index 100% rename from internal/nginx/config/validation/http_filters_test.go rename to internal/mode/static/nginx/config/validation/http_filters_test.go diff --git a/internal/nginx/config/validation/http_njs_match.go b/internal/mode/static/nginx/config/validation/http_njs_match.go similarity index 97% rename from internal/nginx/config/validation/http_njs_match.go rename to internal/mode/static/nginx/config/validation/http_njs_match.go index eb4ec93087..6675f049fa 100644 --- a/internal/nginx/config/validation/http_njs_match.go +++ b/internal/mode/static/nginx/config/validation/http_njs_match.go @@ -8,7 +8,7 @@ import ( k8svalidation "k8s.io/apimachinery/pkg/util/validation" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config" ) // HTTPNJSMatchValidator validates values used for matching a request. diff --git a/internal/nginx/config/validation/http_njs_match_test.go b/internal/mode/static/nginx/config/validation/http_njs_match_test.go similarity index 100% rename from internal/nginx/config/validation/http_njs_match_test.go rename to internal/mode/static/nginx/config/validation/http_njs_match_test.go diff --git a/internal/nginx/config/validation/http_validator.go b/internal/mode/static/nginx/config/validation/http_validator.go similarity index 85% rename from internal/nginx/config/validation/http_validator.go rename to internal/mode/static/nginx/config/validation/http_validator.go index a206bb114d..55af7e3367 100644 --- a/internal/nginx/config/validation/http_validator.go +++ b/internal/mode/static/nginx/config/validation/http_validator.go @@ -1,7 +1,7 @@ package validation import ( - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/validation" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/validation" ) // HTTPValidator validates values that will propagate into the NGINX configuration http context. diff --git a/internal/nginx/config/variable_names.go b/internal/mode/static/nginx/config/variable_names.go similarity index 100% rename from internal/nginx/config/variable_names.go rename to internal/mode/static/nginx/config/variable_names.go diff --git a/internal/nginx/config/variable_names_test.go b/internal/mode/static/nginx/config/variable_names_test.go similarity index 100% rename from internal/nginx/config/variable_names_test.go rename to internal/mode/static/nginx/config/variable_names_test.go diff --git a/internal/nginx/file/file_suite_test.go b/internal/mode/static/nginx/file/file_suite_test.go similarity index 100% rename from internal/nginx/file/file_suite_test.go rename to internal/mode/static/nginx/file/file_suite_test.go diff --git a/internal/nginx/file/filefakes/fake_clear_folders_osfile_manager.go b/internal/mode/static/nginx/file/filefakes/fake_clear_folders_osfile_manager.go similarity index 98% rename from internal/nginx/file/filefakes/fake_clear_folders_osfile_manager.go rename to internal/mode/static/nginx/file/filefakes/fake_clear_folders_osfile_manager.go index 349f88997c..dc4595e44c 100644 --- a/internal/nginx/file/filefakes/fake_clear_folders_osfile_manager.go +++ b/internal/mode/static/nginx/file/filefakes/fake_clear_folders_osfile_manager.go @@ -5,7 +5,7 @@ import ( "io/fs" "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/file" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file" ) type FakeClearFoldersOSFileManager struct { diff --git a/internal/nginx/file/filefakes/fake_dir_entry.go b/internal/mode/static/nginx/file/filefakes/fake_dir_entry.go similarity index 100% rename from internal/nginx/file/filefakes/fake_dir_entry.go rename to internal/mode/static/nginx/file/filefakes/fake_dir_entry.go diff --git a/internal/nginx/file/filefakes/fake_manager.go b/internal/mode/static/nginx/file/filefakes/fake_manager.go similarity index 97% rename from internal/nginx/file/filefakes/fake_manager.go rename to internal/mode/static/nginx/file/filefakes/fake_manager.go index 644e5a3c0f..1e03abfefe 100644 --- a/internal/nginx/file/filefakes/fake_manager.go +++ b/internal/mode/static/nginx/file/filefakes/fake_manager.go @@ -4,7 +4,7 @@ package filefakes import ( "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/file" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file" ) type FakeManager struct { diff --git a/internal/nginx/file/filefakes/fake_osfile_manager.go b/internal/mode/static/nginx/file/filefakes/fake_osfile_manager.go similarity index 99% rename from internal/nginx/file/filefakes/fake_osfile_manager.go rename to internal/mode/static/nginx/file/filefakes/fake_osfile_manager.go index bf03b2080f..edcac47d2b 100644 --- a/internal/nginx/file/filefakes/fake_osfile_manager.go +++ b/internal/mode/static/nginx/file/filefakes/fake_osfile_manager.go @@ -6,7 +6,7 @@ import ( "os" "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/file" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file" ) type FakeOSFileManager struct { diff --git a/internal/nginx/file/folders.go b/internal/mode/static/nginx/file/folders.go similarity index 100% rename from internal/nginx/file/folders.go rename to internal/mode/static/nginx/file/folders.go diff --git a/internal/nginx/file/folders_test.go b/internal/mode/static/nginx/file/folders_test.go similarity index 91% rename from internal/nginx/file/folders_test.go rename to internal/mode/static/nginx/file/folders_test.go index d9ba1a03a8..a04beba584 100644 --- a/internal/nginx/file/folders_test.go +++ b/internal/mode/static/nginx/file/folders_test.go @@ -8,8 +8,8 @@ import ( . "github.com/onsi/gomega" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/file" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/file/filefakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file/filefakes" ) func writeFile(t *testing.T, name string, data []byte) { diff --git a/internal/nginx/file/manager.go b/internal/mode/static/nginx/file/manager.go similarity index 100% rename from internal/nginx/file/manager.go rename to internal/mode/static/nginx/file/manager.go diff --git a/internal/nginx/file/manager_test.go b/internal/mode/static/nginx/file/manager_test.go similarity index 96% rename from internal/nginx/file/manager_test.go rename to internal/mode/static/nginx/file/manager_test.go index 12252ec527..4ef6d1aae9 100644 --- a/internal/nginx/file/manager_test.go +++ b/internal/mode/static/nginx/file/manager_test.go @@ -9,8 +9,8 @@ import ( . "github.com/onsi/gomega" "sigs.k8s.io/controller-runtime/pkg/log/zap" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/file" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/file/filefakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file/filefakes" ) var _ = Describe("EventHandler", func() { diff --git a/internal/nginx/file/os_filemanager.go b/internal/mode/static/nginx/file/os_filemanager.go similarity index 100% rename from internal/nginx/file/os_filemanager.go rename to internal/mode/static/nginx/file/os_filemanager.go diff --git a/internal/nginx/modules/.prettierrc b/internal/mode/static/nginx/modules/.prettierrc similarity index 100% rename from internal/nginx/modules/.prettierrc rename to internal/mode/static/nginx/modules/.prettierrc diff --git a/internal/nginx/modules/README.md b/internal/mode/static/nginx/modules/README.md similarity index 100% rename from internal/nginx/modules/README.md rename to internal/mode/static/nginx/modules/README.md diff --git a/internal/nginx/modules/package-lock.json b/internal/mode/static/nginx/modules/package-lock.json similarity index 100% rename from internal/nginx/modules/package-lock.json rename to internal/mode/static/nginx/modules/package-lock.json diff --git a/internal/nginx/modules/package.json b/internal/mode/static/nginx/modules/package.json similarity index 100% rename from internal/nginx/modules/package.json rename to internal/mode/static/nginx/modules/package.json diff --git a/internal/nginx/modules/src/httpmatches.js b/internal/mode/static/nginx/modules/src/httpmatches.js similarity index 100% rename from internal/nginx/modules/src/httpmatches.js rename to internal/mode/static/nginx/modules/src/httpmatches.js diff --git a/internal/nginx/modules/test/httpmatches.test.js b/internal/mode/static/nginx/modules/test/httpmatches.test.js similarity index 100% rename from internal/nginx/modules/test/httpmatches.test.js rename to internal/mode/static/nginx/modules/test/httpmatches.test.js diff --git a/internal/nginx/runtime/manager.go b/internal/mode/static/nginx/runtime/manager.go similarity index 100% rename from internal/nginx/runtime/manager.go rename to internal/mode/static/nginx/runtime/manager.go diff --git a/internal/nginx/runtime/manager_test.go b/internal/mode/static/nginx/runtime/manager_test.go similarity index 100% rename from internal/nginx/runtime/manager_test.go rename to internal/mode/static/nginx/runtime/manager_test.go diff --git a/internal/nginx/runtime/runtimefakes/fake_manager.go b/internal/mode/static/nginx/runtime/runtimefakes/fake_manager.go similarity index 97% rename from internal/nginx/runtime/runtimefakes/fake_manager.go rename to internal/mode/static/nginx/runtime/runtimefakes/fake_manager.go index 73593d09aa..93b65360a3 100644 --- a/internal/nginx/runtime/runtimefakes/fake_manager.go +++ b/internal/mode/static/nginx/runtime/runtimefakes/fake_manager.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/runtime" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/runtime" ) type FakeManager struct { diff --git a/internal/sort/doc.go b/internal/mode/static/sort/doc.go similarity index 100% rename from internal/sort/doc.go rename to internal/mode/static/sort/doc.go diff --git a/internal/sort/sort.go b/internal/mode/static/sort/sort.go similarity index 100% rename from internal/sort/sort.go rename to internal/mode/static/sort/sort.go diff --git a/internal/sort/sort_test.go b/internal/mode/static/sort/sort_test.go similarity index 100% rename from internal/sort/sort_test.go rename to internal/mode/static/sort/sort_test.go diff --git a/internal/state/change_processor.go b/internal/mode/static/state/change_processor.go similarity index 97% rename from internal/state/change_processor.go rename to internal/mode/static/state/change_processor.go index 6ec5269ec4..075efb8e21 100644 --- a/internal/state/change_processor.go +++ b/internal/mode/static/state/change_processor.go @@ -17,9 +17,9 @@ import ( gwapivalidation "sigs.k8s.io/gateway-api/apis/v1beta1/validation" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/graph" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/relationship" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/validation" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/graph" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/relationship" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/validation" ) const ( diff --git a/internal/state/change_processor_test.go b/internal/mode/static/state/change_processor_test.go similarity index 98% rename from internal/state/change_processor_test.go rename to internal/mode/static/state/change_processor_test.go index 6c26c0763b..54320b99d8 100644 --- a/internal/state/change_processor_test.go +++ b/internal/mode/static/state/change_processor_test.go @@ -16,15 +16,15 @@ import ( "sigs.k8s.io/gateway-api/apis/v1alpha2" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/index" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/graph" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/relationship" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/relationship/relationshipfakes" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/validation" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/validation/validationfakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/graph" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/relationship" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/relationship/relationshipfakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/validation" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/validation/validationfakes" ) const ( diff --git a/internal/state/dataplane/configuration.go b/internal/mode/static/state/dataplane/configuration.go similarity index 99% rename from internal/state/dataplane/configuration.go rename to internal/mode/static/state/dataplane/configuration.go index d3124fb7c6..0205db6415 100644 --- a/internal/state/dataplane/configuration.go +++ b/internal/mode/static/state/dataplane/configuration.go @@ -9,8 +9,8 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/graph" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/resolver" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/graph" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/resolver" ) type PathType string diff --git a/internal/state/dataplane/configuration_test.go b/internal/mode/static/state/dataplane/configuration_test.go similarity index 99% rename from internal/state/dataplane/configuration_test.go rename to internal/mode/static/state/dataplane/configuration_test.go index 553a5776e9..0a4b04951c 100644 --- a/internal/state/dataplane/configuration_test.go +++ b/internal/mode/static/state/dataplane/configuration_test.go @@ -14,10 +14,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/graph" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/resolver" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/resolver/resolverfakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/graph" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/resolver" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/resolver/resolverfakes" ) func TestBuildConfiguration(t *testing.T) { diff --git a/internal/state/dataplane/doc.go b/internal/mode/static/state/dataplane/doc.go similarity index 100% rename from internal/state/dataplane/doc.go rename to internal/mode/static/state/dataplane/doc.go diff --git a/internal/state/dataplane/sort.go b/internal/mode/static/state/dataplane/sort.go similarity index 99% rename from internal/state/dataplane/sort.go rename to internal/mode/static/state/dataplane/sort.go index 9237114c38..7227fb3845 100644 --- a/internal/state/dataplane/sort.go +++ b/internal/mode/static/state/dataplane/sort.go @@ -3,7 +3,7 @@ package dataplane import ( "sort" - nkgsort "github.com/nginxinc/nginx-kubernetes-gateway/internal/sort" + nkgsort "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/sort" ) func sortMatchRules(matchRules []MatchRule) { diff --git a/internal/state/dataplane/sort_test.go b/internal/mode/static/state/dataplane/sort_test.go similarity index 98% rename from internal/state/dataplane/sort_test.go rename to internal/mode/static/state/dataplane/sort_test.go index 42e7fa5cf3..9a2c3d4172 100644 --- a/internal/state/dataplane/sort_test.go +++ b/internal/mode/static/state/dataplane/sort_test.go @@ -8,7 +8,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" ) func TestSort(t *testing.T) { diff --git a/internal/state/graph/backend_refs.go b/internal/mode/static/state/graph/backend_refs.go similarity index 98% rename from internal/state/graph/backend_refs.go rename to internal/mode/static/state/graph/backend_refs.go index b5e7e33990..016a201127 100644 --- a/internal/state/graph/backend_refs.go +++ b/internal/mode/static/state/graph/backend_refs.go @@ -8,7 +8,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" ) // BackendRef is an internal representation of a backendRef in an HTTPRoute. diff --git a/internal/state/graph/backend_refs_test.go b/internal/mode/static/state/graph/backend_refs_test.go similarity index 99% rename from internal/state/graph/backend_refs_test.go rename to internal/mode/static/state/graph/backend_refs_test.go index 81eb66655e..6e06a27551 100644 --- a/internal/state/graph/backend_refs_test.go +++ b/internal/mode/static/state/graph/backend_refs_test.go @@ -11,8 +11,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" ) func getNormalRef() v1beta1.BackendRef { diff --git a/internal/state/graph/doc.go b/internal/mode/static/state/graph/doc.go similarity index 100% rename from internal/state/graph/doc.go rename to internal/mode/static/state/graph/doc.go diff --git a/internal/state/graph/gateway.go b/internal/mode/static/state/graph/gateway.go similarity index 97% rename from internal/state/graph/gateway.go rename to internal/mode/static/state/graph/gateway.go index 50f2fdb0fb..4e19a3b897 100644 --- a/internal/state/graph/gateway.go +++ b/internal/mode/static/state/graph/gateway.go @@ -8,8 +8,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - nkgsort "github.com/nginxinc/nginx-kubernetes-gateway/internal/sort" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + nkgsort "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/sort" ) // Gateway represents the winning Gateway resource. diff --git a/internal/state/graph/gateway_listener.go b/internal/mode/static/state/graph/gateway_listener.go similarity index 99% rename from internal/state/graph/gateway_listener.go rename to internal/mode/static/state/graph/gateway_listener.go index 31119d7abd..ac2207d475 100644 --- a/internal/state/graph/gateway_listener.go +++ b/internal/mode/static/state/graph/gateway_listener.go @@ -10,7 +10,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation/field" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" ) // Listener represents a Listener of the Gateway resource. diff --git a/internal/state/graph/gateway_listener_test.go b/internal/mode/static/state/graph/gateway_listener_test.go similarity index 98% rename from internal/state/graph/gateway_listener_test.go rename to internal/mode/static/state/graph/gateway_listener_test.go index bbc7c66a87..8abb2ed683 100644 --- a/internal/state/graph/gateway_listener_test.go +++ b/internal/mode/static/state/graph/gateway_listener_test.go @@ -8,8 +8,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" ) func TestValidateHTTPListener(t *testing.T) { diff --git a/internal/state/graph/gateway_test.go b/internal/mode/static/state/graph/gateway_test.go similarity index 99% rename from internal/state/graph/gateway_test.go rename to internal/mode/static/state/graph/gateway_test.go index 8738d7d3e3..1114464880 100644 --- a/internal/state/graph/gateway_test.go +++ b/internal/mode/static/state/graph/gateway_test.go @@ -12,8 +12,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" ) func TestProcessedGatewaysGetAllNsNames(t *testing.T) { diff --git a/internal/state/graph/gatewayclass.go b/internal/mode/static/state/graph/gatewayclass.go similarity index 96% rename from internal/state/graph/gatewayclass.go rename to internal/mode/static/state/graph/gatewayclass.go index 8c932939c2..60a6f268d3 100644 --- a/internal/state/graph/gatewayclass.go +++ b/internal/mode/static/state/graph/gatewayclass.go @@ -6,7 +6,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" ) // GatewayClass represents the GatewayClass resource. diff --git a/internal/state/graph/gatewayclass_test.go b/internal/mode/static/state/graph/gatewayclass_test.go similarity index 93% rename from internal/state/graph/gatewayclass_test.go rename to internal/mode/static/state/graph/gatewayclass_test.go index 178f2d04b1..c9c2589982 100644 --- a/internal/state/graph/gatewayclass_test.go +++ b/internal/mode/static/state/graph/gatewayclass_test.go @@ -9,8 +9,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" ) func TestProcessGatewayClasses(t *testing.T) { @@ -150,7 +150,9 @@ func TestBuildGatewayClass(t *testing.T) { Source: invalidGC, Valid: false, Conditions: []conditions.Condition{ - conditions.NewGatewayClassInvalidParameters("spec.parametersRef: Forbidden: parametersRef is not supported"), + conditions.NewGatewayClassInvalidParameters( + "spec.parametersRef: Forbidden: parametersRef is not supported", + ), }, }, name: "invalid gatewayclass", diff --git a/internal/state/graph/graph.go b/internal/mode/static/state/graph/graph.go similarity index 97% rename from internal/state/graph/graph.go rename to internal/mode/static/state/graph/graph.go index b63571802c..8581c35c59 100644 --- a/internal/state/graph/graph.go +++ b/internal/mode/static/state/graph/graph.go @@ -6,7 +6,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/validation" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/validation" ) // ClusterState includes cluster resources necessary to build the Graph. diff --git a/internal/state/graph/graph_test.go b/internal/mode/static/state/graph/graph_test.go similarity index 97% rename from internal/state/graph/graph_test.go rename to internal/mode/static/state/graph/graph_test.go index 3bc5bd5847..c9a57d88fb 100644 --- a/internal/state/graph/graph_test.go +++ b/internal/mode/static/state/graph/graph_test.go @@ -11,9 +11,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/validation" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/validation/validationfakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/validation" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/validation/validationfakes" ) func TestBuildGraph(t *testing.T) { diff --git a/internal/state/graph/httproute.go b/internal/mode/static/state/graph/httproute.go similarity index 99% rename from internal/state/graph/httproute.go rename to internal/mode/static/state/graph/httproute.go index 470863beec..4b31471240 100644 --- a/internal/state/graph/httproute.go +++ b/internal/mode/static/state/graph/httproute.go @@ -12,8 +12,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/validation" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/validation" ) const wildcardHostname = "~^" diff --git a/internal/state/graph/httproute_test.go b/internal/mode/static/state/graph/httproute_test.go similarity index 99% rename from internal/state/graph/httproute_test.go rename to internal/mode/static/state/graph/httproute_test.go index bd83a08760..71ce1ffce5 100644 --- a/internal/state/graph/httproute_test.go +++ b/internal/mode/static/state/graph/httproute_test.go @@ -14,9 +14,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/validation/validationfakes" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/validation/validationfakes" ) const ( diff --git a/internal/state/graph/reference_grant.go b/internal/mode/static/state/graph/reference_grant.go similarity index 100% rename from internal/state/graph/reference_grant.go rename to internal/mode/static/state/graph/reference_grant.go diff --git a/internal/state/graph/reference_grant_test.go b/internal/mode/static/state/graph/reference_grant_test.go similarity index 98% rename from internal/state/graph/reference_grant_test.go rename to internal/mode/static/state/graph/reference_grant_test.go index 3dfe4547e5..7e65ae7b14 100644 --- a/internal/state/graph/reference_grant_test.go +++ b/internal/mode/static/state/graph/reference_grant_test.go @@ -7,7 +7,7 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" ) func TestReferenceGrantResolver(t *testing.T) { diff --git a/internal/state/graph/secret.go b/internal/mode/static/state/graph/secret.go similarity index 100% rename from internal/state/graph/secret.go rename to internal/mode/static/state/graph/secret.go diff --git a/internal/state/graph/secret_test.go b/internal/mode/static/state/graph/secret_test.go similarity index 100% rename from internal/state/graph/secret_test.go rename to internal/mode/static/state/graph/secret_test.go diff --git a/internal/state/graph/validation.go b/internal/mode/static/state/graph/validation.go similarity index 100% rename from internal/state/graph/validation.go rename to internal/mode/static/state/graph/validation.go diff --git a/internal/state/graph/validation_test.go b/internal/mode/static/state/graph/validation_test.go similarity index 100% rename from internal/state/graph/validation_test.go rename to internal/mode/static/state/graph/validation_test.go diff --git a/internal/state/relationship/capturer.go b/internal/mode/static/state/relationship/capturer.go similarity index 97% rename from internal/state/relationship/capturer.go rename to internal/mode/static/state/relationship/capturer.go index 6767e287fc..44bfa7f5a5 100644 --- a/internal/state/relationship/capturer.go +++ b/internal/mode/static/state/relationship/capturer.go @@ -9,8 +9,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/index" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/graph" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/graph" ) //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . Capturer diff --git a/internal/state/relationship/capturer_suite_test.go b/internal/mode/static/state/relationship/capturer_suite_test.go similarity index 100% rename from internal/state/relationship/capturer_suite_test.go rename to internal/mode/static/state/relationship/capturer_suite_test.go diff --git a/internal/state/relationship/capturer_test.go b/internal/mode/static/state/relationship/capturer_test.go similarity index 98% rename from internal/state/relationship/capturer_test.go rename to internal/mode/static/state/relationship/capturer_test.go index eb0b7fce8e..57e495e56f 100644 --- a/internal/state/relationship/capturer_test.go +++ b/internal/mode/static/state/relationship/capturer_test.go @@ -10,9 +10,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/index" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/relationship" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/relationship" ) func createBackendRefs(backendNames ...v1beta1.ObjectName) []v1beta1.HTTPBackendRef { diff --git a/internal/state/relationship/relationshipfakes/fake_capturer.go b/internal/mode/static/state/relationship/relationshipfakes/fake_capturer.go similarity index 98% rename from internal/state/relationship/relationshipfakes/fake_capturer.go rename to internal/mode/static/state/relationship/relationshipfakes/fake_capturer.go index 4307105edf..7f85ab6f8f 100644 --- a/internal/state/relationship/relationshipfakes/fake_capturer.go +++ b/internal/mode/static/state/relationship/relationshipfakes/fake_capturer.go @@ -4,7 +4,7 @@ package relationshipfakes import ( "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/relationship" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/relationship" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" ) diff --git a/internal/state/relationship/relationships_test.go b/internal/mode/static/state/relationship/relationships_test.go similarity index 98% rename from internal/state/relationship/relationships_test.go rename to internal/mode/static/state/relationship/relationships_test.go index 843ea9a449..ce15a03cfd 100644 --- a/internal/state/relationship/relationships_test.go +++ b/internal/mode/static/state/relationship/relationships_test.go @@ -8,7 +8,7 @@ import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" ) func TestGetBackendServiceNamesFromRoute(t *testing.T) { diff --git a/internal/state/resolver/resolver.go b/internal/mode/static/state/resolver/resolver.go similarity index 98% rename from internal/state/resolver/resolver.go rename to internal/mode/static/state/resolver/resolver.go index 7df65b690c..74776f8a67 100644 --- a/internal/state/resolver/resolver.go +++ b/internal/mode/static/state/resolver/resolver.go @@ -10,7 +10,7 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/index" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" ) //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . ServiceResolver diff --git a/internal/state/resolver/resolver_test.go b/internal/mode/static/state/resolver/resolver_test.go similarity index 99% rename from internal/state/resolver/resolver_test.go rename to internal/mode/static/state/resolver/resolver_test.go index d6844a0a5e..bfaa51c7d2 100644 --- a/internal/state/resolver/resolver_test.go +++ b/internal/mode/static/state/resolver/resolver_test.go @@ -10,7 +10,7 @@ import ( discoveryV1 "k8s.io/api/discovery/v1" "k8s.io/apimachinery/pkg/util/intstr" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" ) var ( diff --git a/internal/state/resolver/resolverfakes/fake_service_resolver.go b/internal/mode/static/state/resolver/resolverfakes/fake_service_resolver.go similarity index 97% rename from internal/state/resolver/resolverfakes/fake_service_resolver.go rename to internal/mode/static/state/resolver/resolverfakes/fake_service_resolver.go index f069266fa7..06f223d39b 100644 --- a/internal/state/resolver/resolverfakes/fake_service_resolver.go +++ b/internal/mode/static/state/resolver/resolverfakes/fake_service_resolver.go @@ -5,7 +5,7 @@ import ( "context" "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/resolver" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/resolver" v1 "k8s.io/api/core/v1" ) diff --git a/internal/state/resolver/service_resolver_suite_test.go b/internal/mode/static/state/resolver/service_resolver_suite_test.go similarity index 100% rename from internal/state/resolver/service_resolver_suite_test.go rename to internal/mode/static/state/resolver/service_resolver_suite_test.go diff --git a/internal/state/resolver/service_resolver_test.go b/internal/mode/static/state/resolver/service_resolver_test.go similarity index 96% rename from internal/state/resolver/service_resolver_test.go rename to internal/mode/static/state/resolver/service_resolver_test.go index 5cd8f84e2a..3b367ebb81 100644 --- a/internal/state/resolver/service_resolver_test.go +++ b/internal/mode/static/state/resolver/service_resolver_test.go @@ -13,9 +13,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/index" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/resolver" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/resolver" ) func createSlice( diff --git a/internal/state/state_suite_test.go b/internal/mode/static/state/state_suite_test.go similarity index 100% rename from internal/state/state_suite_test.go rename to internal/mode/static/state/state_suite_test.go diff --git a/internal/state/statefakes/fake_change_processor.go b/internal/mode/static/state/statefakes/fake_change_processor.go similarity index 97% rename from internal/state/statefakes/fake_change_processor.go rename to internal/mode/static/state/statefakes/fake_change_processor.go index 43f7aa3a6e..b24b784043 100644 --- a/internal/state/statefakes/fake_change_processor.go +++ b/internal/mode/static/state/statefakes/fake_change_processor.go @@ -4,8 +4,8 @@ package statefakes import ( "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/graph" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/graph" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" ) diff --git a/internal/state/store.go b/internal/mode/static/state/store.go similarity index 99% rename from internal/state/store.go rename to internal/mode/static/state/store.go index 289e7ce951..40663ce458 100644 --- a/internal/state/store.go +++ b/internal/mode/static/state/store.go @@ -9,7 +9,7 @@ import ( "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/relationship" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/relationship" ) // Updater updates the cluster state. diff --git a/internal/state/validation/validationfakes/fake_httpfields_validator.go b/internal/mode/static/state/validation/validationfakes/fake_httpfields_validator.go similarity index 99% rename from internal/state/validation/validationfakes/fake_httpfields_validator.go rename to internal/mode/static/state/validation/validationfakes/fake_httpfields_validator.go index b26ab548ff..f19519a322 100644 --- a/internal/state/validation/validationfakes/fake_httpfields_validator.go +++ b/internal/mode/static/state/validation/validationfakes/fake_httpfields_validator.go @@ -4,7 +4,7 @@ package validationfakes import ( "sync" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/validation" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/validation" ) type FakeHTTPFieldsValidator struct { diff --git a/internal/state/validation/validator.go b/internal/mode/static/state/validation/validator.go similarity index 100% rename from internal/state/validation/validator.go rename to internal/mode/static/state/validation/validator.go diff --git a/internal/mode/static/static_suite_test.go b/internal/mode/static/static_suite_test.go new file mode 100644 index 0000000000..95fafaeec7 --- /dev/null +++ b/internal/mode/static/static_suite_test.go @@ -0,0 +1,13 @@ +package static_test + +import ( + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +func TestStatic(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Static Suite") +} diff --git a/internal/status/statuses.go b/internal/status/statuses.go deleted file mode 100644 index f7c4a8d46a..0000000000 --- a/internal/status/statuses.go +++ /dev/null @@ -1,229 +0,0 @@ -package status - -import ( - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/gateway-api/apis/v1beta1" - - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/graph" -) - -// ListenerStatuses holds the statuses of listeners where the key is the name of a listener in the Gateway resource. -type ListenerStatuses map[string]ListenerStatus - -// HTTPRouteStatuses holds the statuses of HTTPRoutes where the key is the namespaced name of an HTTPRoute. -type HTTPRouteStatuses map[types.NamespacedName]HTTPRouteStatus - -// GatewayStatuses holds the statuses of Gateways where the key is the namespaced name of a Gateway. -type GatewayStatuses map[types.NamespacedName]GatewayStatus - -// GatewayClassStatuses holds the statuses of GatewayClasses where the key is the namespaced name of a GatewayClass. -type GatewayClassStatuses map[types.NamespacedName]GatewayClassStatus - -// Statuses holds the status-related information about Gateway API resources. -type Statuses struct { - GatewayClassStatuses GatewayClassStatuses - GatewayStatuses GatewayStatuses - HTTPRouteStatuses HTTPRouteStatuses -} - -// GatewayStatus holds the status of the winning Gateway resource. -type GatewayStatus struct { - // ListenerStatuses holds the statuses of listeners defined on the Gateway. - ListenerStatuses ListenerStatuses - // Conditions is the list of conditions for this Gateway. - Conditions []conditions.Condition - // ObservedGeneration is the generation of the resource that was processed. - ObservedGeneration int64 -} - -// ListenerStatus holds the status-related information about a listener in the Gateway resource. -type ListenerStatus struct { - Conditions []conditions.Condition - SupportedKinds []v1beta1.RouteGroupKind - AttachedRoutes int32 -} - -// HTTPRouteStatus holds the status-related information about an HTTPRoute resource. -type HTTPRouteStatus struct { - // ParentStatuses holds the statuses for parentRefs of the HTTPRoute. - ParentStatuses []ParentStatus - // ObservedGeneration is the generation of the resource that was processed. - ObservedGeneration int64 -} - -// ParentStatus holds status-related information related to how the HTTPRoute binds to a specific parentRef. -type ParentStatus struct { - // GatewayNsName is the Namespaced name of the Gateway, which the parentRef references. - GatewayNsName types.NamespacedName - // SectionName is the SectionName of the parentRef. - SectionName *v1beta1.SectionName - // Conditions is the list of conditions that are relevant to the parentRef. - Conditions []conditions.Condition -} - -// GatewayClassStatus holds status-related information about the GatewayClass resource. -type GatewayClassStatus struct { - Conditions []conditions.Condition - ObservedGeneration int64 -} - -type NginxReloadResult struct { - Error error -} - -// BuildStatuses builds statuses from a Graph. -func BuildStatuses(graph *graph.Graph, nginxReloadRes NginxReloadResult) Statuses { - statuses := Statuses{ - HTTPRouteStatuses: make(HTTPRouteStatuses), - } - - statuses.GatewayClassStatuses = buildGatewayClassStatuses(graph.GatewayClass, graph.IgnoredGatewayClasses) - - statuses.GatewayStatuses = buildGatewayStatuses(graph.Gateway, graph.IgnoredGateways, nginxReloadRes) - - for nsname, r := range graph.Routes { - parentStatuses := make([]ParentStatus, 0, len(r.ParentRefs)) - - defaultConds := conditions.NewDefaultRouteConditions() - - for _, ref := range r.ParentRefs { - failedAttachmentCondCount := 0 - if ref.Attachment != nil && !ref.Attachment.Attached { - failedAttachmentCondCount = 1 - } - allConds := make([]conditions.Condition, 0, len(r.Conditions)+len(defaultConds)+failedAttachmentCondCount) - - // We add defaultConds first, so that any additional conditions will override them, which is - // ensured by DeduplicateConditions. - allConds = append(allConds, defaultConds...) - allConds = append(allConds, r.Conditions...) - if failedAttachmentCondCount == 1 { - allConds = append(allConds, ref.Attachment.FailedCondition) - } - - if nginxReloadRes.Error != nil { - allConds = append(allConds, conditions.NewRouteGatewayNotProgrammed(conditions.RouteMessageFailedNginxReload)) - } - - routeRef := r.Source.Spec.ParentRefs[ref.Idx] - - parentStatuses = append(parentStatuses, ParentStatus{ - GatewayNsName: ref.Gateway, - SectionName: routeRef.SectionName, - Conditions: conditions.DeduplicateConditions(allConds), - }) - } - - statuses.HTTPRouteStatuses[nsname] = HTTPRouteStatus{ - ObservedGeneration: r.Source.Generation, - ParentStatuses: parentStatuses, - } - } - - return statuses -} - -func buildGatewayClassStatuses( - gc *graph.GatewayClass, - ignoredGwClasses map[types.NamespacedName]*v1beta1.GatewayClass, -) GatewayClassStatuses { - statuses := make(GatewayClassStatuses) - - if gc != nil { - defaultConds := conditions.NewDefaultGatewayClassConditions() - - conds := make([]conditions.Condition, 0, len(gc.Conditions)+len(defaultConds)) - - // We add default conds first, so that any additional conditions will override them, which is - // ensured by DeduplicateConditions. - conds = append(conds, defaultConds...) - conds = append(conds, gc.Conditions...) - - statuses[client.ObjectKeyFromObject(gc.Source)] = GatewayClassStatus{ - Conditions: conditions.DeduplicateConditions(conds), - ObservedGeneration: gc.Source.Generation, - } - } - - for nsname, gwClass := range ignoredGwClasses { - statuses[nsname] = GatewayClassStatus{ - Conditions: []conditions.Condition{conditions.NewGatewayClassConflict()}, - ObservedGeneration: gwClass.Generation, - } - } - - return statuses -} - -func buildGatewayStatuses( - gateway *graph.Gateway, - ignoredGateways map[types.NamespacedName]*v1beta1.Gateway, - nginxReloadRes NginxReloadResult, -) GatewayStatuses { - statuses := make(GatewayStatuses) - - if gateway != nil { - statuses[client.ObjectKeyFromObject(gateway.Source)] = buildGatewayStatus(gateway, nginxReloadRes) - } - - for nsname, gw := range ignoredGateways { - statuses[nsname] = GatewayStatus{ - Conditions: conditions.NewGatewayConflict(), - ObservedGeneration: gw.Generation, - } - } - - return statuses -} - -func buildGatewayStatus(gateway *graph.Gateway, nginxReloadRes NginxReloadResult) GatewayStatus { - if !gateway.Valid { - return GatewayStatus{ - Conditions: conditions.DeduplicateConditions(gateway.Conditions), - ObservedGeneration: gateway.Source.Generation, - } - } - - listenerStatuses := make(map[string]ListenerStatus) - - validListenerCount := 0 - for name, l := range gateway.Listeners { - var conds []conditions.Condition - - if l.Valid { - conds = conditions.NewDefaultListenerConditions() - validListenerCount++ - } else { - conds = l.Conditions - } - - if nginxReloadRes.Error != nil { - conds = append(conds, conditions.NewListenerNotProgrammedInvalid(conditions.ListenerMessageFailedNginxReload)) - } - - listenerStatuses[name] = ListenerStatus{ - AttachedRoutes: int32(len(l.Routes)), - Conditions: conditions.DeduplicateConditions(conds), - SupportedKinds: l.SupportedKinds, - } - } - - gwConds := conditions.NewDefaultGatewayConditions() - if validListenerCount == 0 { - gwConds = append(gwConds, conditions.NewGatewayNotAcceptedListenersNotValid()...) - } else if validListenerCount < len(gateway.Listeners) { - gwConds = append(gwConds, conditions.NewGatewayAcceptedListenersNotValid()) - } - - if nginxReloadRes.Error != nil { - gwConds = append(gwConds, conditions.NewGatewayNotProgrammedInvalid(conditions.GatewayMessageFailedNginxReload)) - } - - return GatewayStatus{ - Conditions: conditions.DeduplicateConditions(gwConds), - ListenerStatuses: listenerStatuses, - ObservedGeneration: gateway.Source.Generation, - } -} From 2cac322a531872e7f5035ccb4dedbb8697b9a55b Mon Sep 17 00:00:00 2001 From: Kate Osborn Date: Mon, 10 Jul 2023 09:53:26 -0600 Subject: [PATCH 2/7] Fix njs test --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0571eb4711..fe4172d371 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,7 @@ unit-test: ## Run unit tests for the go code njs-unit-test: ## Run unit tests for the njs httpmatches module docker run --rm -w /modules \ - -v $(PWD)/internal/nginx/modules:/modules/ \ + -v $(PWD)/internal/mode/static/nginx/modules:/modules/ \ node:18 \ /bin/bash -c "npm install && npm test && npm run clean" From cd24e40ecc363592b26b33f3302ed2e5a06b622e Mon Sep 17 00:00:00 2001 From: Kate Osborn Date: Mon, 10 Jul 2023 10:00:17 -0600 Subject: [PATCH 3/7] Fix njs test --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48ff2d8050..6f05279a5d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,7 +87,7 @@ jobs: uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0 with: node-version: 18 - - run: npm --prefix ${{ github.workspace }}/internal/nginx/modules install-ci-test + - run: npm --prefix ${{ github.workspace }}/internal/mode/static/nginx/modules install-ci-test release: name: Release From 5f6752a0973d379a6826e3c131c349037857dd80 Mon Sep 17 00:00:00 2001 From: Kate Osborn Date: Mon, 10 Jul 2023 15:16:39 -0600 Subject: [PATCH 4/7] Move config to static; move manager packages to controller --- cmd/gateway/commands.go | 2 +- .../framework/{manager => controller}/filter/filter.go | 0 .../{manager => controller}/filter/filter_test.go | 0 .../{manager => controller}/index/endpointslice.go | 0 .../{manager => controller}/index/endpointslice_test.go | 0 internal/framework/{manager => controller}/index/index.go | 0 .../{manager => controller}/predicate/gatewayclass.go | 0 .../predicate/gatewayclass_test.go | 0 .../{manager => controller}/predicate/service.go | 0 .../{manager => controller}/predicate/service_test.go | 0 internal/framework/controller/register.go | 2 +- internal/framework/controller/register_test.go | 4 ++-- internal/mode/provisioner/manager.go | 2 +- internal/{framework => mode/static}/config/config.go | 0 internal/mode/static/manager.go | 8 ++++---- internal/mode/static/state/change_processor_test.go | 2 +- internal/mode/static/state/relationship/capturer.go | 2 +- internal/mode/static/state/relationship/capturer_test.go | 2 +- internal/mode/static/state/resolver/resolver.go | 2 +- .../mode/static/state/resolver/service_resolver_test.go | 2 +- 20 files changed, 14 insertions(+), 14 deletions(-) rename internal/framework/{manager => controller}/filter/filter.go (100%) rename internal/framework/{manager => controller}/filter/filter_test.go (100%) rename internal/framework/{manager => controller}/index/endpointslice.go (100%) rename internal/framework/{manager => controller}/index/endpointslice_test.go (100%) rename internal/framework/{manager => controller}/index/index.go (100%) rename internal/framework/{manager => controller}/predicate/gatewayclass.go (100%) rename internal/framework/{manager => controller}/predicate/gatewayclass_test.go (100%) rename internal/framework/{manager => controller}/predicate/service.go (100%) rename internal/framework/{manager => controller}/predicate/service_test.go (100%) rename internal/{framework => mode/static}/config/config.go (100%) diff --git a/cmd/gateway/commands.go b/cmd/gateway/commands.go index 6f8cb66837..fa0f9423ce 100644 --- a/cmd/gateway/commands.go +++ b/cmd/gateway/commands.go @@ -9,9 +9,9 @@ import ( utilruntime "k8s.io/apimachinery/pkg/util/runtime" "sigs.k8s.io/controller-runtime/pkg/log/zap" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/config" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/provisioner" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/config" ) const ( diff --git a/internal/framework/manager/filter/filter.go b/internal/framework/controller/filter/filter.go similarity index 100% rename from internal/framework/manager/filter/filter.go rename to internal/framework/controller/filter/filter.go diff --git a/internal/framework/manager/filter/filter_test.go b/internal/framework/controller/filter/filter_test.go similarity index 100% rename from internal/framework/manager/filter/filter_test.go rename to internal/framework/controller/filter/filter_test.go diff --git a/internal/framework/manager/index/endpointslice.go b/internal/framework/controller/index/endpointslice.go similarity index 100% rename from internal/framework/manager/index/endpointslice.go rename to internal/framework/controller/index/endpointslice.go diff --git a/internal/framework/manager/index/endpointslice_test.go b/internal/framework/controller/index/endpointslice_test.go similarity index 100% rename from internal/framework/manager/index/endpointslice_test.go rename to internal/framework/controller/index/endpointslice_test.go diff --git a/internal/framework/manager/index/index.go b/internal/framework/controller/index/index.go similarity index 100% rename from internal/framework/manager/index/index.go rename to internal/framework/controller/index/index.go diff --git a/internal/framework/manager/predicate/gatewayclass.go b/internal/framework/controller/predicate/gatewayclass.go similarity index 100% rename from internal/framework/manager/predicate/gatewayclass.go rename to internal/framework/controller/predicate/gatewayclass.go diff --git a/internal/framework/manager/predicate/gatewayclass_test.go b/internal/framework/controller/predicate/gatewayclass_test.go similarity index 100% rename from internal/framework/manager/predicate/gatewayclass_test.go rename to internal/framework/controller/predicate/gatewayclass_test.go diff --git a/internal/framework/manager/predicate/service.go b/internal/framework/controller/predicate/service.go similarity index 100% rename from internal/framework/manager/predicate/service.go rename to internal/framework/controller/predicate/service.go diff --git a/internal/framework/manager/predicate/service_test.go b/internal/framework/controller/predicate/service_test.go similarity index 100% rename from internal/framework/manager/predicate/service_test.go rename to internal/framework/controller/predicate/service_test.go diff --git a/internal/framework/controller/register.go b/internal/framework/controller/register.go index f51d5a515f..e52e348e44 100644 --- a/internal/framework/controller/register.go +++ b/internal/framework/controller/register.go @@ -10,7 +10,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/predicate" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/index" ) const ( diff --git a/internal/framework/controller/register_test.go b/internal/framework/controller/register_test.go index e2993a9379..942c8dfe33 100644 --- a/internal/framework/controller/register_test.go +++ b/internal/framework/controller/register_test.go @@ -18,8 +18,8 @@ import ( "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/controllerfakes" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/predicate" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/index" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/predicate" ) func TestRegister(t *testing.T) { diff --git a/internal/mode/provisioner/manager.go b/internal/mode/provisioner/manager.go index 96ad19329b..91c074b41e 100644 --- a/internal/mode/provisioner/manager.go +++ b/internal/mode/provisioner/manager.go @@ -15,8 +15,8 @@ import ( embeddedfiles "github.com/nginxinc/nginx-kubernetes-gateway" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/predicate" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/predicate" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" ) diff --git a/internal/framework/config/config.go b/internal/mode/static/config/config.go similarity index 100% rename from internal/framework/config/config.go rename to internal/mode/static/config/config.go diff --git a/internal/mode/static/manager.go b/internal/mode/static/manager.go index c6929580c6..95bedad3bb 100644 --- a/internal/mode/static/manager.go +++ b/internal/mode/static/manager.go @@ -16,13 +16,13 @@ import ( k8spredicate "sigs.k8s.io/controller-runtime/pkg/predicate" gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/config" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/filter" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/index" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/predicate" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/filter" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/predicate" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/config" ngxcfg "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config" ngxvalidation "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config/validation" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file" diff --git a/internal/mode/static/state/change_processor_test.go b/internal/mode/static/state/change_processor_test.go index 54320b99d8..c8046dbda1 100644 --- a/internal/mode/static/state/change_processor_test.go +++ b/internal/mode/static/state/change_processor_test.go @@ -17,8 +17,8 @@ import ( "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/index" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/graph" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/relationship" diff --git a/internal/mode/static/state/relationship/capturer.go b/internal/mode/static/state/relationship/capturer.go index 44bfa7f5a5..ed2a784ea4 100644 --- a/internal/mode/static/state/relationship/capturer.go +++ b/internal/mode/static/state/relationship/capturer.go @@ -9,7 +9,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/index" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/graph" ) diff --git a/internal/mode/static/state/relationship/capturer_test.go b/internal/mode/static/state/relationship/capturer_test.go index 57e495e56f..6faa5de8e5 100644 --- a/internal/mode/static/state/relationship/capturer_test.go +++ b/internal/mode/static/state/relationship/capturer_test.go @@ -10,8 +10,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/index" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/relationship" ) diff --git a/internal/mode/static/state/resolver/resolver.go b/internal/mode/static/state/resolver/resolver.go index 74776f8a67..149edcbb09 100644 --- a/internal/mode/static/state/resolver/resolver.go +++ b/internal/mode/static/state/resolver/resolver.go @@ -10,7 +10,7 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/index" ) //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . ServiceResolver diff --git a/internal/mode/static/state/resolver/service_resolver_test.go b/internal/mode/static/state/resolver/service_resolver_test.go index 3b367ebb81..a525d4dd5b 100644 --- a/internal/mode/static/state/resolver/service_resolver_test.go +++ b/internal/mode/static/state/resolver/service_resolver_test.go @@ -13,8 +13,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/index" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/manager/index" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/resolver" ) From 683b763663f44eb7a1bce447a0002f2f4d8fc527 Mon Sep 17 00:00:00 2001 From: Kate Osborn Date: Mon, 10 Jul 2023 15:17:06 -0600 Subject: [PATCH 5/7] Add period --- internal/mode/static/doc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/mode/static/doc.go b/internal/mode/static/doc.go index 5b4ffcd337..5dcf35b75a 100644 --- a/internal/mode/static/doc.go +++ b/internal/mode/static/doc.go @@ -1,5 +1,5 @@ /* Package static contains all the packages that relate to the static-mode implementation of NKG. -Static-mode configures NGINX in the scope of a single Gateway resource +Static-mode configures NGINX in the scope of a single Gateway resource. */ package static From 41490bb08eaad8683f4e71e86295c810f89b61e2 Mon Sep 17 00:00:00 2001 From: Kate Osborn Date: Mon, 10 Jul 2023 15:54:11 -0600 Subject: [PATCH 6/7] Split conditions --- internal/framework/conditions/conditions.go | 532 ----------------- internal/framework/status/updater_test.go | 12 +- internal/mode/static/build_statuses.go | 32 +- internal/mode/static/build_statuses_test.go | 79 +-- .../static/state/change_processor_test.go | 25 +- .../static/state/conditions/conditions.go | 543 ++++++++++++++++++ .../state}/conditions/conditions_test.go | 6 +- .../mode/static/state/graph/backend_refs.go | 13 +- .../static/state/graph/backend_refs_test.go | 21 +- internal/mode/static/state/graph/gateway.go | 7 +- .../static/state/graph/gateway_listener.go | 33 +- .../state/graph/gateway_listener_test.go | 15 +- .../mode/static/state/graph/gateway_test.go | 36 +- .../mode/static/state/graph/gatewayclass.go | 3 +- .../static/state/graph/gatewayclass_test.go | 3 +- internal/mode/static/state/graph/httproute.go | 21 +- .../mode/static/state/graph/httproute_test.go | 29 +- 17 files changed, 721 insertions(+), 689 deletions(-) create mode 100644 internal/mode/static/state/conditions/conditions.go rename internal/{framework => mode/static/state}/conditions/conditions_test.go (86%) diff --git a/internal/framework/conditions/conditions.go b/internal/framework/conditions/conditions.go index 929731a8b9..8e37e20617 100644 --- a/internal/framework/conditions/conditions.go +++ b/internal/framework/conditions/conditions.go @@ -1,8 +1,6 @@ package conditions import ( - "fmt" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/gateway-api/apis/v1beta1" ) @@ -16,53 +14,6 @@ const ( // 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 v1beta1.ListenerConditionReason = "UnsupportedValue" - - // ListenerMessageFailedNginxReload is a message used with ListenerConditionProgrammed (false) - // when nginx fails to reload. - ListenerMessageFailedNginxReload = "The Listener is not programmed due to a failure to " + - "reload nginx with the configuration" - - // RouteReasonBackendRefUnsupportedValue is used with the "ResolvedRefs" condition when one of the - // Route rules has a backendRef with an unsupported value. - RouteReasonBackendRefUnsupportedValue = "UnsupportedValue" - - // RouteReasonInvalidGateway is used with the "Accepted" (false) condition when the Gateway the Route - // references is invalid. - RouteReasonInvalidGateway = "InvalidGateway" - - // RouteReasonInvalidListener is used with the "Accepted" condition when the Route references an invalid listener. - RouteReasonInvalidListener v1beta1.RouteConditionReason = "InvalidListener" - - // RouteReasonGatewayNotProgrammed is used when the associated Gateway is not programmed. - // Used with Accepted (false). - RouteReasonGatewayNotProgrammed v1beta1.RouteConditionReason = "GatewayNotProgrammed" - - // GatewayReasonGatewayConflict indicates there are multiple Gateway resources to choose from, - // and we ignored the resource in question and picked another Gateway as the winner. - // This reason is used with GatewayConditionAccepted (false). - GatewayReasonGatewayConflict v1beta1.GatewayConditionReason = "GatewayConflict" - - // GatewayMessageGatewayConflict is a message that describes GatewayReasonGatewayConflict. - GatewayMessageGatewayConflict = "The resource is ignored due to a conflicting Gateway resource" - - // GatewayReasonUnsupportedValue is used with GatewayConditionAccepted (false) when a value of a field in a Gateway - // is invalid or not supported. - GatewayReasonUnsupportedValue v1beta1.GatewayConditionReason = "UnsupportedValue" - - // GatewayMessageFailedNginxReload is a message used with GatewayConditionProgrammed (false) - // when nginx fails to reload. - GatewayMessageFailedNginxReload = "The Gateway is not programmed due to a failure to " + - "reload nginx with the configuration" - - // RouteMessageFailedNginxReload is a message used with RouteReasonGatewayNotProgrammed - // when nginx fails to reload. - RouteMessageFailedNginxReload = GatewayMessageFailedNginxReload + ". NGINX may still be configured " + - "for this HTTPRoute. However, future updates to this resource will not be configured until the Gateway " + - "is programmed again" ) // Condition defines a condition to be reported in the status of resources. @@ -73,357 +24,6 @@ type Condition struct { 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 -} - -// NewTODO returns a Condition that can be used as a placeholder for a condition that is not yet implemented. -func NewTODO(msg string) Condition { - return Condition{ - Type: "TODO", - Status: metav1.ConditionTrue, - Reason: "TODO", - Message: fmt.Sprintf("The condition for this has not been implemented yet: %s", msg), - } -} - -// NewDefaultRouteConditions returns the default conditions that must be present in the status of an HTTPRoute. -func NewDefaultRouteConditions() []Condition { - return []Condition{ - NewRouteAccepted(), - NewRouteResolvedRefs(), - } -} - -// NewRouteNotAllowedByListeners returns a Condition that indicates that the HTTPRoute is not allowed by -// any listener. -func NewRouteNotAllowedByListeners() Condition { - return Condition{ - Type: string(v1beta1.RouteConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.RouteReasonNotAllowedByListeners), - Message: "HTTPRoute is not allowed by any listener", - } -} - -// NewRouteNoMatchingListenerHostname returns a Condition that indicates that the hostname of the listener -// does not match the hostnames of the HTTPRoute. -func NewRouteNoMatchingListenerHostname() Condition { - return Condition{ - Type: string(v1beta1.RouteConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.RouteReasonNoMatchingListenerHostname), - Message: "Listener hostname does not match the HTTPRoute hostnames", - } -} - -// NewRouteAccepted returns a Condition that indicates that the HTTPRoute is accepted. -func NewRouteAccepted() Condition { - return Condition{ - Type: string(v1beta1.RouteConditionAccepted), - Status: metav1.ConditionTrue, - Reason: string(v1beta1.RouteReasonAccepted), - Message: "The route is accepted", - } -} - -// NewRouteUnsupportedValue returns a Condition that indicates that the HTTPRoute includes an unsupported value. -func NewRouteUnsupportedValue(msg string) Condition { - return Condition{ - Type: string(v1beta1.RouteConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.RouteReasonUnsupportedValue), - Message: msg, - } -} - -// NewRouteInvalidListener returns a Condition that indicates that the HTTPRoute is not accepted because of an -// invalid listener. -func NewRouteInvalidListener() Condition { - return Condition{ - Type: string(v1beta1.RouteConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(RouteReasonInvalidListener), - Message: "Listener is invalid for this parent ref", - } -} - -// NewRouteResolvedRefs returns a Condition that indicates that all the references on the Route are resolved. -func NewRouteResolvedRefs() Condition { - return Condition{ - Type: string(v1beta1.RouteConditionResolvedRefs), - Status: metav1.ConditionTrue, - Reason: string(v1beta1.RouteReasonResolvedRefs), - Message: "All references are resolved", - } -} - -// NewRouteBackendRefInvalidKind returns a Condition that indicates that the Route has a backendRef with an -// invalid kind. -func NewRouteBackendRefInvalidKind(msg string) Condition { - return Condition{ - Type: string(v1beta1.RouteConditionResolvedRefs), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.RouteReasonInvalidKind), - Message: msg, - } -} - -// NewRouteBackendRefRefNotPermitted returns a Condition that indicates that the Route has a backendRef that -// is not permitted. -func NewRouteBackendRefRefNotPermitted(msg string) Condition { - return Condition{ - Type: string(v1beta1.RouteConditionResolvedRefs), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.RouteReasonRefNotPermitted), - Message: msg, - } -} - -// NewRouteBackendRefRefBackendNotFound returns a Condition that indicates that the Route has a backendRef that -// points to non-existing backend. -func NewRouteBackendRefRefBackendNotFound(msg string) Condition { - return Condition{ - Type: string(v1beta1.RouteConditionResolvedRefs), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.RouteReasonBackendNotFound), - Message: msg, - } -} - -// NewRouteBackendRefUnsupportedValue returns a Condition that indicates that the Route has a backendRef with -// an unsupported value. -func NewRouteBackendRefUnsupportedValue(msg string) Condition { - return Condition{ - Type: string(v1beta1.RouteConditionResolvedRefs), - Status: metav1.ConditionFalse, - Reason: RouteReasonBackendRefUnsupportedValue, - Message: msg, - } -} - -// NewRouteInvalidGateway returns a Condition that indicates that the Route is not Accepted because the Gateway it -// references is invalid. -func NewRouteInvalidGateway() Condition { - return Condition{ - Type: string(v1beta1.RouteConditionAccepted), - Status: metav1.ConditionFalse, - Reason: RouteReasonInvalidGateway, - Message: "Gateway is invalid", - } -} - -// 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() Condition { - return Condition{ - Type: string(v1beta1.RouteConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.RouteReasonNoMatchingParent), - Message: "Listener is not found for this parent ref", - } -} - -// NewRouteGatewayNotProgrammed returns a Condition that indicates that the Gateway it references is not programmed, -// which does not guarantee that the HTTPRoute has been configured. -func NewRouteGatewayNotProgrammed(msg string) Condition { - return Condition{ - Type: string(v1beta1.RouteConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(RouteReasonGatewayNotProgrammed), - Message: msg, - } -} - -// NewDefaultListenerConditions returns the default Conditions that must be present in the status of a Listener. -func NewDefaultListenerConditions() []Condition { - return []Condition{ - NewListenerAccepted(), - NewListenerProgrammed(), - NewListenerResolvedRefs(), - NewListenerNoConflicts(), - } -} - -// NewListenerAccepted returns a Condition that indicates that the Listener is accepted. -func NewListenerAccepted() Condition { - return Condition{ - Type: string(v1beta1.ListenerConditionAccepted), - Status: metav1.ConditionTrue, - Reason: string(v1beta1.ListenerReasonAccepted), - Message: "Listener is accepted", - } -} - -// NewListenerProgrammed returns a Condition that indicates the Listener is programmed. -func NewListenerProgrammed() Condition { - return Condition{ - Type: string(v1beta1.ListenerConditionProgrammed), - Status: metav1.ConditionTrue, - Reason: string(v1beta1.ListenerReasonProgrammed), - Message: "Listener is programmed", - } -} - -// NewListenerResolvedRefs returns a Condition that indicates that all references in a Listener are resolved. -func NewListenerResolvedRefs() Condition { - return Condition{ - Type: string(v1beta1.ListenerConditionResolvedRefs), - Status: metav1.ConditionTrue, - Reason: string(v1beta1.ListenerReasonResolvedRefs), - Message: "All references are resolved", - } -} - -// NewListenerNoConflicts returns a Condition that indicates that there are no conflicts in a Listener. -func NewListenerNoConflicts() Condition { - return Condition{ - Type: string(v1beta1.ListenerConditionConflicted), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.ListenerReasonNoConflicts), - Message: "No conflicts", - } -} - -// 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) Condition { - return Condition{ - Type: string(v1beta1.ListenerConditionProgrammed), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.ListenerReasonInvalid), - Message: msg, - } -} - -// 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) []Condition { - return []Condition{ - { - Type: string(v1beta1.ListenerConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(ListenerReasonUnsupportedValue), - Message: msg, - }, - NewListenerNotProgrammedInvalid(msg), - } -} - -// NewListenerInvalidCertificateRef returns Conditions that indicate that a CertificateRef of a Listener is invalid. -func NewListenerInvalidCertificateRef(msg string) []Condition { - return []Condition{ - { - Type: string(v1beta1.ListenerConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.ListenerReasonInvalidCertificateRef), - Message: msg, - }, - { - Type: string(v1beta1.ListenerReasonResolvedRefs), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.ListenerReasonInvalidCertificateRef), - Message: msg, - }, - NewListenerNotProgrammedInvalid(msg), - } -} - -// NewListenerInvalidRouteKinds returns Conditions that indicate that an invalid or unsupported Route kind is -// specified by the Listener. -func NewListenerInvalidRouteKinds(msg string) []Condition { - return []Condition{ - { - Type: string(v1beta1.ListenerReasonResolvedRefs), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.ListenerReasonInvalidRouteKinds), - Message: msg, - }, - NewListenerNotProgrammedInvalid(msg), - } -} - -// NewListenerProtocolConflict returns Conditions that indicate multiple Listeners are specified with the same -// Listener port number, but have conflicting protocol specifications. -func NewListenerProtocolConflict(msg string) []Condition { - return []Condition{ - { - Type: string(v1beta1.ListenerConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.ListenerReasonProtocolConflict), - Message: msg, - }, - { - Type: string(v1beta1.ListenerConditionConflicted), - Status: metav1.ConditionTrue, - Reason: string(v1beta1.ListenerReasonProtocolConflict), - Message: msg, - }, - NewListenerNotProgrammedInvalid(msg), - } -} - -// NewListenerUnsupportedProtocol returns Conditions that indicate that the protocol of a Listener is unsupported. -func NewListenerUnsupportedProtocol(msg string) []Condition { - return []Condition{ - { - Type: string(v1beta1.ListenerConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.ListenerReasonUnsupportedProtocol), - Message: msg, - }, - NewListenerNotProgrammedInvalid(msg), - } -} - -// NewListenerRefNotPermitted returns Conditions that indicates that the Listener references a TLS secret that is not -// permitted by a ReferenceGrant. -func NewListenerRefNotPermitted(msg string) []Condition { - return []Condition{ - { - Type: string(v1beta1.ListenerConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.ListenerReasonRefNotPermitted), - Message: msg, - }, - { - Type: string(v1beta1.ListenerReasonResolvedRefs), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.ListenerReasonRefNotPermitted), - Message: msg, - }, - NewListenerNotProgrammedInvalid(msg), - } -} - // NewDefaultGatewayClassConditions returns the default Conditions that must be present in the status of a GatewayClass. func NewDefaultGatewayClassConditions() []Condition { return []Condition{ @@ -446,135 +46,3 @@ func NewGatewayClassConflict() Condition { Message: GatewayClassMessageGatewayClassConflict, } } - -// NewGatewayClassInvalidParameters returns a Condition that indicates that the GatewayClass has invalid parameters. -func NewGatewayClassInvalidParameters(msg string) Condition { - return Condition{ - Type: string(v1beta1.GatewayClassConditionStatusAccepted), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.GatewayClassReasonInvalidParameters), - Message: msg, - } -} - -// NewDefaultGatewayConditions returns the default Conditions that must be present in the status of a Gateway. -func NewDefaultGatewayConditions() []Condition { - return []Condition{ - NewGatewayAccepted(), - NewGatewayProgrammed(), - } -} - -// NewGatewayAccepted returns a Condition that indicates the Gateway is accepted. -func NewGatewayAccepted() Condition { - return Condition{ - Type: string(v1beta1.GatewayConditionAccepted), - Status: metav1.ConditionTrue, - Reason: string(v1beta1.GatewayReasonAccepted), - Message: "Gateway is accepted", - } -} - -// NewGatewayConflict returns Conditions that indicate the Gateway has a conflict with another Gateway. -func NewGatewayConflict() []Condition { - return []Condition{ - { - Type: string(v1beta1.GatewayConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(GatewayReasonGatewayConflict), - Message: GatewayMessageGatewayConflict, - }, - NewGatewayConflictNotProgrammed(), - } -} - -// NewGatewayAcceptedListenersNotValid returns a Condition that indicates the Gateway is accepted, -// but has at least one listener that is invalid. -func NewGatewayAcceptedListenersNotValid() Condition { - return Condition{ - Type: string(v1beta1.GatewayConditionAccepted), - Status: metav1.ConditionTrue, - Reason: string(v1beta1.GatewayReasonListenersNotValid), - Message: "Gateway has at least one valid listener", - } -} - -// NewGatewayNotAcceptedListenersNotValid returns Conditions that indicate the Gateway is not accepted, -// because all listeners are invalid. -func NewGatewayNotAcceptedListenersNotValid() []Condition { - msg := "Gateway has no valid listeners" - return []Condition{ - { - Type: string(v1beta1.GatewayConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.GatewayReasonListenersNotValid), - Message: msg, - }, - NewGatewayNotProgrammedInvalid(msg), - } -} - -// 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) []Condition { - return []Condition{ - { - Type: string(v1beta1.GatewayConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.GatewayReasonInvalid), - Message: msg, - }, - NewGatewayNotProgrammedInvalid(msg), - } -} - -// 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) []Condition { - return []Condition{ - { - Type: string(v1beta1.GatewayConditionAccepted), - Status: metav1.ConditionFalse, - Reason: string(GatewayReasonUnsupportedValue), - Message: msg, - }, - { - Type: string(v1beta1.GatewayConditionProgrammed), - Status: metav1.ConditionFalse, - Reason: string(GatewayReasonUnsupportedValue), - Message: msg, - }, - } -} - -// NewGatewayProgrammed returns a Condition that indicates the Gateway is programmed. -func NewGatewayProgrammed() Condition { - return Condition{ - Type: string(v1beta1.GatewayConditionProgrammed), - Status: metav1.ConditionTrue, - Reason: string(v1beta1.GatewayReasonProgrammed), - Message: "Gateway is programmed", - } -} - -// NewGatewayInvalid 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) Condition { - return Condition{ - Type: string(v1beta1.GatewayConditionProgrammed), - Status: metav1.ConditionFalse, - Reason: string(v1beta1.GatewayReasonInvalid), - Message: msg, - } -} - -// NewGatewayConflictNotProgrammed returns a custom Programmed Condition that indicates the Gateway has a -// conflict with another Gateway. -func NewGatewayConflictNotProgrammed() Condition { - return Condition{ - Type: string(v1beta1.GatewayConditionProgrammed), - Status: metav1.ConditionFalse, - Reason: string(GatewayReasonGatewayConflict), - Message: GatewayMessageGatewayConflict, - } -} diff --git a/internal/framework/status/updater_test.go b/internal/framework/status/updater_test.go index b242163494..7791b1ff33 100644 --- a/internal/framework/status/updater_test.go +++ b/internal/framework/status/updater_test.go @@ -14,10 +14,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status/statusfakes" + staticConds "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/conditions" ) var _ = Describe("Updater", func() { @@ -89,7 +89,7 @@ var _ = Describe("Updater", func() { ObservedGeneration: gens.gateways, }, {Namespace: "test", Name: "ignored-gateway"}: { - Conditions: conditions.NewGatewayConflict(), + Conditions: staticConds.NewGatewayConflict(), ObservedGeneration: 1, }, }, @@ -165,16 +165,16 @@ var _ = Describe("Updater", func() { Status: metav1.ConditionFalse, ObservedGeneration: 1, LastTransitionTime: fakeClockTime, - Reason: string(conditions.GatewayReasonGatewayConflict), - Message: conditions.GatewayMessageGatewayConflict, + Reason: string(staticConds.GatewayReasonGatewayConflict), + Message: staticConds.GatewayMessageGatewayConflict, }, { Type: string(v1beta1.GatewayConditionProgrammed), Status: metav1.ConditionFalse, ObservedGeneration: 1, LastTransitionTime: fakeClockTime, - Reason: string(conditions.GatewayReasonGatewayConflict), - Message: conditions.GatewayMessageGatewayConflict, + Reason: string(staticConds.GatewayReasonGatewayConflict), + Message: staticConds.GatewayMessageGatewayConflict, }, }, Addresses: []v1beta1.GatewayAddress{addr}, diff --git a/internal/mode/static/build_statuses.go b/internal/mode/static/build_statuses.go index 10bc5e1373..4b8c7aae77 100644 --- a/internal/mode/static/build_statuses.go +++ b/internal/mode/static/build_statuses.go @@ -7,6 +7,7 @@ import ( "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" + staticConds "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/conditions" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/graph" ) @@ -27,7 +28,7 @@ func buildStatuses(graph *graph.Graph, nginxReloadRes nginxReloadResult) status. for nsname, r := range graph.Routes { parentStatuses := make([]status.ParentStatus, 0, len(r.ParentRefs)) - defaultConds := conditions.NewDefaultRouteConditions() + defaultConds := staticConds.NewDefaultRouteConditions() for _, ref := range r.ParentRefs { failedAttachmentCondCount := 0 @@ -47,7 +48,7 @@ func buildStatuses(graph *graph.Graph, nginxReloadRes nginxReloadResult) status. if nginxReloadRes.error != nil { allConds = append( allConds, - conditions.NewRouteGatewayNotProgrammed(conditions.RouteMessageFailedNginxReload), + staticConds.NewRouteGatewayNotProgrammed(staticConds.RouteMessageFailedNginxReload), ) } @@ -56,7 +57,7 @@ func buildStatuses(graph *graph.Graph, nginxReloadRes nginxReloadResult) status. parentStatuses = append(parentStatuses, status.ParentStatus{ GatewayNsName: ref.Gateway, SectionName: routeRef.SectionName, - Conditions: conditions.DeduplicateConditions(allConds), + Conditions: staticConds.DeduplicateConditions(allConds), }) } @@ -86,7 +87,7 @@ func buildGatewayClassStatuses( conds = append(conds, gc.Conditions...) statuses[client.ObjectKeyFromObject(gc.Source)] = status.GatewayClassStatus{ - Conditions: conditions.DeduplicateConditions(conds), + Conditions: staticConds.DeduplicateConditions(conds), ObservedGeneration: gc.Source.Generation, } } @@ -114,7 +115,7 @@ func buildGatewayStatuses( for nsname, gw := range ignoredGateways { statuses[nsname] = status.GatewayStatus{ - Conditions: conditions.NewGatewayConflict(), + Conditions: staticConds.NewGatewayConflict(), ObservedGeneration: gw.Generation, } } @@ -125,7 +126,7 @@ func buildGatewayStatuses( func buildGatewayStatus(gateway *graph.Gateway, nginxReloadRes nginxReloadResult) status.GatewayStatus { if !gateway.Valid { return status.GatewayStatus{ - Conditions: conditions.DeduplicateConditions(gateway.Conditions), + Conditions: staticConds.DeduplicateConditions(gateway.Conditions), ObservedGeneration: gateway.Source.Generation, } } @@ -137,7 +138,7 @@ func buildGatewayStatus(gateway *graph.Gateway, nginxReloadRes nginxReloadResult var conds []conditions.Condition if l.Valid { - conds = conditions.NewDefaultListenerConditions() + conds = staticConds.NewDefaultListenerConditions() validListenerCount++ } else { conds = l.Conditions @@ -146,30 +147,33 @@ func buildGatewayStatus(gateway *graph.Gateway, nginxReloadRes nginxReloadResult if nginxReloadRes.error != nil { conds = append( conds, - conditions.NewListenerNotProgrammedInvalid(conditions.ListenerMessageFailedNginxReload), + staticConds.NewListenerNotProgrammedInvalid(staticConds.ListenerMessageFailedNginxReload), ) } listenerStatuses[name] = status.ListenerStatus{ AttachedRoutes: int32(len(l.Routes)), - Conditions: conditions.DeduplicateConditions(conds), + Conditions: staticConds.DeduplicateConditions(conds), SupportedKinds: l.SupportedKinds, } } - gwConds := conditions.NewDefaultGatewayConditions() + gwConds := staticConds.NewDefaultGatewayConditions() if validListenerCount == 0 { - gwConds = append(gwConds, conditions.NewGatewayNotAcceptedListenersNotValid()...) + gwConds = append(gwConds, staticConds.NewGatewayNotAcceptedListenersNotValid()...) } else if validListenerCount < len(gateway.Listeners) { - gwConds = append(gwConds, conditions.NewGatewayAcceptedListenersNotValid()) + gwConds = append(gwConds, staticConds.NewGatewayAcceptedListenersNotValid()) } if nginxReloadRes.error != nil { - gwConds = append(gwConds, conditions.NewGatewayNotProgrammedInvalid(conditions.GatewayMessageFailedNginxReload)) + gwConds = append( + gwConds, + staticConds.NewGatewayNotProgrammedInvalid(staticConds.GatewayMessageFailedNginxReload), + ) } return status.GatewayStatus{ - Conditions: conditions.DeduplicateConditions(gwConds), + Conditions: staticConds.DeduplicateConditions(gwConds), ListenerStatuses: listenerStatuses, ObservedGeneration: gateway.Source.Generation, } diff --git a/internal/mode/static/build_statuses_test.go b/internal/mode/static/build_statuses_test.go index 97b3053fe5..f2feb13a0b 100644 --- a/internal/mode/static/build_statuses_test.go +++ b/internal/mode/static/build_statuses_test.go @@ -13,6 +13,7 @@ import ( "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status" + staticConds "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/conditions" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/graph" ) @@ -143,17 +144,17 @@ func TestBuildStatuses(t *testing.T) { }, GatewayStatuses: status.GatewayStatuses{ {Namespace: "test", Name: "gateway"}: { - Conditions: conditions.NewDefaultGatewayConditions(), + Conditions: staticConds.NewDefaultGatewayConditions(), ListenerStatuses: map[string]status.ListenerStatus{ "listener-80-1": { AttachedRoutes: 1, - Conditions: conditions.NewDefaultListenerConditions(), + Conditions: staticConds.NewDefaultListenerConditions(), }, }, ObservedGeneration: 2, }, {Namespace: "test", Name: "ignored-gateway"}: { - Conditions: conditions.NewGatewayConflict(), + Conditions: staticConds.NewGatewayConflict(), ObservedGeneration: 1, }, }, @@ -164,13 +165,13 @@ func TestBuildStatuses(t *testing.T) { { GatewayNsName: client.ObjectKeyFromObject(gw), SectionName: helpers.GetPointer[v1beta1.SectionName]("listener-80-1"), - Conditions: conditions.NewDefaultRouteConditions(), + Conditions: staticConds.NewDefaultRouteConditions(), }, { GatewayNsName: client.ObjectKeyFromObject(gw), SectionName: helpers.GetPointer[v1beta1.SectionName]("listener-80-2"), Conditions: append( - conditions.NewDefaultRouteConditions(), + staticConds.NewDefaultRouteConditions(), invalidAttachmentCondition, ), }, @@ -183,7 +184,7 @@ func TestBuildStatuses(t *testing.T) { GatewayNsName: client.ObjectKeyFromObject(gw), SectionName: helpers.GetPointer[v1beta1.SectionName]("listener-80-1"), Conditions: append( - conditions.NewDefaultRouteConditions(), + staticConds.NewDefaultRouteConditions(), invalidRouteCondition, ), }, @@ -250,17 +251,17 @@ func TestBuildStatusesNginxErr(t *testing.T) { GatewayStatuses: status.GatewayStatuses{ {Namespace: "test", Name: "gateway"}: { Conditions: []conditions.Condition{ - conditions.NewGatewayAccepted(), - conditions.NewGatewayNotProgrammedInvalid(conditions.GatewayMessageFailedNginxReload), + staticConds.NewGatewayAccepted(), + staticConds.NewGatewayNotProgrammedInvalid(staticConds.GatewayMessageFailedNginxReload), }, ListenerStatuses: map[string]status.ListenerStatus{ "listener-80-1": { AttachedRoutes: 1, Conditions: []conditions.Condition{ - conditions.NewListenerAccepted(), - conditions.NewListenerResolvedRefs(), - conditions.NewListenerNoConflicts(), - conditions.NewListenerNotProgrammedInvalid(conditions.ListenerMessageFailedNginxReload), + staticConds.NewListenerAccepted(), + staticConds.NewListenerResolvedRefs(), + staticConds.NewListenerNoConflicts(), + staticConds.NewListenerNotProgrammedInvalid(staticConds.ListenerMessageFailedNginxReload), }, }, }, @@ -275,8 +276,8 @@ func TestBuildStatusesNginxErr(t *testing.T) { GatewayNsName: client.ObjectKeyFromObject(gw), SectionName: helpers.GetPointer[v1beta1.SectionName]("listener-80-1"), Conditions: []conditions.Condition{ - conditions.NewRouteResolvedRefs(), - conditions.NewRouteGatewayNotProgrammed(conditions.RouteMessageFailedNginxReload), + staticConds.NewRouteResolvedRefs(), + staticConds.NewRouteGatewayNotProgrammed(staticConds.RouteMessageFailedNginxReload), }, }, }, @@ -384,11 +385,11 @@ func TestBuildGatewayStatuses(t *testing.T) { }, expected: status.GatewayStatuses{ {Namespace: "test", Name: "ignored-1"}: { - Conditions: conditions.NewGatewayConflict(), + Conditions: staticConds.NewGatewayConflict(), ObservedGeneration: 1, }, {Namespace: "test", Name: "ignored-2"}: { - Conditions: conditions.NewGatewayConflict(), + Conditions: staticConds.NewGatewayConflict(), ObservedGeneration: 2, }, }, @@ -415,15 +416,15 @@ func TestBuildGatewayStatuses(t *testing.T) { }, expected: status.GatewayStatuses{ {Namespace: "test", Name: "gateway"}: { - Conditions: conditions.NewDefaultGatewayConditions(), + Conditions: staticConds.NewDefaultGatewayConditions(), ListenerStatuses: map[string]status.ListenerStatus{ "listener-valid-1": { AttachedRoutes: 1, - Conditions: conditions.NewDefaultListenerConditions(), + Conditions: staticConds.NewDefaultListenerConditions(), }, "listener-valid-2": { AttachedRoutes: 1, - Conditions: conditions.NewDefaultListenerConditions(), + Conditions: staticConds.NewDefaultListenerConditions(), }, }, ObservedGeneration: 2, @@ -443,7 +444,7 @@ func TestBuildGatewayStatuses(t *testing.T) { }, "listener-invalid": { Valid: false, - Conditions: conditions.NewListenerUnsupportedValue("unsupported value"), + Conditions: staticConds.NewListenerUnsupportedValue("unsupported value"), }, }, Valid: true, @@ -451,16 +452,16 @@ func TestBuildGatewayStatuses(t *testing.T) { expected: status.GatewayStatuses{ {Namespace: "test", Name: "gateway"}: { Conditions: []conditions.Condition{ - conditions.NewGatewayProgrammed(), - conditions.NewGatewayAcceptedListenersNotValid(), + staticConds.NewGatewayProgrammed(), + staticConds.NewGatewayAcceptedListenersNotValid(), }, ListenerStatuses: map[string]status.ListenerStatus{ "listener-valid": { AttachedRoutes: 1, - Conditions: conditions.NewDefaultListenerConditions(), + Conditions: staticConds.NewDefaultListenerConditions(), }, "listener-invalid": { - Conditions: conditions.NewListenerUnsupportedValue("unsupported value"), + Conditions: staticConds.NewListenerUnsupportedValue("unsupported value"), }, }, ObservedGeneration: 2, @@ -474,24 +475,24 @@ func TestBuildGatewayStatuses(t *testing.T) { Listeners: map[string]*graph.Listener{ "listener-invalid-1": { Valid: false, - Conditions: conditions.NewListenerUnsupportedProtocol("unsupported protocol"), + Conditions: staticConds.NewListenerUnsupportedProtocol("unsupported protocol"), }, "listener-invalid-2": { Valid: false, - Conditions: conditions.NewListenerUnsupportedValue("unsupported value"), + Conditions: staticConds.NewListenerUnsupportedValue("unsupported value"), }, }, Valid: true, }, expected: status.GatewayStatuses{ {Namespace: "test", Name: "gateway"}: { - Conditions: conditions.NewGatewayNotAcceptedListenersNotValid(), + Conditions: staticConds.NewGatewayNotAcceptedListenersNotValid(), ListenerStatuses: map[string]status.ListenerStatus{ "listener-invalid-1": { - Conditions: conditions.NewListenerUnsupportedProtocol("unsupported protocol"), + Conditions: staticConds.NewListenerUnsupportedProtocol("unsupported protocol"), }, "listener-invalid-2": { - Conditions: conditions.NewListenerUnsupportedValue("unsupported value"), + Conditions: staticConds.NewListenerUnsupportedValue("unsupported value"), }, }, ObservedGeneration: 2, @@ -503,11 +504,11 @@ func TestBuildGatewayStatuses(t *testing.T) { gateway: &graph.Gateway{ Source: gw, Valid: false, - Conditions: conditions.NewGatewayInvalid("no gateway class"), + Conditions: staticConds.NewGatewayInvalid("no gateway class"), }, expected: status.GatewayStatuses{ {Namespace: "test", Name: "gateway"}: { - Conditions: conditions.NewGatewayInvalid("no gateway class"), + Conditions: staticConds.NewGatewayInvalid("no gateway class"), ObservedGeneration: 2, }, }, @@ -517,7 +518,7 @@ func TestBuildGatewayStatuses(t *testing.T) { gateway: &graph.Gateway{ Source: gw, Valid: true, - Conditions: conditions.NewDefaultGatewayConditions(), + Conditions: staticConds.NewDefaultGatewayConditions(), Listeners: map[string]*graph.Listener{ "listener-valid": { Valid: true, @@ -530,17 +531,19 @@ func TestBuildGatewayStatuses(t *testing.T) { expected: status.GatewayStatuses{ {Namespace: "test", Name: "gateway"}: { Conditions: []conditions.Condition{ - conditions.NewGatewayAccepted(), - conditions.NewGatewayNotProgrammedInvalid(conditions.GatewayMessageFailedNginxReload), + staticConds.NewGatewayAccepted(), + staticConds.NewGatewayNotProgrammedInvalid(staticConds.GatewayMessageFailedNginxReload), }, ListenerStatuses: map[string]status.ListenerStatus{ "listener-valid": { AttachedRoutes: 1, Conditions: []conditions.Condition{ - conditions.NewListenerAccepted(), - conditions.NewListenerResolvedRefs(), - conditions.NewListenerNoConflicts(), - conditions.NewListenerNotProgrammedInvalid(conditions.ListenerMessageFailedNginxReload), + staticConds.NewListenerAccepted(), + staticConds.NewListenerResolvedRefs(), + staticConds.NewListenerNoConflicts(), + staticConds.NewListenerNotProgrammedInvalid( + staticConds.ListenerMessageFailedNginxReload, + ), }, }, }, diff --git a/internal/mode/static/state/change_processor_test.go b/internal/mode/static/state/change_processor_test.go index c8046dbda1..a22088b7ad 100644 --- a/internal/mode/static/state/change_processor_test.go +++ b/internal/mode/static/state/change_processor_test.go @@ -20,6 +20,7 @@ import ( "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/index" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state" + staticConds "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/conditions" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/graph" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/relationship" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/relationship/relationshipfakes" @@ -406,7 +407,7 @@ var _ = Describe("ChangeProcessor", func() { }, Valid: true, Conditions: []conditions.Condition{ - conditions.NewRouteBackendRefRefBackendNotFound( + staticConds.NewRouteBackendRefRefBackendNotFound( "spec.rules[0].backendRefs[0].name: Not found: \"service\"", ), }, @@ -506,23 +507,23 @@ var _ = Describe("ChangeProcessor", func() { expGraph.GatewayClass = nil - expGraph.Gateway.Conditions = conditions.NewGatewayInvalid("GatewayClass doesn't exist") + expGraph.Gateway.Conditions = staticConds.NewGatewayInvalid("GatewayClass doesn't exist") expGraph.Gateway.Valid = false expGraph.Gateway.Listeners = nil // no ref grant exists yet for hr1 expGraph.Routes[hr1Name].Conditions = []conditions.Condition{ - conditions.NewRouteBackendRefRefNotPermitted( + staticConds.NewRouteBackendRefRefNotPermitted( "Backend ref to Service service-ns/service not permitted by any ReferenceGrant", ), } expGraph.Routes[hr1Name].ParentRefs[0].Attachment = &graph.ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedCondition: conditions.NewRouteInvalidGateway(), + FailedCondition: staticConds.NewRouteInvalidGateway(), } expGraph.Routes[hr1Name].ParentRefs[1].Attachment = &graph.ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedCondition: conditions.NewRouteInvalidGateway(), + FailedCondition: staticConds.NewRouteInvalidGateway(), } expGraph.ReferencedSecrets = nil @@ -543,7 +544,7 @@ var _ = Describe("ChangeProcessor", func() { Source: gw1.Spec.Listeners[1], Valid: false, Routes: map[types.NamespacedName]*graph.Route{}, - Conditions: conditions.NewListenerRefNotPermitted( + Conditions: staticConds.NewListenerRefNotPermitted( "Certificate ref to secret cert-ns/different-ns-tls-secret not permitted by any ReferenceGrant", ), SupportedKinds: []v1beta1.RouteGroupKind{{Kind: "HTTPRoute"}}, @@ -551,7 +552,7 @@ var _ = Describe("ChangeProcessor", func() { expAttachment := &graph.ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedCondition: conditions.NewRouteInvalidListener(), + FailedCondition: staticConds.NewRouteInvalidListener(), Attached: false, } @@ -560,7 +561,7 @@ var _ = Describe("ChangeProcessor", func() { // no ref grant exists yet for hr1 expGraph.Routes[hr1Name].ParentRefs[1].Attachment = expAttachment expGraph.Routes[hr1Name].Conditions = []conditions.Condition{ - conditions.NewRouteBackendRefRefNotPermitted( + staticConds.NewRouteBackendRefRefNotPermitted( "Backend ref to Service service-ns/service not permitted by any ReferenceGrant", ), } @@ -578,7 +579,7 @@ var _ = Describe("ChangeProcessor", func() { // no ref grant exists yet for hr1 expGraph.Routes[hr1Name].Conditions = []conditions.Condition{ - conditions.NewRouteBackendRefRefNotPermitted( + staticConds.NewRouteBackendRefRefNotPermitted( "Backend ref to Service service-ns/service not permitted by any ReferenceGrant", ), } @@ -739,11 +740,11 @@ var _ = Describe("ChangeProcessor", func() { expGraph.Routes[hr2Name] = expRouteHR2 expGraph.Routes[hr2Name].ParentRefs[0].Attachment = &graph.ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedCondition: conditions.NewTODO("Gateway is ignored"), + FailedCondition: staticConds.NewTODO("Gateway is ignored"), } expGraph.Routes[hr2Name].ParentRefs[1].Attachment = &graph.ParentRefAttachmentStatus{ AcceptedHostnames: map[string][]string{}, - FailedCondition: conditions.NewTODO("Gateway is ignored"), + FailedCondition: staticConds.NewTODO("Gateway is ignored"), } expGraph.ReferencedSecrets[client.ObjectKeyFromObject(diffNsTLSSecret)] = &graph.Secret{ Source: diffNsTLSSecret, @@ -819,7 +820,7 @@ var _ = Describe("ChangeProcessor", func() { expGraph.GatewayClass = nil expGraph.Gateway = &graph.Gateway{ Source: gw2, - Conditions: conditions.NewGatewayInvalid("GatewayClass doesn't exist"), + Conditions: staticConds.NewGatewayInvalid("GatewayClass doesn't exist"), } expGraph.Routes = map[types.NamespacedName]*graph.Route{} expGraph.ReferencedSecrets = nil diff --git a/internal/mode/static/state/conditions/conditions.go b/internal/mode/static/state/conditions/conditions.go new file mode 100644 index 0000000000..72f95a8846 --- /dev/null +++ b/internal/mode/static/state/conditions/conditions.go @@ -0,0 +1,543 @@ +package conditions + +import ( + "fmt" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/gateway-api/apis/v1beta1" + + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" +) + +const ( + // ListenerReasonUnsupportedValue is used with the "Accepted" condition when a value of a field in a Listener + // is invalid or not supported. + ListenerReasonUnsupportedValue v1beta1.ListenerConditionReason = "UnsupportedValue" + + // ListenerMessageFailedNginxReload is a message used with ListenerConditionProgrammed (false) + // when nginx fails to reload. + ListenerMessageFailedNginxReload = "The Listener is not programmed due to a failure to " + + "reload nginx with the configuration" + + // RouteReasonBackendRefUnsupportedValue is used with the "ResolvedRefs" condition when one of the + // Route rules has a backendRef with an unsupported value. + RouteReasonBackendRefUnsupportedValue = "UnsupportedValue" + + // RouteReasonInvalidGateway is used with the "Accepted" (false) condition when the Gateway the Route + // references is invalid. + RouteReasonInvalidGateway = "InvalidGateway" + + // RouteReasonInvalidListener is used with the "Accepted" condition when the Route references an invalid listener. + RouteReasonInvalidListener v1beta1.RouteConditionReason = "InvalidListener" + + // RouteReasonGatewayNotProgrammed is used when the associated Gateway is not programmed. + // Used with Accepted (false). + RouteReasonGatewayNotProgrammed v1beta1.RouteConditionReason = "GatewayNotProgrammed" + + // GatewayReasonGatewayConflict indicates there are multiple Gateway resources to choose from, + // and we ignored the resource in question and picked another Gateway as the winner. + // This reason is used with GatewayConditionAccepted (false). + GatewayReasonGatewayConflict v1beta1.GatewayConditionReason = "GatewayConflict" + + // GatewayMessageGatewayConflict is a message that describes GatewayReasonGatewayConflict. + GatewayMessageGatewayConflict = "The resource is ignored due to a conflicting Gateway resource" + + // GatewayReasonUnsupportedValue is used with GatewayConditionAccepted (false) when a value of a field in a Gateway + // is invalid or not supported. + GatewayReasonUnsupportedValue v1beta1.GatewayConditionReason = "UnsupportedValue" + + // GatewayMessageFailedNginxReload is a message used with GatewayConditionProgrammed (false) + // when nginx fails to reload. + GatewayMessageFailedNginxReload = "The Gateway is not programmed due to a failure to " + + "reload nginx with the configuration" + + // RouteMessageFailedNginxReload is a message used with RouteReasonGatewayNotProgrammed + // when nginx fails to reload. + RouteMessageFailedNginxReload = GatewayMessageFailedNginxReload + ". NGINX may still be configured " + + "for this HTTPRoute. However, future updates to this resource will not be configured until the Gateway " + + "is programmed again" +) + +// DeduplicateConditions removes duplicate conditions based on the condition type. +// The last condition wins. The order of conditions is preserved. +func DeduplicateConditions(conds []conditions.Condition) []conditions.Condition { + type elem struct { + cond conditions.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([]conditions.Condition, len(uniqueElems)) + + for _, el := range uniqueElems { + result[len(result)-el.reverseIdx-1] = el.cond + } + + return result +} + +// NewTODO returns a Condition that can be used as a placeholder for a condition that is not yet implemented. +func NewTODO(msg string) conditions.Condition { + return conditions.Condition{ + Type: "TODO", + Status: metav1.ConditionTrue, + Reason: "TODO", + Message: fmt.Sprintf("The condition for this has not been implemented yet: %s", msg), + } +} + +// NewDefaultRouteConditions returns the default conditions that must be present in the status of an HTTPRoute. +func NewDefaultRouteConditions() []conditions.Condition { + return []conditions.Condition{ + NewRouteAccepted(), + NewRouteResolvedRefs(), + } +} + +// NewRouteNotAllowedByListeners returns a Condition that indicates that the HTTPRoute is not allowed by +// any listener. +func NewRouteNotAllowedByListeners() conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.RouteConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.RouteReasonNotAllowedByListeners), + Message: "HTTPRoute is not allowed by any listener", + } +} + +// NewRouteNoMatchingListenerHostname returns a Condition that indicates that the hostname of the listener +// does not match the hostnames of the HTTPRoute. +func NewRouteNoMatchingListenerHostname() conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.RouteConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.RouteReasonNoMatchingListenerHostname), + Message: "Listener hostname does not match the HTTPRoute hostnames", + } +} + +// NewRouteAccepted returns a Condition that indicates that the HTTPRoute is accepted. +func NewRouteAccepted() conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.RouteConditionAccepted), + Status: metav1.ConditionTrue, + Reason: string(v1beta1.RouteReasonAccepted), + Message: "The route is accepted", + } +} + +// NewRouteUnsupportedValue returns a Condition that indicates that the HTTPRoute includes an unsupported value. +func NewRouteUnsupportedValue(msg string) conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.RouteConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.RouteReasonUnsupportedValue), + Message: msg, + } +} + +// NewRouteInvalidListener returns a Condition that indicates that the HTTPRoute is not accepted because of an +// invalid listener. +func NewRouteInvalidListener() conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.RouteConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(RouteReasonInvalidListener), + Message: "Listener is invalid for this parent ref", + } +} + +// NewRouteResolvedRefs returns a Condition that indicates that all the references on the Route are resolved. +func NewRouteResolvedRefs() conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.RouteConditionResolvedRefs), + Status: metav1.ConditionTrue, + Reason: string(v1beta1.RouteReasonResolvedRefs), + Message: "All references are resolved", + } +} + +// 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{ + Type: string(v1beta1.RouteConditionResolvedRefs), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.RouteReasonInvalidKind), + Message: msg, + } +} + +// 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{ + Type: string(v1beta1.RouteConditionResolvedRefs), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.RouteReasonRefNotPermitted), + Message: msg, + } +} + +// 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{ + Type: string(v1beta1.RouteConditionResolvedRefs), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.RouteReasonBackendNotFound), + Message: msg, + } +} + +// 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{ + Type: string(v1beta1.RouteConditionResolvedRefs), + Status: metav1.ConditionFalse, + Reason: RouteReasonBackendRefUnsupportedValue, + Message: msg, + } +} + +// 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{ + Type: string(v1beta1.RouteConditionAccepted), + Status: metav1.ConditionFalse, + Reason: RouteReasonInvalidGateway, + Message: "Gateway is invalid", + } +} + +// 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{ + Type: string(v1beta1.RouteConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.RouteReasonNoMatchingParent), + Message: "Listener is not found for this parent ref", + } +} + +// NewRouteGatewayNotProgrammed returns a Condition that indicates that the Gateway it references is not programmed, +// which does not guarantee that the HTTPRoute has been configured. +func NewRouteGatewayNotProgrammed(msg string) conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.RouteConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(RouteReasonGatewayNotProgrammed), + Message: msg, + } +} + +// NewDefaultListenerConditions returns the default Conditions that must be present in the status of a Listener. +func NewDefaultListenerConditions() []conditions.Condition { + return []conditions.Condition{ + NewListenerAccepted(), + NewListenerProgrammed(), + NewListenerResolvedRefs(), + NewListenerNoConflicts(), + } +} + +// NewListenerAccepted returns a Condition that indicates that the Listener is accepted. +func NewListenerAccepted() conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.ListenerConditionAccepted), + Status: metav1.ConditionTrue, + Reason: string(v1beta1.ListenerReasonAccepted), + Message: "Listener is accepted", + } +} + +// NewListenerProgrammed returns a Condition that indicates the Listener is programmed. +func NewListenerProgrammed() conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.ListenerConditionProgrammed), + Status: metav1.ConditionTrue, + Reason: string(v1beta1.ListenerReasonProgrammed), + Message: "Listener is programmed", + } +} + +// NewListenerResolvedRefs returns a Condition that indicates that all references in a Listener are resolved. +func NewListenerResolvedRefs() conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.ListenerConditionResolvedRefs), + Status: metav1.ConditionTrue, + Reason: string(v1beta1.ListenerReasonResolvedRefs), + Message: "All references are resolved", + } +} + +// NewListenerNoConflicts returns a Condition that indicates that there are no conflicts in a Listener. +func NewListenerNoConflicts() conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.ListenerConditionConflicted), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.ListenerReasonNoConflicts), + Message: "No conflicts", + } +} + +// 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{ + Type: string(v1beta1.ListenerConditionProgrammed), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.ListenerReasonInvalid), + Message: msg, + } +} + +// 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{ + { + Type: string(v1beta1.ListenerConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(ListenerReasonUnsupportedValue), + Message: msg, + }, + NewListenerNotProgrammedInvalid(msg), + } +} + +// NewListenerInvalidCertificateRef returns Conditions that indicate that a CertificateRef of a Listener is invalid. +func NewListenerInvalidCertificateRef(msg string) []conditions.Condition { + return []conditions.Condition{ + { + Type: string(v1beta1.ListenerConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.ListenerReasonInvalidCertificateRef), + Message: msg, + }, + { + Type: string(v1beta1.ListenerReasonResolvedRefs), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.ListenerReasonInvalidCertificateRef), + Message: msg, + }, + NewListenerNotProgrammedInvalid(msg), + } +} + +// 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{ + { + Type: string(v1beta1.ListenerReasonResolvedRefs), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.ListenerReasonInvalidRouteKinds), + Message: msg, + }, + NewListenerNotProgrammedInvalid(msg), + } +} + +// 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{ + { + Type: string(v1beta1.ListenerConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.ListenerReasonProtocolConflict), + Message: msg, + }, + { + Type: string(v1beta1.ListenerConditionConflicted), + Status: metav1.ConditionTrue, + Reason: string(v1beta1.ListenerReasonProtocolConflict), + Message: msg, + }, + NewListenerNotProgrammedInvalid(msg), + } +} + +// NewListenerUnsupportedProtocol returns Conditions that indicate that the protocol of a Listener is unsupported. +func NewListenerUnsupportedProtocol(msg string) []conditions.Condition { + return []conditions.Condition{ + { + Type: string(v1beta1.ListenerConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.ListenerReasonUnsupportedProtocol), + Message: msg, + }, + NewListenerNotProgrammedInvalid(msg), + } +} + +// 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{ + { + Type: string(v1beta1.ListenerConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.ListenerReasonRefNotPermitted), + Message: msg, + }, + { + Type: string(v1beta1.ListenerReasonResolvedRefs), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.ListenerReasonRefNotPermitted), + Message: msg, + }, + NewListenerNotProgrammedInvalid(msg), + } +} + +// NewGatewayClassInvalidParameters returns a Condition that indicates that the GatewayClass has invalid parameters. +func NewGatewayClassInvalidParameters(msg string) conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.GatewayClassConditionStatusAccepted), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.GatewayClassReasonInvalidParameters), + Message: msg, + } +} + +// NewDefaultGatewayConditions returns the default Conditions that must be present in the status of a Gateway. +func NewDefaultGatewayConditions() []conditions.Condition { + return []conditions.Condition{ + NewGatewayAccepted(), + NewGatewayProgrammed(), + } +} + +// NewGatewayAccepted returns a Condition that indicates the Gateway is accepted. +func NewGatewayAccepted() conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.GatewayConditionAccepted), + Status: metav1.ConditionTrue, + Reason: string(v1beta1.GatewayReasonAccepted), + Message: "Gateway is accepted", + } +} + +// NewGatewayConflict returns Conditions that indicate the Gateway has a conflict with another Gateway. +func NewGatewayConflict() []conditions.Condition { + return []conditions.Condition{ + { + Type: string(v1beta1.GatewayConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(GatewayReasonGatewayConflict), + Message: GatewayMessageGatewayConflict, + }, + NewGatewayConflictNotProgrammed(), + } +} + +// 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{ + Type: string(v1beta1.GatewayConditionAccepted), + Status: metav1.ConditionTrue, + Reason: string(v1beta1.GatewayReasonListenersNotValid), + Message: "Gateway has at least one valid listener", + } +} + +// NewGatewayNotAcceptedListenersNotValid returns Conditions that indicate the Gateway is not accepted, +// because all listeners are invalid. +func NewGatewayNotAcceptedListenersNotValid() []conditions.Condition { + msg := "Gateway has no valid listeners" + return []conditions.Condition{ + { + Type: string(v1beta1.GatewayConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.GatewayReasonListenersNotValid), + Message: msg, + }, + NewGatewayNotProgrammedInvalid(msg), + } +} + +// 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{ + { + Type: string(v1beta1.GatewayConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.GatewayReasonInvalid), + Message: msg, + }, + NewGatewayNotProgrammedInvalid(msg), + } +} + +// 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{ + { + Type: string(v1beta1.GatewayConditionAccepted), + Status: metav1.ConditionFalse, + Reason: string(GatewayReasonUnsupportedValue), + Message: msg, + }, + { + Type: string(v1beta1.GatewayConditionProgrammed), + Status: metav1.ConditionFalse, + Reason: string(GatewayReasonUnsupportedValue), + Message: msg, + }, + } +} + +// NewGatewayProgrammed returns a Condition that indicates the Gateway is programmed. +func NewGatewayProgrammed() conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.GatewayConditionProgrammed), + Status: metav1.ConditionTrue, + Reason: string(v1beta1.GatewayReasonProgrammed), + Message: "Gateway is programmed", + } +} + +// 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{ + Type: string(v1beta1.GatewayConditionProgrammed), + Status: metav1.ConditionFalse, + Reason: string(v1beta1.GatewayReasonInvalid), + Message: msg, + } +} + +// NewGatewayConflictNotProgrammed returns a custom Programmed Condition that indicates the Gateway has a +// conflict with another Gateway. +func NewGatewayConflictNotProgrammed() conditions.Condition { + return conditions.Condition{ + Type: string(v1beta1.GatewayConditionProgrammed), + Status: metav1.ConditionFalse, + Reason: string(GatewayReasonGatewayConflict), + Message: GatewayMessageGatewayConflict, + } +} diff --git a/internal/framework/conditions/conditions_test.go b/internal/mode/static/state/conditions/conditions_test.go similarity index 86% rename from internal/framework/conditions/conditions_test.go rename to internal/mode/static/state/conditions/conditions_test.go index b0510dc667..f1067899c8 100644 --- a/internal/framework/conditions/conditions_test.go +++ b/internal/mode/static/state/conditions/conditions_test.go @@ -5,12 +5,14 @@ import ( . "github.com/onsi/gomega" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" ) func TestDeduplicateConditions(t *testing.T) { g := NewGomegaWithT(t) - conds := []Condition{ + conds := []conditions.Condition{ { Type: "Type1", Status: metav1.ConditionTrue, @@ -38,7 +40,7 @@ func TestDeduplicateConditions(t *testing.T) { }, } - expected := []Condition{ + expected := []conditions.Condition{ { Type: "Type1", Status: metav1.ConditionFalse, diff --git a/internal/mode/static/state/graph/backend_refs.go b/internal/mode/static/state/graph/backend_refs.go index 016a201127..a5a9b2b42f 100644 --- a/internal/mode/static/state/graph/backend_refs.go +++ b/internal/mode/static/state/graph/backend_refs.go @@ -9,6 +9,7 @@ import ( "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + staticConds "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/conditions" ) // BackendRef is an internal representation of a backendRef in an HTTPRoute. @@ -122,7 +123,7 @@ func createBackendRef( Valid: false, } - cond := conditions.NewRouteBackendRefRefBackendNotFound(err.Error()) + cond := staticConds.NewRouteBackendRefRefBackendNotFound(err.Error()) return backendRef, &cond } @@ -168,7 +169,7 @@ func validateHTTPBackendRef( if len(ref.Filters) > 0 { valErr := field.TooMany(path.Child("filters"), len(ref.Filters), 0) - return false, conditions.NewRouteBackendRefUnsupportedValue(valErr.Error()) + return false, staticConds.NewRouteBackendRefUnsupportedValue(valErr.Error()) } return validateBackendRef(ref.BackendRef, routeNs, refGrantResolver, path) @@ -184,12 +185,12 @@ func validateBackendRef( if ref.Group != nil && !(*ref.Group == "core" || *ref.Group == "") { valErr := field.NotSupported(path.Child("group"), *ref.Group, []string{"core", ""}) - return false, conditions.NewRouteBackendRefInvalidKind(valErr.Error()) + return false, staticConds.NewRouteBackendRefInvalidKind(valErr.Error()) } if ref.Kind != nil && *ref.Kind != "Service" { valErr := field.NotSupported(path.Child("kind"), *ref.Kind, []string{"Service"}) - return false, conditions.NewRouteBackendRefInvalidKind(valErr.Error()) + return false, staticConds.NewRouteBackendRefInvalidKind(valErr.Error()) } // no need to validate ref.Name @@ -200,7 +201,7 @@ func validateBackendRef( if !refGrantResolver.refAllowed(toService(refNsName), fromHTTPRoute(routeNs)) { msg := fmt.Sprintf("Backend ref to Service %s not permitted by any ReferenceGrant", refNsName) - return false, conditions.NewRouteBackendRefRefNotPermitted(msg) + return false, staticConds.NewRouteBackendRefRefNotPermitted(msg) } } @@ -213,7 +214,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, conditions.NewRouteBackendRefUnsupportedValue(valErr.Error()) + return false, staticConds.NewRouteBackendRefUnsupportedValue(valErr.Error()) } } diff --git a/internal/mode/static/state/graph/backend_refs_test.go b/internal/mode/static/state/graph/backend_refs_test.go index 6e06a27551..d4fa16b4c2 100644 --- a/internal/mode/static/state/graph/backend_refs_test.go +++ b/internal/mode/static/state/graph/backend_refs_test.go @@ -13,6 +13,7 @@ import ( "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + staticConds "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/conditions" ) func getNormalRef() v1beta1.BackendRef { @@ -57,7 +58,7 @@ func TestValidateHTTPBackendRef(t *testing.T) { }, }, expectedValid: false, - expectedCondition: conditions.NewRouteBackendRefUnsupportedValue( + expectedCondition: staticConds.NewRouteBackendRefUnsupportedValue( "test.filters: Too many: 1: must have at most 0 items", ), }, @@ -70,7 +71,7 @@ func TestValidateHTTPBackendRef(t *testing.T) { }), }, expectedValid: false, - expectedCondition: conditions.NewRouteBackendRefInvalidKind( + expectedCondition: staticConds.NewRouteBackendRefInvalidKind( `test.kind: Unsupported value: "NotService": supported values: "Service"`, ), }, @@ -168,7 +169,7 @@ func TestValidateBackendRef(t *testing.T) { return backend }), expectedValid: false, - expectedCondition: conditions.NewRouteBackendRefInvalidKind( + expectedCondition: staticConds.NewRouteBackendRefInvalidKind( `test.group: Unsupported value: "invalid": supported values: "core", ""`, ), }, @@ -179,7 +180,7 @@ func TestValidateBackendRef(t *testing.T) { return backend }), expectedValid: false, - expectedCondition: conditions.NewRouteBackendRefInvalidKind( + expectedCondition: staticConds.NewRouteBackendRefInvalidKind( `test.kind: Unsupported value: "NotService": supported values: "Service"`, ), }, @@ -190,7 +191,7 @@ func TestValidateBackendRef(t *testing.T) { return backend }), expectedValid: false, - expectedCondition: conditions.NewRouteBackendRefRefNotPermitted( + expectedCondition: staticConds.NewRouteBackendRefRefNotPermitted( "Backend ref to Service invalid/service1 not permitted by any ReferenceGrant", ), }, @@ -201,7 +202,7 @@ func TestValidateBackendRef(t *testing.T) { return backend }), expectedValid: false, - expectedCondition: conditions.NewRouteBackendRefUnsupportedValue( + expectedCondition: staticConds.NewRouteBackendRefUnsupportedValue( "test.weight: Invalid value: -1: must be in the range [0, 1000000]", ), }, @@ -466,7 +467,7 @@ func TestAddBackendRefsToRulesTest(t *testing.T) { }, }, expectedConditions: []conditions.Condition{ - conditions.NewRouteBackendRefInvalidKind( + staticConds.NewRouteBackendRefInvalidKind( `spec.rules[0].backendRefs[0].kind: Unsupported value: "NotService": supported values: "Service"`, ), }, @@ -558,7 +559,7 @@ func TestCreateBackend(t *testing.T) { }, expectedServicePortReference: "", expectedCondition: helpers.GetPointer( - conditions.NewRouteBackendRefUnsupportedValue( + staticConds.NewRouteBackendRefUnsupportedValue( "test.weight: Invalid value: -1: must be in the range [0, 1000000]", ), ), @@ -579,7 +580,7 @@ func TestCreateBackend(t *testing.T) { }, expectedServicePortReference: "", expectedCondition: helpers.GetPointer( - conditions.NewRouteBackendRefInvalidKind( + staticConds.NewRouteBackendRefInvalidKind( `test.kind: Unsupported value: "NotService": supported values: "Service"`, ), ), @@ -600,7 +601,7 @@ func TestCreateBackend(t *testing.T) { }, expectedServicePortReference: "", expectedCondition: helpers.GetPointer( - conditions.NewRouteBackendRefRefBackendNotFound(`test.name: Not found: "not-exist"`), + staticConds.NewRouteBackendRefRefBackendNotFound(`test.name: Not found: "not-exist"`), ), name: "service doesn't exist", }, diff --git a/internal/mode/static/state/graph/gateway.go b/internal/mode/static/state/graph/gateway.go index 4e19a3b897..278cc996a1 100644 --- a/internal/mode/static/state/graph/gateway.go +++ b/internal/mode/static/state/graph/gateway.go @@ -10,6 +10,7 @@ import ( "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" nkgsort "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/sort" + staticConds "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/conditions" ) // Gateway represents the winning Gateway resource. @@ -120,16 +121,16 @@ func validateGateway(gw *v1beta1.Gateway, gc *GatewayClass) []conditions.Conditi var conds []conditions.Condition if gc == nil { - conds = append(conds, conditions.NewGatewayInvalid("GatewayClass doesn't exist")...) + conds = append(conds, staticConds.NewGatewayInvalid("GatewayClass doesn't exist")...) } else if !gc.Valid { - conds = append(conds, conditions.NewGatewayInvalid("GatewayClass is invalid")...) + conds = append(conds, staticConds.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, conditions.NewGatewayUnsupportedValue(valErr.Error())...) + conds = append(conds, staticConds.NewGatewayUnsupportedValue(valErr.Error())...) } return conds diff --git a/internal/mode/static/state/graph/gateway_listener.go b/internal/mode/static/state/graph/gateway_listener.go index ac2207d475..71e66a0f7c 100644 --- a/internal/mode/static/state/graph/gateway_listener.go +++ b/internal/mode/static/state/graph/gateway_listener.go @@ -11,6 +11,7 @@ import ( "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + staticConds "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/conditions" ) // Listener represents a Listener of the Gateway resource. @@ -83,7 +84,7 @@ func newListenerConfiguratorFactory( listener.Protocol, []string{string(v1beta1.HTTPProtocolType), string(v1beta1.HTTPSProtocolType)}, ) - return conditions.NewListenerUnsupportedProtocol(valErr.Error()) + return staticConds.NewListenerUnsupportedProtocol(valErr.Error()) }, }, }, @@ -156,7 +157,7 @@ func (c *listenerConfigurator) configure(listener v1beta1.Listener) *Listener { allowedRouteSelector, err = metav1.LabelSelectorAsSelector(selector) if err != nil { msg := fmt.Sprintf("invalid label selector: %s", err.Error()) - conds = append(conds, conditions.NewListenerUnsupportedValue(msg)...) + conds = append(conds, staticConds.NewListenerUnsupportedValue(msg)...) } } @@ -207,7 +208,7 @@ func validateListenerHostname(listener v1beta1.Listener) []conditions.Condition if err != nil { path := field.NewPath("hostname") valErr := field.Invalid(path, listener.Hostname, err.Error()) - return conditions.NewListenerUnsupportedValue(valErr.Error()) + return staticConds.NewListenerUnsupportedValue(valErr.Error()) } return nil } @@ -242,7 +243,7 @@ func getAndValidateListenerSupportedKinds(listener v1beta1.Listener) ( for _, kind := range listener.AllowedRoutes.Kinds { if !validHTTPRouteKind(kind) { msg := fmt.Sprintf("Unsupported route kind \"%s/%s\"", *kind.Group, kind.Kind) - conds = append(conds, conditions.NewListenerInvalidRouteKinds(msg)...) + conds = append(conds, staticConds.NewListenerInvalidRouteKinds(msg)...) continue } supportedKinds = append(supportedKinds, kind) @@ -268,7 +269,7 @@ func validateListenerLabelSelector(listener v1beta1.Listener) []conditions.Condi *listener.AllowedRoutes.Namespaces.From == v1beta1.NamespacesFromSelector && listener.AllowedRoutes.Namespaces.Selector == nil { msg := "Listener's AllowedRoutes Selector must be set when From is set to type Selector" - return conditions.NewListenerUnsupportedValue(msg) + return staticConds.NewListenerUnsupportedValue(msg) } return nil @@ -278,7 +279,7 @@ func validateHTTPListener(listener v1beta1.Listener) []conditions.Condition { if err := validateListenerPort(listener.Port); err != nil { path := field.NewPath("port") valErr := field.Invalid(path, listener.Port, err.Error()) - return conditions.NewListenerUnsupportedValue(valErr.Error()) + return staticConds.NewListenerUnsupportedValue(valErr.Error()) } if listener.TLS != nil { @@ -303,7 +304,7 @@ func createHTTPSListenerValidator() listenerValidator { if err := validateListenerPort(listener.Port); err != nil { path := field.NewPath("port") valErr := field.Invalid(path, listener.Port, err.Error()) - conds = append(conds, conditions.NewListenerUnsupportedValue(valErr.Error())...) + conds = append(conds, staticConds.NewListenerUnsupportedValue(valErr.Error())...) } if listener.TLS == nil { @@ -318,13 +319,13 @@ func createHTTPSListenerValidator() listenerValidator { *listener.TLS.Mode, []string{string(v1beta1.TLSModeTerminate)}, ) - conds = append(conds, conditions.NewListenerUnsupportedValue(valErr.Error())...) + conds = append(conds, staticConds.NewListenerUnsupportedValue(valErr.Error())...) } if len(listener.TLS.Options) > 0 { path := tlsPath.Child("options") valErr := field.Forbidden(path, "options are not supported") - conds = append(conds, conditions.NewListenerUnsupportedValue(valErr.Error())...) + conds = append(conds, staticConds.NewListenerUnsupportedValue(valErr.Error())...) } if len(listener.TLS.CertificateRefs) == 0 { @@ -338,20 +339,20 @@ func createHTTPSListenerValidator() listenerValidator { if certRef.Kind != nil && *certRef.Kind != "Secret" { path := certRefPath.Child("kind") valErr := field.NotSupported(path, *certRef.Kind, []string{"Secret"}) - conds = append(conds, conditions.NewListenerInvalidCertificateRef(valErr.Error())...) + conds = append(conds, staticConds.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, conditions.NewListenerInvalidCertificateRef(valErr.Error())...) + conds = append(conds, staticConds.NewListenerInvalidCertificateRef(valErr.Error())...) } if l := len(listener.TLS.CertificateRefs); l > 1 { path := tlsPath.Child("certificateRefs") valErr := field.TooMany(path, l, 1) - conds = append(conds, conditions.NewListenerUnsupportedValue(valErr.Error())...) + conds = append(conds, staticConds.NewListenerUnsupportedValue(valErr.Error())...) } return conds @@ -373,7 +374,7 @@ func createPortConflictResolver() listenerConflictResolver { if conflictedPorts[port] { l.Valid = false - conflictedConds := conditions.NewListenerProtocolConflict(fmt.Sprintf(format, port)) + conflictedConds := staticConds.NewListenerProtocolConflict(fmt.Sprintf(format, port)) l.Conditions = append(l.Conditions, conflictedConds...) return } @@ -395,7 +396,7 @@ func createPortConflictResolver() listenerConflictResolver { conflictedPorts[port] = true for _, l := range listenersByPort[port] { l.Valid = false - conflictedConds := conditions.NewListenerProtocolConflict(fmt.Sprintf(format, port)) + conflictedConds := staticConds.NewListenerProtocolConflict(fmt.Sprintf(format, port)) l.Conditions = append(l.Conditions, conflictedConds...) } } @@ -424,7 +425,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, conditions.NewListenerRefNotPermitted(msg)...) + l.Conditions = append(l.Conditions, staticConds.NewListenerRefNotPermitted(msg)...) l.Valid = false return } @@ -435,7 +436,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, conditions.NewListenerInvalidCertificateRef(valErr.Error())...) + l.Conditions = append(l.Conditions, staticConds.NewListenerInvalidCertificateRef(valErr.Error())...) l.Valid = false } else { l.ResolvedSecret = &certRefNsName diff --git a/internal/mode/static/state/graph/gateway_listener_test.go b/internal/mode/static/state/graph/gateway_listener_test.go index 8abb2ed683..191244047d 100644 --- a/internal/mode/static/state/graph/gateway_listener_test.go +++ b/internal/mode/static/state/graph/gateway_listener_test.go @@ -10,6 +10,7 @@ import ( "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + staticConds "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/conditions" ) func TestValidateHTTPListener(t *testing.T) { @@ -29,7 +30,7 @@ func TestValidateHTTPListener(t *testing.T) { l: v1beta1.Listener{ Port: 0, }, - expected: conditions.NewListenerUnsupportedValue(`port: Invalid value: 0: port must be between 1-65535`), + expected: staticConds.NewListenerUnsupportedValue(`port: Invalid value: 0: port must be between 1-65535`), name: "invalid port", }, } @@ -90,7 +91,7 @@ func TestValidateHTTPSListener(t *testing.T) { CertificateRefs: []v1beta1.SecretObjectReference{validSecretRef}, }, }, - expected: conditions.NewListenerUnsupportedValue(`port: Invalid value: 0: port must be between 1-65535`), + expected: staticConds.NewListenerUnsupportedValue(`port: Invalid value: 0: port must be between 1-65535`), name: "invalid port", }, { @@ -102,7 +103,7 @@ func TestValidateHTTPSListener(t *testing.T) { Options: map[v1beta1.AnnotationKey]v1beta1.AnnotationValue{"key": "val"}, }, }, - expected: conditions.NewListenerUnsupportedValue("tls.options: Forbidden: options are not supported"), + expected: staticConds.NewListenerUnsupportedValue("tls.options: Forbidden: options are not supported"), name: "invalid options", }, { @@ -113,7 +114,7 @@ func TestValidateHTTPSListener(t *testing.T) { CertificateRefs: []v1beta1.SecretObjectReference{validSecretRef}, }, }, - expected: conditions.NewListenerUnsupportedValue( + expected: staticConds.NewListenerUnsupportedValue( `tls.mode: Unsupported value: "Passthrough": supported values: "Terminate"`, ), name: "invalid tls mode", @@ -126,7 +127,7 @@ func TestValidateHTTPSListener(t *testing.T) { CertificateRefs: []v1beta1.SecretObjectReference{invalidSecretRefGroup}, }, }, - expected: conditions.NewListenerInvalidCertificateRef( + expected: staticConds.NewListenerInvalidCertificateRef( `tls.certificateRefs[0].group: Unsupported value: "some-group": supported values: ""`, ), name: "invalid cert ref group", @@ -139,7 +140,7 @@ func TestValidateHTTPSListener(t *testing.T) { CertificateRefs: []v1beta1.SecretObjectReference{invalidSecretRefKind}, }, }, - expected: conditions.NewListenerInvalidCertificateRef( + expected: staticConds.NewListenerInvalidCertificateRef( `tls.certificateRefs[0].kind: Unsupported value: "ConfigMap": supported values: "Secret"`, ), name: "invalid cert ref kind", @@ -152,7 +153,7 @@ func TestValidateHTTPSListener(t *testing.T) { CertificateRefs: []v1beta1.SecretObjectReference{validSecretRef, validSecretRef}, }, }, - expected: conditions.NewListenerUnsupportedValue( + expected: staticConds.NewListenerUnsupportedValue( "tls.certificateRefs: Too many: 2: must have at most 1 items", ), name: "too many cert refs", diff --git a/internal/mode/static/state/graph/gateway_test.go b/internal/mode/static/state/graph/gateway_test.go index 1114464880..e5fdb85d44 100644 --- a/internal/mode/static/state/graph/gateway_test.go +++ b/internal/mode/static/state/graph/gateway_test.go @@ -12,8 +12,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + staticConds "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/conditions" ) func TestProcessedGatewaysGetAllNsNames(t *testing.T) { @@ -475,7 +475,7 @@ func TestBuildGateway(t *testing.T) { "listener-cross-ns-secret": { Source: crossNamespaceSecretListener, Valid: false, - Conditions: conditions.NewListenerRefNotPermitted( + Conditions: staticConds.NewListenerRefNotPermitted( `Certificate ref to secret diff-ns/secret not permitted by any ReferenceGrant`, ), Routes: map[types.NamespacedName]*Route{}, @@ -497,7 +497,7 @@ func TestBuildGateway(t *testing.T) { "listener-with-invalid-selector": { Source: listenerInvalidSelector, Valid: false, - Conditions: conditions.NewListenerUnsupportedValue( + Conditions: staticConds.NewListenerUnsupportedValue( `invalid label selector: "invalid" is not a valid label selector operator`, ), SupportedKinds: []v1beta1.RouteGroupKind{ @@ -518,7 +518,7 @@ func TestBuildGateway(t *testing.T) { "invalid-protocol": { Source: invalidProtocolListener, Valid: false, - Conditions: conditions.NewListenerUnsupportedProtocol( + Conditions: staticConds.NewListenerUnsupportedProtocol( `protocol: Unsupported value: "TCP": supported values: "HTTP", "HTTPS"`, ), SupportedKinds: []v1beta1.RouteGroupKind{ @@ -541,7 +541,7 @@ func TestBuildGateway(t *testing.T) { "invalid-port": { Source: invalidPortListener, Valid: false, - Conditions: conditions.NewListenerUnsupportedValue( + Conditions: staticConds.NewListenerUnsupportedValue( `port: Invalid value: 0: port must be between 1-65535`, ), SupportedKinds: []v1beta1.RouteGroupKind{ @@ -551,7 +551,7 @@ func TestBuildGateway(t *testing.T) { "invalid-https-port": { Source: invalidHTTPSPortListener, Valid: false, - Conditions: conditions.NewListenerUnsupportedValue( + Conditions: staticConds.NewListenerUnsupportedValue( `port: Invalid value: 0: port must be between 1-65535`, ), SupportedKinds: []v1beta1.RouteGroupKind{ @@ -574,7 +574,7 @@ func TestBuildGateway(t *testing.T) { "invalid-hostname": { Source: invalidHostnameListener, Valid: false, - Conditions: conditions.NewListenerUnsupportedValue(invalidHostnameMsg), + Conditions: staticConds.NewListenerUnsupportedValue(invalidHostnameMsg), SupportedKinds: []v1beta1.RouteGroupKind{ {Kind: "HTTPRoute"}, }, @@ -582,7 +582,7 @@ func TestBuildGateway(t *testing.T) { "invalid-https-hostname": { Source: invalidHTTPSHostnameListener, Valid: false, - Conditions: conditions.NewListenerUnsupportedValue(invalidHostnameMsg), + Conditions: staticConds.NewListenerUnsupportedValue(invalidHostnameMsg), SupportedKinds: []v1beta1.RouteGroupKind{ {Kind: "HTTPRoute"}, }, @@ -602,7 +602,7 @@ func TestBuildGateway(t *testing.T) { Source: invalidTLSConfigListener, Valid: false, Routes: map[types.NamespacedName]*Route{}, - Conditions: conditions.NewListenerInvalidCertificateRef( + Conditions: staticConds.NewListenerInvalidCertificateRef( `tls.certificateRefs[0]: Invalid value: test/does-not-exist: secret does not exist`, ), SupportedKinds: []v1beta1.RouteGroupKind{ @@ -727,7 +727,7 @@ func TestBuildGateway(t *testing.T) { Source: foo80Listener1, Valid: false, Routes: map[types.NamespacedName]*Route{}, - Conditions: conditions.NewListenerProtocolConflict(conflict80PortMsg), + Conditions: staticConds.NewListenerProtocolConflict(conflict80PortMsg), SupportedKinds: []v1beta1.RouteGroupKind{ {Kind: "HTTPRoute"}, }, @@ -736,7 +736,7 @@ func TestBuildGateway(t *testing.T) { Source: bar80Listener, Valid: false, Routes: map[types.NamespacedName]*Route{}, - Conditions: conditions.NewListenerProtocolConflict(conflict80PortMsg), + Conditions: staticConds.NewListenerProtocolConflict(conflict80PortMsg), SupportedKinds: []v1beta1.RouteGroupKind{ {Kind: "HTTPRoute"}, }, @@ -745,7 +745,7 @@ func TestBuildGateway(t *testing.T) { Source: foo443Listener, Valid: false, Routes: map[types.NamespacedName]*Route{}, - Conditions: conditions.NewListenerProtocolConflict(conflict443PortMsg), + Conditions: staticConds.NewListenerProtocolConflict(conflict443PortMsg), SupportedKinds: []v1beta1.RouteGroupKind{ {Kind: "HTTPRoute"}, }, @@ -754,7 +754,7 @@ func TestBuildGateway(t *testing.T) { Source: foo80HTTPSListener, Valid: false, Routes: map[types.NamespacedName]*Route{}, - Conditions: conditions.NewListenerProtocolConflict(conflict80PortMsg), + Conditions: staticConds.NewListenerProtocolConflict(conflict80PortMsg), ResolvedSecret: helpers.GetPointer(client.ObjectKeyFromObject(secretSameNs)), SupportedKinds: []v1beta1.RouteGroupKind{ {Kind: "HTTPRoute"}, @@ -764,7 +764,7 @@ func TestBuildGateway(t *testing.T) { Source: foo443HTTPSListener1, Valid: false, Routes: map[types.NamespacedName]*Route{}, - Conditions: conditions.NewListenerProtocolConflict(conflict443PortMsg), + Conditions: staticConds.NewListenerProtocolConflict(conflict443PortMsg), ResolvedSecret: helpers.GetPointer(client.ObjectKeyFromObject(secretSameNs)), SupportedKinds: []v1beta1.RouteGroupKind{ {Kind: "HTTPRoute"}, @@ -774,7 +774,7 @@ func TestBuildGateway(t *testing.T) { Source: bar443HTTPSListener, Valid: false, Routes: map[types.NamespacedName]*Route{}, - Conditions: conditions.NewListenerProtocolConflict(conflict443PortMsg), + Conditions: staticConds.NewListenerProtocolConflict(conflict443PortMsg), ResolvedSecret: helpers.GetPointer(client.ObjectKeyFromObject(secretSameNs)), SupportedKinds: []v1beta1.RouteGroupKind{ {Kind: "HTTPRoute"}, @@ -796,7 +796,7 @@ func TestBuildGateway(t *testing.T) { expected: &Gateway{ Source: getLastCreatedGetaway(), Valid: false, - Conditions: conditions.NewGatewayUnsupportedValue("spec." + + Conditions: staticConds.NewGatewayUnsupportedValue("spec." + "addresses: Forbidden: addresses are not supported", ), }, @@ -815,7 +815,7 @@ func TestBuildGateway(t *testing.T) { expected: &Gateway{ Source: getLastCreatedGetaway(), Valid: false, - Conditions: conditions.NewGatewayInvalid("GatewayClass is invalid"), + Conditions: staticConds.NewGatewayInvalid("GatewayClass is invalid"), }, name: "invalid gatewayclass", }, @@ -827,7 +827,7 @@ func TestBuildGateway(t *testing.T) { expected: &Gateway{ Source: getLastCreatedGetaway(), Valid: false, - Conditions: conditions.NewGatewayInvalid("GatewayClass doesn't exist"), + Conditions: staticConds.NewGatewayInvalid("GatewayClass doesn't exist"), }, name: "nil gatewayclass", }, diff --git a/internal/mode/static/state/graph/gatewayclass.go b/internal/mode/static/state/graph/gatewayclass.go index 60a6f268d3..feb0e7989f 100644 --- a/internal/mode/static/state/graph/gatewayclass.go +++ b/internal/mode/static/state/graph/gatewayclass.go @@ -7,6 +7,7 @@ import ( "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + staticConds "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/conditions" ) // GatewayClass represents the GatewayClass resource. @@ -64,7 +65,7 @@ func buildGatewayClass(gc *v1beta1.GatewayClass) *GatewayClass { valErr := validateGatewayClass(gc) if valErr != nil { - conds = append(conds, conditions.NewGatewayClassInvalidParameters(valErr.Error())) + conds = append(conds, staticConds.NewGatewayClassInvalidParameters(valErr.Error())) } return &GatewayClass{ diff --git a/internal/mode/static/state/graph/gatewayclass_test.go b/internal/mode/static/state/graph/gatewayclass_test.go index c9c2589982..789cbe1002 100644 --- a/internal/mode/static/state/graph/gatewayclass_test.go +++ b/internal/mode/static/state/graph/gatewayclass_test.go @@ -11,6 +11,7 @@ import ( "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + staticConds "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/conditions" ) func TestProcessGatewayClasses(t *testing.T) { @@ -150,7 +151,7 @@ func TestBuildGatewayClass(t *testing.T) { Source: invalidGC, Valid: false, Conditions: []conditions.Condition{ - conditions.NewGatewayClassInvalidParameters( + staticConds.NewGatewayClassInvalidParameters( "spec.parametersRef: Forbidden: parametersRef is not supported", ), }, diff --git a/internal/mode/static/state/graph/httproute.go b/internal/mode/static/state/graph/httproute.go index 4b31471240..f0b6d3802d 100644 --- a/internal/mode/static/state/graph/httproute.go +++ b/internal/mode/static/state/graph/httproute.go @@ -13,6 +13,7 @@ import ( "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" + staticConds "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/conditions" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/validation" ) @@ -182,7 +183,7 @@ func buildRoute( err := validateHostnames(ghr.Spec.Hostnames, field.NewPath("spec").Child("hostnames")) if err != nil { r.Valid = false - r.Conditions = append(r.Conditions, conditions.NewRouteUnsupportedValue(err.Error())) + r.Conditions = append(r.Conditions, staticConds.NewRouteUnsupportedValue(err.Error())) return r } @@ -233,10 +234,10 @@ func buildRoute( // FIXME(pleshakov): Partial validity for HTTPRoute rules is not defined in the Gateway API spec yet. // See https://github.com/nginxinc/nginx-kubernetes-gateway/issues/485 msg = "Some rules are invalid: " + msg - r.Conditions = append(r.Conditions, conditions.NewTODO(msg)) + r.Conditions = append(r.Conditions, staticConds.NewTODO(msg)) } else { msg = "All rules are invalid: " + msg - r.Conditions = append(r.Conditions, conditions.NewRouteUnsupportedValue(msg)) + r.Conditions = append(r.Conditions, staticConds.NewRouteUnsupportedValue(msg)) r.Valid = false } @@ -279,7 +280,7 @@ func bindRouteToListeners(r *Route, gw *Gateway, namespaces map[types.Namespaced if routeRef.Port != nil { valErr := field.Forbidden(path.Child("port"), "cannot be set") - attachment.FailedCondition = conditions.NewRouteUnsupportedValue(valErr.Error()) + attachment.FailedCondition = staticConds.NewRouteUnsupportedValue(valErr.Error()) continue } @@ -288,14 +289,14 @@ func bindRouteToListeners(r *Route, gw *Gateway, namespaces map[types.Namespaced referencesWinningGw := ref.Gateway.Namespace == gw.Source.Namespace && ref.Gateway.Name == gw.Source.Name if !referencesWinningGw { - attachment.FailedCondition = conditions.NewTODO("Gateway is ignored") + attachment.FailedCondition = staticConds.NewTODO("Gateway is ignored") continue } // Case 3: Attachment is not possible because Gateway is invalid if !gw.Valid { - attachment.FailedCondition = conditions.NewRouteInvalidGateway() + attachment.FailedCondition = staticConds.NewRouteInvalidGateway() continue } @@ -325,11 +326,11 @@ func tryToAttachRouteToListeners( validListeners, listenerExists := findValidListeners(getSectionName(sectionName), gw.Listeners) if !listenerExists { - return conditions.NewRouteNoMatchingParent(), false + return staticConds.NewRouteNoMatchingParent(), false } if len(validListeners) == 0 { - return conditions.NewRouteInvalidListener(), false + return staticConds.NewRouteInvalidListener(), false } bind := func(l *Listener) (allowed, attached bool) { @@ -357,9 +358,9 @@ func tryToAttachRouteToListeners( if !attached { if !allowed { - return conditions.NewRouteNotAllowedByListeners(), false + return staticConds.NewRouteNotAllowedByListeners(), false } - return conditions.NewRouteNoMatchingListenerHostname(), false + return staticConds.NewRouteNoMatchingListenerHostname(), false } return conditions.Condition{}, true diff --git a/internal/mode/static/state/graph/httproute_test.go b/internal/mode/static/state/graph/httproute_test.go index 71ce1ffce5..2f954f64d8 100644 --- a/internal/mode/static/state/graph/httproute_test.go +++ b/internal/mode/static/state/graph/httproute_test.go @@ -16,6 +16,7 @@ import ( "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers" + staticConds "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/conditions" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/validation/validationfakes" ) @@ -422,7 +423,9 @@ func TestBuildRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - conditions.NewRouteUnsupportedValue(`spec.hostnames[0]: Invalid value: "": cannot be empty string`), + staticConds.NewRouteUnsupportedValue( + `spec.hostnames[0]: Invalid value: "": cannot be empty string`, + ), }, }, name: "invalid hostname", @@ -440,7 +443,7 @@ func TestBuildRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - conditions.NewRouteUnsupportedValue( + staticConds.NewRouteUnsupportedValue( `All rules are invalid: spec.rules[0].matches[0].path.value: Invalid value: "/invalid": invalid path`, ), }, @@ -466,7 +469,7 @@ func TestBuildRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - conditions.NewRouteUnsupportedValue( + staticConds.NewRouteUnsupportedValue( `All rules are invalid: spec.rules[0].filters[0].requestRedirect.hostname: ` + `Invalid value: "invalid.example.com": invalid hostname`), }, @@ -492,7 +495,7 @@ func TestBuildRoute(t *testing.T) { }, }, Conditions: []conditions.Condition{ - conditions.NewTODO( + staticConds.NewTODO( `Some rules are invalid: ` + `[spec.rules[0].matches[0].path.value: Invalid value: "/invalid": invalid path, ` + `spec.rules[1].filters[0].requestRedirect.hostname: Invalid value: ` + @@ -804,7 +807,7 @@ func TestBindRouteToListeners(t *testing.T) { Gateway: client.ObjectKeyFromObject(gw), Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedCondition: conditions.NewRouteInvalidListener(), + FailedCondition: staticConds.NewRouteInvalidListener(), AcceptedHostnames: map[string][]string{}, }, }, @@ -829,7 +832,7 @@ func TestBindRouteToListeners(t *testing.T) { Gateway: client.ObjectKeyFromObject(gw), Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedCondition: conditions.NewRouteUnsupportedValue( + FailedCondition: staticConds.NewRouteUnsupportedValue( `spec.parentRefs[0].port: Forbidden: cannot be set`, ), AcceptedHostnames: map[string][]string{}, @@ -856,7 +859,7 @@ func TestBindRouteToListeners(t *testing.T) { Gateway: client.ObjectKeyFromObject(gw), Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedCondition: conditions.NewRouteNoMatchingParent(), + FailedCondition: staticConds.NewRouteNoMatchingParent(), AcceptedHostnames: map[string][]string{}, }, }, @@ -881,7 +884,7 @@ func TestBindRouteToListeners(t *testing.T) { Gateway: client.ObjectKeyFromObject(gw), Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedCondition: conditions.NewRouteInvalidListener(), + FailedCondition: staticConds.NewRouteInvalidListener(), AcceptedHostnames: map[string][]string{}, }, }, @@ -906,7 +909,7 @@ func TestBindRouteToListeners(t *testing.T) { Gateway: client.ObjectKeyFromObject(gw), Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedCondition: conditions.NewRouteNoMatchingListenerHostname(), + FailedCondition: staticConds.NewRouteNoMatchingListenerHostname(), AcceptedHostnames: map[string][]string{}, }, }, @@ -931,7 +934,7 @@ func TestBindRouteToListeners(t *testing.T) { Gateway: ignoredGwNsName, Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedCondition: conditions.NewTODO("Gateway is ignored"), + FailedCondition: staticConds.NewTODO("Gateway is ignored"), AcceptedHostnames: map[string][]string{}, }, }, @@ -977,7 +980,7 @@ func TestBindRouteToListeners(t *testing.T) { Gateway: client.ObjectKeyFromObject(gw), Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedCondition: conditions.NewRouteInvalidGateway(), + FailedCondition: staticConds.NewRouteInvalidGateway(), AcceptedHostnames: map[string][]string{}, }, }, @@ -1010,7 +1013,7 @@ func TestBindRouteToListeners(t *testing.T) { Gateway: client.ObjectKeyFromObject(gw), Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedCondition: conditions.NewRouteNotAllowedByListeners(), + FailedCondition: staticConds.NewRouteNotAllowedByListeners(), AcceptedHostnames: map[string][]string{}, }, }, @@ -1094,7 +1097,7 @@ func TestBindRouteToListeners(t *testing.T) { Gateway: client.ObjectKeyFromObject(gwDiffNamespace), Attachment: &ParentRefAttachmentStatus{ Attached: false, - FailedCondition: conditions.NewRouteNotAllowedByListeners(), + FailedCondition: staticConds.NewRouteNotAllowedByListeners(), AcceptedHostnames: map[string][]string{}, }, }, From cbaff4d4a6f7df61151ce28b8b1fb5cad8dd1fb1 Mon Sep 17 00:00:00 2001 From: Kate Osborn Date: Tue, 11 Jul 2023 12:54:14 -0600 Subject: [PATCH 7/7] Make static event handler private --- internal/mode/static/handler.go | 72 ++++++++++++++-------------- internal/mode/static/handler_test.go | 21 ++++---- internal/mode/static/manager.go | 16 +++---- 3 files changed, 54 insertions(+), 55 deletions(-) diff --git a/internal/mode/static/handler.go b/internal/mode/static/handler.go index 1376187b0b..2fea22e0b1 100644 --- a/internal/mode/static/handler.go +++ b/internal/mode/static/handler.go @@ -16,77 +16,77 @@ import ( "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/resolver" ) -// EventHandlerConfig holds configuration parameters for EventHandlerImpl. -type EventHandlerConfig struct { - // Processor is the state ChangeProcessor. - Processor state.ChangeProcessor - // ServiceResolver resolves Services to Endpoints. - ServiceResolver resolver.ServiceResolver - // Generator is the nginx config Generator. - Generator config.Generator - // NginxFileMgr is the file Manager for nginx. - NginxFileMgr file.Manager - // NginxRuntimeMgr manages nginx runtime. - NginxRuntimeMgr runtime.Manager - // StatusUpdater updates statuses on Kubernetes resources. - StatusUpdater status.Updater - // Logger is the logger to be used by the EventHandler. - Logger logr.Logger +// eventHandlerConfig holds configuration parameters for eventHandlerImpl. +type eventHandlerConfig struct { + // processor is the state ChangeProcessor. + processor state.ChangeProcessor + // serviceResolver resolves Services to Endpoints. + serviceResolver resolver.ServiceResolver + // generator is the nginx config generator. + generator config.Generator + // nginxFileMgr is the file Manager for nginx. + nginxFileMgr file.Manager + // nginxRuntimeMgr manages nginx runtime. + nginxRuntimeMgr runtime.Manager + // statusUpdater updates statuses on Kubernetes resources. + statusUpdater status.Updater + // logger is the logger to be used by the EventHandler. + logger logr.Logger } -// EventHandlerImpl implements EventHandler. -// EventHandlerImpl is responsible for: +// eventHandlerImpl implements EventHandler. +// eventHandlerImpl is responsible for: // (1) Reconciling the Gateway API and Kubernetes built-in resources with the NGINX configuration. // (2) Keeping the statuses of the Gateway API resources updated. -type EventHandlerImpl struct { - cfg EventHandlerConfig +type eventHandlerImpl struct { + cfg eventHandlerConfig } -// NewEventHandlerImpl creates a new EventHandlerImpl. -func NewEventHandlerImpl(cfg EventHandlerConfig) *EventHandlerImpl { - return &EventHandlerImpl{ +// newEventHandlerImpl creates a new eventHandlerImpl. +func newEventHandlerImpl(cfg eventHandlerConfig) *eventHandlerImpl { + return &eventHandlerImpl{ cfg: cfg, } } -func (h *EventHandlerImpl) HandleEventBatch(ctx context.Context, batch events.EventBatch) { +func (h *eventHandlerImpl) HandleEventBatch(ctx context.Context, batch events.EventBatch) { for _, event := range batch { switch e := event.(type) { case *events.UpsertEvent: - h.cfg.Processor.CaptureUpsertChange(e.Resource) + h.cfg.processor.CaptureUpsertChange(e.Resource) case *events.DeleteEvent: - h.cfg.Processor.CaptureDeleteChange(e.Type, e.NamespacedName) + h.cfg.processor.CaptureDeleteChange(e.Type, e.NamespacedName) default: panic(fmt.Errorf("unknown event type %T", e)) } } - changed, graph := h.cfg.Processor.Process() + changed, graph := h.cfg.processor.Process() if !changed { - h.cfg.Logger.Info("Handling events didn't result into NGINX configuration changes") + h.cfg.logger.Info("Handling events didn't result into NGINX configuration changes") return } var nginxReloadRes nginxReloadResult - err := h.updateNginx(ctx, dataplane.BuildConfiguration(ctx, graph, h.cfg.ServiceResolver)) + err := h.updateNginx(ctx, dataplane.BuildConfiguration(ctx, graph, h.cfg.serviceResolver)) if err != nil { - h.cfg.Logger.Error(err, "Failed to update NGINX configuration") + h.cfg.logger.Error(err, "Failed to update NGINX configuration") nginxReloadRes.error = err } else { - h.cfg.Logger.Info("NGINX configuration was successfully updated") + h.cfg.logger.Info("NGINX configuration was successfully updated") } - h.cfg.StatusUpdater.Update(ctx, buildStatuses(graph, nginxReloadRes)) + h.cfg.statusUpdater.Update(ctx, buildStatuses(graph, nginxReloadRes)) } -func (h *EventHandlerImpl) updateNginx(ctx context.Context, conf dataplane.Configuration) error { - files := h.cfg.Generator.Generate(conf) +func (h *eventHandlerImpl) updateNginx(ctx context.Context, conf dataplane.Configuration) error { + files := h.cfg.generator.Generate(conf) - if err := h.cfg.NginxFileMgr.ReplaceFiles(files); err != nil { + if err := h.cfg.nginxFileMgr.ReplaceFiles(files); err != nil { return fmt.Errorf("failed to replace NGINX configuration files: %w", err) } - if err := h.cfg.NginxRuntimeMgr.Reload(ctx); err != nil { + if err := h.cfg.nginxRuntimeMgr.Reload(ctx); err != nil { return fmt.Errorf("failed to reload NGINX: %w", err) } diff --git a/internal/mode/static/handler_test.go b/internal/mode/static/handler_test.go index e868de1a0c..3d937262ea 100644 --- a/internal/mode/static/handler_test.go +++ b/internal/mode/static/handler_test.go @@ -1,4 +1,4 @@ -package static_test +package static import ( "context" @@ -11,7 +11,6 @@ import ( "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events" "github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/status/statusfakes" - "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/config/configfakes" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file" "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/nginx/file/filefakes" @@ -21,9 +20,9 @@ import ( "github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/state/statefakes" ) -var _ = Describe("EventHandler", func() { +var _ = Describe("eventHandler", func() { var ( - handler *static.EventHandlerImpl + handler *eventHandlerImpl fakeProcessor *statefakes.FakeChangeProcessor fakeGenerator *configfakes.FakeGenerator fakeNginxFileMgr *filefakes.FakeManager @@ -53,13 +52,13 @@ var _ = Describe("EventHandler", func() { fakeNginxRuntimeMgr = &runtimefakes.FakeManager{} fakeStatusUpdater = &statusfakes.FakeUpdater{} - handler = static.NewEventHandlerImpl(static.EventHandlerConfig{ - Processor: fakeProcessor, - Generator: fakeGenerator, - Logger: zap.New(), - NginxFileMgr: fakeNginxFileMgr, - NginxRuntimeMgr: fakeNginxRuntimeMgr, - StatusUpdater: fakeStatusUpdater, + handler = newEventHandlerImpl(eventHandlerConfig{ + processor: fakeProcessor, + generator: fakeGenerator, + logger: zap.New(), + nginxFileMgr: fakeNginxFileMgr, + nginxRuntimeMgr: fakeNginxRuntimeMgr, + statusUpdater: fakeStatusUpdater, }) }) diff --git a/internal/mode/static/manager.go b/internal/mode/static/manager.go index 95bedad3bb..50cd5b078a 100644 --- a/internal/mode/static/manager.go +++ b/internal/mode/static/manager.go @@ -168,14 +168,14 @@ func StartManager(cfg config.Config) error { UpdateGatewayClassStatus: cfg.UpdateGatewayClassStatus, }) - eventHandler := NewEventHandlerImpl(EventHandlerConfig{ - Processor: processor, - ServiceResolver: resolver.NewServiceResolverImpl(mgr.GetClient()), - Generator: configGenerator, - Logger: cfg.Logger.WithName("eventHandler"), - NginxFileMgr: nginxFileMgr, - NginxRuntimeMgr: nginxRuntimeMgr, - StatusUpdater: statusUpdater, + eventHandler := newEventHandlerImpl(eventHandlerConfig{ + processor: processor, + serviceResolver: resolver.NewServiceResolverImpl(mgr.GetClient()), + generator: configGenerator, + logger: cfg.Logger.WithName("eventHandler"), + nginxFileMgr: nginxFileMgr, + nginxRuntimeMgr: nginxRuntimeMgr, + statusUpdater: statusUpdater, }) objects, objectLists := prepareFirstEventBatchPreparerArgs(cfg.GatewayClassName, cfg.GatewayNsName)