Skip to content

Commit 6404de3

Browse files
authored
[Feature] DebugPackage ArangoRoutes (#1719)
1 parent fe97fc3 commit 6404de3

File tree

5 files changed

+127
-0
lines changed

5 files changed

+127
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- (Feature) Scheduler Handler
2828
- (Feature) (Gateway) ArangoDB Auth Token
2929
- (Feature) (Gateway) Dynamic Configuration
30+
- (Feature) DebugPackage ArangoRoutes
3031

3132
## [1.2.42](https://github.com/arangodb/kube-arangodb/tree/1.2.42) (2024-07-23)
3233
- (Maintenance) Go 1.22.4 & Kubernetes 1.29.6 libraries

pkg/crd/crds/database-deployment.schema.generated.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -39611,6 +39611,11 @@ v2alpha1:
3961139611
gateway:
3961239612
description: Gateway defined main Gateway configuration.
3961339613
properties:
39614+
dynamic:
39615+
description: |-
39616+
Dynamic setting enables/disables support dynamic configuration of the gateway in the cluster.
39617+
When enabled, gateway config will be reloaded by ConfigMap live updates.
39618+
type: boolean
3961439619
enabled:
3961539620
description: |-
3961639621
Enabled setting enables/disables support for gateway in the cluster.

pkg/debug_package/generator.go

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var rootFactories = []shared.Factory{
4646
kubernetes.Analytics(),
4747
kubernetes.Backup(),
4848
kubernetes.Scheduler(),
49+
kubernetes.Networking(),
4950
}
5051

5152
func InitCommand(cmd *cobra.Command) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 kubernetes
22+
23+
import (
24+
"github.com/rs/zerolog"
25+
26+
"github.com/arangodb/kube-arangodb/pkg/debug_package/shared"
27+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
28+
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
29+
)
30+
31+
func Networking() shared.Factory {
32+
return shared.NewFactory("networking", true, networking)
33+
}
34+
35+
func networking(logger zerolog.Logger, files chan<- shared.File) error {
36+
k, ok := kclient.GetDefaultFactory().Client()
37+
if !ok {
38+
return errors.Errorf("Client is not initialised")
39+
}
40+
41+
if err := networkingArangoRoutes(logger, files, k); err != nil {
42+
logger.Err(err).Msgf("Error while collecting networking arango routes")
43+
return err
44+
}
45+
46+
return nil
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 kubernetes
22+
23+
import (
24+
"context"
25+
"fmt"
26+
27+
"github.com/rs/zerolog"
28+
29+
networkingApi "github.com/arangodb/kube-arangodb/pkg/apis/networking/v1alpha1"
30+
"github.com/arangodb/kube-arangodb/pkg/debug_package/cli"
31+
"github.com/arangodb/kube-arangodb/pkg/debug_package/shared"
32+
"github.com/arangodb/kube-arangodb/pkg/util/errors"
33+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
34+
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
35+
)
36+
37+
func networkingArangoRoutes(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error {
38+
arangoRoutes, err := listNetowkingArangoRoutes(client)
39+
if err != nil {
40+
if kerrors.IsForbiddenOrNotFound(err) {
41+
return nil
42+
}
43+
44+
return err
45+
}
46+
47+
if err := errors.ExecuteWithErrorArrayP2(networkingArangoRoute, client, files, arangoRoutes...); err != nil {
48+
logger.Err(err).Msgf("Error while collecting networking arango routes")
49+
return err
50+
}
51+
52+
return nil
53+
}
54+
55+
func networkingArangoRoute(client kclient.Client, files chan<- shared.File, ext *networkingApi.ArangoRoute) error {
56+
files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/networking/arangoroutes/%s.yaml", ext.GetName()), func() ([]interface{}, error) {
57+
return []interface{}{ext}, nil
58+
})
59+
60+
return nil
61+
}
62+
63+
func listNetowkingArangoRoutes(client kclient.Client) ([]*networkingApi.ArangoRoute, error) {
64+
return ListObjects[*networkingApi.ArangoRouteList, *networkingApi.ArangoRoute](context.Background(), client.Arango().NetworkingV1alpha1().ArangoRoutes(cli.GetInput().Namespace), func(result *networkingApi.ArangoRouteList) []*networkingApi.ArangoRoute {
65+
q := make([]*networkingApi.ArangoRoute, len(result.Items))
66+
67+
for id, e := range result.Items {
68+
q[id] = e.DeepCopy()
69+
}
70+
71+
return q
72+
})
73+
}

0 commit comments

Comments
 (0)