(config *rest.Config, opts Options)
| 531 | } |
| 532 | |
| 533 | func defaultOpts(config *rest.Config, opts Options) (Options, error) { |
| 534 | config = rest.CopyConfig(config) |
| 535 | if config.UserAgent == "" { |
| 536 | config.UserAgent = rest.DefaultKubernetesUserAgent() |
| 537 | } |
| 538 | |
| 539 | // Use the rest HTTP client for the provided config if unset |
| 540 | if opts.HTTPClient == nil { |
| 541 | var err error |
| 542 | opts.HTTPClient, err = rest.HTTPClientFor(config) |
| 543 | if err != nil { |
| 544 | return Options{}, fmt.Errorf("could not create HTTP client from config: %w", err) |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | // Use the default Kubernetes Scheme if unset |
| 549 | if opts.Scheme == nil { |
| 550 | opts.Scheme = scheme.Scheme |
| 551 | } |
| 552 | |
| 553 | // Construct a new Mapper if unset |
| 554 | if opts.Mapper == nil { |
| 555 | var err error |
| 556 | opts.Mapper, err = apiutil.NewDynamicRESTMapper(config, opts.HTTPClient) |
| 557 | if err != nil { |
| 558 | return Options{}, fmt.Errorf("could not create RESTMapper from config: %w", err) |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | opts.ByObject = maps.Clone(opts.ByObject) |
| 563 | opts.DefaultNamespaces = maps.Clone(opts.DefaultNamespaces) |
| 564 | for obj, byObject := range opts.ByObject { |
| 565 | isNamespaced, err := apiutil.IsObjectNamespaced(obj, opts.Scheme, opts.Mapper) |
| 566 | if err != nil { |
| 567 | return opts, fmt.Errorf("failed to determine if %T is namespaced: %w", obj, err) |
| 568 | } |
| 569 | if !isNamespaced && byObject.Namespaces != nil { |
| 570 | return opts, fmt.Errorf("type %T is not namespaced, but its ByObject.Namespaces setting is not nil", obj) |
| 571 | } |
| 572 | |
| 573 | if isNamespaced && byObject.Namespaces == nil { |
| 574 | byObject.Namespaces = maps.Clone(opts.DefaultNamespaces) |
| 575 | } else { |
| 576 | byObject.Namespaces = maps.Clone(byObject.Namespaces) |
| 577 | } |
| 578 | |
| 579 | // Default the namespace-level configs first, because they need to use the undefaulted type-level config |
| 580 | // to be able to potentially fall through to settings from DefaultNamespaces. |
| 581 | for namespace, config := range byObject.Namespaces { |
| 582 | // 1. Default from the undefaulted type-level config |
| 583 | config = defaultConfig(config, byObjectToConfig(byObject)) |
| 584 | // 2. Default from the namespace-level config. This was defaulted from the global default config earlier, but |
| 585 | // might not have an entry for the current namespace. |
| 586 | if defaultNamespaceSettings, hasDefaultNamespace := opts.DefaultNamespaces[namespace]; hasDefaultNamespace { |
| 587 | config = defaultConfig(config, defaultNamespaceSettings) |
| 588 | } |
| 589 | |
| 590 | // 3. Default from the global defaults |
searching dependent graphs…