-
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?
Feature add controller version to version command #1527
Conversation
I guess this is still a WIP. Not sure how to handle the testing though, guess I can't do a unit testing since I don't have any parameters to pass and not sure how to do an integration testing as I don't see any examples to use for version. If you could give an example I will write an integration test as well. |
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.
This is a great start, thanks for improving the KUDO experience! I agree that this needs integration tests, because there are some subtle things to consider. The controller manager can be configured to run in any namespace, not just kudo-system
and we need to make sure that this is covered by the tests. Take a look at init_integration_test.go
for similar integration tests around kudo init
.
@@ -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 |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Let's return an error instead.
fmt.Printf("KUDO Controller Version: %#v\n", err) | |
return fmt.Errorf("failed to retrieve KUDO controller version: %v\n", err) |
return nil | ||
} | ||
|
||
// GetControllerVersion |
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.
// GetControllerVersion | |
// GetControllerVersion retrieves the version of the controller manager |
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 comment
The 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.
return "", errors.New("<Failed to acquire kudo client>") | |
return "", fmt.Errorf("failed to acquire Kubernetes client: %v", err) |
return "", errors.New("<Failed to acquire kudo client>") | ||
} | ||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be tested because the KUDO manager may be in kudo-system
or other namespaces. We need to ensure that this List
can cover both cases.
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.
We should also use the existing function to pull the labelselectors:
e.g.
kudo/pkg/kudoctl/kudoinit/setup/wait.go
Line 40 in 93b8220
selector := manager.GenerateLabels().AsSelector() |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
return "", errors.New("<Error: Failed to list kudo-manager statefulset>") | |
return "", fmt.Errorf("failed to list kudo-manager statefulset: %v", err) |
for _, d := range statefulsets.Items { | ||
controllerVersion = d.Spec.Template.Spec.Containers[0].Image | ||
} |
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.
There's a lot of assumptions here. Let's be a bit more strict about them. We assume that the StatefulSet
runs a single container which is the manager. Let's add checks to double down on these assumptions:
if len(statefulsets.Items) > 1 {
return errors.New("more than 1 KUDO controller manager running")
}
if len(statefulsets.Items[0].Spec.Template.Spec.Containers) != 1 {
return fmt.Errorf("invalid number of containers in statefulset %s/%s", statefulsets.Items[0].Namespace, statefulsets.Items[0].Name)
}
controllerVersion := statefulsets.Items[0].Spec.Containers[0].Image
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.
Oh, and we also have to handle the case that KUDO isn't deployed on the cluster yet.
@sivaramsk thanks for the PR... I hope you are coming back to update based @nfnt feedback. |
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.
It feels like this should be combined with #1505. Being able to read the current version of the KUDO controller is important to identifying when an upgrade is required. These should use the same function capability instead of doing it separately
return "", errors.New("<Failed to acquire kudo client>") | ||
} | ||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
We should also use the existing function to pull the labelselectors:
e.g.
kudo/pkg/kudoctl/kudoinit/setup/wait.go
Line 40 in 93b8220
selector := manager.GenerateLabels().AsSelector() |
What this PR does / why we need it:
Print the controller version if installed as part of the kudo version command
Fixes #1295