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