-
Notifications
You must be signed in to change notification settings - Fork 10
/
pullpolicy.go
51 lines (42 loc) · 997 Bytes
/
pullpolicy.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
46
47
48
49
50
51
package pullpolicy
import (
"fmt"
"strings"
"github.com/LINBIT/containerapi"
)
const (
Always PullPolicy = "Always"
IfNotExist PullPolicy = "IfNotExist"
Never PullPolicy = "Never"
)
type PullPolicy string
func (p *PullPolicy) UnmarshalText(text []byte) error {
return p.Set(string(text))
}
func (p *PullPolicy) String() string {
return string(*p)
}
func (p *PullPolicy) Set(s string) error {
switch strings.ToLower(s) {
case strings.ToLower(string(Never)), strings.ToLower(string(IfNotExist)), strings.ToLower(string(Always)):
*p = PullPolicy(s)
return nil
default:
return fmt.Errorf("unknown pull policy. [%s, %s, %s]", Always, IfNotExist, Never)
}
}
func (p *PullPolicy) Type() string {
return "pullPolicy"
}
func (p PullPolicy) ForContainer() containerapi.ShouldPull {
switch p {
case Always:
return containerapi.PullAlways
case IfNotExist:
return containerapi.PullIfNotExists
case Never:
return containerapi.PullNever
default:
return nil
}
}