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

Bug 1595153 - Add support for apb test that works in and out of cluster #109

Merged
merged 4 commits into from Aug 14, 2018

Conversation

dymurray
Copy link
Contributor

@dymurray dymurray commented Aug 8, 2018

In the past we were checking the contents of a file on the container to check if the APB succeeded in the test. This seemed incredibly pointless to me so instead I have talked with @djzager and determined we should simply judge a test status on whether or not the container is in a failed state or a succeeded state. This makes the workflow much simpler and now if a person wants to write a set of unit tests they can simply run the fail module in Ansible to signify a failed test which will put the pod in an error state.

@@ -40,7 +40,7 @@ import (
)

// RunBundle will run the bundle's action in the given namespace
func RunBundle(action string, ns string, bundleName string, sandboxRole string, bundleRegistry string, printLogs bool, skipParams bool, args []string) {
func RunBundle(action string, ns string, bundleName string, sandboxRole string, bundleRegistry string, printLogs bool, skipParams bool, args []string) (string, error) {
Copy link
Contributor

@djwhatle djwhatle Aug 8, 2018

Choose a reason for hiding this comment

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

I may be missing something, but I'm having trouble figuring out why we're returning a string here. Looks like it's empty in all return paths below.

Perhaps using named return values would be a good idea if you want to use the string in the future, might make it less ambiguous.

Copy link
Contributor

Choose a reason for hiding this comment

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

Figured it out below, think we should name the string podName

cmd/bundle.go Outdated
@@ -208,16 +238,37 @@ func ListImages() {
}
}

func executeBundle(action string, args []string) {
func executeBundle(action string, args []string) string {
Copy link
Contributor

@djwhatle djwhatle Aug 8, 2018

Choose a reason for hiding this comment

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

Same thing here, what's this return value for?

Edit: I see now, looks like the pod name. Maybe we should name it though. I'll let you decide.

@@ -60,15 +60,15 @@ func RunBundle(action string, ns string, bundleName string, sandboxRole string,
if len(candidateSpecs) == 0 {
if len(bundleRegistry) > 0 {
log.Errorf("Didn't find APB [%v] in registry [%v]\n", bundleName, bundleRegistry)
return
return "", errors.New(fmt.Sprintf("failed to find APB [%v] in registry [%v]", bundleName, bundleRegistry))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we're going to end up with one too many error messages being printed here.

Copy link
Contributor

Choose a reason for hiding this comment

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

ERR - Didn't find APB [bar] in registry foo
ERR - Failed to execute bundle [bar]: [failed to find APB [bar] in registry [foo]]

^ Above will be the output from what I can tell. Seems redundant to print info about not being able to find the APB multiple times.

}
log.Errorf("Didn't find APB [%v] in configured registries\n", bundleName)
return
return "", errors.New(fmt.Sprintf("failed to find APB [%v] on configured registries", bundleName))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing here

// TODO: return an ErrorBundleNotFound
}
if len(candidateSpecs) > 1 {
log.Warnf("Found multiple APBs matching name [%v]. Specify a registry with --registry.", bundleName)
return
return "", errors.New(fmt.Sprintf("found multiple APBs with matching name [%v]", bundleName))
Copy link
Contributor

Choose a reason for hiding this comment

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

And here

@@ -169,7 +169,21 @@ func RunBundle(action string, ns string, bundleName string, sandboxRole string,
}

// TODO: return nil
return
return pn, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, now I see it. I think it would be helpful if we named the return value since the function name doesn't explicitly tell us what kind of return value to expect in the string.

Copy link
Contributor

Choose a reason for hiding this comment

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

at a minimum, I think if you are going to use the named return the names should match.

Copy link
Contributor

@djwhatle djwhatle left a comment

Choose a reason for hiding this comment

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

Think we could make these functions more readable by naming the new return values. I don't have a working cluster to test "apb test" with right now, but that part looks good to me visually.

Also think our error printing is a little weird right now.

@dymurray dymurray dismissed djwhatle’s stale review August 9, 2018 18:24

Thanks Derek! Made the requested changes

Copy link
Contributor

@djzager djzager left a comment

Choose a reason for hiding this comment

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

Looks good, minor nits.

}
}
log.Debugf("Running bundle [%v] with action [%v] in namespace [%v].", args[0], action, bundleNamespace)
runner.RunBundle(action, bundleNamespace, args[0], sandboxRole, bundleRegistry, printLogs, skipParams, args[1:])
pn, err := runner.RunBundle(action, bundleNamespace, args[0], sandboxRole, bundleRegistry, printLogs, skipParams, args[1:])
Copy link
Contributor

Choose a reason for hiding this comment

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

my understanding of how to use "named returns" is based on https://tour.golang.org/basics/7.

Based on that I would think that you should initialize podName in the beginning to an empty string, set it here, and simply use return. I think that way would be much easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wow I had no idea you could do this. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

While the named return is an interesting thing, I would NOT use it in this instance. I think it would be more confusing since then you'd have to look at the empty return, then look at the method signature to see if it is a named return or not. If this were a much SHORTER method then I'd be okay with it. But I would leave it as return pn

@@ -169,7 +169,21 @@ func RunBundle(action string, ns string, bundleName string, sandboxRole string,
}

// TODO: return nil
return
return pn, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

at a minimum, I think if you are going to use the named return the names should match.

Copy link
Contributor

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

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

the initialization of podName and err is weird, much more pythonlike than golike.

}
}
log.Debugf("Running bundle [%v] with action [%v] in namespace [%v].", args[0], action, bundleNamespace)
runner.RunBundle(action, bundleNamespace, args[0], sandboxRole, bundleRegistry, printLogs, skipParams, args[1:])
pn, err := runner.RunBundle(action, bundleNamespace, args[0], sandboxRole, bundleRegistry, printLogs, skipParams, args[1:])
Copy link
Contributor

Choose a reason for hiding this comment

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

While the named return is an interesting thing, I would NOT use it in this instance. I think it would be more confusing since then you'd have to look at the empty return, then look at the method signature to see if it is a named return or not. If this were a much SHORTER method then I'd be okay with it. But I would leave it as return pn

func RunBundle(action string, ns string, bundleName string, sandboxRole string, bundleRegistry string, printLogs bool, skipParams bool, args []string) {
func RunBundle(action string, ns string, bundleName string, sandboxRole string, bundleRegistry string, printLogs bool, skipParams bool, args []string) (podName string, err error) {
podName = ""
err = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be:

var podName string
var err error

They will get the default values of "" and nil respectively.

pod, err := k8scli.Client.CoreV1().Pods(namespace).Get(podName, metav1.GetOptions{})
if err != nil {
log.Errorf("Error getting pod [%v] status: %v", podName, err)
return ""
Copy link
Contributor

Choose a reason for hiding this comment

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

feels like this should return something other than empty string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going to include an error return as well

@dymurray dymurray merged commit edbe861 into automationbroker:master Aug 14, 2018
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.

None yet

4 participants