mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Merge pull request #98311 from jsafrane/fix-cinder-topology-translation
Fix translation of Cinder storage classess to CSI
This commit is contained in:
commit
5cd694ba7d
@ -46,6 +46,7 @@ go_test(
|
||||
"azure_file_test.go",
|
||||
"gce_pd_test.go",
|
||||
"in_tree_volume_test.go",
|
||||
"openstack_cinder_test.go",
|
||||
"vsphere_volume_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
|
@ -18,6 +18,7 @@ package plugins
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
storage "k8s.io/api/storage/v1"
|
||||
@ -45,6 +46,30 @@ func NewOpenStackCinderCSITranslator() InTreePlugin {
|
||||
|
||||
// TranslateInTreeStorageClassParametersToCSI translates InTree Cinder storage class parameters to CSI storage class
|
||||
func (t *osCinderCSITranslator) TranslateInTreeStorageClassToCSI(sc *storage.StorageClass) (*storage.StorageClass, error) {
|
||||
var (
|
||||
params = map[string]string{}
|
||||
)
|
||||
for k, v := range sc.Parameters {
|
||||
switch strings.ToLower(k) {
|
||||
case fsTypeKey:
|
||||
params[csiFsTypeKey] = v
|
||||
default:
|
||||
// All other parameters are supported by the CSI driver.
|
||||
// This includes also "availability", therefore do not translate it to sc.AllowedTopologies
|
||||
params[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
if len(sc.AllowedTopologies) > 0 {
|
||||
newTopologies, err := translateAllowedTopologies(sc.AllowedTopologies, CinderTopologyKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed translating allowed topologies: %v", err)
|
||||
}
|
||||
sc.AllowedTopologies = newTopologies
|
||||
}
|
||||
|
||||
sc.Parameters = params
|
||||
|
||||
return sc, nil
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
storage "k8s.io/api/storage/v1"
|
||||
)
|
||||
|
||||
func TestTranslateCinderInTreeStorageClassToCSI(t *testing.T) {
|
||||
translator := NewOpenStackCinderCSITranslator()
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
sc *storage.StorageClass
|
||||
expSc *storage.StorageClass
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
name: "translate normal",
|
||||
sc: NewStorageClass(map[string]string{"foo": "bar"}, nil),
|
||||
expSc: NewStorageClass(map[string]string{"foo": "bar"}, nil),
|
||||
},
|
||||
{
|
||||
name: "translate empty map",
|
||||
sc: NewStorageClass(map[string]string{}, nil),
|
||||
expSc: NewStorageClass(map[string]string{}, nil),
|
||||
},
|
||||
|
||||
{
|
||||
name: "translate with fstype",
|
||||
sc: NewStorageClass(map[string]string{"fstype": "ext3"}, nil),
|
||||
expSc: NewStorageClass(map[string]string{"csi.storage.k8s.io/fstype": "ext3"}, nil),
|
||||
},
|
||||
{
|
||||
name: "translate with topology in parameters (no translation expected)",
|
||||
sc: NewStorageClass(map[string]string{"availability": "nova"}, nil),
|
||||
expSc: NewStorageClass(map[string]string{"availability": "nova"}, nil),
|
||||
},
|
||||
{
|
||||
name: "translate with topology",
|
||||
sc: NewStorageClass(map[string]string{}, generateToplogySelectors(v1.LabelFailureDomainBetaZone, []string{"nova"})),
|
||||
expSc: NewStorageClass(map[string]string{}, generateToplogySelectors(CinderTopologyKey, []string{"nova"})),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Logf("Testing %v", tc.name)
|
||||
got, err := translator.TranslateInTreeStorageClassToCSI(tc.sc)
|
||||
if err != nil && !tc.expErr {
|
||||
t.Errorf("Did not expect error but got: %v", err)
|
||||
}
|
||||
|
||||
if err == nil && tc.expErr {
|
||||
t.Errorf("Expected error, but did not get one.")
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(got, tc.expSc) {
|
||||
t.Errorf("Got parameters: %v, expected: %v", got, tc.expSc)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user