8000 [Feature] [ML] Use Scheduler API · arangodb/kube-arangodb@600f4ca · GitHub
[go: up one dir, main page]

Skip to content

Commit 600f4ca

Browse files
committed
[Feature] [ML] Use Scheduler API
1 parent 2eb83f3 commit 600f4ca

File tree

8 files changed

+70
-213
lines changed

8 files changed

+70
-213
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- (Feature) Add Core fields to the Scheduler Container Spec
55
- (Feature) Add Metadata fields to the Scheduler Pod Spec
66
- (Feature) Extend Backup Details in DebugPackage
7+
- (Feature) (ML) Use Scheduler API
78

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

pkg/apis/scheduler/v1alpha1/profile_template.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package v1alpha1
2323
import (
2424
schedulerPodApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod"
2525
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
26+
"github.com/arangodb/kube-arangodb/pkg/util"
2627
)
2728

2829
type ProfileTemplate struct {
@@ -33,6 +34,50 @@ type ProfileTemplate struct {
3334
Container *ProfileContainerTemplate `json:"container,omitempty"`
3435
}
3536

37+
func (p *ProfileTemplate) GetPod() *schedulerPodApi.Pod {
38+
if p == nil || p.Pod == nil {
39+
return nil
40+
}
41+
42+
return p.Pod
43+
}
44+
45+
func (p *ProfileTemplate) GetContainer() *ProfileContainerTemplate {
46+
if p == nil || p.Container == nil {
47+
return nil
48+
}
49+
50+
return p.Container
51+
}
52+
53+
func (p *ProfileTemplate) GetPriority() int {
54+
if p == nil || p.Priority == nil {
55+
return 0
56+
}
57+
58+
return *p.Priority
59+
}
60+
61+
func (p *ProfileTemplate) With(other *ProfileTemplate) *ProfileTemplate {
62+
if p == nil && other == nil {
63+
return nil
64+
}
65+
66+
if p == nil {
67+
return other.DeepCopy()
68+
}
69+
70+
if other == nil {
71+
return p.DeepCopy()
72+
}
73+
74+
return &ProfileTemplate{
75+
Priority: util.NewType(max(p.GetPriority(), other.GetPriority())),
76+
Pod: p.Pod.With(other.Pod),
77+
Container: p.Container.With(other.Container),
78+
}
79+
}
80+
3681
func (p *ProfileTemplate) Validate() error {
3782
if p == nil {
3883
return nil

pkg/apis/scheduler/v1alpha1/profile_templates.go

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ import (
2525

2626
core "k8s.io/api/core/v1"
2727

28-
"github.com/arangodb/kube-arangodb/pkg/util"
2928
"github.com/arangodb/kube-arangodb/pkg/util/errors"
3029
)
3130

3231
type ProfileTemplates []*ProfileTemplate
3332

3433
func (p ProfileTemplates) Sort() ProfileTemplates {
3534
sort.Slice(p, func(i, j int) bool {
36-
if a, b := util.WithDefault(p[i].Priority), util.WithDefault(p[j].Priority); a != b {
35+
if a, b := p[i].GetPriority(), p[j].GetPriority(); a != b {
3736
return a < b
3837
}
3938

@@ -43,26 +42,32 @@ func (p ProfileTemplates) Sort() ProfileTemplates {
4342
return p
4443
}
4544

45+
func (p ProfileTemplates) Merge() *ProfileTemplate {
46+
var z *ProfileTemplate
47+
48+
for _, q := range p {
49+
z = z.With(q)
50+
}
51+
52+
return z
53+
}
54+
4655
func (p ProfileTemplates) RenderOnTemplate(pod *core.PodTemplateSpec) error {
56+
t := p.Merge()
57+
4758
// Apply Pod Spec
48-
for id := range p {
49-
if err := p[id].Pod.Apply(pod); err != nil {
50-
return errors.Wrapf(err, "Error while rendering Pod for %d", id)
51-
}
59+
if err := t.GetPod().Apply(pod); err != nil {
60+
return errors.Wrapf(err, "Error while rendering Pod")
5261
}
5362

5463
// Apply Generic Containers Spec
55-
for id := range p {
56-
if err := p[id].Container.ApplyGeneric(pod); err != nil {
57-
return errors.Wrapf(err, "Error while rendering Pod for %d", id)
58-
}
64+
if err := t.GetContainer().ApplyGeneric(pod); err != nil {
65+
return errors.Wrapf(err, "Error while rendering Pod")
5966
}
6067

6168
// Apply Containers Spec
62-
for id := range p {
63-
if err := p[id].Container.ApplyContainers(pod); err != nil {
64-
return errors.Wrapf(err, "Error while rendering Pod for %d", id)
65-
}
69+
if err := t.GetContainer().ApplyContainers(pod); err != nil {
70+
return errors.Wrapf(err, "Error while rendering Pod")
6671
}
6772

6873
return nil

pkg/ml/container_auth_jwt.go

Lines changed: 0 additions & 84 deletions
This file was deleted.

pkg/ml/container_ca.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

pkg/ml/container_jwt.go

Lines changed: 0 additions & 55 deletions
This file was deleted.

pkg/operatorV2/operator_worker.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package operator
2323
import (
2424
"context"
2525
"fmt"
26+
"runtime/debug"
2627

2728
"github.com/arangodb/kube-arangodb/pkg/operatorV2/operation"
2829
"github.com/arangodb/kube-arangodb/pkg/util/errors"
@@ -52,6 +53,10 @@ func (o *operator) processNextItem() bool {
5253
e.Interface("err", obj)
5354
}
5455

56+
if v := debug.Stack(); len(v) != 0 {
57+
e = e.Str("stack", string(v))
58+
}
59+
5560
e.Error("Recovered from panic")
5661
}
5762
}()

pkg/util/k8sutil/helpers/service_account.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,3 @@ func EnsureServiceAccount(ctx context.Context, client kubernetes.Interface, owne
383383

384384
return false, nil
385385
}
386-
387-
func AppendServiceAccount(obj *sharedApi.ServiceAccount, spec *core.PodTemplateSpec) {
388-
if obj == nil || obj.Object == nil || spec == nil {
389-
return
390-
}
391-
392-
spec.Spec.ServiceAccountName = obj.Object.GetName()
393-
spec.Spec.AutomountServiceAccountToken = util.NewType(true)
394-
}

0 commit comments

Comments
 (0)
0