-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathvalidate.go
More file actions
29 lines (25 loc) · 898 Bytes
/
validate.go
File metadata and controls
29 lines (25 loc) · 898 Bytes
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
package genericresource
import (
api "github.com/moby/moby/api/types/swarm"
)
// 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 equalResource(r, res) {
return true
}
}
return false
}
// equalResource matches the resource *type* (named vs discrete), and then kind+value.
func equalResource(a, b api.GenericResource) bool {
switch {
case a.NamedResourceSpec != nil && b.NamedResourceSpec != nil:
return a.NamedResourceSpec.Kind == b.NamedResourceSpec.Kind &&
a.NamedResourceSpec.Value == b.NamedResourceSpec.Value
case a.DiscreteResourceSpec != nil && b.DiscreteResourceSpec != nil:
return a.DiscreteResourceSpec.Kind == b.DiscreteResourceSpec.Kind &&
a.DiscreteResourceSpec.Value == b.DiscreteResourceSpec.Value
}
return false
}