MCPcopy Create free account
hub / github.com/devfile/devworkspace-operator / GetWebhooksCacheFunc

Function GetWebhooksCacheFunc

pkg/cache/cache.go:110–131  ·  view source on GitHub ↗

GetWebhooksCacheFunc returns a new cache function that restricts the cluster items we store in the webhook server's internal cache. This avoids issues where the webhook server's memory usage scales with the number of objects on the cluster, potentially causing out of memory errors in large clusters.

(namespace string)

Source from the content-addressed store, hash-verified

108// server's internal cache. This avoids issues where the webhook server's memory usage scales with the number
109// of objects on the cluster, potentially causing out of memory errors in large clusters.
110func GetWebhooksCacheFunc(namespace string) (cache.NewCacheFunc, error) {
111 // The webhooks server needs to read pods to validate pods/exec requests. These pods must have the DevWorkspace ID and restricted
112 // access labels (other pods are automatically approved)
113 devworkspaceObjectSelector, err := labels.Parse(constants.DevWorkspaceIDLabel)
114 if err != nil {
115 return nil, err
116 }
117
118 selectors := map[client.Object]cache.ByObject{
119 &corev1.Pod{}: {
120 Label: devworkspaceObjectSelector,
121 },
122 }
123
124 return func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
125 opts.ByObject = selectors
126 opts.DefaultNamespaces = map[string]cache.Config{
127 namespace: {},
128 }
129 return cache.New(config, opts)
130 }, nil
131}

Callers 1

mainFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected