Skip to content

Refactor internal package organization #839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ dist/
node_modules/

# JS test coverage
internal/nginx/modules/coverage
internal/mode/static/nginx/modules/coverage
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 4 additions & 4 deletions cmd/gateway/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/mode/provisioner"
"github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static"
"github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/config"
)

const (
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion conformance/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
102 changes: 0 additions & 102 deletions internal/events/handler.go

This file was deleted.

48 changes: 48 additions & 0 deletions internal/framework/conditions/conditions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package conditions

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/gateway-api/apis/v1beta1"
)

const (
// GatewayClassReasonGatewayClassConflict indicates there are multiple GatewayClass resources
// that reference this controller, and we ignored the resource in question and picked the
// GatewayClass that is referenced in the command-line argument.
// This reason is used with GatewayClassConditionAccepted (false).
GatewayClassReasonGatewayClassConflict v1beta1.GatewayClassConditionReason = "GatewayClassConflict"

// GatewayClassMessageGatewayClassConflict is a message that describes GatewayClassReasonGatewayClassConflict.
GatewayClassMessageGatewayClassConflict = "The resource is ignored due to a conflicting GatewayClass resource"
)

// Condition defines a condition to be reported in the status of resources.
type Condition struct {
Type string
Status metav1.ConditionStatus
Reason string
Message string
}

// NewDefaultGatewayClassConditions returns the default Conditions that must be present in the status of a GatewayClass.
func NewDefaultGatewayClassConditions() []Condition {
return []Condition{
{
Type: string(v1beta1.GatewayClassConditionStatusAccepted),
Status: metav1.ConditionTrue,
Reason: string(v1beta1.GatewayClassReasonAccepted),
Message: "GatewayClass is accepted",
},
}
}

// NewGatewayClassConflict returns a Condition that indicates that the GatewayClass is not accepted
// due to a conflict with another GatewayClass.
func NewGatewayClassConflict() Condition {
return Condition{
Type: string(v1beta1.GatewayClassConditionStatusAccepted),
Status: metav1.ConditionFalse,
Reason: string(GatewayClassReasonGatewayClassConflict),
Message: GatewayClassMessageGatewayClassConflict,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import (

func TestControllers(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Reconciler Suite")
RunSpecs(t, "Controller Suite")
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/controller/index"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/controller/index"
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/predicate"
)

func TestRegister(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions internal/framework/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
Package framework contains all the packages that are shared by the provisioner and static modes of the project.
*/
package framework
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 14 additions & 0 deletions internal/framework/events/handler.go
Original file line number Diff line number Diff line change
@@ -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)
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading