diff --git a/pkg/kudoctl/cmd/version.go b/pkg/kudoctl/cmd/version.go index f9582e618..6b4b53898 100644 --- a/pkg/kudoctl/cmd/version.go +++ b/pkg/kudoctl/cmd/version.go @@ -1,10 +1,14 @@ package cmd import ( + "errors" "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 +34,40 @@ 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 + 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, error) { + + controllerVersion := "" + + client, err := kube.GetKubeClient(Settings.KubeConfig) + clog.V(3).Printf("Acquiring kudo client") + if err != nil { + 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 { + 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, nil +}