Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerlynn committed Oct 18, 2023
1 parent 676dd6f commit 91281e5
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions test/eviction/evictpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"log"
"path/filepath"

policy "k8s.io/api/policy/v1beta1"
policy "k8s.io/api/policy/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -31,7 +31,7 @@ import (

// Borrowed from https://stackoverflow.com/questions/62803041/how-to-evict-or-delete-pods-from-kubernetes-using-golang-client
func evictPod(client *kubernetes.Clientset, name, namespace string) error {
return client.PolicyV1beta1().Evictions(namespace).Evict(context.TODO(), &policy.Eviction{
return client.PolicyV1().Evictions(namespace).Evict(context.TODO(), &policy.Eviction{
ObjectMeta: meta_v1.ObjectMeta{
Name: name,
Namespace: namespace,
Expand All @@ -40,27 +40,25 @@ func evictPod(client *kubernetes.Clientset, name, namespace string) error {

func main() {
kubeconfig := flag.String("kubeconfig", filepath.Join(homedir.HomeDir(), ".kube", "config"), "(optional) absolute path to the kubeconfig file")
namespace := flag.String("namespace", "default", "Namespace (required)")
namespace := flag.String("namespace", "default", "Namespace (defaults to `default`)")
pod := flag.String("pod", "", "Pod name (required)")
flag.Parse()

if *pod == "" || *namespace == "" {
log.Fatal("--pod and --namespace must be non-empty")
if *pod == "" {
log.Fatal("--pod must be non-empty")
}

config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
log.Fatalf("Could not create in cluster config: %v", err)
log.Fatalf("Could not build config: %v", err)
}

var kubeClient *kubernetes.Clientset
kubeClient, err = kubernetes.NewForConfig(config)
kubeClient, err := kubernetes.NewForConfig(config)
if err != nil {
log.Fatalf("Could not create the kubernetes clientset: %v", err)
}

err = evictPod(kubeClient, *pod, *namespace)
if err != nil {
if err = evictPod(kubeClient, *pod, *namespace); err != nil {
log.Fatalf("Pod eviction failed: %v", err)
}
}

0 comments on commit 91281e5

Please sign in to comment.