Merge pull request #731 from sargun/document-api
Add documentation to the provider API about concurrency / mutability
This commit is contained in:
@@ -227,7 +227,7 @@ func (p *mockV0Provider) GetPod(ctx context.Context, namespace, name string) (po
|
||||
}
|
||||
|
||||
if pod, ok := p.pods.Load(key); ok {
|
||||
return pod.(*v1.Pod), nil
|
||||
return pod.(*v1.Pod).DeepCopy(), nil
|
||||
}
|
||||
return nil, errdefs.NotFoundf("pod \"%s/%s\" is not known to the provider", namespace, name)
|
||||
}
|
||||
@@ -242,7 +242,7 @@ func (p *mockV0Provider) GetPodStatus(ctx context.Context, namespace, name strin
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pod.Status, nil
|
||||
return pod.Status.DeepCopy(), nil
|
||||
}
|
||||
|
||||
// GetPods returns a list of all pods known to be "running".
|
||||
@@ -252,7 +252,7 @@ func (p *mockV0Provider) GetPods(ctx context.Context) ([]*v1.Pod, error) {
|
||||
var pods []*v1.Pod
|
||||
|
||||
p.pods.Range(func(key, pod interface{}) bool {
|
||||
pods = append(pods, pod.(*v1.Pod))
|
||||
pods = append(pods, pod.(*v1.Pod).DeepCopy())
|
||||
return true
|
||||
})
|
||||
|
||||
|
||||
@@ -55,12 +55,21 @@ type PodLifecycleHandler interface {
|
||||
DeletePod(ctx context.Context, pod *corev1.Pod) error
|
||||
|
||||
// GetPod retrieves a pod by name from the provider (can be cached).
|
||||
// The Pod returned is expected to be immutable, and may be accessed
|
||||
// concurrently outside of the calling goroutine. Therefore it is recommended
|
||||
// to return a version after DeepCopy.
|
||||
GetPod(ctx context.Context, namespace, name string) (*corev1.Pod, error)
|
||||
|
||||
// GetPodStatus retrieves the status of a pod by name from the provider.
|
||||
// The PodStatus returned is expected to be immutable, and may be accessed
|
||||
// concurrently outside of the calling goroutine. Therefore it is recommended
|
||||
// to return a version after DeepCopy.
|
||||
GetPodStatus(ctx context.Context, namespace, name string) (*corev1.PodStatus, error)
|
||||
|
||||
// GetPods retrieves a list of all pods running on the provider (can be cached).
|
||||
// The Pods returned are expected to be immutable, and may be accessed
|
||||
// concurrently outside of the calling goroutine. Therefore it is recommended
|
||||
// to return a version after DeepCopy.
|
||||
GetPods(context.Context) ([]*corev1.Pod, error)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user