-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.go
More file actions
43 lines (36 loc) · 1.21 KB
/
utils.go
File metadata and controls
43 lines (36 loc) · 1.21 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
37
38
39
40
41
42
43
package k8s
import (
"fmt"
v1 "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
}
// SecurityContextFromPrivileged create api.SecurityContext by privileged.
func SecurityContextFromPrivileged(privileged bool) v1.SecurityContext {
return v1.SecurityContext{
Privileged: &privileged,
}
}