Skip to content

Commit e065469

Browse files
authored
Refactor internal package organization (#839)
Problem: After the merge of the provisioner-mode code into the main branch, our codebase now consists of three distinct components or groups: provisioner-mode, static-mode, and framework. However, our current internal package structure does not align with these components. Solution: Align the internal package structure with our three main components by introducing the following internal packages: - framework: code shared between provisioner and static modes - mode/provisioner: all code related to provisioner-mode - mode/static: all code related to static mode In addition, some packages were refactored/split so the framework package would not have any dependencies on the mode/static package.
1 parent d650268 commit e065469

File tree

168 files changed

+915
-828
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+915
-828
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0
8888
with:
8989
node-version: 18
90-
- run: npm --prefix ${{ github.workspace }}/internal/nginx/modules install-ci-test
90+
- run: npm --prefix ${{ github.workspace }}/internal/mode/static/nginx/modules install-ci-test
9191

9292
release:
9393
name: Release

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ dist/
3131
node_modules/
3232

3333
# JS test coverage
34-
internal/nginx/modules/coverage
34+
internal/mode/static/nginx/modules/coverage

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ unit-test: ## Run unit tests for the go code
8080

8181
njs-unit-test: ## Run unit tests for the njs httpmatches module
8282
docker run --rm -w /modules \
83-
-v $(PWD)/internal/nginx/modules:/modules/ \
83+
-v $(PWD)/internal/mode/static/nginx/modules:/modules/ \
8484
node:18 \
8585
/bin/bash -c "npm install && npm test && npm run clean"
8686

cmd/gateway/commands.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1010
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1111

12-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/config"
13-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/manager"
14-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/provisioner"
12+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/provisioner"
13+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static"
14+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/mode/static/config"
1515
)
1616

1717
const (
@@ -149,7 +149,7 @@ func createStaticModeCommand() *cobra.Command {
149149
UpdateGatewayClassStatus: updateGCStatus,
150150
}
151151

152-
if err := manager.Start(conf); err != nil {
152+
if err := static.StartManager(conf); err != nil {
153153
return fmt.Errorf("failed to start control loop: %w", err)
154154
}
155155

conformance/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ prepare-nkg-dependencies: ## Install NKG dependencies on configured kind cluster
4545
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.7.1/standard-install.yaml
4646
kubectl wait --for=condition=available --timeout=60s deployment gateway-api-admission-server -n gateway-system
4747
kubectl apply -f ../deploy/manifests/namespace.yaml
48-
kubectl create configmap njs-modules --from-file=../internal/nginx/modules/src/httpmatches.js -n nginx-gateway
48+
kubectl create configmap njs-modules --from-file=../internal/mode/static/nginx/modules/src/httpmatches.js -n nginx-gateway
4949
kubectl apply -f ../deploy/manifests/nginx-conf.yaml
5050
kubectl apply -f ../deploy/manifests/rbac.yaml
5151
kubectl apply -f ../deploy/manifests/gatewayclass.yaml

docs/installation.md

Lines changed: 1 addition & 1 deletion

internal/events/handler.go

Lines changed: 0 additions & 102 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package conditions
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
"sigs.k8s.io/gateway-api/apis/v1beta1"
6+
)
7+
8+
const (
9+
// GatewayClassReasonGatewayClassConflict indicates there are multiple GatewayClass resources
10+
// that reference this controller, and we ignored the resource in question and picked the
11+
// GatewayClass that is referenced in the command-line argument.
12+
// This reason is used with GatewayClassConditionAccepted (false).
13+
GatewayClassReasonGatewayClassConflict v1beta1.GatewayClassConditionReason = "GatewayClassConflict"
14+
15+
// GatewayClassMessageGatewayClassConflict is a message that describes GatewayClassReasonGatewayClassConflict.
16+
GatewayClassMessageGatewayClassConflict = "The resource is ignored due to a conflicting GatewayClass resource"
17+
)
18+
19+
// Condition defines a condition to be reported in the status of resources.
20+
type Condition struct {
21+
Type string
22+
Status metav1.ConditionStatus
23+
Reason string
24+
Message string
25+
}
26+
27+
// NewDefaultGatewayClassConditions returns the default Conditions that must be present in the status of a GatewayClass.
28+
func NewDefaultGatewayClassConditions() []Condition {
29+
return []Condition{
30+
{
31+
Type: string(v1beta1.GatewayClassConditionStatusAccepted),
32+
Status: metav1.ConditionTrue,
33+
Reason: string(v1beta1.GatewayClassReasonAccepted),
34+
Message: "GatewayClass is accepted",
35+
},
36+
}
37+
}
38+
39+
// NewGatewayClassConflict returns a Condition that indicates that the GatewayClass is not accepted
40+
// due to a conflict with another GatewayClass.
41+
func NewGatewayClassConflict() Condition {
42+
return Condition{
43+
Type: string(v1beta1.GatewayClassConditionStatusAccepted),
44+
Status: metav1.ConditionFalse,
45+
Reason: string(GatewayClassReasonGatewayClassConflict),
46+
Message: GatewayClassMessageGatewayClassConflict,
47+
}
48+
}

internal/controller/controller_suite_test.go renamed to internal/framework/controller/controller_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ import (
99

1010
func TestControllers(t *testing.T) {
1111
RegisterFailHandler(Fail)
12-
RunSpecs(t, "Reconciler Suite")
12+
RunSpecs(t, "Controller Suite")
1313
}

internal/controller/controllerfakes/fake_getter.go renamed to internal/framework/controller/controllerfakes/fake_getter.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.

internal/manager/filter/filter.go renamed to internal/framework/controller/filter/filter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"k8s.io/apimachinery/pkg/types"
77

8-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/controller"
8+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller"
99
)
1010

1111
// CreateSingleResourceFilter creates a filter function that filters out all resources except the one

internal/controller/reconciler.go renamed to internal/framework/controller/reconciler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"sigs.k8s.io/controller-runtime/pkg/log"
1212
"sigs.k8s.io/controller-runtime/pkg/reconcile"
1313

14-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/events"
14+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events"
1515
)
1616

1717
// NamespacedNameFilterFunc is a function that returns true if the resource should be processed by the reconciler.

internal/controller/reconciler_test.go renamed to internal/framework/controller/reconciler_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
"sigs.k8s.io/controller-runtime/pkg/reconcile"
1515
"sigs.k8s.io/gateway-api/apis/v1beta1"
1616

17-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/controller"
18-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/controller/controllerfakes"
19-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/events"
17+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller"
18+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/controllerfakes"
19+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events"
2020
)
2121

2222
type getFunc func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error

internal/controller/register.go renamed to internal/framework/controller/register.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"sigs.k8s.io/controller-runtime/pkg/manager"
1111
"sigs.k8s.io/controller-runtime/pkg/predicate"
1212

13-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/index"
13+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/index"
1414
)
1515

1616
const (

internal/controller/register_test.go renamed to internal/framework/controller/register_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1717
"sigs.k8s.io/gateway-api/apis/v1beta1"
1818

19-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/controller"
20-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/controller/controllerfakes"
21-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/index"
22-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/predicate"
19+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller"
20+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/controllerfakes"
21+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/index"
22+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/controller/predicate"
2323
)
2424

2525
func TestRegister(t *testing.T) {

internal/framework/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*
2+
Package framework contains all the packages that are shared by the provisioner and static modes of the project.
3+
*/
4+
package framework
File renamed without changes.

internal/events/eventsfakes/fake_event_handler.go renamed to internal/framework/events/eventsfakes/fake_event_handler.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/events/eventsfakes/fake_first_event_batch_preparer.go renamed to internal/framework/events/eventsfakes/fake_first_event_batch_preparer.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/events/eventsfakes/fake_reader.go renamed to internal/framework/events/eventsfakes/fake_reader.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/events/first_eventbatch_preparer_test.go renamed to internal/framework/events/first_eventbatch_preparer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"sigs.k8s.io/controller-runtime/pkg/client"
1717
"sigs.k8s.io/gateway-api/apis/v1beta1"
1818

19-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/events"
20-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/events/eventsfakes"
19+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events"
20+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events/eventsfakes"
2121
)
2222

2323
var _ = Describe("FirstEventBatchPreparer", func() {

internal/framework/events/handler.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package events
2+
3+
import (
4+
"context"
5+
)
6+
7+
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . EventHandler
8+
9+
// EventHandler handles events.
10+
type EventHandler interface {
11+
// HandleEventBatch handles a batch of events.
12+
// EventBatch can include duplicated events.
13+
HandleEventBatch(ctx context.Context, batch EventBatch)
14+
}
File renamed without changes.

internal/events/loop_test.go renamed to internal/framework/events/loop_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
. "github.com/onsi/gomega"
99
"sigs.k8s.io/controller-runtime/pkg/log/zap"
1010

11-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/events"
12-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/events/eventsfakes"
11+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events"
12+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/events/eventsfakes"
1313
)
1414

1515
var _ = Describe("EventLoop", func() {
File renamed without changes.

internal/status/clock.go renamed to internal/framework/status/clock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Clock interface {
1111
Now() metav1.Time
1212
}
1313

14-
// Real clock returns the current local time.
14+
// RealClock returns the current local time.
1515
type RealClock struct{}
1616

1717
// NewRealClock creates a new RealClock.

internal/status/conditions.go renamed to internal/framework/status/conditions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package status
33
import (
44
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
55

6-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions"
6+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions"
77
)
88

99
func convertConditions(

internal/status/conditions_test.go renamed to internal/framework/status/conditions_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
. "github.com/onsi/gomega"
88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
99

10-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers"
11-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions"
10+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/conditions"
11+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers"
1212
)
1313

1414
func CreateTestConditions(condType string) []conditions.Condition {
File renamed without changes.

internal/status/gateway_test.go renamed to internal/framework/status/gateway_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
99
"sigs.k8s.io/gateway-api/apis/v1beta1"
1010

11-
"github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers"
11+
"github.com/nginxinc/nginx-kubernetes-gateway/internal/framework/helpers"
1212
)
1313

1414
func TestPrepareGatewayStatus(t *testing.T) {

0 commit comments

Comments
 (0)