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

GCE PD plugin now prevents attaching a regional PD PV with pdName of … #63322

Merged
merged 1 commit into from
Jun 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 3 additions & 7 deletions pkg/cloudprovider/providers/gce/gce_disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,14 +535,10 @@ func (gce *GCECloud) AttachDisk(diskName string, nodeName types.NodeName, readOn
if regional && utilfeature.DefaultFeatureGate.Enabled(features.GCERegionalPersistentDisk) {
disk, err = gce.getRegionalDiskByName(diskName)
Copy link
Contributor

Choose a reason for hiding this comment

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

what is regional is true, but feature is not enabled, or this case is not possible at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that case we fall back to the behavior for a regular disk, as if the regional PD feature doesn't exist.

regional is set if the volume is a PV spec and its zone label has the regional PD format. If the feature gate is disabled, when a user creates a PV with regional PD zone label, the PV is rejected by an admission controller, so usually we don't hit this scenario.

if err != nil {
glog.V(5).Infof("Could not find regional PD named %q to Attach. Will look for a zonal PD", diskName)
err = nil
} else {
mc = newDiskMetricContextRegional("attach", gce.region)
return err
Copy link
Member

Choose a reason for hiding this comment

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

can a unit test be added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A good chunk of disk methods aren't covered by unit tests today. To address that, I'm looking into refactoring gce_disks.go to reduce complexity as part of implementing disk naming disambiguation, and refactoring gce_disks_test.go as well (using mocks from generated cloud provider, pulling out common code, etc). After that I'll add these tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately I didn't have time to do the refactor for this release, and I'm planning to leave this unit test for either after code freeze (ideally) or the next release. Sorry this is non-ideal :(

}
}

if disk == 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 remove if disk == nil {?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before, if a regional PD is not found, we let the rest of the function continue to execute, so the if disk == nil is there to check whether a regional PD has been found.

Now, the function returns right away if an error is found, and disk is always nil if gce.getDiskByName() gets called

mc = newDiskMetricContextRegional("attach", gce.region)
} else {
disk, err = gce.getDiskByName(diskName, instance.Zone)
if err != nil {
return err
Expand Down