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] [ML] Use Scheduler API #1620

Merged
merged 1 commit into from
Mar 18, 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 @@ -4,6 +4,7 @@
- (Feature) Add Core fields to the Scheduler Container Spec
- (Feature) Add Metadata fields to the Scheduler Pod Spec
- (Feature) Extend Backup Details in DebugPackage
- (Feature) (ML) Use Scheduler API

## [1.2.39](https://github.com/arangodb/kube-arangodb/tree/1.2.39) (2024-03-11)
- (Feature) Extract Scheduler API
Expand Down
45 changes: 45 additions & 0 deletions pkg/apis/scheduler/v1alpha1/profile_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package v1alpha1
import (
schedulerPodApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
"github.com/arangodb/kube-arangodb/pkg/util"
)

type ProfileTemplate struct {
Expand All @@ -33,6 +34,50 @@ type ProfileTemplate struct {
Container *ProfileContainerTemplate `json:"container,omitempty"`
}

func (p *ProfileTemplate) GetPod() *schedulerPodApi.Pod {
if p == nil || p.Pod == nil {
return nil
}

return p.Pod
}

func (p *ProfileTemplate) GetContainer() *ProfileContainerTemplate {
if p == nil || p.Container == nil {
return nil
}

return p.Container
}

func (p *ProfileTemplate) GetPriority() int {
if p == nil || p.Priority == nil {
return 0
}

return *p.Priority
}

func (p *ProfileTemplate) With(other *ProfileTemplate) *ProfileTemplate {
if p == nil && other == nil {
return nil
}

if p == nil {
return other.DeepCopy()
}

if other == nil {
return p.DeepCopy()
}

return &ProfileTemplate{
Priority: util.NewType(max(p.GetPriority(), other.GetPriority())),
Pod: p.Pod.With(other.Pod),
Container: p.Container.With(other.Container),
}
}

func (p *ProfileTemplate) Validate() error {
if p == nil {
return nil
Expand Down
33 changes: 19 additions & 14 deletions pkg/apis/scheduler/v1alpha1/profile_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ import (

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

"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)

type ProfileTemplates []*ProfileTemplate

func (p ProfileTemplates) Sort() ProfileTemplates {
sort.Slice(p, func(i, j int) bool {
if a, b := util.WithDefault(p[i].Priority), util.WithDefault(p[j].Priority); a != b {
if a, b := p[i].GetPriority(), p[j].GetPriority(); a != b {
return a < b
}

Expand All @@ -43,26 +42,32 @@ func (p ProfileTemplates) Sort() ProfileTemplates {
return p
}

func (p ProfileTemplates) Merge() *ProfileTemplate {
var z *ProfileTemplate

for _, q := range p {
z = z.With(q)
}

return z
}

func (p ProfileTemplates) RenderOnTemplate(pod *core.PodTemplateSpec) error {
t := p.Merge()

// Apply Pod Spec
for id := range p {
if err := p[id].Pod.Apply(pod); err != nil {
return errors.Wrapf(err, "Error while rendering Pod for %d", id)
}
if err := t.GetPod().Apply(pod); err != nil {
return errors.Wrapf(err, "Error while rendering Pod")
}

// Apply Generic Containers Spec
for id := range p {
if err := p[id].Container.ApplyGeneric(pod); err != nil {
return errors.Wrapf(err, "Error while rendering Pod for %d", id)
}
if err := t.GetContainer().ApplyGeneric(pod); err != nil {
return errors.Wrapf(err, "Error while rendering Pod")
}

// Apply Containers Spec
for id := range p {
if err := p[id].Container.ApplyContainers(pod); err != nil {
return errors.Wrapf(err, "Error while rendering Pod for %d", id)
}
if err := t.GetContainer().ApplyContainers(pod); err != nil {
return errors.Wrapf(err, "Error while rendering Pod")
}

return nil
Expand Down
84 changes: 0 additions & 84 deletions pkg/ml/container_auth_jwt.go

This file was deleted.

51 changes: 0 additions & 51 deletions pkg/ml/container_ca.go

This file was deleted.

55 changes: 0 additions & 55 deletions pkg/ml/container_jwt.go

This file was deleted.

5 changes: 5 additions & 0 deletions pkg/operatorV2/operator_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package operator
import (
"context"
"fmt"
"runtime/debug"

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

if v := debug.Stack(); len(v) != 0 {
e = e.Str("stack", string(v))
}

e.Error("Recovered from panic")
}
}()
Expand Down
9 changes: 0 additions & 9 deletions pkg/util/k8sutil/helpers/service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,3 @@ func EnsureServiceAccount(ctx context.Context, client kubernetes.Interface, owne

return false, nil
}

func AppendServiceAccount(obj *sharedApi.ServiceAccount, spec *core.PodTemplateSpec) {
if obj == nil || obj.Object == nil || spec == nil {
return
}

spec.Spec.ServiceAccountName = obj.Object.GetName()
spec.Spec.AutomountServiceAccountToken = util.NewType(true)
}