|
| 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 | +} |
0 commit comments