Skip to content

Commit

Permalink
weight replaced with quota, add priority classes.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel committed Apr 10, 2024
1 parent 91bad4e commit 574a359
Show file tree
Hide file tree
Showing 11 changed files with 519 additions and 290 deletions.
4 changes: 4 additions & 0 deletions api/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,8 @@ type Task struct {
State string `json:"state"`
Image string `json:"image,omitempty" yaml:",omitempty"`
Pod string `json:"pod,omitempty" yaml:",omitempty"`
CPU uint `json:"cpu,omitempty" yaml:",omitempty"`
Memory uint `json:"memory,omitempty" yaml:",omitempty"`
Retries int `json:"retries,omitempty" yaml:",omitempty"`
Started *time.Time `json:"started,omitempty" yaml:",omitempty"`
Terminated *time.Time `json:"terminated,omitempty" yaml:",omitempty"`
Expand All @@ -601,6 +603,8 @@ func (r *Task) With(m *model.Task) {
r.Started = m.Started
r.Terminated = m.Terminated
r.Pod = m.Pod
r.CPU = m.CPU
r.Memory = m.Memory
r.Retries = m.Retries
r.Canceled = m.Canceled
_ = json.Unmarshal(m.Data, &r.Data)
Expand Down
48 changes: 0 additions & 48 deletions generated/crd/tackle.konveyor.io_tackles.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions generated/crd/tackle.konveyor.io_tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ spec:
type: string
type: array
priority:
description: Priority
type: integer
description: Priority class.
type: string
type: object
status:
description: TaskStatus defines the observed state of Task
Expand Down
4 changes: 2 additions & 2 deletions k8s/api/tackle/v1alpha1/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
type TaskSpec struct {
// Addon selector.
Addon []Selector `json:"addon,omitempty"`
// Priority
Priority int `json:"priority,omitempty"`
// Priority class.
Priority string `json:"priority,omitempty"`
// Dependencies
Dependencies []string `json:"dependencies,omitempty"`
}
Expand Down
3 changes: 2 additions & 1 deletion migration/v13/model/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ type Task struct {
State string `gorm:"index"`
Errors JSON `gorm:"type:json"`
Pod string `gorm:"index"`
PodRef uint
CPU uint
Memory uint
Retries int
Canceled bool
Report *TaskReport `gorm:"constraint:OnDelete:CASCADE"`
Expand Down
19 changes: 11 additions & 8 deletions settings/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
EnvAppName = "APP_NAME"
EnvDisconnected = "DISCONNECTED"
EnvAnalysisReportPath = "ANALYSIS_REPORT_PATH"
EnvTaskWeightLimit = "TASK_WEIGHT_LIMIT"
EnvTaskQuota = "TASK_QUOTA"
)

type Hub struct {
Expand Down Expand Up @@ -64,10 +64,10 @@ type Hub struct {
}
// Task
Task struct {
SA string
Retries int
WeightLimit int
Reaper struct { // minutes.
SA string
Retries int
Quota float32
Reaper struct { // minutes.
Created int
Succeeded int
Failed int
Expand Down Expand Up @@ -162,12 +162,15 @@ func (r *Hub) Load() (err error) {
} else {
r.Task.Retries = 1
}
s, found = os.LookupEnv(EnvTaskWeightLimit)
s, found = os.LookupEnv(EnvTaskQuota)
if found {
n, _ := strconv.Atoi(s)
r.Task.WeightLimit = n
if n > 100 {
n = 100
}
r.Task.Quota = float32(n / 100)
} else {
r.Task.WeightLimit = 50
r.Task.Quota = .80 // 80%
}
s, found = os.LookupEnv(EnvFrequencyTask)
if found {
Expand Down
24 changes: 24 additions & 0 deletions task/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package task
import (
"errors"
"fmt"
"strconv"
)

// KindNotFound used to report profile referenced
Expand Down Expand Up @@ -117,3 +118,26 @@ func (e *NotResolved) Is(err error) (matched bool) {
matched = errors.As(err, &inst)
return
}

// PriorityNotFound report priority class not found.
type PriorityNotFound struct {
Name string
Value int
}

func (e *PriorityNotFound) Error() (s string) {
var d string
if e.Name != "" {
d = fmt.Sprintf("\"%s\"", e.Name)
} else {
d = strconv.Itoa(e.Value)
}
s = fmt.Sprintf("Priority %s not-found.", d)
return
}

func (e *PriorityNotFound) Is(err error) (matched bool) {
var inst *PriorityNotFound
matched = errors.As(err, &inst)
return
}
Loading

0 comments on commit 574a359

Please sign in to comment.