(ctx context.Context)
| 133 | } |
| 134 | |
| 135 | func (g *defaultPodGetter) GetPod(ctx context.Context) (*corev1.Pod, error) { |
| 136 | pod := func() *corev1.Pod { |
| 137 | g.mux.RLock() |
| 138 | defer g.mux.RUnlock() |
| 139 | return g.pod |
| 140 | }() |
| 141 | if pod != nil { |
| 142 | return pod.DeepCopy(), nil |
| 143 | } |
| 144 | g.mux.Lock() |
| 145 | defer g.mux.Unlock() |
| 146 | // guard against the race condition where the pod has been retrieved |
| 147 | // between releasing the read lock and acquiring the write lock |
| 148 | if g.pod != nil { |
| 149 | return g.pod.DeepCopy(), nil |
| 150 | } |
| 151 | pod = fakes.Pod(fakes.WithNamespace(util.GetNamespace()), |
| 152 | fakes.WithName(util.GetPodName())) |
| 153 | key := types.NamespacedName{Namespace: pod.Namespace, Name: pod.Name} |
| 154 | |
| 155 | // use unstructured to avoid inadvertently creating a watch on pods |
| 156 | uPod := &unstructured.Unstructured{} |
| 157 | gvk, err := apiutil.GVKForObject(pod, g.scheme) |
| 158 | if err != nil { |
| 159 | return nil, err |
| 160 | } |
| 161 | uPod.SetGroupVersionKind(gvk) |
| 162 | if err := g.client.Get(ctx, key, uPod); err != nil { |
| 163 | return nil, err |
| 164 | } |
| 165 | if err := g.scheme.Convert(uPod, pod, nil); err != nil { |
| 166 | return nil, err |
| 167 | } |
| 168 | g.pod = pod |
| 169 | return pod.DeepCopy(), nil |
| 170 | } |
| 171 | |
| 172 | // AddToManager adds all Controllers to the Manager. |
| 173 | func AddToManager(m manager.Manager, deps *Dependencies) error { |
nothing calls this directly
no test coverage detected