Created
September 26, 2018 19:21
-
-
Save droot/3a60b97c8b48f8d470796302e87a01ea to your computer and use it in GitHub Desktop.
K8s CLI example using controller-runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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