mirror of
https://github.com/docker/cli.git
synced 2026-01-19 21:41:31 +03:00
full diff: 616e8db4c3...6068d1894d
a replace rule was needed (similar as in github.com/docker/docker) to fix some
dependency issues;
github.com/docker/cli/cli/trust imports
github.com/theupdateframework/notary/trustpinning tested by
github.com/theupdateframework/notary/trustpinning.test imports
github.com/cloudflare/cfssl/helpers imports
github.com/google/certificate-transparency-go imports
go.etcd.io/etcd/v3 imports
go.etcd.io/etcd/tests/v3/integration imports
go.etcd.io/etcd/server/v3/embed imports
go.opentelemetry.io/otel/semconv: module go.opentelemetry.io/otel@latest found (v1.7.0), but does not contain package go.opentelemetry.io/otel/semconv
github.com/docker/cli/cli/trust imports
github.com/theupdateframework/notary/trustpinning tested by
github.com/theupdateframework/notary/trustpinning.test imports
github.com/cloudflare/cfssl/helpers imports
github.com/google/certificate-transparency-go imports
go.etcd.io/etcd/v3 imports
go.etcd.io/etcd/tests/v3/integration imports
go.etcd.io/etcd/server/v3/embed imports
go.opentelemetry.io/otel/exporters/otlp imports
go.opentelemetry.io/otel/sdk/metric/controller/basic imports
go.opentelemetry.io/otel/metric/registry: module go.opentelemetry.io/otel/metric@latest found (v0.30.0), but does not contain package go.opentelemetry.io/otel/metric/registry
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
86 lines
1.8 KiB
Go
86 lines
1.8 KiB
Go
package genericresource
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/moby/swarmkit/v2/api"
|
|
)
|
|
|
|
// ValidateTask validates that the task only uses integers
|
|
// for generic resources
|
|
func ValidateTask(resources *api.Resources) error {
|
|
for _, v := range resources.Generic {
|
|
if v.GetDiscreteResourceSpec() != nil {
|
|
continue
|
|
}
|
|
|
|
return fmt.Errorf("invalid argument for resource %s", Kind(v))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// HasEnough returns true if node can satisfy the task's GenericResource request
|
|
func HasEnough(nodeRes []*api.GenericResource, taskRes *api.GenericResource) (bool, error) {
|
|
t := taskRes.GetDiscreteResourceSpec()
|
|
if t == nil {
|
|
return false, fmt.Errorf("task should only hold Discrete type")
|
|
}
|
|
|
|
if nodeRes == nil {
|
|
return false, nil
|
|
}
|
|
|
|
nrs := GetResource(t.Kind, nodeRes)
|
|
if len(nrs) == 0 {
|
|
return false, nil
|
|
}
|
|
|
|
switch nr := nrs[0].Resource.(type) {
|
|
case *api.GenericResource_DiscreteResourceSpec:
|
|
if t.Value > nr.DiscreteResourceSpec.Value {
|
|
return false, nil
|
|
}
|
|
case *api.GenericResource_NamedResourceSpec:
|
|
if t.Value > int64(len(nrs)) {
|
|
return false, nil
|
|
}
|
|
}
|
|
|
|
return true, nil
|
|
}
|
|
|
|
// HasResource checks if there is enough "res" in the "resources" argument
|
|
func HasResource(res *api.GenericResource, resources []*api.GenericResource) bool {
|
|
for _, r := range resources {
|
|
if Kind(res) != Kind(r) {
|
|
continue
|
|
}
|
|
|
|
switch rtype := r.Resource.(type) {
|
|
case *api.GenericResource_DiscreteResourceSpec:
|
|
if res.GetDiscreteResourceSpec() == nil {
|
|
return false
|
|
}
|
|
|
|
if res.GetDiscreteResourceSpec().Value < rtype.DiscreteResourceSpec.Value {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
case *api.GenericResource_NamedResourceSpec:
|
|
if res.GetNamedResourceSpec() == nil {
|
|
return false
|
|
}
|
|
|
|
if res.GetNamedResourceSpec().Value != rtype.NamedResourceSpec.Value {
|
|
continue
|
|
}
|
|
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|