Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unify k8s client in e2e #68

Closed
nakamasato opened this issue Nov 18, 2021 · 1 comment
Closed

unify k8s client in e2e #68

nakamasato opened this issue Nov 18, 2021 · 1 comment

Comments

@nakamasato
Copy link
Owner

nakamasato commented Nov 18, 2021

there're two ways in e2e:

  1. https://pkg.go.dev/k8s.io/client-go/tools/clientcmd: Package clientcmd provides one stop shopping for building a working client from a fixed config, from a .kubeconfig file, from command line flags, or from any merged combination.

    setup:

    config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)
    if err != nil {
    	log.Fatal(err)
    }
    clientset, err := kubernetes.NewForConfig(config)
    if err != nil {
    	log.Fatal(err)
    }

    example usage:

     deployment, err := clientset.AppsV1().Deployments("default").Get(context.TODO(), name, metav1.GetOptions{})
  2. https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/client: Package client contains functionality for interacting with Kubernetes API servers.
    setup:

    k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
    	  Expect(err).NotTo(HaveOccurred())
    	  Expect(k8sClient).NotTo(BeNil())

    usage:

    Expect(k8sClient.Delete(ctx, mysqlUser)).Should(Succeed())
@nakamasato
Copy link
Owner Author

b2e7e53 removed kubectl.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant