Skip to content

Commit 02728eb

Browse files
committed
[Feature] [Networking] ArangoRoute Protocol
1 parent 44f2bf6 commit 02728eb

13 files changed

+475
-20
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- (Feature) (Platform) Chart Integration
2626
- (Maintenance) Switch to google.golang.org/protobuf
2727
- (Feature) Add DebugPackage to the OPS Binary
28+
- (Feature) (Networking) ArangoRoute Protocol
2829

2930
## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14)
3031
- (Feature) ArangoRoute CRD

docs/api/ArangoRoute.V1Alpha1.md

+27-3
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,34 @@ UID keeps the information about object UID
8383

8484
### .spec.destination.path
8585

86-
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.43/pkg/apis/networking/v1alpha1/route_spec_destination.go#L39)</sup>
86+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.43/pkg/apis/networking/v1alpha1/route_spec_destination.go#L46)</sup>
8787

8888
Path defines service path used for overrides
8989

9090
***
9191

92+
### .spec.destination.protocol
93+
94+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.43/pkg/apis/networking/v1alpha1/route_spec_destination.go#L40)</sup>
95+
96+
Protocol defines http protocol used for the route
97+
98+
Possible Values:
99+
* `"http1"` (default) - HTTP 1.1 Protocol
100+
* `"http2"` - HTTP 2 Protocol
101+
102+
***
103+
92104
### .spec.destination.schema
93105

94-
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.43/pkg/apis/networking/v1alpha1/route_spec_destination.go#L33)</sup>
106+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.43/pkg/apis/networking/v1alpha1/route_spec_destination.go#L35)</sup>
95107

96108
Schema defines HTTP/S schema used for connection
97109

110+
Possible Values:
111+
* `"http"` (default) - HTTP Connection
112+
* `"https"` - HTTPS Connection (HTTP with TLS)
113+
98114
***
99115

100116
### .spec.destination.service.checksum
@@ -238,12 +254,20 @@ Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.
238254

239255
### .status.target.path
240256

241-
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.43/pkg/apis/networking/v1alpha1/route_status_target.go#L43)</sup>
257+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.43/pkg/apis/networking/v1alpha1/route_status_target.go#L46)</sup>
242258

243259
Path specifies request path override
244260

245261
***
246262

263+
### .status.target.protocol
264+
265+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.43/pkg/apis/networking/v1alpha1/route_status_target.go#L40)</sup>
266+
267+
Protocol defines http protocol used for the route
268+
269+
***
270+
247271
### .status.target.TLS.insecure
248272

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

pkg/apis/networking/v1alpha1/route_spec_destination.go

+16
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,15 @@ type ArangoRouteSpecDestination struct {
3030
Endpoints *ArangoRouteSpecDestinationEndpoints `json:"endpoints,omitempty"`
3131

3232
// Schema defines HTTP/S schema used for connection
33+
// +doc/enum: http|HTTP Connection
34+
// +doc/enum: https|HTTPS Connection (HTTP with TLS)
3335
Schema *ArangoRouteSpecDestinationSchema `json:"schema,omitempty"`
3436

37+
// Protocol defines http protocol used for the route
38+
// +doc/enum: http1|HTTP 1.1 Protocol
39+
// +doc/enum: http2|HTTP 2 Protocol
40+
Protocol *ArangoRouteDestinationProtocol `json:"protocol,omitempty"`
41+
3542
// TLS defines TLS Configuration
3643
TLS *ArangoRouteSpecDestinationTLS `json:"tls,omitempty"`
3744

@@ -58,6 +65,14 @@ func (a *ArangoRouteSpecDestination) GetEndpoints() *ArangoRouteSpecDestinationE
5865
return a.Endpoints
5966
}
6067

68+
func (a *ArangoRouteSpecDestination) GetProtocol() *ArangoRouteDestinationProtocol {
69+
if a == nil || a.Schema == nil {
70+
return nil
71+
}
72+
73+
return a.Protocol
74+
}
75+
6176
func (a *ArangoRouteSpecDestination) GetSchema() *ArangoRouteSpecDestinationSchema {
6277
if a == nil || a.Schema == nil {
6378
return nil
@@ -100,6 +115,7 @@ func (a *ArangoRouteSpecDestination) Validate() error {
100115
shared.ValidateOptionalInterfacePath("service", a.Service),
101116
shared.ValidateOptionalInterfacePath("endpoints", a.Endpoints),
102117
shared.ValidateOptionalInterfacePath("schema", a.Schema),
118+
shared.ValidateOptionalInterfacePath("protocol", a.Protocol),
103119
shared.ValidateOptionalInterfacePath("tls", a.TLS),
104120
shared.ValidateOptionalInterfacePath("authentication", a.Authentication),
105121
shared.PrefixResourceError("path", shared.ValidateAPIPath(a.GetPath())),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package v1alpha1
22+
23+
import (
24+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
25+
"github.com/arangodb/kube-arangodb/pkg/util/strings"
26+
)
27+
28+
type ArangoRouteDestinationProtocol string
29+
30+
const (
31+
ArangoRouteDestinationProtocolHTTP1 ArangoRouteDestinationProtocol = "http1"
32+
ArangoRouteDestinationProtocolHTTP2 ArangoRouteDestinationProtocol = "http2"
33+
ArangoRouteDestinationProtocolDefault = ArangoRouteDestinationProtocolHTTP1
34+
)
35+
36+
func (a *ArangoRouteDestinationProtocol) Get() ArangoRouteDestinationProtocol {
37+
if a == nil {
38+
return ArangoRouteDestinationProtocolDefault
39+
}
40+
41+
return ArangoRouteDestinationProtocol(strings.ToLower(string(*a)))
42+
}
43+
44+
func (a *ArangoRouteDestinationProtocol) String() string {
45+
return string(a.Get())
46+
}
47+
48+
func (a *ArangoRouteDestinationProtocol) Validate() error {
49+
switch x := a.Get(); x {
50+
case ArangoRouteDestinationProtocolHTTP1, ArangoRouteDestinationProtocolHTTP2:
51+
return nil
52+
default:
53+
return errors.Errorf("Invalid schema: %s", x.String())
54+
}
55+
}

pkg/apis/networking/v1alpha1/route_status_target.go

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ type ArangoRouteStatusTarget struct {
3636
// TLS Keeps target TLS Settings (if not nil, TLS is enabled)
3737
TLS *ArangoRouteStatusTargetTLS `json:"TLS,omitempty"`
3838

39+
// Protocol defines http protocol used for the route
40+
Protocol ArangoRouteDestinationProtocol `json:"protocol,omitempty"`
41+
3942
// Authentication specifies the authentication details
4043
Authentication ArangoRouteStatusTargetAuthentication `json:"authentication,omitempty"`
4144

pkg/apis/networking/v1alpha1/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/crd/crds/networking-route.schema.generated.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,17 @@ v1alpha1:
4949
path:
5050
description: Path defines service path used for overrides
5151
type: string
52+
protocol:
53+
description: Protocol defines http protocol used for the route
54+
enum:
55+
- http1
56+
- http2
57+
type: string
5258
schema:
5359
description: Schema defines HTTP/S schema used for connection
60+
enum:
61+
- http
62+
- https
5463
type: string
5564
service:
5665
description: Service defines service upstream reference

pkg/deployment/resources/gateway/gateway_config_destination.go

+4-17
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ import (
2424
"time"
2525

2626
clusterAPI "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
27-
coreAPI "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
2827
endpointAPI "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
2928
routeAPI "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
30-
upstreamHttpApi "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3"
3129
"google.golang.org/protobuf/types/known/anypb"
3230
"google.golang.org/protobuf/types/known/durationpb"
3331

@@ -63,6 +61,8 @@ type ConfigDestination struct {
6361

6462
Type *ConfigDestinationType `json:"type,omitempty"`
6563

64+
Protocol *ConfigDestinationProtocol `json:"protocol,omitempty"`
65+
6666
Path *string `json:"path,omitempty"`
6767

6868
AuthExtension *ConfigAuthZExtension `json:"authExtension,omitempty"`
@@ -77,6 +77,7 @@ func (c *ConfigDestination) Validate() error {
7777
return shared.WithErrors(
7878
shared.PrefixResourceError("targets", c.Targets.Validate()),
7979
shared.PrefixResourceError("type", c.Type.Validate()),
80+
shared.PrefixResourceError("protocol", c.Protocol.Validate()),
8081
shared.PrefixResourceError("path", shared.ValidateAPIPath(c.GetPath())),
8182
shared.PrefixResourceError("authExtension", c.AuthExtension.Validate()),
8283
shared.PrefixResourceError("upgradeConfigs", c.UpgradeConfigs.Validate()),
@@ -130,21 +131,7 @@ func (c *ConfigDestination) getUpgradeConfigs() ConfigDestinationsUpgrade {
130131
}
131132

132133
func (c *ConfigDestination) RenderCluster(name string) (*clusterAPI.Cluster, error) {
133-
hpo, err := anypb.New(&upstreamHttpApi.HttpProtocolOptions{
134-
UpstreamProtocolOptions: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig_{
135-
ExplicitHttpConfig: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig{
136-
ProtocolConfig: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig_Http2ProtocolOptions{
137-
Http2ProtocolOptions: &coreAPI.Http2ProtocolOptions{
138-
ConnectionKeepalive: &coreAPI.KeepaliveSettings{
139-
Interval: durationpb.New(15 * time.Second),
140-
Timeout: durationpb.New(30 * time.Second),
141-
ConnectionIdleInterval: durationpb.New(60 * time.Second),
142-
},
143-
},
144-
},
145-
},
146-
},
147-
})
134+
hpo, err := anypb.New(c.Protocol.Options())
148135
if err != nil {
149136
return nil, err
150137
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package gateway
22+
23+
import (
24+
"time"
25+
26+
coreAPI "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
27+
upstreamHttpApi "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3"
28+
"google.golang.org/protobuf/types/known/durationpb"
29+
30+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
31+
)
32+
33+
type ConfigDestinationProtocol int
34+
35+
const (
36+
ConfigDestinationProtocolHTTP1 ConfigDestinationProtocol = iota
37+
ConfigDestinationProtocolHTTP2
38+
)
39+
40+
func (c *ConfigDestinationProtocol) Get() ConfigDestinationProtocol {
41+
if c == nil {
42+
return ConfigDestinationProtocolHTTP1
43+
}
44+
45+
switch v := *c; v {
46+
case ConfigDestinationProtocolHTTP1, ConfigDestinationProtocolHTTP2:
47+
return v
48+
default:
49+
return ConfigDestinationProtocolHTTP1
50+
}
51+
}
52+
53+
func (c *ConfigDestinationProtocol) Options() *upstreamHttpApi.HttpProtocolOptions {
54+
switch c.Get() {
55+
case ConfigDestinationProtocolHTTP1:
56+
return &upstreamHttpApi.HttpProtocolOptions{
57+
UpstreamProtocolOptions: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig_{
58+
ExplicitHttpConfig: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig{
59+
ProtocolConfig: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig_HttpProtocolOptions{
60+
HttpProtocolOptions: &coreAPI.Http1ProtocolOptions{},
61+
},
62+
},
63+
},
64+
}
65+
case ConfigDestinationProtocolHTTP2:
66+
return &upstreamHttpApi.HttpProtocolOptions{
67+
UpstreamProtocolOptions: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig_{
68+
ExplicitHttpConfig: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig{
69+
ProtocolConfig: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig_Http2ProtocolOptions{
70+
Http2ProtocolOptions: &coreAPI.Http2ProtocolOptions{
71+
ConnectionKeepalive: &coreAPI.KeepaliveSettings{
72+
Interval: durationpb.New(15 * time.Second),
73+
Timeout: durationpb.New(30 * time.Second),
74+
ConnectionIdleInterval: durationpb.New(60 * time.Second),
75+
},
76+
},
77+
},
78+
},
79+
},
80+
}
81+
default:
82+
return &upstreamHttpApi.HttpProtocolOptions{
83+
UpstreamProtocolOptions: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig_{
84+
ExplicitHttpConfig: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig{
85+
ProtocolConfig: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig_HttpProtocolOptions{
86+
HttpProtocolOptions: &coreAPI.Http1ProtocolOptions{},
87+
},
88+
},
89+
},
90+
}
91+
}
92+
}
93+
94+
func (c *ConfigDestinationProtocol) Validate() error {
95+
switch c.Get() {
96+
case ConfigDestinationProtocolHTTP1, ConfigDestinationProtocolHTTP2:
97+
return nil
98+
default:
99+
return errors.Errorf("Invalid destination protocol")
100+
}
101+
}

pkg/handlers/networking/route/handler_destination_endpoints.go

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func (h *handler) HandleArangoDestinationEndpoints(ctx context.Context, item ope
120120

121121
target.Path = dest.GetPath()
122122
target.Type = networkingApi.ArangoRouteStatusTargetEndpointsType
123+
target.Protocol = dest.GetProtocol().Get()
123124

124125
// Render Auth Settings
125126

0 commit comments

Comments
 (0)