-
Notifications
You must be signed in to change notification settings - Fork 546
/
resourceconstraints.go
45 lines (36 loc) · 1.41 KB
/
resourceconstraints.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package resourcemanager
import (
pluginCore "github.com/flyteorg/flyte/flyteplugins/go/tasks/pluginmachinery/core"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
)
type ResourceConstraint interface {
IsAllowed(int64) bool
}
func isAllowed(constraintValue int64, actualValue int64) bool {
return constraintValue > actualValue
}
type BaseResourceConstraint struct {
Value int64
}
func (brc *BaseResourceConstraint) IsAllowed(actualValue int64) bool {
return isAllowed(brc.Value, actualValue)
}
type FullyQualifiedResourceConstraint struct {
TargetedPrefixString string
Value int64
}
func (fqrc *FullyQualifiedResourceConstraint) IsAllowed(actualValue int64) bool {
return isAllowed(fqrc.Value, actualValue)
}
func composeFullyQualifiedProjectScopeResourceConstraint(spec pluginCore.ResourceConstraintsSpec, id *core.TaskExecutionIdentifier) FullyQualifiedResourceConstraint {
return FullyQualifiedResourceConstraint{
TargetedPrefixString: string(composeProjectScopePrefix(id)),
Value: spec.ProjectScopeResourceConstraint.Value,
}
}
func composeFullyQualifiedNamespaceScopeResourceConstraint(spec pluginCore.ResourceConstraintsSpec, id *core.TaskExecutionIdentifier) FullyQualifiedResourceConstraint {
return FullyQualifiedResourceConstraint{
TargetedPrefixString: string(composeNamespaceScopePrefix(id)),
Value: spec.NamespaceScopeResourceConstraint.Value,
}
}