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

gcp: verify project services are enabled before install #3773

Merged
merged 1 commit into from Jul 4, 2020

Conversation

SujanaN08
Copy link
Contributor

@SujanaN08 SujanaN08 commented Jun 18, 2020

xref: https://issues.redhat.com/browse/CORS-1254

  1. To verify the list of services that are enabled before a cluster is installed we are making a call to
    https://serviceusage.googleapis.com/v1/{parent=*/*}/services via the gcp client.go.
    The link to the documentaion is here
  2. In platformpermscheck.go we get the list of services and check if all the required services are enabled , else it returns an error.
  3. The gcp validation.go checks for the list of services code.

@SujanaN08 SujanaN08 marked this pull request as draft June 18, 2020 14:50
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 18, 2020
@patrickdillon
Copy link
Contributor

/assign

@SujanaN08 SujanaN08 changed the title Cors 1254 Cors 1254 - Verify project services are enabled before install Jun 18, 2020
@SujanaN08 SujanaN08 marked this pull request as ready for review June 18, 2020 21:25
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 18, 2020
@SujanaN08
Copy link
Contributor Author

/assign @abhinavdahiya

@abhinavdahiya abhinavdahiya changed the title Cors 1254 - Verify project services are enabled before install gcp: verify project services are enabled before install Jun 19, 2020
.idea/.gitignore Outdated
@@ -0,0 +1,8 @@
# Default ignored files
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you intented to add .idea files to the PR.
You can look at https://stackoverflow.com/a/1753078 to add .idea/ to your local git repo so it doesn't show up in unstaged files.

@@ -133,3 +133,18 @@ func validateMachineNetworksContainIP(fldPath *field.Path, networks []types.Mach
}
return field.ErrorList{field.Invalid(fldPath, subnetName, fmt.Sprintf("subnet CIDR range start %s is outside of the specified machine networks", ip))}
}

func CheckForServicesToBeEnabled(projectServices []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.

https://blog.golang.org/godoc

provide good info on how you should document functions are that public API of a package.

@@ -133,3 +133,18 @@ func validateMachineNetworksContainIP(fldPath *field.Path, networks []types.Mach
}
return field.ErrorList{field.Invalid(fldPath, subnetName, fmt.Sprintf("subnet CIDR range start %s is outside of the specified machine networks", ip))}
}

func CheckForServicesToBeEnabled(projectServices []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.

Suggested change
func CheckForServicesToBeEnabled(projectServices []string) error {
func ValidateEnabledServices(services []string) error {

remember in Go, the package name is usually part of the call site, so keeping that in mind gcp.ValidateEnabledServices is much closer describing what the function does.

@@ -133,3 +133,18 @@ func validateMachineNetworksContainIP(fldPath *field.Path, networks []types.Mach
}
return field.ErrorList{field.Invalid(fldPath, subnetName, fmt.Sprintf("subnet CIDR range start %s is outside of the specified machine networks", ip))}
}

func CheckForServicesToBeEnabled(projectServices []string) error {
services := map[string]string{"compute.googleapis.com": "enabled", "cloudapis.googleapis.com": "enabled",
Copy link
Contributor

Choose a reason for hiding this comment

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

try using https://godoc.org/k8s.io/apimachinery/pkg/util/sets

that package provides an easy sets.NewString(<list of string values>) to easily run a check Has(<service>)

Comment on lines 145 to 171
if _, ok := services[service]; ok {
return errors.New(service + "is not enabled")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If we were using sets,

requiredServices Set;
enabledServices Set;
if remaining := requiredServices.Difference(enabledService); remainging.Len() > 0 {
   return error that remaining.List() services are not enabled but required.
}

Comment on lines 234 to 263


Copy link
Contributor

Choose a reason for hiding this comment

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

extra lines

"github.com/openshift/installer/pkg/types/aws"
"github.com/openshift/installer/pkg/types/azure"
"github.com/openshift/installer/pkg/types/baremetal"
"github.com/openshift/installer/pkg/types/gcp"
gcp "github.com/openshift/installer/pkg/types/gcp"
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
gcp "github.com/openshift/installer/pkg/types/gcp"
"github.com/openshift/installer/pkg/types/gcp"

should also just work.. ?

}
services, err := client.GetEnabledServices(ctx, ic.Config.GCP.ProjectID)
if err != nil {
return err
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 enabled services for the project")

}
err = gcpconfig.CheckForServicesToBeEnabled(services)
if err != nil {
return err
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, "validating required services")

@abhinavdahiya
Copy link
Contributor

abhinavdahiya commented Jun 19, 2020

I think you need to run gofmt and golint on the code, you can run ./hack/go-fmt.sh && ./hack/go-lint.sh
For more info look the failing jobs go-fmt and go-lint
Also I think your idea editor should also have a way to run these at save.

Secondly, using the new services client requires updating the vendor, so run go mod tidy && go mod vendor and add that as a separate commit. there should be changes in go.mod go.sum and vendor/ i think

@abhinavdahiya
Copy link
Contributor

/test e2e-gcp

@@ -133,3 +134,25 @@ func validateMachineNetworksContainIP(fldPath *field.Path, networks []types.Mach
}
return field.ErrorList{field.Invalid(fldPath, subnetName, fmt.Sprintf("subnet CIDR range start %s is outside of the specified machine networks", ip))}
}

func CheckForServicesToBeEnabled(projectServices []string) error {
services := sets.NewString("compute.googleapis.com", "cloudapis.googleapis.com",
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
services := sets.NewString("compute.googleapis.com", "cloudapis.googleapis.com",
services := sets.NewString("compute.googleapis.com", "cloudapis.googleapis.com",

@abhinavdahiya
Copy link
Contributor

Also maybe something to look into will be, if we get Unauthorized error when listing the services enabled for the project, we should just skip the check and continue as warning.

@abhinavdahiya
Copy link
Contributor

Also currently the commits have changes across multiple one for the same file, try to collect them into logical groups. keep the vendor update separate, the rest can stay as one.

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 a good start. left some suggestions.

go.mod Outdated
@@ -26,6 +26,7 @@ require (
github.com/coreos/etcd v3.3.18+incompatible // indirect
github.com/coreos/go-systemd v0.0.0 // indirect
github.com/coreos/ignition v0.35.0
github.com/davecgh/go-spew v1.1.1
Copy link
Contributor

Choose a reason for hiding this comment

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

Spew probably crept in while you were debugging but should not be added to the repo.

@@ -133,3 +134,25 @@ func validateMachineNetworksContainIP(fldPath *field.Path, networks []types.Mach
}
return field.ErrorList{field.Invalid(fldPath, subnetName, fmt.Sprintf("subnet CIDR range start %s is outside of the specified machine networks", ip))}
}

func CheckForServicesToBeEnabled(projectServices []string) error {
services := sets.NewString("compute.googleapis.com", "cloudapis.googleapis.com",
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 these are hard to read. Try listing them out on individual lines.

var count int = 0
for _, service := range projectServices {
if services.Has(service) {
count++
Copy link
Contributor

Choose a reason for hiding this comment

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

this approach is reasonable and works.

To me, a more intuitive approach would be to make a set of the project's enabled services and iterate through the required services, checking if each is enabled.

This would have the added benefit that if a required service was not found, you could append the missing service to a slice then include the slice of all missing services in an error message to the user, so they could see which service needs to be enabled.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also in the same area for improvement #3773 (comment)

if err != nil {
return err
}
services, err := client.GetEnabledServices(ctx, "projects/"+ic.Config.GCP.ProjectID)
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 calling this here in platformpermscheck, I would pass the client to your validation function and get the services there.

if err != nil {
return err
}
services, err := client.GetEnabledServices(ctx, "projects/"+ic.Config.GCP.ProjectID)
Copy link
Contributor

Choose a reason for hiding this comment

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

It was good that you figured out the API issue here.

A few things:

  1. concatenating strings within a function's parameters is hard to read. you should move this a variable, probably named parent
  2. Also you could probably do that string formatting within GetEnabledServices, so it is still just taking the project ID and then is transformed into parent in the function. Also you should probably use Sprintf instead of concatentation
  3. The idea of parent is new to me in the Google API and I don't think I have seen examples in our codebase but I do see some context is provided in the docs I would leave a brief comment that would provide some context of why we need to prepend "projects/" before projectID

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 24, 2020
@SujanaN08 SujanaN08 force-pushed the CORS-1254 branch 2 times, most recently from 4b2e8e8 to 16cae1e Compare June 24, 2020 14:29
@openshift-bot
Copy link
Contributor

/retest

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

22 similar comments
@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@openshift-bot
Copy link
Contributor

/retest

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

@abhinavdahiya
Copy link
Contributor

/override ci/prow/e2e-aws

Previous e2e AWS failed on of adm must gather flake, e2e gcp is already green

@openshift-ci-robot
Copy link
Contributor

@abhinavdahiya: Overrode contexts on behalf of abhinavdahiya: ci/prow/e2e-aws

In response to this:

/override ci/prow/e2e-aws

Previous e2e AWS failed on of adm must gather flake, e2e gcp is already green

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.

@abhinavdahiya
Copy link
Contributor

/override ci/prow/e2e-aws

@openshift-ci-robot
Copy link
Contributor

@abhinavdahiya: Overrode contexts on behalf of abhinavdahiya: ci/prow/e2e-aws

In response to this:

/override ci/prow/e2e-aws

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-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

@SujanaN08: The following tests failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
ci/prow/e2e-openstack-upi 1550fd6 link /test e2e-openstack-upi
ci/prow/e2e-metal-ipi 1550fd6 link /test e2e-metal-ipi
ci/prow/e2e-ovirt ebfe8b1 link /test e2e-ovirt
ci/prow/e2e-openstack ebfe8b1 link /test e2e-openstack
ci/prow/e2e-aws-scaleup-rhel7 ebfe8b1 link /test e2e-aws-scaleup-rhel7

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.

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-merge-robot openshift-merge-robot merged commit c7d9de6 into openshift:master Jul 4, 2020
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. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants