Skip to content

Commit

Permalink
fix(drain): Pass context to drainer
Browse files Browse the repository at this point in the history
Fixes #27
  • Loading branch information
TwiN committed Aug 11, 2022
1 parent fceac23 commit 5dc0b06
Show file tree
Hide file tree
Showing 223 changed files with 23,347 additions and 2 deletions.
5 changes: 3 additions & 2 deletions k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ type KubernetesClientApi interface {
}

type KubernetesClient struct {
client *kubernetes.Clientset
client kubernetes.Interface
}

// NewKubernetesClient creates a new KubernetesClient
func NewKubernetesClient(client *kubernetes.Clientset) *KubernetesClient {
func NewKubernetesClient(client kubernetes.Interface) *KubernetesClient {
return &KubernetesClient{
client: client,
}
Expand Down Expand Up @@ -134,6 +134,7 @@ func (k *KubernetesClient) Drain(nodeName string, ignoreDaemonSets, deleteEmptyD
DeleteEmptyDirData: deleteEmptyDirData,
GracePeriodSeconds: -1,
Timeout: 5 * time.Minute,
Ctx: context.TODO(),
Out: drainLogger{NodeName: nodeName},
ErrOut: drainLogger{NodeName: nodeName},
OnPodDeletedOrEvicted: func(pod *v1.Pod, usingEviction bool) {
Expand Down
18 changes: 18 additions & 0 deletions k8s/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package k8s

import (
"testing"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
fakekubernetes "k8s.io/client-go/kubernetes/fake"
)

func TestKubernetesClient_Drain(t *testing.T) {
fakeKubernetesClient := fakekubernetes.NewSimpleClientset(&v1.Node{ObjectMeta: metav1.ObjectMeta{Name: "default"}})
kc := NewKubernetesClient(fakeKubernetesClient)
err := kc.Drain("default", true, true)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
}
166 changes: 166 additions & 0 deletions vendor/k8s.io/client-go/discovery/fake/discovery.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5dc0b06

Please sign in to comment.