MCPcopy
hub / github.com/open-policy-agent/gatekeeper / GetPod

Method GetPod

pkg/controller/controller.go:135–170  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

133}
134
135func (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.
173func AddToManager(m manager.Manager, deps *Dependencies) error {

Callers

nothing calls this directly

Calls 9

PodFunction · 0.92
WithNamespaceFunction · 0.92
GetNamespaceFunction · 0.92
WithNameFunction · 0.92
GetPodNameFunction · 0.92
RLockMethod · 0.80
RUnlockMethod · 0.80
DeepCopyMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected