Skip to content

Commit

Permalink
[Feature] [Networking] ArangoRotue WebSocket Support (#1759)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanikow authored Nov 5, 2024
1 parent 70ba9f9 commit 52087c1
Show file tree
Hide file tree
Showing 14 changed files with 478 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- (Feature) (Platform) Storage V1Alpha1
- (Feature) StorageV2 Integration Service Implementation
- (Feature) (Platform) Storage V1Alpha1 RC
- (Feature) (Networking) ArangoRotue WebSocket Support

## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14)
- (Feature) ArangoRoute CRD
Expand Down
19 changes: 19 additions & 0 deletions docs/api/ArangoRoute.V1Alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ Insecure allows Insecure traffic

***

### .spec.options.upgrade\[int\].enabled

Type: `boolean` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.43/pkg/apis/networking/v1alpha1/route_spec_options_upgrade.go#L37)</sup>

Enabled defines if upgrade option is enabled

***

### .spec.options.upgrade\[int\].type

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.43/pkg/apis/networking/v1alpha1/route_spec_options_upgrade.go#L34)</sup>

Type defines type of the Upgrade

Possible Values:
* `"websocket"` (default) - HTTP WebSocket Upgrade type

***

### .spec.route.path

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.43/pkg/apis/networking/v1alpha1/route_spec_route.go#L29)</sup>
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/networking/v1alpha1/route_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type ArangoRouteSpec struct {

// Route defines the route spec
Route *ArangoRouteSpecRoute `json:"route,omitempty"`

// Options defines connection upgrade options
Options *ArangoRouteSpecOptions `json:"options,omitempty"`
}

func (s *ArangoRouteSpec) GetDeployment() string {
Expand Down Expand Up @@ -65,6 +68,7 @@ func (s *ArangoRouteSpec) Validate() error {
shared.PrefixResourceErrors("deployment", shared.ValidateResourceNamePointer(s.Deployment)),
shared.ValidateRequiredInterfacePath("destination", s.Destination),
shared.ValidateOptionalInterfacePath("route", s.Route),
shared.ValidateOptionalInterfacePath("options", s.Options),
)); err != nil {
return err
}
Expand Down
42 changes: 42 additions & 0 deletions pkg/apis/networking/v1alpha1/route_spec_options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package v1alpha1

import shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"

type ArangoRouteSpecOptions struct {
// Upgrade keeps the connection upgrade options
Upgrade ArangoRouteSpecOptionsUpgrade `json:"upgrade,omitempty"`
}

func (a *ArangoRouteSpecOptions) Validate() error {
if a == nil {
a = &ArangoRouteSpecOptions{}
}

if err := shared.WithErrors(
shared.ValidateOptionalInterfacePath("upgrade", a.Upgrade),
); err != nil {
return err
}

return nil
}
48 changes: 48 additions & 0 deletions pkg/apis/networking/v1alpha1/route_spec_options_upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package v1alpha1

import shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"

type ArangoRouteSpecOptionsUpgrade []ArangoRouteSpecOptionUpgrade

func (a ArangoRouteSpecOptionsUpgrade) Validate() error {
return shared.ValidateInterfaceList(a)
}

type ArangoRouteSpecOptionUpgrade struct {
// Type defines type of the Upgrade
// +doc/enum: websocket|HTTP WebSocket Upgrade type
Type ArangoRouteUpgradeOptionType `json:"type"`

// Enabled defines if upgrade option is enabled
Enabled *bool `json:"enabled,omitempty"`
}

func (a ArangoRouteSpecOptionUpgrade) Validate() error {
if err := shared.WithErrors(
shared.ValidateRequiredInterfacePath("type", a.Type),
); err != nil {
return err
}

return nil
}
38 changes: 38 additions & 0 deletions pkg/apis/networking/v1alpha1/route_upgrade_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package v1alpha1

import "github.com/arangodb/kube-arangodb/pkg/util/errors"

type ArangoRouteUpgradeOptionType string

const (
ArangoRouteUpgradeOptionWebsocket ArangoRouteUpgradeOptionType = "websocket"
)

func (a ArangoRouteUpgradeOptionType) Validate() error {
switch a {
case ArangoRouteUpgradeOptionWebsocket:
return nil
default:
return errors.Errorf("Invalid UpgradeOptionType: %s", a)
}
}
62 changes: 62 additions & 0 deletions pkg/apis/networking/v1alpha1/zz_generated.deepcopy.go

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

11 changes: 11 additions & 0 deletions pkg/apis/shared/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ func ValidateRequiredInterfacePath[T ValidateInterface](path string, in T) error
return PrefixResourceErrors(path, ValidateRequiredInterface(in))
}

// ValidateInterfaceList Validates object if is not nil with path
func ValidateInterfaceList[T ValidateInterface](in []T) error {
errors := make([]error, len(in))

for id := range in {
errors[id] = PrefixResourceError(fmt.Sprintf("[%d]", id), in[id].Validate())
}

return WithErrors(errors...)
}

// ValidateList validates all elements on the list
func ValidateList[T any](in []T, validator func(T) error, checks ...func(in []T) error) error {
errors := make([]error, len(in)+len(checks))
Expand Down
18 changes: 18 additions & 0 deletions pkg/crd/crds/networking-route.schema.generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ v1alpha1:
type: boolean
type: object
type: object
options:
description: Options defines connection upgrade options
properties:
upgrade:
description: Upgrade keeps the connection upgrade options
items:
properties:
enabled:
description: Enabled defines if upgrade option is enabled
type: boolean
type:
description: Type defines type of the Upgrade
enum:
- websocket
type: string
type: object
type: array
type: object
route:
description: Route defines the route spec
properties:
Expand Down
14 changes: 13 additions & 1 deletion pkg/deployment/resources/gateway/gateway_config_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type ConfigDestination struct {
Path *string `json:"path,omitempty"`

AuthExtension *ConfigAuthZExtension `json:"authExtension,omitempty"`

UpgradeConfigs ConfigDestinationsUpgrade `json:"upgradeConfigs,omitempty"`
}

func (c *ConfigDestination) Validate() error {
Expand All @@ -78,6 +80,7 @@ func (c *ConfigDestination) Validate() error {
shared.PrefixResourceError("type", c.Type.Validate()),
shared.PrefixResourceError("path", shared.ValidateAPIPath(c.GetPath())),
shared.PrefixResourceError("authExtension", c.AuthExtension.Validate()),
shared.PrefixResourceError("upgradeConfigs", c.UpgradeConfigs.Validate()),
)
}

Expand Down Expand Up @@ -111,13 +114,22 @@ func (c *ConfigDestination) RenderRoute(name, prefix string) (*routeAPI.Route, e
ClusterSpecifier: &routeAPI.RouteAction_Cluster{
Cluster: name,
},
PrefixRewrite: c.GetPath(),
UpgradeConfigs: c.getUpgradeConfigs().render(),
PrefixRewrite: c.GetPath(),
},
},
TypedPerFilterConfig: tc,
}, nil
}

func (c *ConfigDestination) getUpgradeConfigs() ConfigDestinationsUpgrade {
if c == nil {
return nil
}

return c.UpgradeConfigs
}

func (c *ConfigDestination) RenderCluster(name string) (*clusterAPI.Cluster, error) {
hpo, err := anypb.New(&upstreamHttpApi.HttpProtocolOptions{
UpstreamProtocolOptions: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig_{
Expand Down
Loading

0 comments on commit 52087c1

Please sign in to comment.