Skip to content

Conversation

@rna-afk
Copy link
Contributor

@rna-afk rna-afk commented Apr 20, 2020

GCP: Fix error message for Invalid Project ID entry

Fixes the error message that occurs after the region selection when an
invalid project ID is entered. Solved by picking up the list of projects
that the user has in their GCP account and offers a select option on the
project entry to select the one that they want. Reduces the chance of
picking an invalid project ID and avoids the error message.

Sample Output:

? SSH Public Key /home/***/.ssh/id_rsa.pub
? Platform gcp
INFO Credentials loaded from file "/home/***/.gcp/osServiceAccount.json" 
? Project ID  [Use arrows to move, enter to select, type to filter, ? for more help]
  OpenShift Dev - Installer (openshift-dev-installer)
> OpenShift GCE Devel (openshift-gce-devel)
  OpenShift GCE Devel - CI Jobs (openshift-gce-devel-ci)
  OpenShift Perf and Scalability (openshift-perfscale)
  OpenShift RHCOS devel (openshift-rhcos-devel)

@rna-afk rna-afk force-pushed the gcp_project_basenames_validation branch 4 times, most recently from a91b1ed to ea3538b Compare April 20, 2020 22:32
Copy link
Contributor

@patrickdillon patrickdillon 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 off to a good start. This only adds validation for the TUI wizard. Validation also should be added for the install-config. That can be done by adding to the Validate function here: https://github.com/openshift/installer/blob/master/pkg/asset/installconfig/gcp/validation.go#L15

You should also add a test for a valid and invalid project.

The commit message begins with script: Not sure what that refers to.

return svc, nil
}

//GetListOfProjects gets the list of project names and ids associated with the current user.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: there should be a space between // and the first word.

}

//GetListOfProjects gets the list of project names and ids associated with the current user.
func (c *Client) GetListOfProjects(ctx context.Context) ([]string, []string, error) {
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 it's better for this to return a map or other data structure. I don't think it's good to rely on corresponding indices between two slices--what if you sort one?

ssn: ssn,
}

var listOfCombo []string
Copy link
Contributor

Choose a reason for hiding this comment

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

A better name would be something like projectChoices. Don't begin variable names with types or pseudo types like list; combo is vague.

Prompt: &survey.Select{
Message: "Project",
Help: "The GCP project to be used for installation.",
Default: fmt.Sprintf("%s", defaultValue),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is strange... Does this just evaluate to defaultValue so why usefmt.Sprintf?

listOfCombo = append(listOfCombo, listOfNames[i]+" ("+v+")")
}

defaultValue := listOfNames[index] + " (" + defaultProject + ")"
Copy link
Contributor

Choose a reason for hiding this comment

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

but you should be using fmt.Sprintf here.

if v == defaultProject {
index = i
}
listOfCombo = append(listOfCombo, listOfNames[i]+" ("+v+")")
Copy link
Contributor

Choose a reason for hiding this comment

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

the string formatting here should use fmt.Sprintf. Also I think it's more readable to have the string formatting in its own line and assigned to a variable, rather than as an arg to append.

Default: fmt.Sprintf("%s", defaultValue),
Options: listOfCombo,
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
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 survey already limits choices to Options so I don't think this extra validator is needed.

Comment on lines 81 to 82
selectedProject = strings.SplitN(selectedProject, " (", 2)[1]
selectedProject = selectedProject[:len(selectedProject)-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than all of this string manipulation, I think it's better when you create options to also create a map with option as key and the id as value.

Message: "Project",
Help: "The GCP project to be used for installation.",
Default: fmt.Sprintf("%s", defaultValue),
Options: listOfCombo,
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 it is good for the values passed to Options to be sorted.

@rna-afk rna-afk force-pushed the gcp_project_basenames_validation branch 7 times, most recently from 18029ac to 83fa604 Compare April 21, 2020 15:37
@rna-afk rna-afk changed the title Added validation for GCP Project ID & basedomain access Bug 1826414 - Added validation for GCP Project ID & basedomain access Apr 21, 2020
@rna-afk
Copy link
Contributor Author

rna-afk commented Apr 21, 2020

/bugzilla refresh

1 similar comment
@rna-afk
Copy link
Contributor Author

rna-afk commented Apr 21, 2020

/bugzilla refresh

@openshift-ci-robot
Copy link
Contributor

@rna-afk: No Bugzilla bug is referenced in the title of this pull request.
To reference a bug, add 'Bug XXX:' to the title of this pull request and request another bug refresh with /bugzilla refresh.

Details

In response to this:

/bugzilla refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@rna-afk rna-afk changed the title Bug 1826414 - Added validation for GCP Project ID & basedomain access Bug 1826414: Added validation for GCP Project ID & basedomain access Apr 21, 2020
@rna-afk
Copy link
Contributor Author

rna-afk commented Apr 21, 2020

/bugzilla refresh

@openshift-ci-robot
Copy link
Contributor

@rna-afk: An error was encountered adding this pull request to the external tracker bugs for bug 1826414 on the Bugzilla server at https://bugzilla.redhat.com:

JSONRPC error 32000: There was an error reported for a GitHub REST call. URL: https://api.github.com/repos/openshift/installer/pulls/3484 Error: 500 Internal Server Error at /loader/0x5556fb1cd1d8/Bugzilla/Extension/ExternalBugs/Type/GitHub.pm line 107. at /loader/0x5556fb1cd1d8/Bugzilla/Extension/ExternalBugs/Type/GitHub.pm line 107. eval {...} called at /loader/0x5556fb1cd1d8/Bugzilla/Extension/ExternalBugs/Type/GitHub.pm line 94 Bugzilla::Extension::ExternalBugs::Type::GitHub::_do_rest_call('Bugzilla::Extension::ExternalBugs::Type::GitHub=HASH(0x5556fe...', 'https://api.github.com/repos/openshift/installer/pulls/3484', 'GET') called at /loader/0x5556fb1cd1d8/Bugzilla/Extension/ExternalBugs/Type/GitHub.pm line 58 Bugzilla::Extension::ExternalBugs::Type::GitHub::get_data('Bugzilla::Extension::ExternalBugs::Type::GitHub=HASH(0x5556fe...', 'Bugzilla::Extension::ExternalBugs::Bug=HASH(0x5556ff459360)') called at /loader/0x5556fb1cd1d8/Bugzilla/Extension/ExternalBugs/Bug.pm line 298 eval {...} called at /loader/0x5556fb1cd1d8/Bugzilla/Extension/ExternalBugs/Bug.pm line 298 Bugzilla::Extension::ExternalBugs::Bug::update_ext_info('Bugzilla::Extension::ExternalBugs::Bug=HASH(0x5556ff459360)', 1) called at /loader/0x5556fb1cd1d8/Bugzilla/Extension/ExternalBugs/Bug.pm line 121 Bugzilla::Extension::ExternalBugs::Bug::create('Bugzilla::Extension::ExternalBugs::Bug', 'HASH(0x5556ff7bd5a0)') called at /var/www/html/bugzilla/extensions/ExternalBugs/Extension.pm line 873 Bugzilla::Extension::ExternalBugs::bug_start_of_update('Bugzilla::Extension::ExternalBugs=HASH(0x5556ff45d870)', 'HASH(0x5556ffd118c0)') called at /var/www/html/bugzilla/Bugzilla/Hook.pm line 21 Bugzilla::Hook::process('bug_start_of_update', 'HASH(0x5556ffd118c0)') called at /var/www/html/bugzilla/Bugzilla/Bug.pm line 1170 Bugzilla::Bug::update('Bugzilla::Bug=HASH(0x5556ff38a938)') called at /loader/0x5556fb1cd1d8/Bugzilla/Extension/ExternalBugs/WebService.pm line 84 Bugzilla::Extension::ExternalBugs::WebService::add_external_bug('Bugzilla::WebService::Server::JSONRPC::Bugzilla::Extension::E...', 'HASH(0x5556ff36e5c0)') called at (eval 2195) line 1 eval ' $procedure->{code}->($self, @params) ;' called at /usr/share/perl5/vendor_perl/JSON/RPC/Legacy/Server.pm line 220 JSON::RPC::Legacy::Server::_handle('Bugzilla::WebService::Server::JSONRPC::Bugzilla::Extension::E...', 'HASH(0x5556ffca7fd8)') called at /var/www/html/bugzilla/Bugzilla/WebService/Server/JSONRPC.pm line 295 Bugzilla::WebService::Server::JSONRPC::_handle('Bugzilla::WebService::Server::JSONRPC::Bugzilla::Extension::E...', 'HASH(0x5556ffca7fd8)') called at /usr/share/perl5/vendor_perl/JSON/RPC/Legacy/Server.pm line 126 JSON::RPC::Legacy::Server::handle('Bugzilla::WebService::Server::JSONRPC::Bugzilla::Extension::E...') called at /var/www/html/bugzilla/Bugzilla/WebService/Server/JSONRPC.pm line 70 Bugzilla::WebService::Server::JSONRPC::handle('Bugzilla::WebService::Server::JSONRPC::Bugzilla::Extension::E...') called at /var/www/html/bugzilla/jsonrpc.cgi line 31 ModPerl::ROOT::Bugzilla::ModPerl::ResponseHandler::var_www_html_bugzilla_jsonrpc_2ecgi::handler('Apache2::RequestRec=SCALAR(0x5556ff24ddb0)') called at /usr/lib64/perl5/vendor_perl/ModPerl/RegistryCooker.pm line 207 eval {...} called at /usr/lib64/perl5/vendor_perl/ModPerl/RegistryCooker.pm line 207 ModPerl::RegistryCooker::run('Bugzilla::ModPerl::ResponseHandler=HASH(0x5556ffcceed8)') called at /usr/lib64/perl5/vendor_perl/ModPerl/RegistryCooker.pm line 173 ModPerl::RegistryCooker::default_handler('Bugzilla::ModPerl::ResponseHandler=HASH(0x5556ffcceed8)') called at /usr/lib64/perl5/vendor_perl/ModPerl/Registry.pm line 32 ModPerl::Registry::handler('Bugzilla::ModPerl::ResponseHandler', 'Apache2::RequestRec=SCALAR(0x5556ff24ddb0)') called at /var/www/html/bugzilla/mod_perl.pl line 139 Bugzilla::ModPerl::ResponseHandler::handler('Bugzilla::ModPerl::ResponseHandler', 'Apache2::RequestRec=SCALAR(0x5556ff24ddb0)') called at (eval 2195) line 0 eval {...} called at (eval 2195) line 0
Please contact an administrator to resolve this issue, then request a bug refresh with /bugzilla refresh.

Details

In response to this:

Bug 1826414: Added validation for GCP Project ID & basedomain access

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot
Copy link
Contributor

@rna-afk: This pull request references Bugzilla bug 1826414, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.5.0) matches configured target release for branch (4.5.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)
Details

In response to this:

/bugzilla refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Apr 21, 2020
@rna-afk rna-afk force-pushed the gcp_project_basenames_validation branch 2 times, most recently from ef7884b to 1d82772 Compare April 21, 2020 17:35
Copy link
Contributor

@patrickdillon patrickdillon left a comment

Choose a reason for hiding this comment

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

Left a few more comments. This is in good shape.

Can you update the commit message heading to make it more obvious this relates to GCP?

There are two different conventions generally followed. You can start with something like

pkg/asset/installconfig/gcp: or GCP: but anything that gives more context is fine. Also in general commit messages should be imperative, so Fix error message for Invalid GCP Project ID entry instead of Fixed...

Also we removed the basedomain portion of this card so I was a little thrown initially by the PR title.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change GetListOfProjects -> GetProjects ? Also if you're changing the comment, can you put in the comment that id is key of map and name is value?

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: personally I think just projects is better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't include type in variable name. You could just call this projectIDs, or ids.

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 this line shows that these variable names are confusing.

What about something like:

for id, name := range projects {
		option := fmt.Sprintf("%s (%s)", name, id)
		ids[option] = id
		if option == defaultProject {
			defaultValue = option
		}
		options = append(options, option)

Copy link
Contributor

Choose a reason for hiding this comment

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

error strings like this should start with lowercase letters. Invalid -> invalid. https://github.com/golang/go/wiki/CodeReviewComments#error-strings

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you shorten all of this to:

	gcpClient.EXPECT().GetListOfProjects(gomock.Any()).Return({"valid-project" : "valid-project"}, nil).AnyTimes()

@rna-afk rna-afk changed the title Bug 1826414: Added validation for GCP Project ID & basedomain access Bug 1826414: Added validation for GCP Project ID access Apr 21, 2020
@openshift-ci-robot
Copy link
Contributor

@rna-afk: This pull request references Bugzilla bug 1826414, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.5.0) matches configured target release for branch (4.5.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)
Details

In response to this:

Bug 1826414: Added validation for GCP Project ID access

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@rna-afk rna-afk force-pushed the gcp_project_basenames_validation branch from 1d82772 to c534fcb Compare April 21, 2020 18:25
@patrickdillon
Copy link
Contributor

You should add new test cases in: pkg/asset/installconfig/gcp/validation_test.go

There is an existing test case for invalid project in the context of BYO networking. But your code is more general and catches an error with a minimal gcp platform with an invalid project. So I would recommend a similar test case, which only specifies a valid region and invalid project. You could use the editFunctions removeVPC and removeSubnets to make a minimal install config.

@rna-afk rna-afk force-pushed the gcp_project_basenames_validation branch from c534fcb to 4e5147c Compare April 21, 2020 20:27
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return "", err
return "", errors.Wrap(err, "failed to get projects")

Copy link
Contributor

Choose a reason for hiding this comment

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

try to include the path in the expectedErrMsg, makes it much clearer in terms of what we are testing.

Copy link
Contributor

Choose a reason for hiding this comment

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

so this should be an InternalError, because it didn't have anything to do with the project field technically.

@abhinavdahiya
Copy link
Contributor

/test e2e-gcp

@openshift-ci-robot
Copy link
Contributor

@rna-afk: This pull request references Bugzilla bug 1826414, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.5.0) matches configured target release for branch (4.5.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)
Details

In response to this:

Bug 1826414: Added validation for GCP Project ID access

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@rna-afk rna-afk force-pushed the gcp_project_basenames_validation branch from 4e5147c to efd48f6 Compare April 22, 2020 14:57
@abhinavdahiya
Copy link
Contributor

/approve

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abhinavdahiya

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 22, 2020
Copy link
Contributor

Choose a reason for hiding this comment

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

Abhinav's point in #3484 (comment) was that field.Invalid -> field.InternalError. field.Invalid means the user's input was bad, but in this case there was an error when calling the gcloud API.

You could fix the preexisting code in a separate commit as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Abhinav's point in #3484 (comment) was that field.Invalid -> field.InternalError.

I get it now thanks.

You could fix the preexisting code in a separate commit as well.

Got it. Will follow that next time.

Copy link
Contributor

Choose a reason for hiding this comment

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

You could fix the preexisting code in a separate commit as well.

Got it. Will follow that next time.

No I meant that the earlier code (that I wrote) has the same issue and you could fix it in a separate commit.

Fixes the error message that occurs after the region selection when an
invalid project ID is entered. Solved by picking up the list of projects
that the user has in their GCP account and offers a select option on the
project entry to select the one that they want. Reduces the chance of
picking an invalid project ID and avoids the error.

CloudResourceManager is used to pick up the list of projects for current
user and survey is populated with the values obtained.

Generated the gcpclient_generated.go mock file using mockgen and replaced
the existing file to add the GetListOfProjects function. Running
hack/go-genmock.sh did not work after I changed the interface and ran it.
@rna-afk rna-afk force-pushed the gcp_project_basenames_validation branch from efd48f6 to 6035d38 Compare April 22, 2020 18:01
@patrickdillon
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 22, 2020
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Apr 22, 2020

@rna-afk: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
ci/prow/e2e-ovirt 6035d38 link /test e2e-ovirt

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit bdf803f into openshift:master Apr 22, 2020
@openshift-ci-robot
Copy link
Contributor

@rna-afk: All pull requests linked via external trackers have merged: openshift/installer#3484. Bugzilla bug 1826414 has been moved to the MODIFIED state.

Details

In response to this:

Bug 1826414: Added validation for GCP Project ID access

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@patrickdillon
Copy link
Contributor

patrickdillon commented Apr 22, 2020

Fixes #3044

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants