mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-29 21:29:24 +00:00
Merge pull request #98700 from Jiawei0227/update_label
Update gce-pd volume topology label to GA
This commit is contained in:
@@ -515,7 +515,10 @@ func (g *Cloud) GetLabelsForVolume(ctx context.Context, pv *v1.PersistentVolume)
|
||||
|
||||
// If the zone is already labeled, honor the hint
|
||||
name := pv.Spec.GCEPersistentDisk.PDName
|
||||
zone := pv.Labels[v1.LabelFailureDomainBetaZone]
|
||||
zone := pv.Labels[v1.LabelTopologyZone]
|
||||
if zone == "" {
|
||||
zone = pv.Labels[v1.LabelFailureDomainBetaZone]
|
||||
}
|
||||
|
||||
disk, err := g.getDiskByNameAndOptionalLabelZones(name, zone)
|
||||
if err != nil {
|
||||
@@ -848,7 +851,7 @@ func (g *Cloud) ResizeDisk(diskToResize string, oldSize resource.Quantity, newSi
|
||||
}
|
||||
|
||||
// GetAutoLabelsForPD builds the labels that should be automatically added to a PersistentVolume backed by a GCE PD
|
||||
// Specifically, this builds FailureDomain (zone) and Region labels.
|
||||
// Specifically, this builds Topology (zone) and Region labels.
|
||||
// The PersistentVolumeLabel admission controller calls this and adds the labels when a PV is created.
|
||||
func (g *Cloud) GetAutoLabelsForPD(disk *Disk) (map[string]string, error) {
|
||||
labels := make(map[string]string)
|
||||
@@ -858,16 +861,16 @@ func (g *Cloud) GetAutoLabelsForPD(disk *Disk) (map[string]string, error) {
|
||||
// Unexpected, but sanity-check
|
||||
return nil, fmt.Errorf("PD did not have zone/region information: %v", disk)
|
||||
}
|
||||
labels[v1.LabelFailureDomainBetaZone] = zoneInfo.zone
|
||||
labels[v1.LabelFailureDomainBetaRegion] = disk.Region
|
||||
labels[v1.LabelTopologyZone] = zoneInfo.zone
|
||||
labels[v1.LabelTopologyRegion] = disk.Region
|
||||
case multiZone:
|
||||
if zoneInfo.replicaZones == nil || zoneInfo.replicaZones.Len() <= 0 {
|
||||
// Unexpected, but sanity-check
|
||||
return nil, fmt.Errorf("PD is regional but does not have any replicaZones specified: %v", disk)
|
||||
}
|
||||
labels[v1.LabelFailureDomainBetaZone] =
|
||||
labels[v1.LabelTopologyZone] =
|
||||
volumehelpers.ZonesSetToLabelValue(zoneInfo.replicaZones)
|
||||
labels[v1.LabelFailureDomainBetaRegion] = disk.Region
|
||||
labels[v1.LabelTopologyRegion] = disk.Region
|
||||
case nil:
|
||||
// Unexpected, but sanity-check
|
||||
return nil, fmt.Errorf("PD did not have ZoneInfo: %v", disk)
|
||||
|
||||
@@ -443,7 +443,7 @@ func pv(name, zone string) *v1.PersistentVolume {
|
||||
return &v1.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
v1.LabelFailureDomainBetaZone: zone,
|
||||
v1.LabelTopologyZone: zone,
|
||||
},
|
||||
},
|
||||
Spec: v1.PersistentVolumeSpec{
|
||||
@@ -484,12 +484,12 @@ func TestGetLabelsForVolume_Basic(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if labels[v1.LabelFailureDomainBetaZone] != zone {
|
||||
t.Errorf("Failure domain is '%v', but zone is '%v'",
|
||||
labels[v1.LabelFailureDomainBetaZone], zone)
|
||||
if labels[v1.LabelTopologyZone] != zone {
|
||||
t.Errorf("Topology Zone is '%v', but zone is '%v'",
|
||||
labels[v1.LabelTopologyZone], zone)
|
||||
}
|
||||
if labels[v1.LabelFailureDomainBetaRegion] != gceRegion {
|
||||
t.Errorf("Region is '%v', but region is 'us-central1'", labels[v1.LabelFailureDomainBetaRegion])
|
||||
if labels[v1.LabelTopologyRegion] != gceRegion {
|
||||
t.Errorf("Region is '%v', but region is 'us-central1'", labels[v1.LabelTopologyRegion])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,7 +515,7 @@ func TestGetLabelsForVolume_NoZone(t *testing.T) {
|
||||
gce.CreateDisk(diskName, diskType, zone, sizeGb, nil)
|
||||
|
||||
pv := pv(diskName, zone)
|
||||
delete(pv.Labels, v1.LabelFailureDomainBetaZone)
|
||||
delete(pv.Labels, v1.LabelTopologyZone)
|
||||
|
||||
/* Act */
|
||||
labels, err := gce.GetLabelsForVolume(ctx, pv)
|
||||
@@ -524,12 +524,12 @@ func TestGetLabelsForVolume_NoZone(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if labels[v1.LabelFailureDomainBetaZone] != zone {
|
||||
t.Errorf("Failure domain is '%v', but zone is '%v'",
|
||||
labels[v1.LabelFailureDomainBetaZone], zone)
|
||||
if labels[v1.LabelTopologyZone] != zone {
|
||||
t.Errorf("Topology Zone is '%v', but zone is '%v'",
|
||||
labels[v1.LabelTopologyZone], zone)
|
||||
}
|
||||
if labels[v1.LabelFailureDomainBetaRegion] != gceRegion {
|
||||
t.Errorf("Region is '%v', but region is 'europe-west1'", labels[v1.LabelFailureDomainBetaRegion])
|
||||
if labels[v1.LabelTopologyRegion] != gceRegion {
|
||||
t.Errorf("Region is '%v', but region is 'europe-west1'", labels[v1.LabelTopologyRegion])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -575,7 +575,7 @@ func TestGetLabelsForVolume_DiskNotFoundAndNoZone(t *testing.T) {
|
||||
}
|
||||
|
||||
pv := pv(diskName, zone)
|
||||
delete(pv.Labels, v1.LabelFailureDomainBetaZone)
|
||||
delete(pv.Labels, v1.LabelTopologyZone)
|
||||
|
||||
/* Act */
|
||||
_, err := gce.GetLabelsForVolume(ctx, pv)
|
||||
@@ -617,12 +617,12 @@ func TestGetLabelsForVolume_DupDisk(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("Disk name and zone uniquely identifies a disk, yet an error is returned.")
|
||||
}
|
||||
if labels[v1.LabelFailureDomainBetaZone] != zone {
|
||||
t.Errorf("Failure domain is '%v', but zone is '%v'",
|
||||
labels[v1.LabelFailureDomainBetaZone], zone)
|
||||
if labels[v1.LabelTopologyZone] != zone {
|
||||
t.Errorf("Topology Zone is '%v', but zone is '%v'",
|
||||
labels[v1.LabelTopologyZone], zone)
|
||||
}
|
||||
if labels[v1.LabelFailureDomainBetaRegion] != gceRegion {
|
||||
t.Errorf("Region is '%v', but region is 'us-west1'", labels[v1.LabelFailureDomainBetaRegion])
|
||||
if labels[v1.LabelTopologyRegion] != gceRegion {
|
||||
t.Errorf("Region is '%v', but region is 'us-west1'", labels[v1.LabelTopologyRegion])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -651,7 +651,7 @@ func TestGetLabelsForVolume_DupDiskNoZone(t *testing.T) {
|
||||
}
|
||||
|
||||
pv := pv(diskName, zone)
|
||||
delete(pv.Labels, v1.LabelFailureDomainBetaZone)
|
||||
delete(pv.Labels, v1.LabelTopologyZone)
|
||||
|
||||
/* Act */
|
||||
_, err := gce.GetLabelsForVolume(ctx, pv)
|
||||
@@ -746,13 +746,13 @@ func TestGetAutoLabelsForPD(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
if got := labels[v1.LabelFailureDomainBetaZone]; !tc.wantZoneLabel.Has(got) {
|
||||
t.Errorf("labels[v1.LabelFailureDomainBetaZone] = %v; want one of: %v", got, tc.wantZoneLabel.List())
|
||||
if got := labels[v1.LabelTopologyZone]; !tc.wantZoneLabel.Has(got) {
|
||||
t.Errorf("labels[v1.LabelTopologyZone] = %v; want one of: %v", got, tc.wantZoneLabel.List())
|
||||
}
|
||||
|
||||
// Validate labels
|
||||
if got := labels[v1.LabelFailureDomainBetaRegion]; got != gceRegion {
|
||||
t.Errorf("labels[v1.LabelFailureDomainBetaRegion] = %v; want: %v", got, gceRegion)
|
||||
if got := labels[v1.LabelTopologyRegion]; got != gceRegion {
|
||||
t.Errorf("labels[v1.LabelTopologyRegion] = %v; want: %v", got, gceRegion)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user