Last active
August 4, 2022 14:35
-
-
Save jsnouffer/2a1d85e9cbe71965dca47aabd0edfce2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
v1 "k8s.io/api/apps/v1" | |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | |
"k8s.io/client-go/kubernetes" | |
ctrl "sigs.k8s.io/controller-runtime" | |
) | |
func main() { | |
ctx := context.Background() | |
config := ctrl.GetConfigOrDie() | |
clientset := kubernetes.NewForConfigOrDie(config) | |
namespace := "default" | |
items, err := GetDeployments(clientset, ctx, namespace) | |
if err != nil { | |
fmt.Println(err) | |
} else { | |
for _, item := range items { | |
fmt.Printf("%+v\n", item) | |
} | |
} | |
} | |
func GetDeployments(clientset *kubernetes.Clientset, ctx context.Context, | |
namespace string) ([]v1.Deployment, error) { | |
list, err := clientset.AppsV1().Deployments(namespace). | |
List(ctx, metav1.ListOptions{}) | |
if err != nil { | |
return nil, err | |
} | |
return list.Items, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment