-
Notifications
You must be signed in to change notification settings - Fork 460
refactor the kubernetes provider to be provider-agnostic #3213
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
Comments
Make sense to me, it helps for multi-provider support. |
will try to first refactor the current existing k8s provider, and then implement for the new coming file provider. |
This issue has been automatically marked as stale because it has not had activity in the last 30 days. |
Is it possible with this refactoring that part of the gateway resources come from k8s and another part from files ( Gateway api related)? |
hey @sky92zwq we'll need to update the |
This issue has been automatically marked as stale because it has not had activity in the last 30 days. |
Found a simple yet effective way to let other provider (like file provider) to reuse the k8s reconcile logic. Create a offline k8s controller structure, like: package kubernetes
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/envoygateway"
"github.com/envoyproxy/gateway/internal/envoygateway/config"
"github.com/envoyproxy/gateway/internal/message"
)
// OfflineGatewayAPIReconciler
type OfflineGatewayAPIReconciler struct {
gatewayAPIReconciler
// offline Client
Client client.Client
}
func NewOfflineGatewayAPIController(
ctx context.Context, cfg *config.Server, su Updater, resources *message.ProviderResources,
) (*OfflineGatewayAPIReconciler, error) {
// Do not allow k8s provider to use this controller.
if cfg.EnvoyGateway.Provider.Type == egv1a1.ProviderTypeKubernetes {
return nil, fmt.Errorf("offline ")
}
// Gather additional resources to watch from registered extensions
var (
extGVKs []schema.GroupVersionKind
extServerPoliciesGVKs []schema.GroupVersionKind
)
if cfg.EnvoyGateway.ExtensionManager != nil {
for _, rsrc := range cfg.EnvoyGateway.ExtensionManager.Resources {
gvk := schema.GroupVersionKind(rsrc)
extGVKs = append(extGVKs, gvk)
}
for _, rsrc := range cfg.EnvoyGateway.ExtensionManager.PolicyResources {
gvk := schema.GroupVersionKind(rsrc)
extServerPoliciesGVKs = append(extServerPoliciesGVKs, gvk)
}
}
// Using fake client to store resources.
cli := fake.NewClientBuilder().
WithScheme(envoygateway.GetScheme()).
WithIndex(&gwapiv1.Gateway{}, classGatewayIndex, func(rawObj client.Object) []string {
gateway := rawObj.(*gwapiv1.Gateway)
return []string{string(gateway.Spec.GatewayClassName)}
}).
WithIndex(&gwapiv1.HTTPRoute{}, gatewayHTTPRouteIndex, gatewayHTTPRouteIndexFunc).
// with other index ...
Build()
r := gatewayAPIReconciler{
client: cli,
log: cfg.Logger,
classController: gwapiv1.GatewayController(cfg.EnvoyGateway.Gateway.ControllerName),
namespace: cfg.Namespace,
statusUpdater: su, // todo
resources: resources,
extGVKs: extGVKs,
store: newProviderStore(),
envoyGateway: cfg.EnvoyGateway,
mergeGateways: sets.New[string](),
extServerPolicies: extServerPoliciesGVKs,
}
if byNamespaceSelectorEnabled(cfg.EnvoyGateway) {
r.namespaceLabel = cfg.EnvoyGateway.Provider.Kubernetes.Watch.NamespaceSelector // todo
}
r.log.Info("created offline gatewayapi controller")
r.subscribeAndUpdateStatus(ctx, cfg.EnvoyGateway.EnvoyGatewaySpec.ExtensionManager != nil)
return &OfflineGatewayAPIReconciler{
gatewayAPIReconciler: r,
Client: cli,
}, nil
}
// Reconcile
func (r *OfflineGatewayAPIReconciler) Reconcile(ctx context.Context) error {
_, err := r.gatewayAPIReconciler.Reconcile(ctx, reconcile.Request{})
return err
}
|
Description:
For now, all the resources related process method in k8s provider are coupling deeply with k8s client, we should free these method from it.
gateway/internal/provider/kubernetes/controller.go
Line 698 in e8b8074
So I propose a refactor: the basic idea is to separate how we process resources and how we retrieve resources.
By defining
Operations
interface andResourceProcessor
structure, each provider can maintain their own implemention ofOperations
, and different provider can share the sameResourceProcessor
.we can
[optional Relevant Links:]
The text was updated successfully, but these errors were encountered: