Skip to content

refactor the kubernetes provider to be provider-agnostic #3213

@shawnh2

Description

@shawnh2

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.

func (r *gatewayAPIReconciler) processGateways(ctx context.Context, managedGC *gwapiv1.GatewayClass, resourceMap *resourceMappings, resourceTree *gatewayapi.Resources) error {

So I propose a refactor: the basic idea is to separate how we process resources and how we retrieve resources.

By defining Operations interface and ResourceProcessor structure, each provider can maintain their own implemention of Operations, and different provider can share the same ResourceProcessor.

type Operations interface {
    ListGateways()
    ListHTTPRoutes()
    FindReferenceGrant()
    ...
}

type ResourceProcessor struct {
    Operations
}

func (r *ResourceProcessor) ProcessGateways() {
    // use r.ListGateways() to retrieve all Gateway resources
}
func (r *ResourceProcessor) ProcessHTTPRoutes() {}
func (r *ResourceProcessor) findReferenceGrant() {}
...

we can

  • let k8s provider only foucs on how to retrieve resources, so does file provider
  • the k8s and file provider can share the same process logic for resources, and we don't need to maintain two places of code for each provider type

[optional Relevant Links:]

Any extra documentation required to understand the issue.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions