8000 [Bugfix] Fix Gateway Options (#1753) · arangodb/kube-arangodb@0a339b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a339b4

Browse files
authored
[Bugfix] Fix Gateway Options (#1753)
1 parent 87d14d5 commit 0a339b4

File tree

10 files changed

+143
-61
lines changed

10 files changed

+143
-61
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- (Feature) (Integration) SchedulerV2
1010
- (Feature) (Integration) Basic Envs
1111
- (Maintenance) Inspector Generics
12+
- (Bugfix) Fix Gateway Options
1213

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

chart/kube-arangodb/templates/deployment-operator/role.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ rules:
1616
- apiGroups: ["database.arangodb.com"]
1717
resources: ["arangodeployments", "arangodeployments/status","arangomembers", "arangomembers/status"]
1818
verbs: ["*"]
19-
- apiGroups: ["networking.arangodb.com"]
20-
resources: ["arangoroutes", "arangoroutes/status"]
21-
verbs: ["*"]
2219
{{- if .Values.rbac.extensions.acs }}
2320
- apiGroups: ["database.arangodb.com"]
2421
resources: ["arangoclustersynchronizations", "arangoclustersynchronizations/status"]

chart/kube-arangodb/templates/networking-operator/role.yaml

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,11 @@ metadata:
1313
app.kubernetes.io/instance: {{ .Release.Name }}
1414
release: {{ .Release.Name }}
1515
rules:
16-
- apiGroups:
17-
- "ml.arangodb.com"
18-
resources:
19-
- "arangomlextensions"
20-
- "arangomlextensions/status"
21-
- "arangomlbatchjobs"
22-
- "arangomlbatchjobs/status"
23-
- "arangomlcronjobs"
24-
- "arangomlcronjobs/status"
25-
- "arangomlstorages"
26-
- "arangomlstorages/status"
27-
verbs:
28-
- "*"
29-
- apiGroups:
30-
- "scheduler.arangodb.com"
31-
resources:
32-
- "arangoprofiles"
33-
- "arangoprofiles/status"
34-
verbs:
35-
- "*"
36-
- apiGroups:
37-
- "database.arangodb.com"
38-
resources:
39-
- "arangodeployments"
40-
verbs:
41-
- "get"
42-
- "list"
43-
- "watch"
44-
- apiGroups:
45-
- "rbac.authorization.k8s.io"
46-
resources:
47-
- "roles"
48-
- "rolebindings"
49-
verbs: ["*"]
50-
- apiGroups:
51-
- "batch"
52-
resources:
53-
- "cronjobs"
54-
- "jobs"
55-
verbs: ["*"]
56-
- apiGroups: ["apps"]
57-
resources:
58-
- "statefulsets"
59-
verbs: ["*"]
60-
- apiGroups: [""]
61-
resources:
62-
- "pods"
63-
- "secrets"
64-
- "services"
65-
- "serviceaccounts"
66-
verbs: ["*"]
16+
- apiGroups: ["networking.arangodb.com"]
17+
resources: ["arangoroutes", "arangoroutes/status"]
18+
verbs: ["*"]
19+
- apiGroups: [""]
20+
resources: ["pods", "services", "endpoints"]
21+
verbs: ["get", "list", "watch"]
6722
{{- end }}
6823
{{- end }}

pkg/apis/networking/v1alpha1/route_spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type ArangoRouteSpec struct {
3434
}
3535

3636
func (s *ArangoRouteSpec) GetDeployment() string {
37-
if s == nil || s.Destination == nil {
37+
if s == nil || s.Deployment == nil {
3838
return ""
3939
}
4040

pkg/deployment/resources/gateway/gateway_config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,13 @@ func (c Config) RenderClusters() ([]*clusterAPI.Cluster, error) {
170170
UpstreamProtocolOptions: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig_{
171171
ExplicitHttpConfig: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig{
172172
ProtocolConfig: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig_Http2ProtocolOptions{
173-
Http2ProtocolOptions: &coreAPI.Http2ProtocolOptions{},
173+
Http2ProtocolOptions: &coreAPI.Http2ProtocolOptions{
174+
ConnectionKeepalive: &coreAPI.KeepaliveSettings{
175+
Interval: durationpb.New(15 * time.Second),
176+
Timeout: durationpb.New(30 * time.Second),
177+
ConnectionIdleInterval: durationpb.New(60 * time.Second),
178+
},
179+
},
174180
},
175181
},
176182
},

pkg/deployment/resources/gateway/gateway_config_destination.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ 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"
2728
endpointAPI "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
2829
routeAPI "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
30+
upstreamHttpApi "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3"
31+
"github.com/golang/protobuf/ptypes/any"
32+
"google.golang.org/protobuf/types/known/anypb"
2933
"google.golang.org/protobuf/types/known/durationpb"
3034

3135
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
@@ -115,6 +119,25 @@ func (c *ConfigDestination) RenderRoute(name, prefix string) (*routeAPI.Route, e
115119
}
116120

117121
func (c *ConfigDestination) RenderCluster(name string) (*clusterAPI.Cluster, error) {
122+
hpo, err := anypb.New(&upstreamHttpApi.HttpProtocolOptions{
123+
UpstreamProtocolOptions: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig_{
124+
ExplicitHttpConfig: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig{
125+
ProtocolConfig: &upstreamHttpApi.HttpProtocolOptions_ExplicitHttpConfig_Http2ProtocolOptions{
126+
Http2ProtocolOptions: &coreAPI.Http2ProtocolOptions{
127+
ConnectionKeepalive: &coreAPI.KeepaliveSettings{
128+
Interval: durationpb.New(15 * time.Second),
129+
Timeout: durationpb.New(30 * time.Second),
130+
ConnectionIdleInterval: durationpb.New(60 * time.Second),
131+
},
132+
},
133+
},
134+
},
135+
},
136+
})
137+
if err != nil {
138+
return nil, err
139+
}
140+
118141
cluster := &clusterAPI.Cluster{
119142
Name: name,
120143
ConnectTimeout: durationpb.New(time.Second),
@@ -127,6 +150,9 @@ func (c *ConfigDestination) RenderCluster(name string) (*clusterAPI.Cluster, err
127150
},
128151
},
129152
},
153+
TypedExtensionProtocolOptions: map[string]*any.Any{
154+
"envoy.extensions.upstreams.http.v3.HttpProtocolOptions": hpo,
155+
},
130156
}
131157

132158
if t, err := c.Type.RenderUpstreamTransportSocket(); err != nil {

pkg/deployment/resources/gateway/gateway_config_sni.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import (
3232
type ConfigSNIList []ConfigSNI
3333

3434
func (c ConfigSNIList) RenderFilterChain(filters []*listenerAPI.Filter) ([]*listenerAPI.FilterChain, error) {
35-
var r = make([]*listenerAPI.FilterChain, len(filters))
36-
for id := range filters {
35+
var r = make([]*listenerAPI.FilterChain, len(c))
36+
for id := range c {
3737
if f, err := c[id].RenderFilterChain(filters); err != nil {
3838
return nil, err
3939
} else {

pkg/deployment/resources/gateway/gateway_config_test.go

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package gateway
2222

2323
import (
24+
"fmt"
2425
"testing"
2526

2627
bootstrapAPI "github.com/envoyproxy/go-control-plane/envoy/config/bootstrap/v3"
@@ -29,14 +30,18 @@ import (
2930
"github.com/arangodb/kube-arangodb/pkg/util"
3031
)
3132

32-
func renderAndPrintGatewayConfig(t *testing.T, cfg Config) *bootstrapAPI.Bootstrap {
33+
func renderAndPrintGatewayConfig(t *testing.T, cfg Config, validates ...func(t *testing.T, b *bootstrapAPI.Bootstrap)) {
3334
data, checksum, obj, err := cfg.RenderYAML()
3435
require.NoError(t, err)
3536

3637
t.Logf("Checksum: %s", checksum)
3738
t.Log(string(data))
3839

39-
return obj
40+
for id := range validates {
41+
t.Run(fmt.Sprintf("Validation%d", id), func(t *testing.T) {
42+
validates[id](t, obj)
43+
})
44+
}
4045
}
4146

4247
func Test_GatewayConfig(t *testing.T) {
@@ -50,8 +55,27 @@ func Test_GatewayConfig(t *testing.T) {
5055
},
5156
},
5257
},
58+
}, func(t *testing.T, b *bootstrapAPI.Bootstrap) {
59+
require.NotNil(t, b)
60+
require.NotNil(t, b.StaticResources)
61+
require.NotNil(t, b.StaticResources.Clusters)
62+
require.Len(t, b.StaticResources.Clusters, 1)
63+
require.NotNil(t, b.StaticResources.Clusters[0])
64+
require.NotNil(t, b.StaticResources.Clusters[0].LoadAssignment)
65+
require.NotNil(t, b.StaticResources.Clusters[0].LoadAssignment.Endpoints)
66+
require.Len(t, b.StaticResources.Clusters[0].LoadAssignment.Endpoints, 1)
67+
require.NotNil(t, b.StaticResources.Clusters[0].LoadAssignment.Endpoints[0])
68+
require.NotNil(t, b.StaticResources.Clusters[0].LoadAssignment.Endpoints[0].LbEndpoints)
69+
require.Len(t, b.StaticResources.Clusters[0].LoadAssignment.Endpoints[0].LbEndpoints, 1)
70+
require.NotNil(t, b.StaticResources.Clusters[0].LoadAssignment.Endpoints[0].LbEndpoints[0])
71+
require.NotNil(t, b.StaticResources.Clusters[0].LoadAssignment.Endpoints[0].LbEndpoints[0].GetEndpoint())
72+
require.NotNil(t, b.StaticResources.Clusters[0].LoadAssignment.Endpoints[0].LbEndpoints[0].GetEndpoint().Address)
73+
require.NotNil(t, b.StaticResources.Clusters[0].LoadAssignment.Endpoints[0].LbEndpoints[0].GetEndpoint().Address.GetSocketAddress())
74+
require.EqualValues(t, "127.0.0.1", b.StaticResources.Clusters[0].LoadAssignment.Endpoints[0].LbEndpoints[0].GetEndpoint().Address.GetSocketAddress().Address)
75+
require.EqualValues(t, 12345, b.StaticResources.Clusters[0].LoadAssignment.Endpoints[0].LbEndpoints[0].GetEndpoint().Address.GetSocketAddress().GetPortValue())
5376
})
5477
})
78+
5579
t.Run("Default", func(t *testing.T) {
5680
renderAndPrintGatewayConfig(t, Config{
5781
DefaultDestination: ConfigDestination{
@@ -69,6 +93,7 @@ func Test_GatewayConfig(t *testing.T) {
6993
},
7094
})
7195
})
96+
7297
t.Run("Default", func(t *testing.T) {
7398
renderAndPrintGatewayConfig(t, Config{
7499
DefaultDestination: ConfigDestination{
@@ -87,6 +112,7 @@ func Test_GatewayConfig(t *testing.T) {
87112
},
88113
})
89114
})
115+
90116
t.Run("Default", func(t *testing.T) {
91117
renderAndPrintGatewayConfig(t, Config{
92118
DefaultDestination: ConfigDestination{
@@ -117,6 +143,38 @@ func Test_GatewayConfig(t *testing.T) {
117143
},
118144
})
119145
})
146+
147+
t.Run("Default", func(t *testing.T) {
148+
renderAndPrintGatewayConfig(t, Config{
149+
DefaultDestination: ConfigDestination{
150+
Targets: []ConfigDestinationTarget{
151+
{
152+
Host: "127.0.0.1",
153+
Port: 12345,
154+
},
155+
},
156+
Path: util.NewType("/test/path/"),
157+
Type: util.NewType(ConfigDestinationTypeHTTPS),
158+
},
159+
DefaultTLS: &ConfigTLS{
160+
CertificatePath: "/test",
161+
PrivateKeyPath: "/test12",
162+
},
163+
Destinations: ConfigDestinations{
164+
"/_test/": {
165+
Targets: []ConfigDestinationTarget{
166+
{
167+
Host: "127.0.0.1",
168+
Port: 12346,
169+
},
170+
},
171+
Path: util.NewType("/test/path/"),
172+
Type: util.NewType(ConfigDestinationTypeHTTP),
173+
},
174+
},
175+
})
176+
})
177+
120178
t.Run("Default", func(t *testing.T) {
121179
renderAndPrintGatewayConfig(t, Config{
122180
DefaultDestination: ConfigDestination{
@@ -133,6 +191,17 @@ func Test_GatewayConfig(t *testing.T) {
133191
CertificatePath: "/test",
134192
PrivateKeyPath: "/test12",
135193
},
194+
SNI: []ConfigSNI{
195+
{
196+
ConfigTLS: ConfigTLS{
197+
CertificatePath: "/cp",
198+
PrivateKeyPath: "/pp",
199+
},
200+
ServerNames: []string{
201+
"example.com",
202+
},
203+
},
204+
},
136205
Destinations: ConfigDestinations{
137206
"/_test/": {
138207
Targets: []ConfigDestinationTarget{
@@ -147,6 +216,7 @@ func Test_GatewayConfig(t *testing.T) {
147216
},
148217
})
149218
})
219+
150220
t.Run("Default", func(t *testing.T) {
151221
renderAndPrintGatewayConfig(t, Config{
152222
DefaultDestination: ConfigDestination{
@@ -173,6 +243,15 @@ func Test_GatewayConfig(t *testing.T) {
173243
"example.com",
174244
},
175245
},
246+
{
247+
ConfigTLS: ConfigTLS{
248+
CertificatePath: "/c2",
249+
PrivateKeyPath: "/p2",
250+
},
251+
ServerNames: []string{
252+
"2.example.com",
253+
},
254+
},
176255
},
177256
Destinations: ConfigDestinations{
178257
"/_test/": {

pkg/deployment/resources/gateway/marshal.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,13 @@ func Marshal[T proto.Message](in T) ([]byte, string, T, error) {
3939
data, err = yaml.JSONToYAML(data)
4040
return data, util.SHA256(data), in, err
4141
}
42+
43+
func Unmarshal[T proto.Message](data []byte) (T, error) {
44+
var v T
45+
46+
if err := (protojson.UnmarshalOptions{}).Unmarshal(data, v); err != nil {
47+
return util.Default[T](), err
48+
}
49+
50+
return v, nil
51+
}

pkg/scheduler/profiles.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,15 @@ func Profiles(ctx context.Context, client generic.ListInterface[*schedulerApi.Ar
8181
})
8282

8383
extractedProfiles = extractedProfiles.Sort(func(a, b *schedulerApi.ArangoProfile) bool {
84-
return a.Spec.Template.GetPriority() > b.Spec.Template.GetPriority()
84+
if ca, cb := a.Spec.Template.GetPriority(), b.Spec.Template.GetPriority(); ca != cb {
85+
return ca > cb
86+
}
87+
88+
if ca, cb := a.GetName(), b.GetName(); ca != cb {
89+
return ca > cb
90+
}
91+
92+
return a.GetCreationTimestamp().After(b.GetCreationTimestamp().Time)
8593
})
8694

8795
// Check if everything is valid

0 commit comments

Comments
 (0)
0