mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #109154 from jsafrane/fix-azure-disk-migrated-zones
Fix translation of Azure availability zones
This commit is contained in:
commit
c6478308f8
@ -45,6 +45,7 @@ var (
|
|||||||
managedDiskPathRE = regexp.MustCompile(`.*/subscriptions/(?:.*)/resourceGroups/(?:.*)/providers/Microsoft.Compute/disks/(.+)`)
|
managedDiskPathRE = regexp.MustCompile(`.*/subscriptions/(?:.*)/resourceGroups/(?:.*)/providers/Microsoft.Compute/disks/(.+)`)
|
||||||
unmanagedDiskPathRE = regexp.MustCompile(`http(?:.*)://(?:.*)/vhds/(.+)`)
|
unmanagedDiskPathRE = regexp.MustCompile(`http(?:.*)://(?:.*)/vhds/(.+)`)
|
||||||
managed = string(v1.AzureManagedDisk)
|
managed = string(v1.AzureManagedDisk)
|
||||||
|
unzonedCSIRegionRE = regexp.MustCompile(`^[0-9]+$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ InTreePlugin = &azureDiskCSITranslator{}
|
var _ InTreePlugin = &azureDiskCSITranslator{}
|
||||||
@ -86,6 +87,7 @@ func (t *azureDiskCSITranslator) TranslateInTreeStorageClassToCSI(sc *storage.St
|
|||||||
}
|
}
|
||||||
sc.AllowedTopologies = newTopologies
|
sc.AllowedTopologies = newTopologies
|
||||||
}
|
}
|
||||||
|
sc.AllowedTopologies = t.replaceFailureDomainsToCSI(sc.AllowedTopologies)
|
||||||
|
|
||||||
sc.Parameters = params
|
sc.Parameters = params
|
||||||
|
|
||||||
@ -273,3 +275,34 @@ func getDiskName(diskURI string) (string, error) {
|
|||||||
}
|
}
|
||||||
return matches[1], nil
|
return matches[1], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replace topology values for failure domains ("<number>") to "",
|
||||||
|
// as it's the value that the CSI driver expects.
|
||||||
|
func (t *azureDiskCSITranslator) replaceFailureDomainsToCSI(terms []v1.TopologySelectorTerm) []v1.TopologySelectorTerm {
|
||||||
|
if terms == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
newTopologies := []v1.TopologySelectorTerm{}
|
||||||
|
for _, term := range terms {
|
||||||
|
newTerm := term.DeepCopy()
|
||||||
|
for i := range newTerm.MatchLabelExpressions {
|
||||||
|
exp := &newTerm.MatchLabelExpressions[i]
|
||||||
|
if exp.Key == AzureDiskTopologyKey {
|
||||||
|
for j := range exp.Values {
|
||||||
|
if unzonedCSIRegionRE.Match([]byte(exp.Values[j])) {
|
||||||
|
// Topologies "0", "1" etc are used when in-tree topology is translated to CSI in Azure
|
||||||
|
// regions that don't have availability zones. E.g.:
|
||||||
|
// topology.kubernetes.io/region: westus
|
||||||
|
// topology.kubernetes.io/zone: "0"
|
||||||
|
// The CSI driver uses zone "" instead of "0" in this case.
|
||||||
|
// topology.disk.csi.azure.com/zone": ""
|
||||||
|
exp.Values[j] = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newTopologies = append(newTopologies, *newTerm)
|
||||||
|
}
|
||||||
|
return newTopologies
|
||||||
|
}
|
||||||
|
@ -97,7 +97,7 @@ func TestGetDiskName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTranslateAzureDiskInTreeStorageClassToCSI(t *testing.T) {
|
func TestTranslateAzureDiskInTreeInlineVolumeToCSI(t *testing.T) {
|
||||||
sharedBlobDiskKind := v1.AzureDedicatedBlobDisk
|
sharedBlobDiskKind := v1.AzureDedicatedBlobDisk
|
||||||
translator := NewAzureDiskCSITranslator()
|
translator := NewAzureDiskCSITranslator()
|
||||||
|
|
||||||
@ -495,6 +495,21 @@ func TestTranslateInTreeStorageClassToCSI(t *testing.T) {
|
|||||||
options: NewStorageClass(map[string]string{"zone": "foo"}, generateToplogySelectors(AzureDiskTopologyKey, []string{"foo"})),
|
options: NewStorageClass(map[string]string{"zone": "foo"}, generateToplogySelectors(AzureDiskTopologyKey, []string{"foo"})),
|
||||||
expErr: true,
|
expErr: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "topology in regions without zones",
|
||||||
|
options: NewStorageClass(map[string]string{}, generateToplogySelectors(v1.LabelTopologyZone, []string{"0"})),
|
||||||
|
expOptions: NewStorageClass(map[string]string{}, generateToplogySelectors(AzureDiskTopologyKey, []string{""})),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "longer topology in regions without zones",
|
||||||
|
options: NewStorageClass(map[string]string{}, generateToplogySelectors(v1.LabelTopologyZone, []string{"1234"})),
|
||||||
|
expOptions: NewStorageClass(map[string]string{}, generateToplogySelectors(AzureDiskTopologyKey, []string{""})),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "topology in regions with zones",
|
||||||
|
options: NewStorageClass(map[string]string{}, generateToplogySelectors(v1.LabelTopologyZone, []string{"centralus-1"})),
|
||||||
|
expOptions: NewStorageClass(map[string]string{}, generateToplogySelectors(AzureDiskTopologyKey, []string{"centralus-1"})),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range tcs {
|
for _, tc := range tcs {
|
||||||
|
Loading…
Reference in New Issue
Block a user