-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpull_policy.go
More file actions
35 lines (30 loc) · 1022 Bytes
/
pull_policy.go
File metadata and controls
35 lines (30 loc) · 1022 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
30
31
32
33
34
35
package k8s
import (
"fmt"
"k8s.io/api/core/v1"
)
var (
emptyPullPolicy = v1.PullPolicy("")
// ValidPullPolicies is the set of pull policies that this package considers valid
ValidPullPolicies = map[v1.PullPolicy]struct{}{
v1.PullAlways: {},
v1.PullIfNotPresent: {},
v1.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) (v1.PullPolicy, error) {
candidatePP := v1.PullPolicy(ppStr)
if _, ok := ValidPullPolicies[candidatePP]; !ok {
return emptyPullPolicy, ErrInvalidPullPolicy{str: ppStr}
}
return candidatePP, nil
}