-
Notifications
You must be signed in to change notification settings - Fork 38.6k
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
Feature gate for regional PDs #60337
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,8 @@ import ( | |
computealpha "google.golang.org/api/compute/v0.alpha" | ||
compute "google.golang.org/api/compute/v1" | ||
"google.golang.org/api/googleapi" | ||
utilfeature "k8s.io/apiserver/pkg/util/feature" | ||
"k8s.io/kubernetes/pkg/features" | ||
) | ||
|
||
type DiskType string | ||
|
@@ -143,7 +145,7 @@ func (manager *gceServiceManager) CreateRegionalDiskOnCloudProvider( | |
diskType string, | ||
replicaZones sets.String) (gceObject, error) { | ||
|
||
if manager.gce.AlphaFeatureGate.Enabled(AlphaFeatureGCEDisk) { | ||
if utilfeature.DefaultFeatureGate.Enabled(features.GCERegionalPersistentDisk) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the error below. It is no longer valid: Ditto below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also since you have a k8s feature gate, maybe you can do the gating at the GCE Volume Plugin layer now instead of in the cloud provider code? Your call. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep it's gated at volume plugin layer as well. It's left here as a safeguard. |
||
diskTypeURI, err := manager.getDiskTypeURI( | ||
manager.gce.region /* diskRegion */, multiZone{replicaZones}, diskType, true /* useAlphaAPI */) | ||
if err != nil { | ||
|
@@ -166,7 +168,7 @@ func (manager *gceServiceManager) CreateRegionalDiskOnCloudProvider( | |
manager.gce.projectID, manager.gce.region, diskToCreateAlpha).Do() | ||
} | ||
|
||
return nil, fmt.Errorf("The regional PD feature is only available via the GCE Alpha API. Enable \"DiskAlphaAPI\" in the list of \"alpha-features\" in \"gce.conf\" to use the feature.") | ||
return nil, fmt.Errorf("the regional PD feature is only available with the %s Kubernetes feature gate enabled", features.GCERegionalPersistentDisk) | ||
} | ||
|
||
func (manager *gceServiceManager) AttachDiskOnCloudProvider( | ||
|
@@ -238,7 +240,7 @@ func (manager *gceServiceManager) GetDiskFromCloudProvider( | |
func (manager *gceServiceManager) GetRegionalDiskFromCloudProvider( | ||
diskName string) (*GCEDisk, error) { | ||
|
||
if manager.gce.AlphaFeatureGate.Enabled(AlphaFeatureGCEDisk) { | ||
if utilfeature.DefaultFeatureGate.Enabled(features.GCERegionalPersistentDisk) { | ||
diskAlpha, err := manager.gce.serviceAlpha.RegionDisks.Get( | ||
manager.gce.projectID, manager.gce.region, diskName).Do() | ||
if err != nil { | ||
|
@@ -260,7 +262,7 @@ func (manager *gceServiceManager) GetRegionalDiskFromCloudProvider( | |
}, nil | ||
} | ||
|
||
return nil, fmt.Errorf("The regional PD feature is only available via the GCE Alpha API. Enable \"DiskAlphaAPI\" in the list of \"alpha-features\" in \"gce.conf\" to use the feature.") | ||
return nil, fmt.Errorf("the regional PD feature is only available with the %s Kubernetes feature gate enabled", features.GCERegionalPersistentDisk) | ||
} | ||
|
||
func (manager *gceServiceManager) DeleteDiskOnCloudProvider( | ||
|
@@ -272,12 +274,12 @@ func (manager *gceServiceManager) DeleteDiskOnCloudProvider( | |
|
||
func (manager *gceServiceManager) DeleteRegionalDiskOnCloudProvider( | ||
diskName string) (gceObject, error) { | ||
if manager.gce.AlphaFeatureGate.Enabled(AlphaFeatureGCEDisk) { | ||
if utilfeature.DefaultFeatureGate.Enabled(features.GCERegionalPersistentDisk) { | ||
return manager.gce.serviceAlpha.RegionDisks.Delete( | ||
manager.gce.projectID, manager.gce.region, diskName).Do() | ||
} | ||
|
||
return nil, fmt.Errorf("DeleteRegionalDiskOnCloudProvider is a regional PD feature and is only available via the GCE Alpha API. Enable \"DiskAlphaAPI\" in the list of \"alpha-features\" in \"gce.conf\" to use the feature.") | ||
return nil, fmt.Errorf("the regional PD feature is only available with the %s Kubernetes feature gate enabled", features.GCERegionalPersistentDisk) | ||
} | ||
|
||
func (manager *gceServiceManager) WaitForZoneOp( | ||
|
@@ -417,13 +419,13 @@ func (manager *gceServiceManager) ResizeDiskOnCloudProvider(disk *GCEDisk, sizeG | |
} | ||
|
||
func (manager *gceServiceManager) RegionalResizeDiskOnCloudProvider(disk *GCEDisk, sizeGb int64) (gceObject, error) { | ||
if manager.gce.AlphaFeatureGate.Enabled(AlphaFeatureGCEDisk) { | ||
if utilfeature.DefaultFeatureGate.Enabled(features.GCERegionalPersistentDisk) { | ||
resizeServiceRequest := &computealpha.RegionDisksResizeRequest{ | ||
SizeGb: sizeGb, | ||
} | ||
return manager.gce.serviceAlpha.RegionDisks.Resize(manager.gce.projectID, disk.Region, disk.Name, resizeServiceRequest).Do() | ||
} | ||
return nil, fmt.Errorf("RegionalResizeDiskOnCloudProvider is a regional PD feature and is only available via the GCE Alpha API. Enable \"DiskAlphaAPI\" in the list of \"alpha-features\" in \"gce.conf\" to use the feature.") | ||
return nil, fmt.Errorf("the regional PD feature is only available with the %s Kubernetes feature gate enabled", features.GCERegionalPersistentDisk) | ||
} | ||
|
||
// Disks is interface for manipulation with GCE PDs. | ||
|
@@ -530,7 +532,7 @@ func (gce *GCECloud) AttachDisk(diskName string, nodeName types.NodeName, readOn | |
// Try fetching as regional PD | ||
var disk *GCEDisk | ||
var mc *metricContext | ||
if regional { | ||
if regional && utilfeature.DefaultFeatureGate.Enabled(features.GCERegionalPersistentDisk) { | ||
disk, err = gce.getRegionalDiskByName(diskName) | ||
if err != nil { | ||
glog.V(5).Infof("Could not find regional PD named %q to Attach. Will look for a zonal PD", diskName) | ||
|
@@ -795,17 +797,20 @@ func (gce *GCECloud) ResizeDisk(diskToResize string, oldSize resource.Quantity, | |
} | ||
return newSizeQuant, nil | ||
case multiZone: | ||
mc = newDiskMetricContextRegional("resize", disk.Region) | ||
resizeOp, err := gce.manager.RegionalResizeDiskOnCloudProvider(disk, requestGB) | ||
if utilfeature.DefaultFeatureGate.Enabled(features.GCERegionalPersistentDisk) { | ||
mc = newDiskMetricContextRegional("resize", disk.Region) | ||
resizeOp, err := gce.manager.RegionalResizeDiskOnCloudProvider(disk, requestGB) | ||
|
||
if err != nil { | ||
return oldSize, mc.Observe(err) | ||
} | ||
waitErr := gce.manager.WaitForRegionalOp(resizeOp, mc) | ||
if waitErr != nil { | ||
return oldSize, waitErr | ||
if err != nil { | ||
return oldSize, mc.Observe(err) | ||
} | ||
waitErr := gce.manager.WaitForRegionalOp(resizeOp, mc) | ||
if waitErr != nil { | ||
return oldSize, waitErr | ||
} | ||
return newSizeQuant, nil | ||
} | ||
return newSizeQuant, nil | ||
return oldSize, fmt.Errorf("disk.ZoneInfo has unexpected type %T", zoneInfo) | ||
case nil: | ||
return oldSize, fmt.Errorf("PD has nil ZoneInfo: %v", disk) | ||
default: | ||
|
@@ -838,19 +843,26 @@ func (gce *GCECloud) GetAutoLabelsForPD(name string, zone string) (map[string]st | |
// We could assume the disks exists; we have all the information we need | ||
// However it is more consistent to ensure the disk exists, | ||
// and in future we may gather addition information (e.g. disk type, IOPS etc) | ||
zoneSet, err := volumeutil.LabelZonesToSet(zone) | ||
if err != nil { | ||
glog.Warningf("Failed to parse zone field: %q. Will use raw field.", zone) | ||
} | ||
|
||
if len(zoneSet) > 1 { | ||
// Regional PD | ||
disk, err = gce.getRegionalDiskByName(name) | ||
if utilfeature.DefaultFeatureGate.Enabled(features.GCERegionalPersistentDisk) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be gating this? At this point the disk has already been created. Doing this will just not report the correct info back to the scheduler. But I can buy the argument, that disabling the feature means disabling all of it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this check, a user can manually provision a PV with with zones label There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it fall back to non-regional behavior in that case, or be completely unusable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
zoneSet, err := volumeutil.LabelZonesToSet(zone) | ||
if err != nil { | ||
return nil, err | ||
glog.Warningf("Failed to parse zone field: %q. Will use raw field.", zone) | ||
} | ||
|
||
if len(zoneSet) > 1 { | ||
// Regional PD | ||
disk, err = gce.getRegionalDiskByName(name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} else { | ||
// Zonal PD | ||
disk, err = gce.getDiskByName(name, zone) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
} else { | ||
// Zonal PD | ||
disk, err = gce.getDiskByName(name, zone) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -936,7 +948,7 @@ func (gce *GCECloud) getRegionalDiskByName(diskName string) (*GCEDisk, error) { | |
// Prefer getDiskByName, if the zone can be established | ||
// Return cloudprovider.DiskNotFound if the given disk cannot be found in any zone | ||
func (gce *GCECloud) GetDiskByNameUnknownZone(diskName string) (*GCEDisk, error) { | ||
if gce.AlphaFeatureGate.Enabled(AlphaFeatureGCEDisk) { | ||
if utilfeature.DefaultFeatureGate.Enabled(features.GCERegionalPersistentDisk) { | ||
regionalDisk, err := gce.getRegionalDiskByName(diskName) | ||
if err == nil { | ||
return regionalDisk, err | ||
|
@@ -1020,12 +1032,15 @@ func (gce *GCECloud) doDeleteDisk(diskToDelete string) error { | |
} | ||
return gce.manager.WaitForZoneOp(deleteOp, zoneInfo.zone, mc) | ||
case multiZone: | ||
mc = newDiskMetricContextRegional("delete", disk.Region) | ||
deleteOp, err := gce.manager.DeleteRegionalDiskOnCloudProvider(disk.Name) | ||
if err != nil { | ||
return mc.Observe(err) | ||
if utilfeature.DefaultFeatureGate.Enabled(features.GCERegionalPersistentDisk) { | ||
mc = newDiskMetricContextRegional("delete", disk.Region) | ||
deleteOp, err := gce.manager.DeleteRegionalDiskOnCloudProvider(disk.Name) | ||
if err != nil { | ||
return mc.Observe(err) | ||
} | ||
return gce.manager.WaitForRegionalOp(deleteOp, mc) | ||
} | ||
return gce.manager.WaitForRegionalOp(deleteOp, mc) | ||
return fmt.Errorf("disk.ZoneInfo has unexpected type %T", zoneInfo) | ||
case nil: | ||
return fmt.Errorf("PD has nil ZoneInfo: %v", disk) | ||
default: | ||
|
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.
Double check removing this feature does not cause any failures if old code still passes the flag in.
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 is the only spot that passes in an alpha features list that could contain "DiskAlphaAPI", and it just logs the error if the feature doesn't exist.
kubernetes/pkg/cloudprovider/providers/gce/gce.go
Line 294 in 6a7656b