@@ -10,14 +10,16 @@ import (
1010 "github.com/virtual-kubelet/virtual-kubelet/log"
1111 v1 "k8s.io/api/core/v1"
1212 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+ "k8s.io/apimachinery/pkg/types"
1314)
1415
1516const (
1617 mockProviderPodDeletedReason = "MockProviderPodDeleted"
1718)
1819
1920var (
20- _ PodLifecycleHandler = (* mockProvider )(nil )
21+ _ PodLifecycleHandler = (* mockProvider )(nil )
22+ _ PodUIDLifecycleHandler = (* mockProvider )(nil )
2123)
2224
2325type mockProvider struct {
@@ -175,11 +177,15 @@ func (p *mockProvider) DeletePod(ctx context.Context, pod *v1.Pod) (err error) {
175177 return nil
176178}
177179
178- // GetPod returns a pod by name that is stored in memory.
179180func (p * mockProvider ) GetPod (ctx context.Context , namespace , name string ) (pod * v1.Pod , err error ) {
180- log .G (ctx ).Infof ("receive GetPod %q" , name )
181+ panic ("GetPod not called when GetPodByUID implemented" )
182+ }
183+
184+ // GetPodByUID returns a pod by name that is stored in memory.
185+ func (p * mockProvider ) GetPodByUID (ctx context.Context , namespace , name string , uid types.UID ) (pod * v1.Pod , err error ) {
186+ log .G (ctx ).Infof ("receive GetPodByUID %q" , name )
181187
182- key , err := buildKeyFromNames (namespace , name )
188+ key , err := buildKeyFromNames (namespace , name , uid )
183189 if err != nil {
184190 return nil , err
185191 }
@@ -190,12 +196,16 @@ func (p *mockProvider) GetPod(ctx context.Context, namespace, name string) (pod
190196 return nil , errdefs .NotFoundf ("pod \" %s/%s\" is not known to the provider" , namespace , name )
191197}
192198
193- // GetPodStatus returns the status of a pod by name that is "running".
199+ func (p * mockProvider ) GetPodStatus (ctx context.Context , namespace , name string ) (pod * v1.PodStatus , err error ) {
200+ panic ("GetPodStatus not called when GetPodByUID implemented" )
201+ }
202+
203+ // GetPodStatusByUID returns the status of a pod by name that is "running".
194204// returns nil if a pod by that name is not found.
195- func (p * mockProvider ) GetPodStatus (ctx context.Context , namespace , name string ) (* v1.PodStatus , error ) {
196- log .G (ctx ).Infof ("receive GetPodStatus %q" , name )
205+ func (p * mockProvider ) GetPodStatusByUID (ctx context.Context , namespace , name string , uid types. UID ) (* v1.PodStatus , error ) {
206+ log .G (ctx ).Infof ("receive GetPodStatusByUID %q" , name )
197207
198- pod , err := p .GetPod (ctx , namespace , name )
208+ pod , err := p .GetPodByUID (ctx , namespace , name , uid )
199209 if err != nil {
200210 return nil , err
201211 }
@@ -237,8 +247,8 @@ func (p *mockProvider) getUpdates() *waitableInt {
237247 return p .updates
238248}
239249
240- func buildKeyFromNames (namespace string , name string ) (string , error ) {
241- return fmt .Sprintf ("%s-%s " , namespace , name ), nil
250+ func buildKeyFromNames (namespace string , name string , uid types. UID ) (string , error ) {
251+ return fmt .Sprintf ("%s/%s/%s " , namespace , name , uid ), nil
242252}
243253
244254// buildKey is a helper for building the "key" for the providers pod store.
@@ -251,7 +261,11 @@ func buildKey(pod *v1.Pod) (string, error) {
251261 return "" , fmt .Errorf ("pod name not found" )
252262 }
253263
254- return buildKeyFromNames (pod .ObjectMeta .Namespace , pod .ObjectMeta .Name )
264+ if pod .ObjectMeta .UID == "" {
265+ return "" , fmt .Errorf ("pod UID not found" )
266+ }
267+
268+ return buildKeyFromNames (pod .ObjectMeta .Namespace , pod .ObjectMeta .Name , pod .ObjectMeta .UID )
255269}
256270
257271type mockProviderAsync struct {
0 commit comments