From 7654cb6f245fa1c615e8a00cd25dd02d22ba89d3 Mon Sep 17 00:00:00 2001 From: Sarthak Agrawal <68310924+sarthyparty@users.noreply.github.com> Date: Wed, 12 Jun 2024 11:34:54 -0600 Subject: [PATCH] Refacter code to use new ObjectType (#2121) * Refacter code to use new ObjectType Problem: We currently use the variable objType to refer to a client.Object's type (skeleton of an object). We also use the variable obj to refer to a full client.Object (object with fields filled out). However, in many parts of the codebase these two variables are used closely together and are both of type client.Object which can be a little confusing. Solution: I created a new type called ObjectType and refactored the codebase to utilize it. --- internal/framework/controller/reconciler.go | 5 ++-- internal/framework/controller/register.go | 5 ++-- .../framework/controller/register_test.go | 4 ++-- internal/framework/events/event.go | 4 +++- internal/framework/status/updater.go | 5 ++-- internal/framework/types/doc.go | 4 ++++ internal/framework/types/types.go | 7 ++++++ internal/mode/provisioner/manager.go | 3 ++- internal/mode/static/manager.go | 3 ++- .../mode/static/state/change_processor.go | 9 ++++---- .../static/state/change_processor_test.go | 3 ++- .../mode/static/state/changed_predicate.go | 12 ++++++---- .../static/state/changed_predicate_test.go | 6 +++-- internal/mode/static/state/graph/graph.go | 3 ++- .../state/statefakes/fake_change_processor.go | 19 +++++++-------- internal/mode/static/state/store.go | 23 ++++++++++--------- .../static/status/prepare_requests_test.go | 3 ++- 17 files changed, 74 insertions(+), 44 deletions(-) create mode 100644 internal/framework/types/doc.go create mode 100644 internal/framework/types/types.go diff --git a/internal/framework/controller/reconciler.go b/internal/framework/controller/reconciler.go index 5d90891da5..629c0ba5f0 100644 --- a/internal/framework/controller/reconciler.go +++ b/internal/framework/controller/reconciler.go @@ -13,6 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/events" + ngftypes "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" ) // NamespacedNameFilterFunc is a function that returns true if the resource should be processed by the reconciler. @@ -24,7 +25,7 @@ type ReconcilerConfig struct { // Getter gets a resource from the k8s API. Getter Getter // ObjectType is the type of the resource that the reconciler will reconcile. - ObjectType client.Object + ObjectType ngftypes.ObjectType // EventCh is the channel where the reconciler will send events. EventCh chan<- interface{} // NamespacedNameFilter filters resources the controller will process. Can be nil. @@ -52,7 +53,7 @@ func NewReconciler(cfg ReconcilerConfig) *Reconciler { } } -func (r *Reconciler) newObject(objectType client.Object) client.Object { +func (r *Reconciler) newObject(objectType ngftypes.ObjectType) ngftypes.ObjectType { if r.cfg.OnlyMetadata { partialObj := &metav1.PartialObjectMetadata{} partialObj.SetGroupVersionKind(objectType.GetObjectKind().GroupVersionKind()) diff --git a/internal/framework/controller/register.go b/internal/framework/controller/register.go index fbb5a7e712..dc4c6e0f33 100644 --- a/internal/framework/controller/register.go +++ b/internal/framework/controller/register.go @@ -12,6 +12,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/predicate" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/controller/index" + ngftypes "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" ) const ( @@ -82,7 +83,7 @@ func defaultConfig() config { // The registered controller will send events to the provided channel. func Register( ctx context.Context, - objectType client.Object, + objectType ngftypes.ObjectType, mgr manager.Manager, eventCh chan<- interface{}, options ...Option, @@ -137,7 +138,7 @@ func Register( func addIndex( ctx context.Context, indexer client.FieldIndexer, - objectType client.Object, + objectType ngftypes.ObjectType, field string, indexerFunc client.IndexerFunc, ) error { diff --git a/internal/framework/controller/register_test.go b/internal/framework/controller/register_test.go index 3f6f01fe21..f9cfc06cd6 100644 --- a/internal/framework/controller/register_test.go +++ b/internal/framework/controller/register_test.go @@ -13,7 +13,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" "sigs.k8s.io/controller-runtime/pkg/log/zap" v1 "sigs.k8s.io/gateway-api/apis/v1" @@ -24,6 +23,7 @@ import ( "github.com/nginxinc/nginx-gateway-fabric/internal/framework/controller/index" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/controller/predicate" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/kinds" + ngftypes "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" ) func TestRegister(t *testing.T) { @@ -62,7 +62,7 @@ func TestRegister(t *testing.T) { tests := []struct { fakes fakes - objectType client.Object + objectType ngftypes.ObjectType expectedErr error msg string expectedMgrAddCallCount int diff --git a/internal/framework/events/event.go b/internal/framework/events/event.go index 2d3944854d..13bc1cad22 100644 --- a/internal/framework/events/event.go +++ b/internal/framework/events/event.go @@ -3,6 +3,8 @@ package events import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" + + ngftypes "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" ) // EventBatch is a batch of events to be handled at once. @@ -17,7 +19,7 @@ type UpsertEvent struct { // DeleteEvent representing deleting a resource. type DeleteEvent struct { // Type is the resource type. For example, if the event is for *v1.HTTPRoute, pass &v1.HTTPRoute{} as Type. - Type client.Object + Type ngftypes.ObjectType // NamespacedName is the namespace & name of the deleted resource. NamespacedName types.NamespacedName } diff --git a/internal/framework/status/updater.go b/internal/framework/status/updater.go index f28fdacf5e..b66dd733ff 100644 --- a/internal/framework/status/updater.go +++ b/internal/framework/status/updater.go @@ -12,11 +12,12 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/controller" + ngftypes "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" ) // UpdateRequest is a request to update the status of a resource. type UpdateRequest struct { - ResourceType client.Object + ResourceType ngftypes.ObjectType Setter Setter NsName types.NamespacedName } @@ -83,7 +84,7 @@ func (u *Updater) Update(ctx context.Context, reqs ...UpdateRequest) { func (u *Updater) writeStatuses( ctx context.Context, nsname types.NamespacedName, - resourceType client.Object, + resourceType ngftypes.ObjectType, statusSetter Setter, ) { obj := resourceType.DeepCopyObject().(client.Object) diff --git a/internal/framework/types/doc.go b/internal/framework/types/doc.go new file mode 100644 index 0000000000..f479c9ba99 --- /dev/null +++ b/internal/framework/types/doc.go @@ -0,0 +1,4 @@ +/* +Package types contains types that are shared by the provisioner and static modes. +*/ +package types diff --git a/internal/framework/types/types.go b/internal/framework/types/types.go new file mode 100644 index 0000000000..78ccc25a8f --- /dev/null +++ b/internal/framework/types/types.go @@ -0,0 +1,7 @@ +package types + +import "sigs.k8s.io/controller-runtime/pkg/client" + +// ObjectType is used when we only care about the type of client.Object. +// The fields of the client.Object may be empty. +type ObjectType client.Object diff --git a/internal/mode/provisioner/manager.go b/internal/mode/provisioner/manager.go index 4776cceb5a..13924e6966 100644 --- a/internal/mode/provisioner/manager.go +++ b/internal/mode/provisioner/manager.go @@ -21,6 +21,7 @@ import ( "github.com/nginxinc/nginx-gateway-fabric/internal/framework/events" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/gatewayclass" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/status" + ngftypes "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" ) // Config is configuration for the provisioner mode. @@ -63,7 +64,7 @@ func StartManager(cfg Config) error { // Note: for any new object type or a change to the existing one, // make sure to also update firstBatchPreparer creation below controllerRegCfgs := []struct { - objectType client.Object + objectType ngftypes.ObjectType options []controller.Option }{ { diff --git a/internal/mode/static/manager.go b/internal/mode/static/manager.go index f3b92ad076..36db684cb5 100644 --- a/internal/mode/static/manager.go +++ b/internal/mode/static/manager.go @@ -45,6 +45,7 @@ import ( "github.com/nginxinc/nginx-gateway-fabric/internal/framework/kinds" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/runnables" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/status" + ngftypes "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/config" "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/metrics/collectors" ngxcfg "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/nginx/config" @@ -356,7 +357,7 @@ func registerControllers( controlConfigNSName types.NamespacedName, ) error { type ctlrCfg struct { - objectType client.Object + objectType ngftypes.ObjectType options []controller.Option } diff --git a/internal/mode/static/state/change_processor.go b/internal/mode/static/state/change_processor.go index d3bb4c131a..3fdcd55d97 100644 --- a/internal/mode/static/state/change_processor.go +++ b/internal/mode/static/state/change_processor.go @@ -18,6 +18,7 @@ import ( ngfAPI "github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha1" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/gatewayclass" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/kinds" + ngftypes "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/policies" "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/graph" "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/validation" @@ -50,7 +51,7 @@ type ChangeProcessor interface { // CaptureDeleteChange captures a delete change to a resource. // The method panics if the resource is of unsupported type or if the passed Gateway is different from the one // this ChangeProcessor was created for. - CaptureDeleteChange(resourceType client.Object, nsname types.NamespacedName) + CaptureDeleteChange(resourceType ngftypes.ObjectType, nsname types.NamespacedName) // Process produces a graph-like representation of GatewayAPI resources. // If no changes were captured, the changed return argument will be NoChange and graph will be empty. Process() (changeType ChangeType, graphCfg *graph.Graph) @@ -114,11 +115,11 @@ func NewChangeProcessorImpl(cfg ChangeProcessorConfig) *ChangeProcessorImpl { clusterState: clusterStore, } - isReferenced := func(obj client.Object, nsname types.NamespacedName) bool { + isReferenced := func(obj ngftypes.ObjectType, nsname types.NamespacedName) bool { return processor.latestGraph != nil && processor.latestGraph.IsReferenced(obj, nsname) } - isNGFPolicyRelevant := func(obj client.Object, nsname types.NamespacedName) bool { + isNGFPolicyRelevant := func(obj ngftypes.ObjectType, nsname types.NamespacedName) bool { pol, ok := obj.(policies.Policy) if !ok { return false @@ -241,7 +242,7 @@ func (c *ChangeProcessorImpl) CaptureUpsertChange(obj client.Object) { c.updater.Upsert(obj) } -func (c *ChangeProcessorImpl) CaptureDeleteChange(resourceType client.Object, nsname types.NamespacedName) { +func (c *ChangeProcessorImpl) CaptureDeleteChange(resourceType ngftypes.ObjectType, nsname types.NamespacedName) { c.lock.Lock() defer c.lock.Unlock() diff --git a/internal/mode/static/state/change_processor_test.go b/internal/mode/static/state/change_processor_test.go index 53d1e7c04d..103f1e9a42 100644 --- a/internal/mode/static/state/change_processor_test.go +++ b/internal/mode/static/state/change_processor_test.go @@ -25,6 +25,7 @@ import ( "github.com/nginxinc/nginx-gateway-fabric/internal/framework/gatewayclass" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/kinds" + ngftypes "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state" staticConds "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/conditions" "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/graph" @@ -2328,7 +2329,7 @@ var _ = Describe("ChangeProcessor", func() { DescribeTable( "CaptureDeleteChange must panic", - func(resourceType client.Object, nsname types.NamespacedName) { + func(resourceType ngftypes.ObjectType, nsname types.NamespacedName) { process := func() { processor.CaptureDeleteChange(resourceType, nsname) } diff --git a/internal/mode/static/state/changed_predicate.go b/internal/mode/static/state/changed_predicate.go index 44b1ff71c9..e8df5581ea 100644 --- a/internal/mode/static/state/changed_predicate.go +++ b/internal/mode/static/state/changed_predicate.go @@ -3,6 +3,8 @@ package state import ( "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" + + ngftypes "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" ) // stateChangedPredicate determines whether upsert and delete events constitute a change in state. @@ -10,13 +12,13 @@ type stateChangedPredicate interface { // upsert returns true if the newObject changes state. upsert(oldObject, newObject client.Object) bool // delete returns true if the deletion of the object changes state. - delete(object client.Object, nsname types.NamespacedName) bool + delete(object ngftypes.ObjectType, nsname types.NamespacedName) bool } // funcPredicate applies the stateChanged function on upsert and delete. On upsert, the newObject is passed. // Implements stateChangedPredicate. type funcPredicate struct { - stateChanged func(object client.Object, nsname types.NamespacedName) bool + stateChanged func(object ngftypes.ObjectType, nsname types.NamespacedName) bool } func (f funcPredicate) upsert(_, newObject client.Object) bool { @@ -27,7 +29,7 @@ func (f funcPredicate) upsert(_, newObject client.Object) bool { return f.stateChanged(newObject, client.ObjectKeyFromObject(newObject)) } -func (f funcPredicate) delete(object client.Object, nsname types.NamespacedName) bool { +func (f funcPredicate) delete(object ngftypes.ObjectType, nsname types.NamespacedName) bool { return f.stateChanged(object, nsname) } @@ -53,4 +55,6 @@ func (a annotationChangedPredicate) upsert(oldObject, newObject client.Object) b return oldAnnotation != newAnnotation } -func (a annotationChangedPredicate) delete(_ client.Object, _ types.NamespacedName) bool { return true } +func (a annotationChangedPredicate) delete(_ ngftypes.ObjectType, _ types.NamespacedName) bool { + return true +} diff --git a/internal/mode/static/state/changed_predicate_test.go b/internal/mode/static/state/changed_predicate_test.go index f82eda158f..7e7bf7304d 100644 --- a/internal/mode/static/state/changed_predicate_test.go +++ b/internal/mode/static/state/changed_predicate_test.go @@ -8,10 +8,12 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" + + ngftypes "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" ) func TestFuncPredicate(t *testing.T) { - alwaysTrueFunc := func(_ client.Object, _ types.NamespacedName) bool { return true } + alwaysTrueFunc := func(_ ngftypes.ObjectType, _ types.NamespacedName) bool { return true } emptyObject := &v1.Pod{} p := funcPredicate{stateChanged: alwaysTrueFunc} @@ -23,7 +25,7 @@ func TestFuncPredicate(t *testing.T) { } func TestFuncPredicate_Panic(t *testing.T) { - alwaysTrueFunc := func(_ client.Object, _ types.NamespacedName) bool { return true } + alwaysTrueFunc := func(_ ngftypes.ObjectType, _ types.NamespacedName) bool { return true } p := funcPredicate{stateChanged: alwaysTrueFunc} diff --git a/internal/mode/static/state/graph/graph.go b/internal/mode/static/state/graph/graph.go index 050ff3409d..4fc86119cb 100644 --- a/internal/mode/static/state/graph/graph.go +++ b/internal/mode/static/state/graph/graph.go @@ -15,6 +15,7 @@ import ( ngfAPI "github.com/nginxinc/nginx-gateway-fabric/apis/v1alpha1" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/controller/index" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/kinds" + ngftypes "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/policies" "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/validation" ) @@ -79,7 +80,7 @@ type Graph struct { type ProtectedPorts map[int32]string // IsReferenced returns true if the Graph references the resource. -func (g *Graph) IsReferenced(resourceType client.Object, nsname types.NamespacedName) bool { +func (g *Graph) IsReferenced(resourceType ngftypes.ObjectType, nsname types.NamespacedName) bool { switch obj := resourceType.(type) { case *v1.Secret: _, exists := g.ReferencedSecrets[nsname] diff --git a/internal/mode/static/state/statefakes/fake_change_processor.go b/internal/mode/static/state/statefakes/fake_change_processor.go index 1b710d4148..7e512a4518 100644 --- a/internal/mode/static/state/statefakes/fake_change_processor.go +++ b/internal/mode/static/state/statefakes/fake_change_processor.go @@ -4,18 +4,19 @@ package statefakes import ( "sync" + "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state" "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/graph" - "k8s.io/apimachinery/pkg/types" + typesa "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" ) type FakeChangeProcessor struct { - CaptureDeleteChangeStub func(client.Object, types.NamespacedName) + CaptureDeleteChangeStub func(types.ObjectType, typesa.NamespacedName) captureDeleteChangeMutex sync.RWMutex captureDeleteChangeArgsForCall []struct { - arg1 client.Object - arg2 types.NamespacedName + arg1 types.ObjectType + arg2 typesa.NamespacedName } CaptureUpsertChangeStub func(client.Object) captureUpsertChangeMutex sync.RWMutex @@ -48,11 +49,11 @@ type FakeChangeProcessor struct { invocationsMutex sync.RWMutex } -func (fake *FakeChangeProcessor) CaptureDeleteChange(arg1 client.Object, arg2 types.NamespacedName) { +func (fake *FakeChangeProcessor) CaptureDeleteChange(arg1 types.ObjectType, arg2 typesa.NamespacedName) { fake.captureDeleteChangeMutex.Lock() fake.captureDeleteChangeArgsForCall = append(fake.captureDeleteChangeArgsForCall, struct { - arg1 client.Object - arg2 types.NamespacedName + arg1 types.ObjectType + arg2 typesa.NamespacedName }{arg1, arg2}) stub := fake.CaptureDeleteChangeStub fake.recordInvocation("CaptureDeleteChange", []interface{}{arg1, arg2}) @@ -68,13 +69,13 @@ func (fake *FakeChangeProcessor) CaptureDeleteChangeCallCount() int { return len(fake.captureDeleteChangeArgsForCall) } -func (fake *FakeChangeProcessor) CaptureDeleteChangeCalls(stub func(client.Object, types.NamespacedName)) { +func (fake *FakeChangeProcessor) CaptureDeleteChangeCalls(stub func(types.ObjectType, typesa.NamespacedName)) { fake.captureDeleteChangeMutex.Lock() defer fake.captureDeleteChangeMutex.Unlock() fake.CaptureDeleteChangeStub = stub } -func (fake *FakeChangeProcessor) CaptureDeleteChangeArgsForCall(i int) (client.Object, types.NamespacedName) { +func (fake *FakeChangeProcessor) CaptureDeleteChangeArgsForCall(i int) (types.ObjectType, typesa.NamespacedName) { fake.captureDeleteChangeMutex.RLock() defer fake.captureDeleteChangeMutex.RUnlock() argsForCall := fake.captureDeleteChangeArgsForCall[i] diff --git a/internal/mode/static/state/store.go b/internal/mode/static/state/store.go index 163d051972..a03cc7f6a5 100644 --- a/internal/mode/static/state/store.go +++ b/internal/mode/static/state/store.go @@ -9,6 +9,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/kinds" + ngftypes "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/policies" "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/graph" ) @@ -16,14 +17,14 @@ import ( // Updater updates the cluster state. type Updater interface { Upsert(obj client.Object) - Delete(objType client.Object, nsname types.NamespacedName) + Delete(objType ngftypes.ObjectType, nsname types.NamespacedName) } // objectStore is a store of client.Object type objectStore interface { - get(objType client.Object, nsname types.NamespacedName) client.Object + get(objType ngftypes.ObjectType, nsname types.NamespacedName) client.Object upsert(obj client.Object) - delete(objType client.Object, nsname types.NamespacedName) + delete(objType ngftypes.ObjectType, nsname types.NamespacedName) } // ngfPolicyObjectStore is a store of policies.Policy. @@ -44,7 +45,7 @@ func newNGFPolicyObjectStore( } } -func (p *ngfPolicyObjectStore) get(objType client.Object, nsname types.NamespacedName) client.Object { +func (p *ngfPolicyObjectStore) get(objType ngftypes.ObjectType, nsname types.NamespacedName) client.Object { key := graph.PolicyKey{ NsName: nsname, GVK: p.extractGVKFunc(objType), @@ -67,7 +68,7 @@ func (p *ngfPolicyObjectStore) upsert(obj client.Object) { p.policies[key] = pol } -func (p *ngfPolicyObjectStore) delete(objType client.Object, nsname types.NamespacedName) { +func (p *ngfPolicyObjectStore) delete(objType ngftypes.ObjectType, nsname types.NamespacedName) { key := graph.PolicyKey{ NsName: nsname, GVK: p.extractGVKFunc(objType), @@ -88,7 +89,7 @@ func newObjectStoreMapAdapter[T client.Object](objects map[types.NamespacedName] } } -func (m *objectStoreMapAdapter[T]) get(_ client.Object, nsname types.NamespacedName) client.Object { +func (m *objectStoreMapAdapter[T]) get(_ ngftypes.ObjectType, nsname types.NamespacedName) client.Object { obj, exist := m.objects[nsname] if !exist { return nil @@ -105,7 +106,7 @@ func (m *objectStoreMapAdapter[T]) upsert(obj client.Object) { m.objects[client.ObjectKeyFromObject(obj)] = t } -func (m *objectStoreMapAdapter[T]) delete(_ client.Object, nsname types.NamespacedName) { +func (m *objectStoreMapAdapter[T]) delete(_ ngftypes.ObjectType, nsname types.NamespacedName) { delete(m.objects, nsname) } @@ -150,7 +151,7 @@ func (m *multiObjectStore) mustFindStoreForObj(obj client.Object) objectStore { return store } -func (m *multiObjectStore) get(objType client.Object, nsname types.NamespacedName) client.Object { +func (m *multiObjectStore) get(objType ngftypes.ObjectType, nsname types.NamespacedName) client.Object { return m.mustFindStoreForObj(objType).get(objType, nsname) } @@ -158,7 +159,7 @@ func (m *multiObjectStore) upsert(obj client.Object) { m.mustFindStoreForObj(obj).upsert(obj) } -func (m *multiObjectStore) delete(objType client.Object, nsname types.NamespacedName) { +func (m *multiObjectStore) delete(objType ngftypes.ObjectType, nsname types.NamespacedName) { m.mustFindStoreForObj(objType).delete(objType, nsname) } @@ -257,7 +258,7 @@ func (s *changeTrackingUpdater) Upsert(obj client.Object) { s.setChangeType(obj, changingUpsert) } -func (s *changeTrackingUpdater) delete(objType client.Object, nsname types.NamespacedName) (changed bool) { +func (s *changeTrackingUpdater) delete(objType ngftypes.ObjectType, nsname types.NamespacedName) (changed bool) { objTypeGVK := s.extractGVK(objType) if s.store.persists(objTypeGVK) { @@ -276,7 +277,7 @@ func (s *changeTrackingUpdater) delete(objType client.Object, nsname types.Names return stateChanged.delete(objType, nsname) } -func (s *changeTrackingUpdater) Delete(objType client.Object, nsname types.NamespacedName) { +func (s *changeTrackingUpdater) Delete(objType ngftypes.ObjectType, nsname types.NamespacedName) { s.assertSupportedGVK(s.extractGVK(objType)) changingDelete := s.delete(objType, nsname) diff --git a/internal/mode/static/status/prepare_requests_test.go b/internal/mode/static/status/prepare_requests_test.go index 407aff11e1..c0629a18f1 100644 --- a/internal/mode/static/status/prepare_requests_test.go +++ b/internal/mode/static/status/prepare_requests_test.go @@ -23,11 +23,12 @@ import ( "github.com/nginxinc/nginx-gateway-fabric/internal/framework/helpers" "github.com/nginxinc/nginx-gateway-fabric/internal/framework/kinds" statusFramework "github.com/nginxinc/nginx-gateway-fabric/internal/framework/status" + ngftypes "github.com/nginxinc/nginx-gateway-fabric/internal/framework/types" staticConds "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/conditions" "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/state/graph" ) -func createK8sClientFor(resourceType client.Object) client.Client { +func createK8sClientFor(resourceType ngftypes.ObjectType) client.Client { scheme := runtime.NewScheme() // for simplicity, we add all used schemes here