MCPcopy
hub / github.com/operator-framework/operator-sdk / configureSelectors

Function configureSelectors

internal/cmd/helm-operator/run/cmd.go:263–293  ·  view source on GitHub ↗
(opts *manager.Options, ws []watches.Watch, sch *apimachruntime.Scheme)

Source from the content-addressed store, hash-verified

261}
262
263func configureSelectors(opts *manager.Options, ws []watches.Watch, sch *apimachruntime.Scheme) error {
264 selectorsByObject := map[client.Object]cache.ByObject{}
265 chartNames := make([]string, 0, len(ws))
266 for _, w := range ws {
267 sch.AddKnownTypeWithName(w.GroupVersionKind, &unstructured.Unstructured{})
268
269 crObj := &unstructured.Unstructured{}
270 crObj.SetGroupVersionKind(w.GroupVersionKind)
271 sel, err := metav1.LabelSelectorAsSelector(&w.Selector)
272 if err != nil {
273 return fmt.Errorf("unable to parse watch selector for %s: %v", w.GroupVersionKind, err)
274 }
275 selectorsByObject[crObj] = cache.ByObject{Label: sel}
276
277 chrt, err := loader.LoadDir(w.ChartDir)
278 if err != nil {
279 return fmt.Errorf("unable to load chart for %s: %v", w.GroupVersionKind, err)
280 }
281 chartNames = append(chartNames, chrt.Name())
282
283 }
284 req, err := labels.NewRequirement("helm.sdk.operatorframework.io/chart", selection.In, chartNames)
285 if err != nil {
286 return fmt.Errorf("unable to create label requirement for cache default selector: %v", err)
287 }
288 defaultSelector := labels.NewSelector().Add(*req)
289
290 opts.Cache.ByObject = selectorsByObject
291 opts.Cache.DefaultLabelSelector = defaultSelector
292 return nil
293}

Callers 1

runFunction · 0.85

Calls 1

NameMethod · 0.45

Tested by

no test coverage detected