Skip to content

Commit 491f7d8

Browse files
authored
[Feature] [Platform] ArangoRoute Redirect (#1991)
1 parent feee614 commit 491f7d8

19 files changed

+709
-44
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- (Bugfix) (Platform) Installer move to OCI
1919
- (Bugfix) (Platform) Fix Monitoring RBAC
2020
- (Feature) (Platform) Do not require LM during install commands
21+
- (Feature) (Platform) ArangoRoute Redirect
2122

2223
## [1.3.1](https://github.com/arangodb/kube-arangodb/tree/1.3.1) (2025-10-07)
2324
- (Documentation) Add ArangoPlatformStorage Docs & Examples

docs/api/ArangoRoute.V1Beta1.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ Port defines Port or Port Name used as destination
7373

7474
### .spec.destination.path
7575

76-
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.3.1/pkg/apis/networking/v1beta1/route_spec_destination.go#L52)</sup>
76+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.3.1/pkg/apis/networking/v1beta1/route_spec_destination.go#L57)</sup>
7777

7878
Path defines service path used for overrides
7979

8080
***
8181

8282
### .spec.destination.protocol
8383

84-
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.3.1/pkg/apis/networking/v1beta1/route_spec_destination.go#L46)</sup>
84+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.3.1/pkg/apis/networking/v1beta1/route_spec_destination.go#L51)</sup>
8585

8686
Protocol defines http protocol used for the route
8787

@@ -91,9 +91,19 @@ Possible Values:
9191

9292
***
9393

94+
### .spec.destination.redirect.code
95+
96+
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.3.1/pkg/apis/networking/v1beta1/route_spec_destination_redirect.go#L33)</sup>
97+
98+
Code the redirection response status code
99+
100+
Default Value: `307`
101+
102+
***
103+
94104
### .spec.destination.schema
95105

96-
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.3.1/pkg/apis/networking/v1beta1/route_spec_destination.go#L41)</sup>
106+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.3.1/pkg/apis/networking/v1beta1/route_spec_destination.go#L45)</sup>
97107

98108
Schema defines HTTP/S schema used for connection
99109

@@ -133,7 +143,7 @@ Port defines Port or Port Name used as destination
133143

134144
### .spec.destination.timeout
135145

136-
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.3.1/pkg/apis/networking/v1beta1/route_spec_destination.go#L60)</sup>
146+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.3.1/pkg/apis/networking/v1beta1/route_spec_destination.go#L65)</sup>
137147

138148
Timeout specify the upstream request timeout
139149

pkg/apis/networking/v1beta1/route_spec_destination.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@ type ArangoRouteSpecDestination struct {
3535
// Endpoints defines service upstream reference - which is used to find endpoints
3636
Endpoints *ArangoRouteSpecDestinationEndpoints `json:"endpoints,omitempty"`
3737

38+
// Redirect defines redirect instruction
39+
Redirect *ArangoRouteSpecDestinationRedirect `json:"redirect,omitempty"`
40+
3841
// Schema defines HTTP/S schema used for connection
42+
// +doc/default: http
3943
// +doc/enum: http|HTTP Connection
4044
// +doc/enum: https|HTTPS Connection (HTTP with TLS)
4145
Schema *ArangoRouteSpecDestinationSchema `json:"schema,omitempty"`
4246

4347
// Protocol defines http protocol used for the route
48+
// +doc/default: http1
4449
// +doc/enum: http1|HTTP 1.1 Protocol
4550
// +doc/enum: http2|HTTP 2 Protocol
4651
Protocol *ArangoRouteDestinationProtocol `json:"protocol,omitempty"`
@@ -68,6 +73,14 @@ func (a *ArangoRouteSpecDestination) GetService() *ArangoRouteSpecDestinationSer
6873
return a.Service
6974
}
7075

76+
func (a *ArangoRouteSpecDestination) GetRedirect() *ArangoRouteSpecDestinationRedirect {
77+
if a == nil || a.Redirect == nil {
78+
return nil
79+
}
80+
81+
return a.Redirect
82+
}
83+
7184
func (a *ArangoRouteSpecDestination) GetEndpoints() *ArangoRouteSpecDestinationEndpoints {
7285
if a == nil || a.Endpoints == nil {
7386
return nil
@@ -132,9 +145,10 @@ func (a *ArangoRouteSpecDestination) Validate() error {
132145
}
133146

134147
if err := shared.WithErrors(
135-
shared.ValidateExclusiveFields(a, 1, "Service", "Endpoints"),
148+
shared.ValidateExclusiveFields(a, 1, "Service", "Endpoints", "Redirect"),
136149
shared.ValidateOptionalInterfacePath("service", a.Service),
137150
shared.ValidateOptionalInterfacePath("endpoints", a.Endpoints),
151+
shared.ValidateOptionalInterfacePath("redirect", a.Redirect),
138152
shared.ValidateOptionalInterfacePath("schema", a.Schema),
139153
shared.ValidateOptionalInterfacePath("protocol", a.Protocol),
140154
shared.ValidateOptionalInterfacePath("tls", a.TLS),
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2025 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 v1beta1
22+
23+
import (
24+
goHttp "net/http"
25+
26+
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
27+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
28+
)
29+
30+
type ArangoRouteSpecDestinationRedirect struct {
31+
// Code the redirection response status code
32+
// +doc/default: 307
33+
Code *int `json:"code,omitempty"`
34+
}
35+
36+
func (a *ArangoRouteSpecDestinationRedirect) GetCode() int {
37+
if a == nil || a.Code == nil {
38+
return goHttp.StatusTemporaryRedirect
39+
}
40+
return *a.Code
41+
}
42+
43+
func (a *ArangoRouteSpecDestinationRedirect) Validate() error {
44+
if a == nil {
45+
a = &ArangoRouteSpecDestinationRedirect{}
46+
}
47+
48+
if err := shared.WithErrors(
49+
shared.ValidateOptionalPath("code", a.Code, func(i int) error {
50+
if i == goHttp.StatusTemporaryRedirect || i == goHttp.StatusMovedPermanently {
51+
return nil
52+
}
53+
54+
return errors.Errorf("Invalid code. Got %d, allowed 301 & 307", i)
55+
}),
56+
); err != nil {
57+
return err
58+
}
59+
60+
return nil
61+
}
62+
63+
func (a *ArangoRouteSpecDestinationRedirect) AsStatus() ArangoRouteStatusTargetRedirect {
64+
if a == nil {
65+
return ArangoRouteStatusTargetRedirect{}
66+
}
67+
68+
return ArangoRouteStatusTargetRedirect{
69+
Code: a.GetCode(),
70+
}
71+
}

pkg/apis/networking/v1beta1/route_status_target.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ type ArangoRouteStatusTarget struct {
5555

5656
// Timeout specify the upstream request timeout
5757
Timeout meta.Duration `json:"timeout,omitempty"`
58+
59+
// Redirect defines the route status
60+
Redirect ArangoRouteStatusTargetRedirect `json:"redirect,omitempty"`
5861
}
5962

6063
func (a *ArangoRouteStatusTarget) RenderURLs() []string {
@@ -81,5 +84,5 @@ func (a *ArangoRouteStatusTarget) Hash() string {
8184
if a == nil {
8285
return ""
8386
}
84-
return util.SHA256FromStringArray(a.Destinations.Hash(), a.Type.Hash(), a.TLS.Hash(), a.Protocol.String(), a.Path, a.Authentication.Hash(), a.Options.Hash(), a.Timeout.String(), a.Route.Hash())
87+
return util.SHA256FromNonEmptyStringArray(a.Destinations.Hash(), a.Type.Hash(), a.TLS.Hash(), a.Protocol.String(), a.Path, a.Authentication.Hash(), a.Options.Hash(), a.Timeout.String(), a.Route.Hash(), a.Redirect.Hash())
8588
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2025 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 v1beta1
22+
23+
import (
24+
"fmt"
25+
26+
"github.com/arangodb/kube-arangodb/pkg/util"
27+
)
28+
29+
type ArangoRouteStatusTargetRedirect struct {
30+
Code int `json:"code,omitempty"`
31+
}
32+
33+
func (a ArangoRouteStatusTargetRedirect) Hash() string {
34+
return util.SHA256FromStringArray(fmt.Sprintf("%d", a.Code))
35+
}

pkg/apis/networking/v1beta1/route_status_target_type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ func (a ArangoRouteStatusTargetType) Hash() string {
3131
const (
3232
ArangoRouteStatusTargetServiceType ArangoRouteStatusTargetType = "service"
3333
ArangoRouteStatusTargetEndpointsType ArangoRouteStatusTargetType = "endpoints"
34+
ArangoRouteStatusTargetRedirectType ArangoRouteStatusTargetType = "redirect"
3435
)

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

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/shared/validate.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ func ValidatePath[T any](path string, in T, validator func(T) error) error {
205205
return PrefixResourceErrors(path, validator(in))
206206
}
207207

208+
// ValidateMultiPath Validates object
209+
func ValidateMultiPath[T any](path string, in T, validators ...func(T) error) error {
210+
return PrefixResourceErrors(path, util.FormatList(validators, func(a func(T) error) error {
211+
return a(in)
212+
})...)
213+
}
214+
208215
// ValidateRequiredPath Validates object and required not nil value
209216
func ValidateRequiredPath[T any](path string, in *T, validator func(T) error) error {
210217
return PrefixResourceErrors(path, ValidateRequired(in, validator))

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ v1beta1:
174174
- http1
175175
- http2
176176
type: string
177+
redirect:
178+
description: Redirect defines redirect instruction
179+
properties:
180+
code:
181+
description: Code the redirection response status code
182+
format: int32
183+
type: integer
184+
type: object
177185
schema:
178186
description: Schema defines HTTP/S schema used for connection
179187
enum:

0 commit comments

Comments
 (0)