8000 [Feature] Extend Backup Details · arangodb/kube-arangodb@83903ee · GitHub
[go: up one dir, main page]

Skip to content

Commit 83903ee

Browse files
committed
[Feature] Extend Backup Details
1 parent 67f4077 commit 83903ee

File tree

5 files changed

+200
-0
lines changed

5 files changed

+200
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- (Feature) Add Core fields to the Scheduler Container Spec
55
- (Feature) Add Metadata fields to the Scheduler Pod Spec
6+
- (Feature) Extend Backup Details in DebugPackage
67

78
## [1.2.39](https://github.com/arangodb/kube-arangodb/tree/1.2.39) (2024-03-11)
89
- (Feature) Extract Scheduler API

pkg/debug_package/generator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var rootFactories = []shared.Factory{
4343
kubernetes.Deployments(),
4444
kubernetes.AgencyDump(),
4545
kubernetes.ML(),
46+
kubernetes.Backup(),
4647
}
4748

4849
func InitCommand(cmd *cobra.Command) {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 Backup() shared.Factory {
32+
return shared.NewFactory("backupBackup", true, backup)
33+
}
34+
35+
func backup(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 := backupBackups(logger, files, k); err != nil {
42+
logger.Err(err).Msgf("Error while collecting arango ml extension")
43+
return err
44+
}
45+
46+
if err := backupPolicies(logger, files, k); err != nil {
47+
logger.Err(err).Msgf("Error while collecting arango ml storage")
48+
return err
49+
}
50+
51+
return nil
52+
}
Lines changed: 73 additions & 0 deletions
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+
backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"
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 backupBackups(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error {
38+
backups, err := listBackupBackups(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(backupBackup, client, files, backups...); err != nil {
48+
logger.Err(err).Msgf("Error while collecting arango ml batchjobs")
49+
return err
50+
}
51+
52+
return nil
53+
}
54+
55+
func backupBackup(client kclient.Client, files chan<- shared.File, ext *backupApi.ArangoBackup) error {
56+
files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/backupBackup/backups/%s.yaml", ext.GetName()), func() ([]interface{}, error) {
57+
return []interface{}{ext}, nil
58+
})
59+
60+
return nil
61+
}
62+
63+
func listBackupBackups(client kclient.Client) ([]*backupApi.ArangoBackup, error) {
64+
return ListObjects[*backupApi.ArangoBackupList, *backupApi.ArangoBackup](context.Background(), client.Arango().BackupV1().ArangoBackups(cli.GetInput().Namespace), func(result *backupApi.ArangoBackupList) []*backupApi.ArangoBackup {
65+
q := make([]*backupApi.ArangoBackup, len(result.Items))
66+
67+
for id, e := range result.Items {
68+
q[id] = e.DeepCopy()
69+
}
70+
71+
return q
72+
})
73+
}
Lines changed: 73 additions & 0 deletions
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+
backupApi "github.com/arangodb/kube-arangodb/pkg/apis/backup/v1"
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 backupPolicies(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error {
38+
backups, err := listBackupPolicies(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(backupPolicy, client, files, backups...); err != nil {
48+
logger.Err(err).Msgf("Error while collecting arango ml batchjobs")
49+
return err
50+
}
51+
52+
return nil
53+
}
54+
55+
func backupPolicy(client kclient.Client, files chan<- shared.File, ext *backupApi.ArangoBackupPolicy) error {
56+
files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/backup/policies/%s.yaml", ext.GetName()), func() ([]interface{}, error) {
57+
return []interface{}{ext}, nil
58+
})
59+
60+
return nil
61+
}
62+
63+
func listBackupPolicies(client kclient.Client) ([]*backupApi.ArangoBackupPolicy, error) {
64+
return ListObjects[*backupApi.ArangoBackupPolicyList, *backupApi.ArangoBackupPolicy](context.Background(), client.Arango().BackupV1().ArangoBackupPolicies(cli.GetInput().Namespace), func(result *backupApi.ArangoBackupPolicyList) []*backupApi.ArangoBackupPolicy {
65+
q := make([]*backupApi.ArangoBackupPolicy, 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)
0