Skip to content

Commit 612699c

Browse files
authored
[Feature] DebugPackage ArangoProfiles (#1630)
1 parent 39638b1 commit 612699c

File tree

7 files changed

+211
-3
lines changed

7 files changed

+211
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- (Maintenance) Move Container utils functions
1212
- (Feature) ArangoProfile Selectors
1313
- (Bugfix) Remove ImagePullSecrets Reference from Container
14+
- (Feature) DebugPackage ArangoProfiles
1415

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

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

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ rules:
2626
- "arangomlstorages/status"
2727
verbs:
2828
- "*"
29+
- apiGroups:
30+
- "scheduler.arangodb.com"
31+
resources:
32+
- "arangoprofiles"
33+
- "arangoprofiles/status"
34+
verbs:
35+
- "*"
2936
- apiGroups:
3037
- "database.arangodb.com"
3138
resources:

pkg/debug_package/generator.go

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var rootFactories = []shared.Factory{
4444
kubernetes.AgencyDump(),
4545
kubernetes.ML(),
4646
kubernetes.Backup(),
47+
kubernetes.Scheduler(),
4748
}
4849

4950
func InitCommand(cmd *cobra.Command) {

pkg/debug_package/generators/kubernetes/arango_backup_backup.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func backupBackups(logger zerolog.Logger, files chan<- shared.File, client kclie
5353
}
5454

5555
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) {
56+
files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/backup/backups/%s.yaml", ext.GetName()), func() ([]interface{}, error) {
5757
return []interface{}{ext}, nil
5858
})
5959

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2023-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 Scheduler() shared.Factory {
32+
return shared.NewFactory("scheduler", true, scheduler)
33+
}
34+
35+
func scheduler(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 := schedulerProfiles(logger, files, k); err != nil {
42+
logger.Err(err).Msgf("Error while collecting arango scheduler extension")
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+
schedulerApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/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 schedulerProfiles(logger zerolog.Logger, files chan<- shared.File, client kclient.Client) error {
38+
profiles, err := listSchedulerProfiles(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(schedulerProfile, client, files, profiles...); err != nil {
48+
logger.Err(err).Msgf("Error while collecting arango scheduler profiles")
49+
return err
50+
}
51+
52+
return nil
53+
}
54+
55+
func schedulerProfile(client kclient.Client, files chan<- shared.File, ext *schedulerApi.ArangoProfile) error {
56+
files <- shared.NewYAMLFile(fmt.Sprintf("kubernetes/arango/scheduler/profiles/%s.yaml", ext.GetName()), func() ([]interface{}, error) {
57+
return []interface{}{ext}, nil
58+
})
59+
60+
return nil
61+
}
62+
63+
func listSchedulerProfiles(client kclient.Client) ([]*schedulerApi.ArangoProfile, error) {
64+
return ListObjects[*schedulerApi.ArangoProfileList, *schedulerApi.ArangoProfile](context.Background(), client.Arango().SchedulerV1alpha1().ArangoProfiles(cli.GetInput().Namespace), func(result *schedulerApi.ArangoProfileList) []*schedulerApi.ArangoProfile {
65+
q := make([]*schedulerApi.ArangoProfile, len(result.Items))
66+
67+
for id, e := range result.Items {
68+
q[id] = e.DeepCopy()
69+
}
70+
71+
return q
72+
})
73+
}

pkg/debug_package/generators/kubernetes/lister.go

+81-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -22,16 +22,95 @@ package kubernetes
2222

2323
import (
2424
"context"
25+
"sort"
2526

2627
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
"k8s.io/apimachinery/pkg/types"
2829

30+
"github.com/arangodb/kube-arangodb/pkg/util"
2931
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
3032
)
3133

34+
func Extract[T1, T2 any](in List[T1], ex func(in T1) T2) List[T2] {
35+
r := make(List[T2], len(in))
36+
37+
for id := range r {
38+
r[id] = ex(in[id])
39+
}
40+
41+
return r
42+
}
43+
44+
type List[T any] []T
45+
46+
func (l List[T]) Sort(pred func(a, b T) bool) List[T] {
47+
sort.Slice(l, func(i, j int) bool {
48+
return pred(l[i], l[j])
49+
})
50+
51+
return l
52+
}
53+
54+
func (l List[T]) Append(obj ...T) List[T] {
55+
r := make(List[T], 0, len(l)+len(obj))
56+
57+
r = append(r, l...)
58+
r = append(r, obj...)
59+
60+
return r
61+
}
62+
63+
func (l List[T]) Filter(f func(a T) bool) List[T] {
64+
r := make(List[T], 0, len(l))
65+
66+
for _, o := range l {
67+
if !f(o) {
68+
continue
69+
}
70+
71+
r = append(r, o)
72+
}
73+
74+
return r
75+
}
76+
77+
func (l List[T]) Contains(f func(a T) bool) bool {
78+
for _, o := range l {
79+
if f(o) {
80+
return true
81+
}
82+
}
83+
84+
return false
85+
}
86+
87+
func (l List[T]) Unique(f func(existing List[T], a T) bool) List[T] {
88+
r := make(List[T], 0, len(l))
89+
90+
for _, o := range l {
91+
if f(r, o) {
92+
continue
93+
}
94+
95+
r = append(r, o)
96+
}
97+
98+
return r
99+
}
100+
32101
type ObjectList[T meta.Object] map[types.UID]T
33102

34-
func (d ObjectList[T]) AsList() []T {
103+
func (d ObjectList[T]) ByName(name string) (T, bool) {
104+
for _, obj := range d {
105+
if obj.GetName() == name {
106+
return obj, true
107+
}
108+
}
109+
110+
return util.Default[T](), false
111+
}
112+
113+
func (d ObjectList[T]) AsList() List[T] {
35114
list := make([]T, 0, len(d))
36115
for _, p := range d {
37116
list = append(list, p)

0 commit comments

Comments
 (0)