Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use controllers.DataPlane interface instead of concrete *dataplane.KongClient #4383

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion hack/generators/controllers/networking/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/kong/kubernetes-ingress-controller/v2/internal/controllers"
ctrlref "github.com/kong/kubernetes-ingress-controller/v2/internal/controllers/reference"
ctrlutils "github.com/kong/kubernetes-ingress-controller/v2/internal/controllers/utils"
"github.com/kong/kubernetes-ingress-controller/v2/internal/dataplane"
Expand Down Expand Up @@ -420,7 +421,7 @@ type {{.PackageAlias}}{{.Kind}}Reconciler struct {

Log logr.Logger
Scheme *runtime.Scheme
DataplaneClient *dataplane.KongClient
DataplaneClient controllers.DataPlane
CacheSyncTimeout time.Duration
{{- if .CapableOfStatusUpdates }}

Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/configuration/object_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kong/kubernetes-ingress-controller/v2/internal/annotations"
"github.com/kong/kubernetes-ingress-controller/v2/internal/controllers"
ctrlref "github.com/kong/kubernetes-ingress-controller/v2/internal/controllers/reference"
"github.com/kong/kubernetes-ingress-controller/v2/internal/dataplane"
kongv1 "github.com/kong/kubernetes-ingress-controller/v2/pkg/apis/configuration/v1"
kongv1beta1 "github.com/kong/kubernetes-ingress-controller/v2/pkg/apis/configuration/v1beta1"
)
Expand All @@ -19,7 +19,7 @@ import (
// currently it only updates reference records to secrets, since we wanted to limit cache size of secrets:
// https://github.com/Kong/kubernetes-ingress-controller/issues/2868
func updateReferredObjects(
ctx context.Context, client client.Client, refIndexers ctrlref.CacheIndexers, dataplaneClient *dataplane.KongClient, obj client.Object,
ctx context.Context, client client.Client, refIndexers ctrlref.CacheIndexers, dataplaneClient controllers.DataPlane, obj client.Object,
) error {
referredSecretNameMap := make(map[k8stypes.NamespacedName]struct{})
var referredSecretList []k8stypes.NamespacedName
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/configuration/secret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/kong/kubernetes-ingress-controller/v2/internal/controllers"
ctrlref "github.com/kong/kubernetes-ingress-controller/v2/internal/controllers/reference"
"github.com/kong/kubernetes-ingress-controller/v2/internal/dataplane"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util"
)

Expand All @@ -36,7 +36,7 @@ type CoreV1SecretReconciler struct {

Log logr.Logger
Scheme *runtime.Scheme
DataplaneClient *dataplane.KongClient
DataplaneClient controllers.DataPlane
CacheSyncTimeout time.Duration

ReferenceIndexers ctrlref.CacheIndexers
Expand Down
25 changes: 13 additions & 12 deletions internal/controllers/configuration/zz_generated_controllers.go

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

9 changes: 4 additions & 5 deletions internal/controllers/dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ import (
)

// DataPlane is a common interface that is used by reconcilers to interact
// with the dataplane.
//
// TODO: This can probably be used in other reconcilers as well.
// Related issue: https://github.com/Kong/kubernetes-ingress-controller/issues/3794
// with the Kong dataplane.
type DataPlane interface {
DataPlaneClient

Listeners(ctx context.Context) ([]kong.ProxyListener, []kong.StreamListener, error)
AreKubernetesObjectReportsEnabled() bool
KubernetesObjectConfigurationStatus(obj client.Object) k8sobj.ConfigurationStatus
KubernetesObjectIsConfigured(obj client.Object) bool
}

// DataPlaneClient is a common client interface that is used by reconcilers to interact
// with the dataplane to perform CRUD operations on provided objects.
// with the Kong dataplane to perform CRUD operations on provided objects.
type DataPlaneClient interface {
UpdateObject(obj client.Object) error
DeleteObject(obj client.Object) error
ObjectExists(obj client.Object) (bool, error)
}
4 changes: 2 additions & 2 deletions internal/controllers/gateway/grpcroute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/kong/kubernetes-ingress-controller/v2/internal/dataplane"
"github.com/kong/kubernetes-ingress-controller/v2/internal/controllers"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util"
k8sobj "github.com/kong/kubernetes-ingress-controller/v2/internal/util/kubernetes/object"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util/kubernetes/object/status"
Expand All @@ -40,7 +40,7 @@ type GRPCRouteReconciler struct {

Log logr.Logger
Scheme *runtime.Scheme
DataplaneClient *dataplane.KongClient
DataplaneClient controllers.DataPlane
StatusQueue *status.Queue
// If EnableReferenceGrant is true, we will check for ReferenceGrant if backend in another
// namespace is in backendRefs.
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/gateway/referencegrant_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/kong/kubernetes-ingress-controller/v2/internal/dataplane"
"github.com/kong/kubernetes-ingress-controller/v2/internal/controllers"
)

// ReferenceGrantReconciler reconciles a ReferenceGrant object.
type ReferenceGrantReconciler struct {
client.Client
Log logr.Logger
Scheme *runtime.Scheme
DataplaneClient *dataplane.KongClient
DataplaneClient controllers.DataPlane

CacheSyncTimeout time.Duration
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/gateway/tcproute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/kong/kubernetes-ingress-controller/v2/internal/dataplane"
"github.com/kong/kubernetes-ingress-controller/v2/internal/controllers"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util"
k8sobj "github.com/kong/kubernetes-ingress-controller/v2/internal/util/kubernetes/object"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util/kubernetes/object/status"
Expand All @@ -40,7 +40,7 @@ type TCPRouteReconciler struct {

Log logr.Logger
Scheme *runtime.Scheme
DataplaneClient *dataplane.KongClient
DataplaneClient controllers.DataPlane
CacheSyncTimeout time.Duration
StatusQueue *status.Queue
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/gateway/tlsroute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/kong/kubernetes-ingress-controller/v2/internal/dataplane"
"github.com/kong/kubernetes-ingress-controller/v2/internal/controllers"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util"
k8sobj "github.com/kong/kubernetes-ingress-controller/v2/internal/util/kubernetes/object"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util/kubernetes/object/status"
Expand All @@ -40,7 +40,7 @@ type TLSRouteReconciler struct {

Log logr.Logger
Scheme *runtime.Scheme
DataplaneClient *dataplane.KongClient
DataplaneClient controllers.DataPlane
CacheSyncTimeout time.Duration
StatusQueue *status.Queue
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/gateway/udproute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/kong/kubernetes-ingress-controller/v2/internal/dataplane"
"github.com/kong/kubernetes-ingress-controller/v2/internal/controllers"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util"
k8sobj "github.com/kong/kubernetes-ingress-controller/v2/internal/util/kubernetes/object"
"github.com/kong/kubernetes-ingress-controller/v2/internal/util/kubernetes/object/status"
Expand All @@ -40,7 +40,7 @@ type UDPRouteReconciler struct {

Log logr.Logger
Scheme *runtime.Scheme
DataplaneClient *dataplane.KongClient
DataplaneClient controllers.DataPlane
CacheSyncTimeout time.Duration
StatusQueue *status.Queue
}
Expand Down
3 changes: 2 additions & 1 deletion internal/controllers/knative/knative.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/kong/kubernetes-ingress-controller/v2/internal/controllers"
ctrlref "github.com/kong/kubernetes-ingress-controller/v2/internal/controllers/reference"
ctrlutils "github.com/kong/kubernetes-ingress-controller/v2/internal/controllers/utils"
"github.com/kong/kubernetes-ingress-controller/v2/internal/dataplane"
Expand All @@ -39,7 +40,7 @@ type Knativev1alpha1IngressReconciler struct {

Log logr.Logger
Scheme *runtime.Scheme
DataplaneClient *dataplane.KongClient
DataplaneClient controllers.DataPlane

DataplaneAddressFinder *dataplane.AddressFinder
StatusQueue *status.Queue
Expand Down
2 changes: 2 additions & 0 deletions internal/dataplane/kong_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ func (c *KongClient) KubernetesObjectIsConfigured(obj client.Object) bool {
return c.kubernetesObjectReportsFilter.Get(obj) == k8sobj.ConfigurationStatusSucceeded
}

// KubernetesObjectConfigurationStatus reports the status of applying provided object's
// configuration to the data-plane.
func (c *KongClient) KubernetesObjectConfigurationStatus(obj client.Object) k8sobj.ConfigurationStatus {
c.kubernetesObjectReportLock.RLock()
defer c.kubernetesObjectReportLock.RUnlock()
Expand Down
3 changes: 2 additions & 1 deletion internal/manager/controllerdef.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/kong/kubernetes-ingress-controller/v2/internal/controllers"
"github.com/kong/kubernetes-ingress-controller/v2/internal/controllers/configuration"
"github.com/kong/kubernetes-ingress-controller/v2/internal/controllers/crds"
"github.com/kong/kubernetes-ingress-controller/v2/internal/controllers/gateway"
Expand Down Expand Up @@ -59,7 +60,7 @@ func (c *ControllerDef) MaybeSetupWithManager(mgr ctrl.Manager) error {

func setupControllers(
mgr manager.Manager,
dataplaneClient *dataplane.KongClient,
dataplaneClient controllers.DataPlane,
dataplaneAddressFinder *dataplane.AddressFinder,
udpDataplaneAddressFinder *dataplane.AddressFinder,
kubernetesStatusQueue *status.Queue,
Expand Down
13 changes: 11 additions & 2 deletions test/mocks/dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ func (d Dataplane) DeleteObject(_ client.Object) error {
return nil
}

func (d Dataplane) ObjectExists(obj client.Object) (bool, error) {
_, exists := d.ObjectsStatuses[obj.GetNamespace()][obj.GetName()]
return exists, nil
}

func (d Dataplane) Listeners(context.Context) ([]kong.ProxyListener, []kong.StreamListener, error) {
return nil, nil, nil
}

func (d Dataplane) AreKubernetesObjectReportsEnabled() bool {
return d.KubernetesObjectReportsEnabled
}
Expand All @@ -34,6 +43,6 @@ func (d Dataplane) KubernetesObjectConfigurationStatus(obj client.Object) k8sobj
return d.ObjectsStatuses[obj.GetNamespace()][obj.GetName()]
}

func (d Dataplane) Listeners(context.Context) ([]kong.ProxyListener, []kong.StreamListener, error) {
return nil, nil, nil
func (d Dataplane) KubernetesObjectIsConfigured(obj client.Object) bool {
return d.ObjectsStatuses[obj.GetNamespace()][obj.GetName()] == k8sobj.ConfigurationStatusSucceeded
}