Skip to content

Commit

Permalink
make the hooks section in extensions config tiered
Browse files Browse the repository at this point in the history
Signed-off-by: Hamzah Qudsi <[email protected]>
  • Loading branch information
Hamzah Qudsi committed Mar 22, 2023
1 parent 75d4cb5 commit 7ecf1db
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 37 deletions.
22 changes: 20 additions & 2 deletions api/config/v1alpha1/envoygateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ type Extension struct {
// Hooks defines the set of hooks the extension supports
//
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinItems=1
Hooks []ExtensionHook `json:"hooks,omitempty"`
Hooks *ExtensionHooks `json:"hooks,omitempty"`

// Service defines the configuration of the extension service that the Envoy
// Gateway Control Plane will call through extension hooks.
Expand All @@ -162,6 +161,25 @@ type Extension struct {
Service *ExtensionService `json:"service,omitempty"`
}

// ExtensionHooks defines extension hooks across all supported runners
type ExtensionHooks struct {
// XDS defines all the supported extension hooks for the XDS runner
XDS *XDSHooks `json:"xds,omitempty"`
}

// RunnerHooks is a generic type that contains all the pre and post hook for a runner.
// We disable DeepCopy generation and instead concretely instantiate types so that controller-gen
// will generate the DeepCopy methods correctly.
//
// +kubebuilder:object:generate=false
type RunnerHooks[T ExtensionHook] struct {
Pre []T `json:"pre,omitempty"`
Post []T `json:"post,omitempty"`
}

// XDSHooks contains all the pre and post hooks for the XDS translation runner
type XDSHooks RunnerHooks[XDSHook]

// ExtensionService defines the configuration for connecting to a registered extension service.
type ExtensionService struct {
// Host define the extension service hostname.
Expand Down
21 changes: 14 additions & 7 deletions api/config/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,21 @@ type KubernetesServiceSpec struct {
// TODO: Expose config as use cases are better understood, e.g. labels.
}

// ExtensionHook defines the types of hooks that an Envoy Gateway extension may support
// ExtensionHook is a type constraint to represent all supported hook types
//
// +kubebuilder:validation:Enum=XDSVirtualHost;XDSRoute;XDSHTTPListener;XDSPostTranslation
type ExtensionHook string
// +kubebuilder:object:generate=false
type ExtensionHook interface {
XDSHook
}

// XDSHook defines the types of XDS hooks that an Envoy Gateway extension may support
//
// +kubebuilder:validation:Enum=VirtualHost;Route;HTTPListener;Translation
type XDSHook string

const (
XDSVirtualHost ExtensionHook = "XDSVirtualHost"
XDSRoute ExtensionHook = "XDSRoute"
XDSHTTPListener ExtensionHook = "XDSHTTPListener"
XDSPostTranslation ExtensionHook = "XDSPostTranslation"
XDSPostVirtualHost XDSHook = "VirtualHost"
XDSPostRoute XDSHook = "Route"
XDSPostHTTPListener XDSHook = "HTTPListener"
XDSPostTranslation XDSHook = "Translation"
)
49 changes: 47 additions & 2 deletions api/config/v1alpha1/zz_generated.deepcopy.go

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

6 changes: 5 additions & 1 deletion internal/envoygateway/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ func (s *Server) Validate() error {
return fmt.Errorf("unknown ratelimit redis url format: %w", err)
}
case s.EnvoyGateway.Extension != nil:
if len(s.EnvoyGateway.Extension.Hooks) == 0 {
if s.EnvoyGateway.Extension.Hooks == nil || s.EnvoyGateway.Extension.Hooks.XDS == nil {
return fmt.Errorf("registered extension has no hooks specified")
}

if len(s.EnvoyGateway.Extension.Hooks.XDS.Pre) == 0 && len(s.EnvoyGateway.Extension.Hooks.XDS.Post) == 0 {
return fmt.Errorf("registered extension has no hooks specified")
}

Expand Down
75 changes: 50 additions & 25 deletions internal/envoygateway/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,16 @@ func TestValidate(t *testing.T) {
Kind: "Foo",
},
},
Hooks: []v1alpha1.ExtensionHook{
v1alpha1.XDSHTTPListener,
v1alpha1.XDSPostTranslation,
v1alpha1.XDSRoute,
v1alpha1.XDSVirtualHost,
Hooks: &v1alpha1.ExtensionHooks{
XDS: &v1alpha1.XDSHooks{
Pre: []v1alpha1.XDSHook{},
Post: []v1alpha1.XDSHook{
v1alpha1.XDSPostHTTPListener,
v1alpha1.XDSPostTranslation,
v1alpha1.XDSPostRoute,
v1alpha1.XDSPostVirtualHost,
},
},
},
Service: &v1alpha1.ExtensionService{
Host: "foo.extension",
Expand Down Expand Up @@ -227,11 +232,16 @@ func TestValidate(t *testing.T) {
Kind: "Foo",
},
},
Hooks: []v1alpha1.ExtensionHook{
v1alpha1.XDSHTTPListener,
v1alpha1.XDSPostTranslation,
v1alpha1.XDSRoute,
v1alpha1.XDSVirtualHost,
Hooks: &v1alpha1.ExtensionHooks{
XDS: &v1alpha1.XDSHooks{
Pre: []v1alpha1.XDSHook{},
Post: []v1alpha1.XDSHook{
v1alpha1.XDSPostHTTPListener,
v1alpha1.XDSPostTranslation,
v1alpha1.XDSPostRoute,
v1alpha1.XDSPostVirtualHost,
},
},
},
Service: &v1alpha1.ExtensionService{
Host: "foo.extension",
Expand All @@ -258,11 +268,16 @@ func TestValidate(t *testing.T) {
Gateway: v1alpha1.DefaultGateway(),
Provider: v1alpha1.DefaultProvider(),
Extension: &v1alpha1.Extension{
Hooks: []v1alpha1.ExtensionHook{
v1alpha1.XDSHTTPListener,
v1alpha1.XDSPostTranslation,
v1alpha1.XDSRoute,
v1alpha1.XDSVirtualHost,
Hooks: &v1alpha1.ExtensionHooks{
XDS: &v1alpha1.XDSHooks{
Pre: []v1alpha1.XDSHook{},
Post: []v1alpha1.XDSHook{
v1alpha1.XDSPostHTTPListener,
v1alpha1.XDSPostTranslation,
v1alpha1.XDSPostRoute,
v1alpha1.XDSPostVirtualHost,
},
},
},
Service: &v1alpha1.ExtensionService{
Host: "foo.extension",
Expand Down Expand Up @@ -296,11 +311,16 @@ func TestValidate(t *testing.T) {
Kind: "Foo",
},
},
Hooks: []v1alpha1.ExtensionHook{
v1alpha1.XDSHTTPListener,
v1alpha1.XDSPostTranslation,
v1alpha1.XDSRoute,
v1alpha1.XDSVirtualHost,
Hooks: &v1alpha1.ExtensionHooks{
XDS: &v1alpha1.XDSHooks{
Pre: []v1alpha1.XDSHook{},
Post: []v1alpha1.XDSHook{
v1alpha1.XDSPostHTTPListener,
v1alpha1.XDSPostTranslation,
v1alpha1.XDSPostRoute,
v1alpha1.XDSPostVirtualHost,
},
},
},
Service: &v1alpha1.ExtensionService{
Host: "foo.extension",
Expand Down Expand Up @@ -334,11 +354,16 @@ func TestValidate(t *testing.T) {
Kind: "Foo",
},
},
Hooks: []v1alpha1.ExtensionHook{
v1alpha1.XDSHTTPListener,
v1alpha1.XDSPostTranslation,
v1alpha1.XDSRoute,
v1alpha1.XDSVirtualHost,
Hooks: &v1alpha1.ExtensionHooks{
XDS: &v1alpha1.XDSHooks{
Pre: []v1alpha1.XDSHook{},
Post: []v1alpha1.XDSHook{
v1alpha1.XDSPostHTTPListener,
v1alpha1.XDSPostTranslation,
v1alpha1.XDSPostRoute,
v1alpha1.XDSPostVirtualHost,
},
},
},
},
},
Expand Down

0 comments on commit 7ecf1db

Please sign in to comment.