Skip to content

Commit

Permalink
feat: generate UUID for each filter instance (#335)
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Yang <[email protected]>
  • Loading branch information
reaver-flomesh authored Sep 11, 2024
1 parent d0dac23 commit f27a3c8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pkg/gateway/fgw/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type Listener struct {
type ListenerFilter struct {
Type string `json:"type"`
ExtensionConfig map[string]string `json:"extensionConfig,omitempty"`
Key string `json:"key,omitempty"`
}

type GatewayTLSConfig struct {
Expand Down Expand Up @@ -229,6 +230,7 @@ type HTTPRouteFilter struct {
RequestRedirect *gwv1.HTTPRequestRedirectFilter `json:"requestRedirect,omitempty"`
URLRewrite *gwv1.HTTPURLRewriteFilter `json:"urlRewrite,omitempty"`
ExtensionConfig map[string]string `json:"extensionConfig,omitempty"`
Key string `json:"key,omitempty"`
}

// ---
Expand Down Expand Up @@ -262,6 +264,7 @@ type GRPCRouteFilter struct {
ResponseHeaderModifier *gwv1.HTTPHeaderFilter `json:"responseHeaderModifier,omitempty"`
RequestMirror *HTTPRequestMirrorFilter `json:"requestMirror,omitempty"`
ExtensionConfig map[string]string `json:"extensionConfig,omitempty"`
Key string `json:"key,omitempty"`
}

// ---
Expand Down
3 changes: 3 additions & 0 deletions pkg/gateway/processor/v2/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"github.com/google/uuid"

"k8s.io/utils/ptr"

"k8s.io/apimachinery/pkg/fields"
Expand Down Expand Up @@ -171,6 +173,7 @@ func (c *ConfigGenerator) processListenerFilters(l gwtypes.Listener, v2l *fgwv2.
v2l.Filters = append(v2l.Filters, fgwv2.ListenerFilter{
Type: filterType,
ExtensionConfig: f.Spec.Config,
Key: uuid.NewString(),
})

if c.filters[*protocol] == nil {
Expand Down
6 changes: 5 additions & 1 deletion pkg/gateway/processor/v2/grpcroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package v2
import (
"context"

"github.com/google/uuid"

extv1alpha1 "github.com/flomesh-io/fsm/pkg/apis/extension/v1alpha1"

fgwv2 "github.com/flomesh-io/fsm/pkg/gateway/fgw"
Expand Down Expand Up @@ -136,6 +138,7 @@ func (c *ConfigGenerator) toV2GRPCRouteFilters(grpcRoute *gwv1.GRPCRoute, routeF
RequestMirror: &fgwv2.HTTPRequestMirrorFilter{
BackendRef: fgwv2.NewBackendRefWithWeight(svcPort.String(), 1),
},
Key: uuid.NewString(),
})

// TODO: process backend level policies here??? TBD
Expand All @@ -161,14 +164,15 @@ func (c *ConfigGenerator) toV2GRPCRouteFilters(grpcRoute *gwv1.GRPCRoute, routeF
filters = append(filters, fgwv2.GRPCRouteFilter{
Type: gwv1.GRPCRouteFilterType(filterType),
ExtensionConfig: filter.Spec.Config,
Key: uuid.NewString(),
})

if c.filters[filterProtocol] == nil {
c.filters[filterProtocol] = map[string]string{}
}
c.filters[filterProtocol][filterType] = filter.Spec.Script
default:
f2 := fgwv2.GRPCRouteFilter{}
f2 := fgwv2.GRPCRouteFilter{Key: uuid.NewString()}
if err := gwutils.DeepCopy(&f2, &f); err != nil {
continue
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/gateway/processor/v2/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package v2
import (
"context"

"github.com/google/uuid"

extv1alpha1 "github.com/flomesh-io/fsm/pkg/apis/extension/v1alpha1"

fgwv2 "github.com/flomesh-io/fsm/pkg/gateway/fgw"
Expand Down Expand Up @@ -136,6 +138,7 @@ func (c *ConfigGenerator) toV2HTTPRouteFilters(httpRoute *gwv1.HTTPRoute, routeF
RequestMirror: &fgwv2.HTTPRequestMirrorFilter{
BackendRef: fgwv2.NewBackendRefWithWeight(svcPort.String(), 1),
},
Key: uuid.NewString(),
})

// TODO: process backend level policies here??? TBD
Expand All @@ -160,14 +163,15 @@ func (c *ConfigGenerator) toV2HTTPRouteFilters(httpRoute *gwv1.HTTPRoute, routeF
filters = append(filters, fgwv2.HTTPRouteFilter{
Type: gwv1.HTTPRouteFilterType(filterType),
ExtensionConfig: filter.Spec.Config,
Key: uuid.NewString(),
})

if c.filters[filterProtocol] == nil {
c.filters[filterProtocol] = map[string]string{}
}
c.filters[filterProtocol][filterType] = filter.Spec.Script
default:
f2 := fgwv2.HTTPRouteFilter{}
f2 := fgwv2.HTTPRouteFilter{Key: uuid.NewString()}
if err := gwutils.DeepCopy(f2, f); err != nil {
continue
}
Expand Down

0 comments on commit f27a3c8

Please sign in to comment.