Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

sivaramsk
Copy link
Contributor

What this PR does / why we need it:
Print the controller version if installed as part of the kudo version command

Fixes #1295

@sivaramsk
Copy link
Contributor Author

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.

@nfnt nfnt self-assigned this May 18, 2020
Copy link
Member

@nfnt nfnt left a 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
Copy link
Member

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)
Copy link
Member

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.

Suggested change
fmt.Printf("KUDO Controller Version: %#v\n", err)
return fmt.Errorf("failed to retrieve KUDO controller version: %v\n", err)

return nil
}

// GetControllerVersion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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>")
Copy link
Member

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.

Suggested change
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"})
Copy link
Member

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.

Copy link
Member

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.

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>")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return "", errors.New("<Error: Failed to list kudo-manager statefulset>")
return "", fmt.Errorf("failed to list kudo-manager statefulset: %v", err)

Comment on lines +68 to +70
for _, d := range statefulsets.Items {
controllerVersion = d.Spec.Template.Spec.Containers[0].Image
}
Copy link
Member

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

Copy link
Member

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.

@kensipe kensipe changed the base branch from master to main June 24, 2020 00:38
@kensipe
Copy link
Member

kensipe commented Jun 24, 2020

@sivaramsk thanks for the PR... I hope you are coming back to update based @nfnt feedback.
I have a request... we are removing master branch and working off main. I updated this PR to be against main.
thanks!

Copy link
Member

@runyontr runyontr left a 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"})
Copy link
Member

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.

selector := manager.GenerateLabels().AsSelector()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Print controller version as part of kubectl kudo version
4 participants