| 637 | } |
| 638 | |
| 639 | func defaultClient() (client.Client, error) { |
| 640 | config, err := rest.InClusterConfig() |
| 641 | if err != nil { |
| 642 | // Load kubeconfig from default location or specified path |
| 643 | kubeConfigPath := clientcmd.RecommendedHomeFile |
| 644 | config, err = clientcmd.NewNonInteractiveDeferredLoadingClientConfig( |
| 645 | &clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeConfigPath}, |
| 646 | &clientcmd.ConfigOverrides{}, |
| 647 | ).ClientConfig() |
| 648 | if err != nil { |
| 649 | return nil, errors.Wrap(err, "failed to load in-cluster configuration") |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | // Create a new scheme and register the API types |
| 654 | scheme := newScheme() |
| 655 | |
| 656 | // Create the controller-runtime client using the impersonated rest.Config |
| 657 | c, err := client.New(config, client.Options{Scheme: scheme}) |
| 658 | if err != nil { |
| 659 | return nil, fmt.Errorf("failed to create controller-runtime client: %v", err) |
| 660 | } |
| 661 | |
| 662 | return c, nil |
| 663 | } |
| 664 | |
| 665 | // CheckArgs should be used to ensure the right command line arguments are |
| 666 | // passed before executing an example. |