From d07581fe9101da6e25ef451aef02f77460496295 Mon Sep 17 00:00:00 2001 From: ajanikow <12255597+ajanikow@users.noreply.github.com> Date: Mon, 9 Sep 2024 12:44:42 +0000 Subject: [PATCH] [Feature] DebugPackage ArangoRoutes --- CHANGELOG.md | 1 + .../database-deployment.schema.generated.yaml | 5 ++ pkg/debug_package/generator.go | 1 + .../kubernetes/arango_networking.go | 47 ++++++++++++ .../kubernetes/arango_networking_ar.go | 73 +++++++++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 pkg/debug_package/generators/kubernetes/arango_networking.go create mode 100644 pkg/debug_package/generators/kubernetes/arango_networking_ar.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 9338e16d8..9b7e733cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - (Feature) Scheduler Handler - (Feature) (Gateway) ArangoDB Auth Token - (Feature) (Gateway) Dynamic Configuration +- (Feature) DebugPackage ArangoRoutes ## [1.2.42](https://github.com/arangodb/kube-arangodb/tree/1.2.42) (2024-07-23) - (Maintenance) Go 1.22.4 & Kubernetes 1.29.6 libraries diff --git a/pkg/crd/crds/database-deployment.schema.generated.yaml b/pkg/crd/crds/database-deployment.schema.generated.yaml index 2ee177b8e..578c15216 100644 --- a/pkg/crd/crds/database-deployment.schema.generated.yaml +++ b/pkg/crd/crds/database-deployment.schema.generated.yaml @@ -39611,6 +39611,11 @@ v2alpha1: gateway: description: Gateway defined main Gateway configuration. properties: + dynamic: + description: |- + Dynamic setting enables/disables support dynamic configuration of the gateway in the cluster. + When enabled, gateway config will be reloaded by ConfigMap live updates. + type: boolean enabled: description: |- Enabled setting enables/disables support for gateway in the cluster. diff --git a/pkg/debug_package/generator.go b/pkg/debug_package/generator.go index d8c24a0eb..098d34390 100644 --- a/pkg/debug_package/generator.go +++ b/pkg/debug_package/generator.go @@ -46,6 +46,7 @@ var rootFactories = []shared.Factory{ kubernetes.Analytics(), kubernetes.Backup(), kubernetes.Scheduler(), + kubernetes.Networking(), } func InitCommand(cmd *cobra.Command) { diff --git a/pkg/debug_package/generators/kubernetes/arango_networking.go b/pkg/debug_package/generators/kubernetes/arango_networking.go new file mode 100644 index 000000000..8837b089b --- /dev/null +++ b/pkg/debug_package/generators/kubernetes/arango_networking.go @@ -0,0 +1,47 @@ +// +// 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 kubernetes + +import ( + "github.com/rs/zerolog" + + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/errors" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func Networking() shared.Factory { + return shared.NewFactory("networking", true, networking) +} + +func networking(logger zerolog.Logger, files chan<- shared.File) error { + k, ok := kclient.GetDefaultFactory().Client() + if !ok { + return errors.Errorf("Client is not initialised") + } + + if err := networkingArangoRoutes(logger, files, k); err != nil { + logger.Err(err).Msgf("Error while collecting networking arango routes") + return err + } + + return nil +} diff --git a/pkg/debug_package/generators/kubernetes/arango_networking_ar.go b/pkg/debug_package/generators/kubernetes/arango_networking_ar.go new file mode 100644 index 000000000..8d26b0e2f --- /dev/null +++ b/pkg/debug_package/generators/kubernetes/arango_networking_ar.go @@ -0,0 +1,73 @@ +// +// 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 kubernetes + +import ( + "context" + "fmt" + + "github.com/rs/zerolog" + + networkingApi "github.com/arangodb/kube-arangodb/pkg/apis/networking/v1alpha1" + "github.com/arangodb/kube-arangodb/pkg/debug_package/cli" + "github.com/arangodb/kube-arangodb/pkg/debug_package/shared" + "github.com/arangodb/kube-arangodb/pkg/util/errors" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors" + "github.com/arangodb/kube-arangodb/pkg/util/kclient" +) + +func networkingArangoRoutes(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error { + arangoRoutes, err := listNetowkingArangoRoutes(client) + if err != nil { + if kerrors.IsForbiddenOrNotFound(err) { + return nil + } + + return err + } + + if err := errors.ExecuteWithErrorArrayP2(networkingArangoRoute, client, files, arangoRoutes...); err != nil { + logger.Err(err).Msgf("Error while collecting networking arango routes") + return err + } + + return nil +} + +func networkingArangoRoute(client kclient.Client, files chan<- shared.File, ext *networkingApi.ArangoRoute) error { + files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/networking/arangoroutes/%s.yaml", ext.GetName()), func() ([]interface{}, error) { + return []interface{}{ext}, nil + }) + + return nil +} + +func listNetowkingArangoRoutes(client kclient.Client) ([]*networkingApi.ArangoRoute, error) { + return ListObjects[*networkingApi.ArangoRouteList, *networkingApi.ArangoRoute](context.Background(), client.Arango().NetworkingV1alpha1().ArangoRoutes(cli.GetInput().Namespace), func(result *networkingApi.ArangoRouteList) []*networkingApi.ArangoRoute { + q := make([]*networkingApi.ArangoRoute, len(result.Items)) + + for id, e := range result.Items { + q[id] = e.DeepCopy() + } + + return q + }) +}