Skip to content

Add information about ports to odo create output #610

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

Merged
merged 11 commits into from
Aug 9, 2018

Conversation

anmolbabu
Copy link
Contributor

@anmolbabu anmolbabu commented Aug 1, 2018

This PR adds message of the form:
"Component $componentName was created and ports $containerPort/$containerProtocol,.... were opened."

fixes #608
Signed-off-by: anmolbabu [email protected]

@anmolbabu anmolbabu added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. label Aug 1, 2018
@anmolbabu anmolbabu self-assigned this Aug 1, 2018
@anmolbabu
Copy link
Contributor Author

Will change fmt.Print statements to glog statements once #590 is in

@anmolbabu anmolbabu removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. Required by Prow. label Aug 1, 2018
@kadel
Copy link
Member

kadel commented Aug 1, 2018

Will change fmt.Print statements to glog statements once #590 is in

user messages like this should remain fmt.Print

@@ -68,6 +68,31 @@ func CreateFromGit(client *occlient.Client, name string, ctype string, url strin
return nil
}

// GetComponentPorts provides map[container_name][]array_of_ports
func GetComponentPorts(client *occlient.Client, componentName string, applicationName string, additional bool) (res []string, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

additional argument is never used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aah my bad :(

@@ -68,6 +68,31 @@ func CreateFromGit(client *occlient.Client, name string, ctype string, url strin
return nil
}

// GetComponentPorts provides map[container_name][]array_of_ports
Copy link
Member

Choose a reason for hiding this comment

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

the comment says that provides map but this function returns a slice of strings

Copy link
Contributor Author

@anmolbabu anmolbabu Aug 1, 2018

Choose a reason for hiding this comment

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

Will fix it to slice.
Forgot to modify comment post changing code


dc, err := client.GetOneDeploymentConfigFromSelector(componentSelector)
if err != nil {
return nil, errors.Wrapf(err, "Unable to fetch deployment configs for the selector %v", componentSelector)
Copy link
Member

Choose a reason for hiding this comment

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

Go errors shouldn't start with a capital letter. - https://github.com/golang/go/wiki/Errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack

// Wait for Pod to be in running state otherwise we can't sync data to it.
pod, err := client.WaitAndGetPod(podSelector)
if err != nil {
return nil, errors.Wrapf(err, "Error fetching pod for podselector %v", podSelector)
Copy link
Member

Choose a reason for hiding this comment

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

Go errors shouldn't start with a capital letter. - https://github.com/golang/go/wiki/Errors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack

@kadel
Copy link
Member

kadel commented Aug 1, 2018

odo-bug-id: #608

Please use "fixes #608" GitHub will automatically close that issue when we merge this PR. Otherwise, it is easy to forget to close the issue.

@anmolbabu
Copy link
Contributor Author

anmolbabu commented Aug 1, 2018

@kadel Done incorporated your comments
Can you please revisit the PR

cmd/create.go Outdated
}
ports, err := component.GetComponentPorts(client, componentName, applicationName, false)
Copy link
Member

Choose a reason for hiding this comment

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

it doesn't really make sense to call this function with additional flag set to true.
You can just completely remove this argument from the function and always call componentlabels.GetLabels with false. Sorry this was what I meant with my previous comment 😇

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh ok np :)

@anmolbabu
Copy link
Contributor Author

anmolbabu commented Aug 1, 2018

@kadel Incorporated your comments
Please review

!! Verified !!

@anmolbabu
Copy link
Contributor Author

@cdrage @surajnarwade @syamgk @mik-dass Please review

Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

Needs tests!

cmd/create.go Outdated
} else if len(ports) == 1 {
fmt.Printf(" and port %s was opened\n", ports[0])
}
fmt.Printf("To push source code to the component run 'odo push'\n")
Copy link
Member

Choose a reason for hiding this comment

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

The code above is a bit too cluttered. Please add newlines / spacing between the different parts of the code. For example:

		ports, err := component.GetComponentPorts(client, componentName, applicationName)
		checkError(err, "")
		fmt.Printf("Component '%s' was created", componentName)

		if len(ports) > 1 {
			fmt.Printf(" and ports %s were opened\n", strings.Join(ports, ","))
		} else if len(ports) == 1 {
			fmt.Printf(" and port %s was opened\n", ports[0])
		}

		fmt.Printf("To push source code to the component run 'odo push'\n"

Copy link
Member

Choose a reason for hiding this comment

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

This helps ensure clarity in the code when reading

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

if err != nil {
return nil, errors.Wrapf(err, "unable to fetch deployment configs for the selector %v", componentSelector)
}
// Find Pod for component
Copy link
Member

Choose a reason for hiding this comment

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

newline above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

}
// Find Pod for component
podSelector := fmt.Sprintf("deploymentconfig=%s", dc.Name)
// Wait for Pod to be in running state otherwise we can't sync data to it.
Copy link
Member

Choose a reason for hiding this comment

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

newline above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

if err != nil {
return nil, errors.Wrapf(err, "error fetching pod for podselector %v", podSelector)
}
//Iterate and fetch ports
Copy link
Member

Choose a reason for hiding this comment

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

newline above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

@@ -68,6 +68,31 @@ func CreateFromGit(client *occlient.Client, name string, ctype string, url strin
return nil
}

// GetComponentPorts provides slice of ports used by the component in the form port_no/protocol
func GetComponentPorts(client *occlient.Client, componentName string, applicationName string) (res []string, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

Hate to say this, but you'll need to add a test for this function 😄

If you need help, feel free to PM / ping me or @ashetty1 / @mik-dass ! I just finished doing #565 and adding tests there and had to learn a bunch of new stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

@@ -68,6 +68,31 @@ func CreateFromGit(client *occlient.Client, name string, ctype string, url strin
return nil
}

// GetComponentPorts provides slice of ports used by the component in the form port_no/protocol
func GetComponentPorts(client *occlient.Client, componentName string, applicationName string) (res []string, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

a different variable name than res would be better.

Maybe ports ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

// Find Pod for component
podSelector := fmt.Sprintf("deploymentconfig=%s", dc.Name)
// Wait for Pod to be in running state otherwise we can't sync data to it.
pod, err := client.WaitAndGetPod(podSelector)
Copy link
Contributor

@mik-dass mik-dass Aug 2, 2018

Choose a reason for hiding this comment

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

I guess we can get the containers and thus the ports from dc.Spec.Template.Spec.Containers instead of retrieving the Pod

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

@anmolbabu
Copy link
Contributor Author

anmolbabu commented Aug 4, 2018

cmd/create.go Outdated
fmt.Printf(" and port %s was opened\n", ports[0])
}

fmt.Printf("To push source code to the component run 'odo push'\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't need this line if our source is git

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

}
}

/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

@anmolbabu
Copy link
Contributor Author

@surajnarwade Incoporated your comments Please revisit the PR

@kadel @cdrage @surajnarwade @syamgk @mik-dass Please review

@anmolbabu
Copy link
Contributor Author

Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

@mik-dass and @ashetty1 please review the tests as you two are the review masterssss!

just a quick question from me @anmolbabu but this looks great so far!

// Fake the client with the appropriate arguments
client, fakeClientSet := occlient.FakeNew()
fakeClientSet.AppsClientset.PrependReactor("list", "deploymentconfigs", func(action ktesting.Action) (bool, runtime.Object, error) {
//return true, testingutil.FakeDeploymentConfigs(tt.args.namespace, tt.args.componentName, tt.args.componentType, tt.args.applicationName, tt.args.containerPort), nil
Copy link
Member

Choose a reason for hiding this comment

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

why aren't we using this one instead (generating the deploymentmentconfigs with passed in params)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

only to avoid long list of parameters and multiple calls like if you see https://github.com/redhat-developer/odo/pull/610/files#diff-d89c4df0f7eae3a323f4958758b13435R28,

In some cases I have 2 containers per dc in some 1 and within a container, I have in some cases 2 ports exposed and in some, 1 which means the private functions in that file will also need to be exported. In fact the huge list of parameters vs long list of function calls made me feel would clutter the code here so felt it would be nice to keep it in the file where mock data is present :)

Copy link
Member

Choose a reason for hiding this comment

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

okay. can you remove this line @anmolbabu since it's commented out?

// The function we are testing
output, err := GetComponentPorts(client, tt.args.componentName, tt.args.applicationName)

//Checks for error in positive cases
Copy link
Member

Choose a reason for hiding this comment

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

add spacing after //

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack

Copy link
Contributor

@mik-dass mik-dass left a comment

Choose a reason for hiding this comment

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

LGTM :)

@kadel
Copy link
Member

kadel commented Aug 8, 2018

@cdrage @surajnarwade please check if your comments were addressed so we can merge it

This PR adds message of the form:
"Component $componentName was created and ports $containerPort/$containerProtocol,.... were opened."

fixes redhat-developer#608
Signed-off-by: anmolbabu <[email protected]>
Signed-off-by: anmolbabu <[email protected]>
Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

Please remove the commented out code. Other than that, LGTM.

// Fake the client with the appropriate arguments
client, fakeClientSet := occlient.FakeNew()
fakeClientSet.AppsClientset.PrependReactor("list", "deploymentconfigs", func(action ktesting.Action) (bool, runtime.Object, error) {
//return true, testingutil.FakeDeploymentConfigs(tt.args.namespace, tt.args.componentName, tt.args.componentType, tt.args.applicationName, tt.args.containerPort), nil
Copy link
Member

Choose a reason for hiding this comment

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

okay. can you remove this line @anmolbabu since it's commented out?

@anmolbabu
Copy link
Contributor Author

@cdrage Done.Can you push this in if looks good?

@cdrage
Copy link
Member

cdrage commented Aug 8, 2018

Tests were a false-positive. I'm re-running them to see if it passes and then we'll merge!

@surajnarwade
Copy link
Contributor

surajnarwade commented Aug 9, 2018

Travis status is not green, I am retriggering the build. if it get passed, I'll merge it :)

@surajnarwade surajnarwade merged commit f880cc2 into redhat-developer:master Aug 9, 2018
@surajnarwade surajnarwade mentioned this pull request Aug 24, 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.

Add information about ports to odo create output
5 participants