From deaf3e4710255fef0c7264a189caf3bdc3da2342 Mon Sep 17 00:00:00 2001 From: Sivaram Kannan Date: Sat, 25 Apr 2020 16:47:22 +0530 Subject: [PATCH 1/2] Add function to print controller version and print it. --- pkg/kudoctl/cmd/version.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/kudoctl/cmd/version.go b/pkg/kudoctl/cmd/version.go index f9582e618..1d2340015 100644 --- a/pkg/kudoctl/cmd/version.go +++ b/pkg/kudoctl/cmd/version.go @@ -4,7 +4,10 @@ import ( "fmt" "github.com/spf13/cobra" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/kudobuilder/kudo/pkg/kudoctl/clog" + "github.com/kudobuilder/kudo/pkg/kudoctl/kube" "github.com/kudobuilder/kudo/pkg/version" ) @@ -30,5 +33,33 @@ func newVersionCmd() *cobra.Command { func VersionCmd(cmd *cobra.Command, args []string) error { kudoVersion := version.Get() fmt.Printf("KUDO Version: %s\n", fmt.Sprintf("%#v", kudoVersion)) + + // Print the Controller Version + fmt.Printf("KUDO Controller Version: %s\n", GetControllerVersion()) + return nil } + +// GetControllerVersion +func GetControllerVersion() string { + + controllerVersion := "" + + client, err := kube.GetKubeClient(Settings.KubeConfig) + clog.V(3).Printf("acquiring kudo client") + if err != nil { + clog.V(3).Printf("failed to acquire client") + return controllerVersion + } + + statefulsets, err := client.KubeClient.AppsV1().StatefulSets("").List(metav1.ListOptions{LabelSelector: "app=kudo-manager"}) + if err != nil { + return controllerVersion + } + + for _, d := range statefulsets.Items { + controllerVersion = d.Spec.Template.Spec.Containers[0].Image + } + + return controllerVersion +} From 614d72833b44fdc27c364813c16fdeba1eb95937 Mon Sep 17 00:00:00 2001 From: Sivaram Kannan Date: Fri, 15 May 2020 21:04:09 +0530 Subject: [PATCH 2/2] Add controller version to the kudo version command. --- pkg/kudoctl/cmd/version.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pkg/kudoctl/cmd/version.go b/pkg/kudoctl/cmd/version.go index 1d2340015..6b4b53898 100644 --- a/pkg/kudoctl/cmd/version.go +++ b/pkg/kudoctl/cmd/version.go @@ -1,6 +1,7 @@ package cmd import ( + "errors" "fmt" "github.com/spf13/cobra" @@ -35,31 +36,38 @@ func VersionCmd(cmd *cobra.Command, args []string) error { fmt.Printf("KUDO Version: %s\n", fmt.Sprintf("%#v", kudoVersion)) // Print the Controller Version - fmt.Printf("KUDO Controller Version: %s\n", GetControllerVersion()) + controllerVersion, err := GetControllerVersion() + if err != nil { + fmt.Printf("KUDO Controller Version: %s\n", controllerVersion) + } else { + fmt.Printf("KUDO Controller Version: %#v\n", err) + } return nil } // GetControllerVersion -func GetControllerVersion() string { +func GetControllerVersion() (string, error) { - controllerVersion := "" + controllerVersion := "" client, err := kube.GetKubeClient(Settings.KubeConfig) - clog.V(3).Printf("acquiring kudo client") + clog.V(3).Printf("Acquiring kudo client") if err != nil { - clog.V(3).Printf("failed to acquire client") - return controllerVersion + clog.V(3).Printf("Failed to acquire kudo client") + return "", errors.New("") } statefulsets, err := client.KubeClient.AppsV1().StatefulSets("").List(metav1.ListOptions{LabelSelector: "app=kudo-manager"}) + clog.V(3).Printf("List statefulsets and filter kudo-manager") if err != nil { - return controllerVersion + clog.V(3).Printf("Failed to list kudo-manager statefulset") + return "", errors.New("") } for _, d := range statefulsets.Items { controllerVersion = d.Spec.Template.Spec.Containers[0].Image } - return controllerVersion + return controllerVersion, nil }