Skip to content

Add ocdev link command #354

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 1 commit into from
Apr 16, 2018
Merged

Add ocdev link command #354

merged 1 commit into from
Apr 16, 2018

Conversation

concaf
Copy link
Contributor

@concaf concaf commented Apr 12, 2018

This commit adds the ocdev link command which injects the
connection information from the target component to the source
component

@concaf
Copy link
Contributor Author

concaf commented Apr 12, 2018

Fix #342

@kadel kadel added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Apr 13, 2018
// GetComponentService returns the Service object associated with the given
// component.
// An error is thrown when exactly one Service is not found for the component.
func GetComponentService(client *occlient.Client, componentName string, applicationName string) (*corev1.Service, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that this function belongs here. If you really want to keep it here than it definitely shouldn't be public. Otherwise, it is a potential risk for creating cyclic imports like in the storage :-(

It might be better to do it similarly like here: f2d5b10#diff-6025e9b620e9321c03c11bf29e5c4dbdR1190

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved this similar to the current deployment config logic

// LinkInfo contains the information about the link being created between
// components
type LinkInfo struct {
ComponentName string
Copy link
Member

Choose a reason for hiding this comment

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

Is this source or target component name?
Why is there only one?
There should be either comment, or better variable name should specify that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added source and target components

}

return &LinkInfo{
ComponentName: sourceComponent,
Copy link
Member

Choose a reason for hiding this comment

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

Why are we returning just sourceComponent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

modified LinkInfo to include both source and target components

cmd/link.go Outdated
printed to STDOUT.
`,
Example: `
# Link current component to a component 'nodejs'
Copy link
Member

Choose a reason for hiding this comment

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

There should be just two spaces at the beginning of each line, to make it properly align

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

cmd/link.go Outdated
`,
Example: `
# Link current component to a component 'nodejs'
ocdev link nodejs
Copy link
Member

@kadel kadel Apr 16, 2018

Choose a reason for hiding this comment

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

A better example would be to do ocdev link mariadb as you will be injecting variables about mariadb to current component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

cmd/link.go Outdated
ocdev link nodejs

# Link 'nodejs' component to 'mariadb' component
ocdev link nodejs --component mariadb
Copy link
Member

Choose a reason for hiding this comment

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

again this should be the other way around ocdev link mariadb --component nodejs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

cmd/util.go Outdated
checkError(err, "Could not get current component")
return c
}
return inputComponent
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to check if the component exists here, so we don't have to do it each time we call this function.

(we need to check it only if len(inputComponent)!=0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@@ -7,11 +7,15 @@ import (
buildv1 "github.com/openshift/api/build/v1"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"

"strings"
Copy link
Member

Choose a reason for hiding this comment

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

please group this with other standard library imports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

// component as environment variables
func Link(client *occlient.Client, sourceComponent, targetComponent, applicationName string) (*LinkInfo, error) {
// Get Service associated with the target component
targetService, err := client.GetOneServiceFromSelector(
Copy link
Member

Choose a reason for hiding this comment

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

my head hurts from trying to parse this :-(
Would it be better to have separate this? It is hard to parse 3 nested function calls :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha, fixed

}

// getPortFromService returns the first port listed in the service
func getPortFromService(service *corev1.Service) (int32, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need a separate function that is just one if statement and nothing more? This is used just in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

imo it makes the Link() function look cleaner

Copy link
Member

Choose a reason for hiding this comment

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

IMO it makes it harder to read ;-)

checkError(err, "Could not get current component")
return c
}
exists, err := component.Exists(client, inputComponent, applicationName, projectName)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to check that component exists if we got it from GetCurrent?
Exists is expensive it might be enough to put into else block for previous if.

Copy link
Contributor Author

@concaf concaf Apr 16, 2018

Choose a reason for hiding this comment

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

we're not checking if we're getting it from GetCurrent. The if block has a return statement, we don't need an else here, wdyt

Copy link
Member

Choose a reason for hiding this comment

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

ah, sorry, Didn't notice return there. LGTM than ;-)

@concaf concaf removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Required by Prow. label Apr 16, 2018
This commit adds the `ocdev link` command which injects the
connection information from the target component to the source
component
@kadel kadel merged commit bbbc3d2 into redhat-developer:master Apr 16, 2018
@concaf concaf mentioned this pull request Apr 16, 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.

2 participants