Skip to content

Commit

Permalink
[simple-backup] fix get ready pods, fixes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
maorfr committed Dec 19, 2018
1 parent d0a3b35 commit 08a6ae5
Showing 1 changed file with 3 additions and 39 deletions.
42 changes: 3 additions & 39 deletions pkg/utils/kube.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
package utils

import (
"log"
"os"
"path/filepath"

"github.com/nuvo/skbn/pkg/skbn"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)

// GetReadyPods gets a list of all ready ports according to defined namespace and selector
func GetReadyPods(iClient interface{}, namespace, selector string) ([]string, error) {

clientSet := GetClientSet()
pods, err := clientSet.CoreV1().Pods(namespace).List(metav1.ListOptions{
k8sClient := *iClient.(*skbn.K8sClient)
pods, err := k8sClient.ClientSet.CoreV1().Pods(namespace).List(metav1.ListOptions{
LabelSelector: selector,
})
if err != nil {
Expand All @@ -38,33 +32,3 @@ func GetReadyPods(iClient interface{}, namespace, selector string) ([]string, er

return podList, nil
}

// GetClientSet returns a kubernetes ClientSet
func GetClientSet() *kubernetes.Clientset {
var kubeconfig string
if kubeConfigPath := os.Getenv("KUBECONFIG"); kubeConfigPath != "" {
kubeconfig = kubeConfigPath
} else {
kubeconfig = filepath.Join(os.Getenv("HOME"), ".kube", "config")
}

config, err := buildConfigFromFlags("", kubeconfig)
if err != nil {
log.Fatal(err.Error())
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
log.Fatal(err.Error())
}

return clientset
}

func buildConfigFromFlags(context, kubeconfigPath string) (*rest.Config, error) {
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfigPath},
&clientcmd.ConfigOverrides{
CurrentContext: context,
}).ClientConfig()
}

0 comments on commit 08a6ae5

Please # to comment.