Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] DebugPackage ArangoRoutes #1719

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/crd/crds/database-deployment.schema.generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions pkg/debug_package/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var rootFactories = []shared.Factory{
kubernetes.Analytics(),
kubernetes.Backup(),
kubernetes.Scheduler(),
kubernetes.Networking(),
}

func InitCommand(cmd *cobra.Command) {
Expand Down
47 changes: 47 additions & 0 deletions pkg/debug_package/generators/kubernetes/arango_networking.go
Original file line number Diff line number Diff line change
@@ -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
}
73 changes: 73 additions & 0 deletions pkg/debug_package/generators/kubernetes/arango_networking_ar.go
Original file line number Diff line number Diff line change
@@ -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
})
}