Skip to content

Commit

Permalink
Refactored some of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
vs4vijay committed Apr 19, 2020
1 parent c83e035 commit c8d36b4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
2 changes: 0 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ var rootCmd = &cobra.Command{
return err
}

fmt.Println("kubeapi", kubeapi)

app, err := tui.NewApp(kubeapi)
if err != nil {
return err
Expand Down
33 changes: 4 additions & 29 deletions pkg/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,6 @@ func BuildConfig(kubeConfig KubeConfig) (*rest.Config, error) {
return config, err
}

func GetClientset(kubeConfig KubeConfig) (*kubernetes.Clientset, error) {
config, err := BuildConfig(kubeConfig)
if err != nil {
return nil, err
}

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

// api := clientset.CoreV1()
// c, _ :=clientcmd.DefaultClientConfig.ClientConfig()

// clientcmd.DirectClientConfig

// clientcmd.DirectClientConfig{}

// rawConfig, _ := clientcmd.DirectClientConfig.RawConfig()
// // rawConfig.
// fmt.Println("rawConfig", rawConfig)

return clientset, nil
}

// func (kubeapi *KubeAPI) SearchNamespaces() ([]v1.Namespace, error) {
// namespaceList, err := kubeapi.Clientset.CoreV1().Namespaces().List(metav1.ListOptions{})
// if err != nil {
Expand All @@ -99,7 +74,7 @@ func GetClientset(kubeConfig KubeConfig) (*kubernetes.Clientset, error) {
// return namespaceList.Items, nil
// }

func (kubeapi *KubeAPI) SearchNodes() ([]v1.Node, error) {
func (kubeapi *KubeAPI) GetNodes() ([]v1.Node, error) {
nodeList, err := kubeapi.Clientset.CoreV1().Nodes().List(metav1.ListOptions{})
if err != nil {
return nil, err
Expand All @@ -121,7 +96,7 @@ func (kubeapi *KubeAPI) SearchNodes() ([]v1.Node, error) {
return nodeList.Items, nil
}

func (kubeapi *KubeAPI) SearchPods(namespace string) ([]v1.Pod, error) {
func (kubeapi *KubeAPI) GetPods(namespace string) ([]v1.Pod, error) {
podList, err := kubeapi.Clientset.CoreV1().Pods(namespace).List(metav1.ListOptions{})
if err != nil {
return nil, err
Expand All @@ -133,7 +108,7 @@ func (kubeapi *KubeAPI) SearchPods(namespace string) ([]v1.Pod, error) {
return podList.Items, nil
}

func (kubeapi *KubeAPI) SearchServices(namespace string) ([]v1.Service, error) {
func (kubeapi *KubeAPI) GetServices(namespace string) ([]v1.Service, error) {
serviceList, err := kubeapi.Clientset.CoreV1().Services(namespace).List(metav1.ListOptions{})
if err != nil {
return nil, err
Expand Down Expand Up @@ -179,7 +154,7 @@ func (kubeapi *KubeAPI) GetContainerLogs(namespace string, podName string, conta
return err
}

func (kubeapi *KubeAPI) SearchDeployments(namespace v1.Namespace) ([]v1beta1.Deployment, error) {
func (kubeapi *KubeAPI) GetDeployments(namespace v1.Namespace) ([]v1beta1.Deployment, error) {
deploymentList, err := kubeapi.Clientset.ExtensionsV1beta1().Deployments(namespace.GetName()).List(metav1.ListOptions{})
// AppsV1().Deployments(namespace).List(metav1.ListOptions{})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func onSelectNamespace(g *gocui.Gui, v *gocui.View) error {
podsView, _ := g.View("Main")
podsView.Clear()

pods, _ := app.kubeapi.SearchPods(namespaceName)
pods, _ := app.kubeapi.GetPods(namespaceName)
podsView.Title = fmt.Sprintf("Pods(%v) - %v", len(pods), namespaceName)
fmt.Fprintf(podsView, "%-20s %-15s\n", "POD NAME", "POD STATUS")
for _, item := range pods {
Expand All @@ -179,7 +179,7 @@ func onSelectNamespace(g *gocui.Gui, v *gocui.View) error {
servicesView, _ := g.View("Services")
servicesView.Clear()

services, _ := app.kubeapi.SearchServices(namespaceName)
services, _ := app.kubeapi.GetServices(namespaceName)
servicesView.Title = fmt.Sprintf("Services(%s)", namespaceName)
for _, item := range services {
fmt.Fprintln(servicesView, item.GetName())
Expand Down

0 comments on commit c8d36b4

Please sign in to comment.