@@ -19,9 +19,11 @@ package images
19
19
import (
20
20
"context"
21
21
"errors"
22
+ "time"
22
23
23
24
v1 "k8s.io/api/core/v1"
24
25
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
26
+ kubeletconfiginternal "k8s.io/kubernetes/pkg/kubelet/apis/config"
25
27
)
26
28
27
29
var (
@@ -52,3 +54,52 @@ type ImageManager interface {
52
54
53
55
// TODO(ronl): consolidating image managing and deleting operation in this interface
54
56
}
57
+
58
+ // ImagePullManager keeps the state of images that were pulled and which are
59
+ // currently still being pulled.
60
+ // It should keep an internal state of images currently being pulled by the kubelet
61
+ // in order to determine whether to destroy a "pulling" record should an image
62
+ // pull fail.
63
+ type ImagePullManager interface {
64
+ // RecordPullIntent records an intent to pull an image and should be called
65
+ // before a pull of the image occurs.
66
+ //
67
+ // RecordPullIntent() should be called before every image pull. Each call of
68
+ // RecordPullIntent() must match exactly one call of RecordImagePulled()/RecordImagePullFailed().
69
+ //
70
+ // `image` is the content of the pod's container `image` field.
71
+ RecordPullIntent (image string ) error
72
+ // RecordImagePulled writes a record of an image being successfully pulled
73
+ // with ImagePullCredentials.
74
+ //
75
+ // `credentials` must not be nil and must contain either exactly one Kubernetes
76
+ // Secret coordinates in the `.KubernetesSecrets` slice or set `.NodePodsAccessible`
77
+ // to `true`.
78
+ //
79
+ // `image` is the content of the pod's container `image` field.
80
+ RecordImagePulled (image , imageRef string , credentials * kubeletconfiginternal.ImagePullCredentials )
81
+ // RecordImagePullFailed should be called if an image failed to pull.
82
+ //
83
+ // Internally, it lowers its reference counter for the given image. If the
84
+ // counter reaches zero, the pull intent record for the image is removed.
85
+ //
86
+ // `image` is the content of the pod's container `image` field.
87
+ RecordImagePullFailed (image string )
88
+ // MustAttemptImagePull evaluates the policy for the image specified in
89
+ // `image` and if the policy demands verification, it checks the internal
90
+ // cache to see if there's a record of pulling the image with the presented
91
+ // set of credentials or if the image can be accessed by any of the node's pods.
92
+ //
93
+ // Returns true if the policy demands verification and no record of the pull
94
+ // was found in the cache.
95
+ //
96
+ // `image` is the content of the pod's container `image` field.
97
+ MustAttemptImagePull (image , imageRef string , credentials []kubeletconfiginternal.ImagePullSecret ) bool
98
+ // PruneUnknownRecords deletes all of the cache ImagePulledRecords for each of the images
99
+ // whose imageRef does not appear in the `imageList` iff such an record was last updated
100
+ // _before_ the `until` timestamp.
101
+ //
102
+ // This method is only expected to be called by the kubelet's image garbage collector.
103
+ // `until` is a timestamp created _before_ the `imageList` was requested from the CRI.
104
+ PruneUnknownRecords (imageList []string , until time.Time )
105
+ }
0 commit comments