MCPcopy Index your code
hub / github.com/helm/helm / newLookupFunction

Function newLookupFunction

pkg/engine/lookup_func.go:57–94  ·  view source on GitHub ↗
(clientProvider ClientProvider)

Source from the content-addressed store, hash-verified

55}
56
57func newLookupFunction(clientProvider ClientProvider) lookupFunc {
58 return func(apiversion string, kind string, namespace string, name string) (map[string]any, error) {
59 var client dynamic.ResourceInterface
60 c, namespaced, err := clientProvider.GetClientFor(apiversion, kind)
61 if err != nil {
62 return map[string]any{}, err
63 }
64 if namespaced && namespace != "" {
65 client = c.Namespace(namespace)
66 } else {
67 client = c
68 }
69 if name != "" {
70 // this will return a single object
71 obj, err := client.Get(context.Background(), name, metav1.GetOptions{})
72 if err != nil {
73 if apierrors.IsNotFound(err) {
74 // Just return an empty interface when the object was not found.
75 // That way, users can use `if not (lookup ...)` in their templates.
76 return map[string]any{}, nil
77 }
78 return map[string]any{}, err
79 }
80 return obj.UnstructuredContent(), nil
81 }
82 // this will return a list
83 obj, err := client.List(context.Background(), metav1.ListOptions{})
84 if err != nil {
85 if apierrors.IsNotFound(err) {
86 // Just return an empty interface when the object was not found.
87 // That way, users can use `if not (lookup ...)` in their templates.
88 return map[string]any{}, nil
89 }
90 return map[string]any{}, err
91 }
92 return obj.UnstructuredContent(), nil
93 }
94}
95
96// getDynamicClientOnKind returns a dynamic client on an Unstructured type. This client can be further namespaced.
97func getDynamicClientOnKind(apiversion string, kind string, config *rest.Config) (dynamic.NamespaceableResourceInterface, bool, error) {

Callers 2

initFunMapMethod · 0.85
NewLookupFunctionFunction · 0.85

Calls 4

GetClientForMethod · 0.65
NamespaceMethod · 0.65
GetMethod · 0.65
ListMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…