Skip to content

Commit ef4d82f

Browse files
committed
Revert reference check
1 parent 85a2955 commit ef4d82f

File tree

4 files changed

+34
-102
lines changed

4 files changed

+34
-102
lines changed

internal/mode/static/state/graph/graph.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ func (g *Graph) IsReferenced(resourceType client.Object, nsname types.Namespaced
103103
// Service Namespace should be the same Namespace as the EndpointSlice
104104
_, exists := g.ReferencedServices[types.NamespacedName{Namespace: nsname.Namespace, Name: svcName}]
105105
return exists
106-
// Similar to Namespace above, NginxProxy reference exists if it once was or currently is linked to a GatewayClass.
106+
// NginxProxy reference exists if it is linked to a GatewayClass.
107107
case *ngfAPI.NginxProxy:
108-
return isNginxProxyReferenced(nsname, g)
108+
return isNginxProxyReferenced(nsname, g.GatewayClass)
109109
default:
110110
return false
111111
}

internal/mode/static/state/graph/graph_test.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -625,24 +625,18 @@ func TestIsReferenced(t *testing.T) {
625625
},
626626
}
627627

628-
npInGraph := &ngfAPI.NginxProxy{
628+
npNotInGatewayClass := &ngfAPI.NginxProxy{
629629
ObjectMeta: metav1.ObjectMeta{
630630
Name: "nginx-proxy",
631631
},
632632
}
633633

634-
npNotInGraphButInGatewayClass := &ngfAPI.NginxProxy{
634+
npInGatewayClass := &ngfAPI.NginxProxy{
635635
ObjectMeta: metav1.ObjectMeta{
636636
Name: "nginx-proxy-in-gc",
637637
},
638638
}
639639

640-
npNotInGraph := &ngfAPI.NginxProxy{
641-
ObjectMeta: metav1.ObjectMeta{
642-
Name: "nginx-proxy-not-referenced",
643-
},
644-
}
645-
646640
graph := &Graph{
647641
Gateway: gw,
648642
ReferencedSecrets: map[types.NamespacedName]*Secret{
@@ -662,7 +656,6 @@ func TestIsReferenced(t *testing.T) {
662656
CACert: []byte(caBlock),
663657
},
664658
},
665-
NginxProxy: npInGraph,
666659
}
667660

668661
tests := []struct {
@@ -781,21 +774,15 @@ func TestIsReferenced(t *testing.T) {
781774

782775
// NginxProxy tests
783776
{
784-
name: "NginxProxy in the Graph is referenced",
785-
resource: npInGraph,
786-
graph: graph,
787-
expected: true,
788-
},
789-
{
790-
name: "NginxProxy is not yet in Graph but is referenced in GatewayClass",
791-
resource: npNotInGraphButInGatewayClass,
777+
name: "NginxProxy is referenced in GatewayClass",
778+
resource: npInGatewayClass,
792779
gc: gcWithNginxProxy,
793780
graph: graph,
794781
expected: true,
795782
},
796783
{
797-
name: "NginxProxy not in Graph or referenced in GatewayClass",
798-
resource: npNotInGraph,
784+
name: "NginxProxy is not referenced in GatewayClass",
785+
resource: npNotInGatewayClass,
799786
gc: gcWithNginxProxy,
800787
graph: graph,
801788
expected: false,

internal/mode/static/state/graph/nginxproxy.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package graph
33
import (
44
"k8s.io/apimachinery/pkg/types"
55
"k8s.io/apimachinery/pkg/util/validation/field"
6-
"sigs.k8s.io/controller-runtime/pkg/client"
76
v1 "sigs.k8s.io/gateway-api/apis/v1"
87

98
ngfAPI "github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha1"
@@ -23,11 +22,8 @@ func getNginxProxy(
2322
}
2423

2524
// isNginxProxyReferenced returns whether or not a specific NginxProxy is referenced in the GatewayClass.
26-
func isNginxProxyReferenced(npNSName types.NamespacedName, g *Graph) bool {
27-
existed := g.NginxProxy != nil && npNSName == client.ObjectKeyFromObject(g.NginxProxy)
28-
gc := g.GatewayClass
29-
exists := gc != nil && gcReferencesAnyNginxProxy(gc.Source) && gc.Source.Spec.ParametersRef.Name == npNSName.Name
30-
return existed || exists
25+
func isNginxProxyReferenced(npNSName types.NamespacedName, gc *GatewayClass) bool {
26+
return gc != nil && gcReferencesAnyNginxProxy(gc.Source) && gc.Source.Spec.ParametersRef.Name == npNSName.Name
3127
}
3228

3329
// gcReferencesNginxProxy returns whether a GatewayClass references any NginxProxy resource.

internal/mode/static/state/graph/nginxproxy_test.go

Lines changed: 24 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -85,115 +85,64 @@ func TestGetNginxProxy(t *testing.T) {
8585

8686
func TestIsNginxProxyReferenced(t *testing.T) {
8787
tests := []struct {
88-
g *Graph
88+
gc *GatewayClass
8989
npName types.NamespacedName
9090
name string
9191
expRes bool
9292
}{
9393
{
94-
g: &Graph{
95-
GatewayClass: &GatewayClass{
96-
Source: &v1.GatewayClass{
97-
Spec: v1.GatewayClassSpec{
98-
ParametersRef: &v1.ParametersReference{
99-
Group: ngfAPI.GroupName,
100-
Kind: v1.Kind("NginxProxy"),
101-
Name: "nginx-proxy",
102-
},
94+
gc: &GatewayClass{
95+
Source: &v1.GatewayClass{
96+
Spec: v1.GatewayClassSpec{
97+
ParametersRef: &v1.ParametersReference{
98+
Group: ngfAPI.GroupName,
99+
Kind: v1.Kind("NginxProxy"),
100+
Name: "nginx-proxy",
103101
},
104102
},
105103
},
106104
},
107-
npName: types.NamespacedName{Name: "not referenced"},
105+
npName: types.NamespacedName{},
108106
expRes: false,
109-
name: "nginxproxy not in graph and not referenced in gatewayclass",
107+
name: "nil nginxproxy",
110108
},
111109
{
112-
g: &Graph{
113-
GatewayClass: nil,
114-
NginxProxy: nil,
115-
},
110+
gc: nil,
116111
npName: types.NamespacedName{Name: "nginx-proxy"},
117112
expRes: false,
118-
name: "nil gatewayclass and nginxproxy not in graph",
113+
name: "nil gatewayclass",
119114
},
120115
{
121-
g: &Graph{
122-
GatewayClass: &GatewayClass{
123-
Source: nil,
124-
},
125-
NginxProxy: nil,
116+
gc: &GatewayClass{
117+
Source: nil,
126118
},
127119
npName: types.NamespacedName{Name: "nginx-proxy"},
128120
expRes: false,
129-
name: "nil gatewayclass source and nginxproxy not in graph",
121+
name: "nil gatewayclass source",
130122
},
131123
{
132-
g: &Graph{
133-
GatewayClass: &GatewayClass{
134-
Source: &v1.GatewayClass{
135-
Spec: v1.GatewayClassSpec{
136-
ParametersRef: &v1.ParametersReference{
137-
Group: ngfAPI.GroupName,
138-
Kind: v1.Kind("NginxProxy"),
139-
Name: "nginx-proxy",
140-
},
124+
gc: &GatewayClass{
125+
Source: &v1.GatewayClass{
126+
Spec: v1.GatewayClassSpec{
127+
ParametersRef: &v1.ParametersReference{
128+
Group: ngfAPI.GroupName,
129+
Kind: v1.Kind("NginxProxy"),
130+
Name: "nginx-proxy",
141131
},
142132
},
143133
},
144-
NginxProxy: nil,
145-
},
146-
npName: types.NamespacedName{Name: "nginx-proxy"},
147-
expRes: true,
148-
name: "nginxproxy not in graph but referenced in gatewayclass",
149-
},
150-
{
151-
g: &Graph{
152-
GatewayClass: &GatewayClass{
153-
Source: &v1.GatewayClass{
154-
Spec: v1.GatewayClassSpec{},
155-
},
156-
},
157-
NginxProxy: &ngfAPI.NginxProxy{
158-
ObjectMeta: metav1.ObjectMeta{
159-
Name: "nginx-proxy",
160-
},
161-
},
162-
},
163-
npName: types.NamespacedName{Name: "nginx-proxy"},
164-
expRes: true,
165-
name: "nginxproxy in graph but not referenced in gatewayclass",
166-
},
167-
{
168-
g: &Graph{
169-
GatewayClass: &GatewayClass{
170-
Source: &v1.GatewayClass{
171-
Spec: v1.GatewayClassSpec{
172-
ParametersRef: &v1.ParametersReference{
173-
Group: ngfAPI.GroupName,
174-
Kind: v1.Kind("NginxProxy"),
175-
Name: "nginx-proxy",
176-
},
177-
},
178-
},
179-
},
180-
NginxProxy: &ngfAPI.NginxProxy{
181-
ObjectMeta: metav1.ObjectMeta{
182-
Name: "nginx-proxy",
183-
},
184-
},
185134
},
186135
npName: types.NamespacedName{Name: "nginx-proxy"},
187136
expRes: true,
188-
name: "references the nginxproxy and exists in graph",
137+
name: "references the NginxProxy",
189138
},
190139
}
191140

192141
for _, test := range tests {
193142
t.Run(test.name, func(t *testing.T) {
194143
g := NewWithT(t)
195144

196-
g.Expect(isNginxProxyReferenced(test.npName, test.g)).To(Equal(test.expRes))
145+
g.Expect(isNginxProxyReferenced(test.npName, test.gc)).To(Equal(test.expRes))
197146
})
198147
}
199148
}

0 commit comments

Comments
 (0)