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
}

0 commit comments

Comments
 (0)