MCPcopy Index your code
hub / github.com/kubernetes-client/python / _meta_namespace_key

Function _meta_namespace_key

kubernetes/informer/cache.py:20–42  ·  view source on GitHub ↗

Build a lookup key from object metadata. Supports both dict-based objects and generated model objects. Returns namespace/name for namespaced objects, just name otherwise.

(obj)

Source from the content-addressed store, hash-verified

18
19
20def _meta_namespace_key(obj):
21 """Build a lookup key from object metadata.
22
23 Supports both dict-based objects and generated model objects.
24 Returns namespace/name for namespaced objects, just name otherwise.
25 """
26 if isinstance(obj, dict):
27 meta = obj.get("metadata") or {}
28 ns = meta.get("namespace") or ""
29 name = meta.get("name") or ""
30 else:
31 meta = getattr(obj, "metadata", None)
32 if meta is None:
33 return ""
34 if hasattr(meta, "namespace"):
35 ns = getattr(meta, "namespace", None) or ""
36 name = getattr(meta, "name", None) or ""
37 else:
38 ns = meta.get("namespace") or ""
39 name = meta.get("name") or ""
40 if ns:
41 return "{}/{}".format(ns, name)
42 return name
43
44
45class ObjectCache:

Callers 4

test_namespaced_dictMethod · 0.90
test_no_metadataMethod · 0.90
test_model_objectMethod · 0.90

Calls 2

getMethod · 0.45
formatMethod · 0.45

Tested by 4

test_namespaced_dictMethod · 0.72
test_no_metadataMethod · 0.72
test_model_objectMethod · 0.72