-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature add controller version to version command #1527
base: main
Are you sure you want to change the base?
Changes from all commits
deaf3e4
4456fab
551fd42
614d728
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's return an error instead.
Suggested change
|
||||||
} | ||||||
|
||||||
return nil | ||||||
} | ||||||
|
||||||
// GetControllerVersion | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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("<Failed to acquire kudo client>") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please return an error message that includes the underlying error. Also let's stay consistent with other error messages.
Suggested change
|
||||||
} | ||||||
|
||||||
statefulsets, err := client.KubeClient.AppsV1().StatefulSets("").List(metav1.ListOptions{LabelSelector: "app=kudo-manager"}) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be tested because the KUDO manager may be in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also use the existing function to pull the labelselectors: kudo/pkg/kudoctl/kudoinit/setup/wait.go Line 40 in 93b8220
|
||||||
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("<Error: Failed to list kudo-manager statefulset>") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
for _, d := range statefulsets.Items { | ||||||
controllerVersion = d.Spec.Template.Spec.Containers[0].Image | ||||||
} | ||||||
Comment on lines
+68
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a lot of assumptions here. Let's be a bit more strict about them. We assume that the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, and we also have to handle the case that KUDO isn't deployed on the cluster yet. |
||||||
|
||||||
return controllerVersion, nil | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary comment, it's clear from the code what this does.