-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpull_policy.go
More file actions
36 lines (30 loc) · 1.01 KB
/
pull_policy.go
File metadata and controls
36 lines (30 loc) · 1.01 KB
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
package k8s
import (
"fmt"
"k8s.io/kubernetes/pkg/api"
)
var (
emptyPullPolicy = api.PullPolicy("")
// ValidPullPolicies is the set of pull policies that this package considers valid
ValidPullPolicies = map[api.PullPolicy]struct{}{
api.PullAlways: {},
api.PullIfNotPresent: {},
api.PullNever: {},
}
)
// ErrInvalidPullPolicy is the error returned when trying to convert an unknown string to an api.PullPolicy
type ErrInvalidPullPolicy struct {
str string
}
// Error is the error interface implementation
func (e ErrInvalidPullPolicy) Error() string {
return fmt.Sprintf("%s is an invalid pull policy", e.str)
}
// PullPolicyFromString converts a string into an api.PullPolicy. returns an error if the string does not match a pull policy in ValidPullPolicies()
func PullPolicyFromString(ppStr string) (api.PullPolicy, error) {
candidatePP := api.PullPolicy(ppStr)
if _, ok := ValidPullPolicies[candidatePP]; !ok {
return emptyPullPolicy, ErrInvalidPullPolicy{str: ppStr}
}
return candidatePP, nil
}