Skip to content

Commit

Permalink
move ks client reader to separated directory (#3018)
Browse files Browse the repository at this point in the history
Problem: Adding update of ks client Reader interface and FakeReader into separated directory.

Solution: Moved files, updated import paths.
  • Loading branch information
miledxz authored Jan 15, 2025
1 parent c9ec2a3 commit b5b8783
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
15 changes: 4 additions & 11 deletions internal/framework/events/first_eventbatch_preparer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/nginx/nginx-gateway-fabric/internal/framework/kubernetes"
)

//counterfeiter:generate . FirstEventBatchPreparer
Expand All @@ -20,22 +22,13 @@ type FirstEventBatchPreparer interface {
Prepare(ctx context.Context) (EventBatch, error)
}

//counterfeiter:generate . Reader

// Reader allows getting and listing resources from a cache.
// This interface is introduced for testing to mock the methods from
// sigs.k8s.io/controller-runtime/pkg/client.Reader.
type Reader interface {
client.Reader
}

// EachListItemFunc lists each item of a client.ObjectList.
// It is from k8s.io/apimachinery/pkg/api/meta.
type EachListItemFunc func(obj runtime.Object, fn func(runtime.Object) error) error

// FirstEventBatchPreparerImpl is an implementation of FirstEventBatchPreparer.
type FirstEventBatchPreparerImpl struct {
reader Reader
reader kubernetes.Reader
eachListItem EachListItemFunc
objects []client.Object
objectLists []client.ObjectList
Expand All @@ -48,7 +41,7 @@ type FirstEventBatchPreparerImpl struct {
// For each list from objectLists, FirstEventBatchPreparerImpl will list the resources of the corresponding type from
// the reader.
func NewFirstEventBatchPreparerImpl(
reader Reader,
reader kubernetes.Reader,
objects []client.Object,
objectLists []client.ObjectList,
) *FirstEventBatchPreparerImpl {
Expand Down
6 changes: 3 additions & 3 deletions internal/framework/events/first_eventbatch_preparer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ import (
v1 "sigs.k8s.io/gateway-api/apis/v1"

"github.com/nginx/nginx-gateway-fabric/internal/framework/events"
"github.com/nginx/nginx-gateway-fabric/internal/framework/events/eventsfakes"
"github.com/nginx/nginx-gateway-fabric/internal/framework/kubernetes/kubernetesfakes"
)

var _ = Describe("FirstEventBatchPreparer", func() {
var (
fakeReader *eventsfakes.FakeReader
fakeReader *kubernetesfakes.FakeReader
preparer *events.FirstEventBatchPreparerImpl
)

const gcName = "my-class"

BeforeEach(func() {
fakeReader = &eventsfakes.FakeReader{}
fakeReader = &kubernetesfakes.FakeReader{}
preparer = events.NewFirstEventBatchPreparerImpl(
fakeReader,
[]client.Object{&v1.GatewayClass{ObjectMeta: metav1.ObjectMeta{Name: gcName}}},
Expand Down
14 changes: 14 additions & 0 deletions internal/framework/kubernetes/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package kubernetes

import "sigs.k8s.io/controller-runtime/pkg/client"

//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate

//counterfeiter:generate . Reader

// Reader allows getting and listing resources from a cache.
// This interface is introduced for testing to mock the methods from
// sigs.k8s.io/controller-runtime/pkg/client.Reader.
type Reader interface {
client.Reader
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions internal/mode/static/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"

ngfAPI "github.com/nginx/nginx-gateway-fabric/apis/v1alpha1"
"github.com/nginx/nginx-gateway-fabric/internal/framework/events/eventsfakes"
"github.com/nginx/nginx-gateway-fabric/internal/framework/kinds"
"github.com/nginx/nginx-gateway-fabric/internal/framework/kubernetes/kubernetesfakes"
"github.com/nginx/nginx-gateway-fabric/internal/mode/static/config"
"github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/dataplane"
"github.com/nginx/nginx-gateway-fabric/internal/mode/static/state/graph"
Expand Down Expand Up @@ -73,7 +73,7 @@ func createGetCallsFunc(objects ...client.Object) getCallsFunc {

var _ = Describe("Collector", Ordered, func() {
var (
k8sClientReader *eventsfakes.FakeReader
k8sClientReader *kubernetesfakes.FakeReader
fakeGraphGetter *telemetryfakes.FakeGraphGetter
fakeConfigurationGetter *telemetryfakes.FakeConfigurationGetter
dataCollector telemetry.DataCollector
Expand Down Expand Up @@ -178,7 +178,7 @@ var _ = Describe("Collector", Ordered, func() {
SnippetsFiltersDirectivesCount: []int64{},
}

k8sClientReader = &eventsfakes.FakeReader{}
k8sClientReader = &kubernetesfakes.FakeReader{}
fakeGraphGetter = &telemetryfakes.FakeGraphGetter{}
fakeConfigurationGetter = &telemetryfakes.FakeConfigurationGetter{}

Expand Down

0 comments on commit b5b8783

Please sign in to comment.