mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-13 13:14:05 +00:00
Merge pull request #97823 from Jiawei0227/translation-lib
Preparation for Topology migration to GA for CSI migration
This commit is contained in:
@@ -130,7 +130,7 @@ func (l *persistentVolumeLabel) Admit(ctx context.Context, a admission.Attribute
|
||||
|
||||
// Set NodeSelectorRequirements based on the labels
|
||||
var values []string
|
||||
if k == v1.LabelFailureDomainBetaZone {
|
||||
if k == v1.LabelTopologyZone || k == v1.LabelFailureDomainBetaZone {
|
||||
zones, err := volumehelpers.LabelZonesToSet(v)
|
||||
if err != nil {
|
||||
return admission.NewForbidden(a, fmt.Errorf("failed to convert label string for Zone: %s to a Set", v))
|
||||
@@ -172,15 +172,31 @@ func (l *persistentVolumeLabel) findVolumeLabels(volume *api.PersistentVolume) (
|
||||
existingLabels := volume.Labels
|
||||
|
||||
// All cloud providers set only these two labels.
|
||||
domain, domainOK := existingLabels[v1.LabelFailureDomainBetaZone]
|
||||
region, regionOK := existingLabels[v1.LabelFailureDomainBetaRegion]
|
||||
topologyLabelGA := true
|
||||
domain, domainOK := existingLabels[v1.LabelTopologyZone]
|
||||
region, regionOK := existingLabels[v1.LabelTopologyRegion]
|
||||
// If they dont have GA labels we should check for failuredomain beta labels
|
||||
// TODO: remove this once all the cloud provider change to GA topology labels
|
||||
if !domainOK || !regionOK {
|
||||
topologyLabelGA = false
|
||||
domain, domainOK = existingLabels[v1.LabelFailureDomainBetaZone]
|
||||
region, regionOK = existingLabels[v1.LabelFailureDomainBetaRegion]
|
||||
}
|
||||
|
||||
isDynamicallyProvisioned := metav1.HasAnnotation(volume.ObjectMeta, persistentvolume.AnnDynamicallyProvisioned)
|
||||
if isDynamicallyProvisioned && domainOK && regionOK {
|
||||
// PV already has all the labels and we can trust the dynamic provisioning that it provided correct values.
|
||||
if topologyLabelGA {
|
||||
return map[string]string{
|
||||
v1.LabelTopologyZone: domain,
|
||||
v1.LabelTopologyRegion: region,
|
||||
}, nil
|
||||
}
|
||||
return map[string]string{
|
||||
v1.LabelFailureDomainBetaZone: domain,
|
||||
v1.LabelFailureDomainBetaRegion: region,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
// Either missing labels or we don't trust the user provided correct values.
|
||||
|
@@ -66,9 +66,9 @@ func Test_PVLAdmission(t *testing.T) {
|
||||
name: "non-cloud PV ignored",
|
||||
handler: newPersistentVolumeLabel(),
|
||||
pvlabeler: mockVolumeLabels(map[string]string{
|
||||
"a": "1",
|
||||
"b": "2",
|
||||
v1.LabelFailureDomainBetaZone: "1__2__3",
|
||||
"a": "1",
|
||||
"b": "2",
|
||||
v1.LabelTopologyZone: "1__2__3",
|
||||
}),
|
||||
preAdmissionPV: &api.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "noncloud", Namespace: "myns"},
|
||||
@@ -234,7 +234,7 @@ func Test_PVLAdmission(t *testing.T) {
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
name: "existing labels from dynamic provisioning are not changed",
|
||||
name: "existing Beta labels from dynamic provisioning are not changed",
|
||||
handler: newPersistentVolumeLabel(),
|
||||
pvlabeler: mockVolumeLabels(map[string]string{
|
||||
v1.LabelFailureDomainBetaZone: "domain1",
|
||||
@@ -301,6 +301,74 @@ func Test_PVLAdmission(t *testing.T) {
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
name: "existing GA labels from dynamic provisioning are not changed",
|
||||
handler: newPersistentVolumeLabel(),
|
||||
pvlabeler: mockVolumeLabels(map[string]string{
|
||||
v1.LabelTopologyZone: "domain1",
|
||||
v1.LabelTopologyRegion: "region1",
|
||||
}),
|
||||
preAdmissionPV: &api.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "awsebs", Namespace: "myns",
|
||||
Labels: map[string]string{
|
||||
v1.LabelTopologyZone: "existingDomain",
|
||||
v1.LabelTopologyRegion: "existingRegion",
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
persistentvolume.AnnDynamicallyProvisioned: "kubernetes.io/aws-ebs",
|
||||
},
|
||||
},
|
||||
Spec: api.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||
AWSElasticBlockStore: &api.AWSElasticBlockStoreVolumeSource{
|
||||
VolumeID: "123",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
postAdmissionPV: &api.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "awsebs",
|
||||
Namespace: "myns",
|
||||
Labels: map[string]string{
|
||||
v1.LabelTopologyZone: "existingDomain",
|
||||
v1.LabelTopologyRegion: "existingRegion",
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
persistentvolume.AnnDynamicallyProvisioned: "kubernetes.io/aws-ebs",
|
||||
},
|
||||
},
|
||||
Spec: api.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: api.PersistentVolumeSource{
|
||||
AWSElasticBlockStore: &api.AWSElasticBlockStoreVolumeSource{
|
||||
VolumeID: "123",
|
||||
},
|
||||
},
|
||||
NodeAffinity: &api.VolumeNodeAffinity{
|
||||
Required: &api.NodeSelector{
|
||||
NodeSelectorTerms: []api.NodeSelectorTerm{
|
||||
{
|
||||
MatchExpressions: []api.NodeSelectorRequirement{
|
||||
{
|
||||
Key: v1.LabelTopologyRegion,
|
||||
Operator: api.NodeSelectorOpIn,
|
||||
Values: []string{"existingRegion"},
|
||||
},
|
||||
{
|
||||
Key: v1.LabelTopologyZone,
|
||||
Operator: api.NodeSelectorOpIn,
|
||||
Values: []string{"existingDomain"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
name: "existing labels from user are changed",
|
||||
handler: newPersistentVolumeLabel(),
|
||||
@@ -367,9 +435,9 @@ func Test_PVLAdmission(t *testing.T) {
|
||||
name: "GCE PD PV labeled correctly",
|
||||
handler: newPersistentVolumeLabel(),
|
||||
pvlabeler: mockVolumeLabels(map[string]string{
|
||||
"a": "1",
|
||||
"b": "2",
|
||||
v1.LabelFailureDomainBetaZone: "1__2__3",
|
||||
"a": "1",
|
||||
"b": "2",
|
||||
v1.LabelTopologyZone: "1__2__3",
|
||||
}),
|
||||
preAdmissionPV: &api.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "gcepd", Namespace: "myns"},
|
||||
@@ -386,9 +454,9 @@ func Test_PVLAdmission(t *testing.T) {
|
||||
Name: "gcepd",
|
||||
Namespace: "myns",
|
||||
Labels: map[string]string{
|
||||
"a": "1",
|
||||
"b": "2",
|
||||
v1.LabelFailureDomainBetaZone: "1__2__3",
|
||||
"a": "1",
|
||||
"b": "2",
|
||||
v1.LabelTopologyZone: "1__2__3",
|
||||
},
|
||||
},
|
||||
Spec: api.PersistentVolumeSpec{
|
||||
@@ -413,7 +481,7 @@ func Test_PVLAdmission(t *testing.T) {
|
||||
Values: []string{"2"},
|
||||
},
|
||||
{
|
||||
Key: v1.LabelFailureDomainBetaZone,
|
||||
Key: v1.LabelTopologyZone,
|
||||
Operator: api.NodeSelectorOpIn,
|
||||
Values: []string{"1", "2", "3"},
|
||||
},
|
||||
|
Reference in New Issue
Block a user