-
Notifications
You must be signed in to change notification settings - Fork 243
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
Conversation
Will change fmt.Print statements to glog statements once #590 is in |
user messages like this should remain |
pkg/component/component.go
Outdated
@@ -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) { |
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.
additional
argument is never used
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.
Aah my bad :(
pkg/component/component.go
Outdated
@@ -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 |
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.
the comment says that provides map
but this function returns a slice of strings
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.
Will fix it to slice.
Forgot to modify comment post changing code
pkg/component/component.go
Outdated
|
||
dc, err := client.GetOneDeploymentConfigFromSelector(componentSelector) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "Unable to fetch deployment configs for the selector %v", componentSelector) |
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.
Go errors shouldn't start with a capital letter. - https://github.com/golang/go/wiki/Errors
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.
ack
pkg/component/component.go
Outdated
// 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) |
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.
Go errors shouldn't start with a capital letter. - https://github.com/golang/go/wiki/Errors
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.
ack
@kadel Done incorporated your comments |
cmd/create.go
Outdated
} | ||
ports, err := component.GetComponentPorts(client, componentName, applicationName, false) |
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 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 😇
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 ok np :)
@kadel Incorporated your comments !! Verified !! |
@cdrage @surajnarwade @syamgk @mik-dass Please review |
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.
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") |
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.
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"
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 helps ensure clarity in the code when reading
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.
Ack
pkg/component/component.go
Outdated
if err != nil { | ||
return nil, errors.Wrapf(err, "unable to fetch deployment configs for the selector %v", componentSelector) | ||
} | ||
// Find Pod for component |
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.
newline above
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.
Ack
pkg/component/component.go
Outdated
} | ||
// 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. |
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.
newline above
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.
Ack
pkg/component/component.go
Outdated
if err != nil { | ||
return nil, errors.Wrapf(err, "error fetching pod for podselector %v", podSelector) | ||
} | ||
//Iterate and fetch ports |
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.
newline above
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.
Ack
pkg/component/component.go
Outdated
@@ -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) { |
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 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.
Ack
pkg/component/component.go
Outdated
@@ -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) { |
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.
a different variable name than res
would be better.
Maybe ports
?
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.
Ack
pkg/component/component.go
Outdated
// 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) |
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.
I guess we can get the containers and thus the ports from dc.Spec.Template.Spec.Containers
instead of retrieving the Pod
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.
Ack
Verified as in https://gist.github.com/anmolbabu/fb066e37739750064c49797eeae8c00c |
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") |
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 don't need this line if our source is git
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.
Ack
pkg/testingutil/deploymentconfigs.go
Outdated
} | ||
} | ||
|
||
/* |
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.
Remove comments
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.
Ack
@surajnarwade Incoporated your comments Please revisit the PR @kadel @cdrage @surajnarwade @syamgk @mik-dass Please review |
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.
@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!
pkg/component/component_test.go
Outdated
// 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 |
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.
why aren't we using this one instead (generating the deploymentmentconfigs with passed in params)?
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.
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 :)
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.
okay. can you remove this line @anmolbabu since it's commented out?
pkg/component/component_test.go
Outdated
// The function we are testing | ||
output, err := GetComponentPorts(client, tt.args.componentName, tt.args.applicationName) | ||
|
||
//Checks for error in positive 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.
add spacing after //
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.
Ack
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.
LGTM :)
@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]>
fixes redhat-developer#608 Signed-off-by: anmolbabu <[email protected]>
fixes redhat-developer#608 Signed-off-by: anmolbabu <[email protected]>
fixes redhat-developer#608 Signed-off-by: anmolbabu <[email protected]>
fixes redhat-developer#608 Signed-off-by: anmolbabu <[email protected]>
fixes redhat-developer#608 Signed-off-by: anmolbabu <[email protected]>
fixes redhat-developer#608 Signed-off-by: anmolbabu <[email protected]>
Signed-off-by: anmolbabu <[email protected]>
fixes redhat-developer#608 Signed-off-by: anmolbabu <[email protected]>
fixes redhat-developer#608 Signed-off-by: anmolbabu <[email protected]>
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 remove the commented out code. Other than that, LGTM.
pkg/component/component_test.go
Outdated
// 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 |
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.
okay. can you remove this line @anmolbabu since it's commented out?
@cdrage Done.Can you push this in if looks good? |
Tests were a false-positive. I'm re-running them to see if it passes and then we'll merge! |
Travis status is not green, I am retriggering the build. if it get passed, I'll merge it :) |
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]