Skip to content

Instantly share code, notes, and snippets.

@droot
Created September 26, 2018 19:21
Show Gist options
  • Save droot/3a60b97c8b48f8d470796302e87a01ea to your computer and use it in GitHub Desktop.
Save droot/3a60b97c8b48f8d470796302e87a01ea to your computer and use it in GitHub Desktop.
K8s CLI example using controller-runtime
package main
import (
"context"
"fmt"
"os"
"k8s.io/api/core/v1"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)
func main() {
cl, err := client.New(config.GetConfigOrDie(), client.Options{})
if err != nil {
fmt.Println("failed to create client")
os.Exit(1)
}
podList := &v1.PodList{}
err = cl.List(context.Background(), client.InNamespace("default"), podList)
if err != nil {
fmt.Println("failed to create client")
os.Exit(1)
}
fmt.Println("found podlist :%v", podList)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment