/
imagepullpolicy_pullpolicy.go
50 lines (38 loc) · 1.1 KB
/
imagepullpolicy_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
// Copyright 2020-2023 Project Capsule Authors.
// SPDX-License-Identifier: Apache-2.0
package pod
import (
"strings"
capsulev1beta2 "github.com/projectcapsule/capsule/api/v1beta2"
)
type PullPolicy interface {
IsPolicySupported(policy string) bool
AllowedPullPolicies() []string
}
type imagePullPolicyValidator struct {
allowedPolicies []string
}
func (i imagePullPolicyValidator) IsPolicySupported(policy string) bool {
for _, allowed := range i.allowedPolicies {
if strings.EqualFold(allowed, policy) {
return true
}
}
return false
}
func (i imagePullPolicyValidator) AllowedPullPolicies() []string {
return i.allowedPolicies
}
func NewPullPolicy(tenant *capsulev1beta2.Tenant) PullPolicy {
// the Tenant doesn't enforce the allowed image pull policy, returning nil
if len(tenant.Spec.ImagePullPolicies) == 0 {
return nil
}
allowedPolicies := make([]string, 0, len(tenant.Spec.ImagePullPolicies))
for _, policy := range tenant.Spec.ImagePullPolicies {
allowedPolicies = append(allowedPolicies, policy.String())
}
return &imagePullPolicyValidator{
allowedPolicies: allowedPolicies,
}
}