1
1
package state
2
2
3
3
import (
4
- "fmt"
5
4
"sync"
6
5
7
6
"github.com/go-logr/logr"
8
7
apiv1 "k8s.io/api/core/v1"
9
8
discoveryV1 "k8s.io/api/discovery/v1"
10
9
apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
11
10
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12
- "k8s.io/apimachinery/pkg/runtime"
13
- "k8s.io/apimachinery/pkg/runtime/schema"
14
11
"k8s.io/apimachinery/pkg/types"
15
12
"k8s.io/client-go/tools/record"
16
13
"sigs.k8s.io/controller-runtime/pkg/client"
17
- "sigs.k8s.io/controller-runtime/pkg/client/apiutil"
18
14
v1 "sigs.k8s.io/gateway-api/apis/v1"
19
15
"sigs.k8s.io/gateway-api/apis/v1alpha3"
20
16
"sigs.k8s.io/gateway-api/apis/v1beta1"
21
17
22
18
ngfAPI "github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha1"
23
19
"github.com/nginxinc/nginx-gateway-fabric/internal/framework/gatewayclass"
20
+ "github.com/nginxinc/nginx-gateway-fabric/internal/framework/kinds"
24
21
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/policies"
25
22
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/graph"
26
23
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/validation"
@@ -65,8 +62,8 @@ type ChangeProcessorConfig struct {
65
62
Validators validation.Validators
66
63
// EventRecorder records events for Kubernetes resources.
67
64
EventRecorder record.EventRecorder
68
- // Scheme is the Kubernetes scheme .
69
- Scheme * runtime. Scheme
65
+ // MustExtractGVK is a function that extracts schema.GroupVersionKind from a client.Object .
66
+ MustExtractGVK kinds. MustExtractGVK
70
67
// ProtectedPorts are the ports that may not be configured by a listener with a descriptive name of the ports.
71
68
ProtectedPorts graph.ProtectedPorts
72
69
// Logger is the logger for this Change Processor.
@@ -110,14 +107,6 @@ func NewChangeProcessorImpl(cfg ChangeProcessorConfig) *ChangeProcessorImpl {
110
107
NGFPolicies : make (map [graph.PolicyKey ]policies.Policy ),
111
108
}
112
109
113
- extractGVK := func (obj client.Object ) schema.GroupVersionKind {
114
- gvk , err := apiutil .GVKForObject (obj , cfg .Scheme )
115
- if err != nil {
116
- panic (fmt .Errorf ("failed to get GVK for object %T: %w" , obj , err ))
117
- }
118
- return gvk
119
- }
120
-
121
110
processor := & ChangeProcessorImpl {
122
111
cfg : cfg ,
123
112
clusterState : clusterStore ,
@@ -133,84 +122,84 @@ func NewChangeProcessorImpl(cfg ChangeProcessorConfig) *ChangeProcessorImpl {
133
122
return false
134
123
}
135
124
136
- gvk := extractGVK (obj )
125
+ gvk := cfg . MustExtractGVK (obj )
137
126
138
127
return processor .latestGraph != nil && processor .latestGraph .IsNGFPolicyRelevant (pol , gvk , nsname )
139
128
}
140
129
141
130
// Use this object store for all NGF policies
142
- commonPolicyObjectStore := newNGFPolicyObjectStore (clusterStore .NGFPolicies , extractGVK )
131
+ commonPolicyObjectStore := newNGFPolicyObjectStore (clusterStore .NGFPolicies , cfg . MustExtractGVK )
143
132
144
133
trackingUpdater := newChangeTrackingUpdater (
145
- extractGVK ,
134
+ cfg . MustExtractGVK ,
146
135
[]changeTrackingUpdaterObjectTypeCfg {
147
136
{
148
- gvk : extractGVK (& v1.GatewayClass {}),
137
+ gvk : cfg . MustExtractGVK (& v1.GatewayClass {}),
149
138
store : newObjectStoreMapAdapter (clusterStore .GatewayClasses ),
150
139
predicate : nil ,
151
140
},
152
141
{
153
- gvk : extractGVK (& v1.Gateway {}),
142
+ gvk : cfg . MustExtractGVK (& v1.Gateway {}),
154
143
store : newObjectStoreMapAdapter (clusterStore .Gateways ),
155
144
predicate : nil ,
156
145
},
157
146
{
158
- gvk : extractGVK (& v1.HTTPRoute {}),
147
+ gvk : cfg . MustExtractGVK (& v1.HTTPRoute {}),
159
148
store : newObjectStoreMapAdapter (clusterStore .HTTPRoutes ),
160
149
predicate : nil ,
161
150
},
162
151
{
163
- gvk : extractGVK (& v1beta1.ReferenceGrant {}),
152
+ gvk : cfg . MustExtractGVK (& v1beta1.ReferenceGrant {}),
164
153
store : newObjectStoreMapAdapter (clusterStore .ReferenceGrants ),
165
154
predicate : nil ,
166
155
},
167
156
{
168
- gvk : extractGVK (& v1alpha3.BackendTLSPolicy {}),
157
+ gvk : cfg . MustExtractGVK (& v1alpha3.BackendTLSPolicy {}),
169
158
store : newObjectStoreMapAdapter (clusterStore .BackendTLSPolicies ),
170
159
predicate : nil ,
171
160
},
172
161
{
173
- gvk : extractGVK (& v1.GRPCRoute {}),
162
+ gvk : cfg . MustExtractGVK (& v1.GRPCRoute {}),
174
163
store : newObjectStoreMapAdapter (clusterStore .GRPCRoutes ),
175
164
predicate : nil ,
176
165
},
177
166
{
178
- gvk : extractGVK (& apiv1.Namespace {}),
167
+ gvk : cfg . MustExtractGVK (& apiv1.Namespace {}),
179
168
store : newObjectStoreMapAdapter (clusterStore .Namespaces ),
180
169
predicate : funcPredicate {stateChanged : isReferenced },
181
170
},
182
171
{
183
- gvk : extractGVK (& apiv1.Service {}),
172
+ gvk : cfg . MustExtractGVK (& apiv1.Service {}),
184
173
store : newObjectStoreMapAdapter (clusterStore .Services ),
185
174
predicate : funcPredicate {stateChanged : isReferenced },
186
175
},
187
176
{
188
- gvk : extractGVK (& discoveryV1.EndpointSlice {}),
177
+ gvk : cfg . MustExtractGVK (& discoveryV1.EndpointSlice {}),
189
178
store : nil ,
190
179
predicate : funcPredicate {stateChanged : isReferenced },
191
180
},
192
181
{
193
- gvk : extractGVK (& apiv1.Secret {}),
182
+ gvk : cfg . MustExtractGVK (& apiv1.Secret {}),
194
183
store : newObjectStoreMapAdapter (clusterStore .Secrets ),
195
184
predicate : funcPredicate {stateChanged : isReferenced },
196
185
},
197
186
{
198
- gvk : extractGVK (& apiv1.ConfigMap {}),
187
+ gvk : cfg . MustExtractGVK (& apiv1.ConfigMap {}),
199
188
store : newObjectStoreMapAdapter (clusterStore .ConfigMaps ),
200
189
predicate : funcPredicate {stateChanged : isReferenced },
201
190
},
202
191
{
203
- gvk : extractGVK (& apiext.CustomResourceDefinition {}),
192
+ gvk : cfg . MustExtractGVK (& apiext.CustomResourceDefinition {}),
204
193
store : newObjectStoreMapAdapter (clusterStore .CRDMetadata ),
205
194
predicate : annotationChangedPredicate {annotation : gatewayclass .BundleVersionAnnotation },
206
195
},
207
196
{
208
- gvk : extractGVK (& ngfAPI.NginxProxy {}),
197
+ gvk : cfg . MustExtractGVK (& ngfAPI.NginxProxy {}),
209
198
store : newObjectStoreMapAdapter (clusterStore .NginxProxies ),
210
199
predicate : funcPredicate {stateChanged : isReferenced },
211
200
},
212
201
{
213
- gvk : extractGVK (& ngfAPI.ClientSettingsPolicy {}),
202
+ gvk : cfg . MustExtractGVK (& ngfAPI.ClientSettingsPolicy {}),
214
203
store : commonPolicyObjectStore ,
215
204
predicate : funcPredicate {stateChanged : isNGFPolicyRelevant },
216
205
},
0 commit comments