-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pkg storage: for detect storageclass name
- Loading branch information
1 parent
cadfc85
commit 2960151
Showing
3 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// 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 storage | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/erda-project/erda/apistructs" | ||
) | ||
|
||
func VolumeTypeToSCName(diskType string, vendor string) (string, error) { | ||
// 卷类型以 'DICE-' 作为前缀的,表示使用 dice volume 插件,与 vender 无关 | ||
switch diskType { | ||
case apistructs.VolumeTypeDiceNAS: | ||
// volume.type == "DICE-NAS" SC="dice-nfs-volume" | ||
return apistructs.DiceNFSVolumeSC, nil | ||
|
||
case apistructs.VolumeTypeDiceLOCAL: | ||
// volume.type == "DICE-LOCAL" SC="dice-local-volume" | ||
return apistructs.DiceLocalVolumeSC, nil | ||
|
||
// 卷类型不以 'DICE-' 作为前缀的,表示与 vender 有关,结合 vendor 选择 sc | ||
// 'SSD' | ||
case apistructs.VolumeTypeSSD: | ||
switch vendor { | ||
case apistructs.CSIVendorAlibaba: | ||
// vendor = "AliCloud" volume.type="SSD" SC="alicloud-disk-ssd-on-erda" | ||
return apistructs.AlibabaSSDSC, nil | ||
|
||
case apistructs.CSIVendorTencent: | ||
// vendor = "TencentCloud" volume.type="SSD" SC="tencent-disk-ssd-on-erda" | ||
return apistructs.TencentSSDSC, nil | ||
|
||
case apistructs.CSIVendorHuawei: | ||
// vendor = "HuaweiCloud" volume.type="SSD" SC="huawei-disk-ssd-on-erda" | ||
return apistructs.HuaweiSSDSC, nil | ||
} | ||
// 'NAS' | ||
case apistructs.VolumeTypeNAS: | ||
switch vendor { | ||
case apistructs.CSIVendorAlibaba: | ||
// vendor = "AliCloud" volume.type="SSD" SC="alicloud-disk-ssd-on-erda" | ||
return apistructs.AlibabaNASSC, nil | ||
|
||
case apistructs.CSIVendorTencent: | ||
// vendor = "TencentCloud" volume.type="SSD" SC="tencent-disk-ssd-on-erda" | ||
return apistructs.TencentNASSC, nil | ||
|
||
case apistructs.CSIVendorHuawei: | ||
// vendor = "HuaweiCloud" volume.type="SSD" SC="huawei-disk-ssd-on-erda" | ||
return apistructs.HuaweiNASSC, nil | ||
} | ||
/* | ||
// 'OSS' | ||
case apistructs.VolumeTypeOSS: | ||
switch vendor { | ||
case apistructs.CSIVendorAlibaba: | ||
// vendor = "AliCloud" volume.type="SSD" SC="alicloud-disk-ssd-on-erda" | ||
return apistructs.AlibabaOSSSC, nil | ||
case apistructs.CSIVendorTencent: | ||
// vendor = "TencentCloud" volume.type="SSD" SC="tencent-disk-ssd-on-erda" | ||
return apistructs.TencentOSSSC, nil | ||
case apistructs.CSIVendorHuawei: | ||
// vendor = "HuaweiCloud" volume.type="SSD" SC="huawei-disk-ssd-on-erda" | ||
return apistructs.HuaweiOSSSC, nil | ||
} | ||
*/ | ||
case "": | ||
return apistructs.DiceLocalVolumeSC, nil | ||
//case apistructs.VolumeTypeOSS: | ||
default: | ||
return "", errors.New(fmt.Sprintf("unsupported disk type %s", diskType)) | ||
} | ||
|
||
return "", errors.New(fmt.Sprintf("can not detect storageclass for disktype [%s] vendor [%s] ", diskType, vendor)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Copyright (c) 2021 Terminus, Inc. | ||
// | ||
// 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 storage | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/erda-project/erda/apistructs" | ||
) | ||
|
||
func TestVolumeTypeToSCName(t *testing.T) { | ||
type args struct { | ||
diskType string | ||
vendor string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr bool | ||
}{ | ||
// TODO: Add test cases. | ||
{ | ||
name: "test01", | ||
args: args{ | ||
vendor: apistructs.CSIVendorAlibaba, | ||
}, | ||
want: apistructs.DiceLocalVolumeSC, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "test02", | ||
args: args{ | ||
diskType: "DICE-LOCAL", | ||
vendor: apistructs.CSIVendorAlibaba, | ||
}, | ||
want: apistructs.DiceLocalVolumeSC, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "test03", | ||
args: args{ | ||
diskType: "DICE-NAS", | ||
vendor: apistructs.CSIVendorAlibaba, | ||
}, | ||
want: apistructs.DiceNFSVolumeSC, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "test04", | ||
args: args{ | ||
diskType: apistructs.VolumeTypeSSD, | ||
vendor: apistructs.CSIVendorAlibaba, | ||
}, | ||
want: apistructs.AlibabaSSDSC, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "test05", | ||
args: args{ | ||
diskType: apistructs.VolumeTypeNAS, | ||
vendor: apistructs.CSIVendorAlibaba, | ||
}, | ||
want: apistructs.AlibabaNASSC, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "test06", | ||
args: args{ | ||
diskType: apistructs.VolumeTypeSSD, | ||
vendor: apistructs.CSIVendorTencent, | ||
}, | ||
want: apistructs.TencentSSDSC, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "test07", | ||
args: args{ | ||
diskType: apistructs.VolumeTypeNAS, | ||
vendor: apistructs.CSIVendorTencent, | ||
}, | ||
want: apistructs.TencentNASSC, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "test08", | ||
args: args{ | ||
diskType: apistructs.VolumeTypeSSD, | ||
vendor: apistructs.CSIVendorHuawei, | ||
}, | ||
want: apistructs.HuaweiSSDSC, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "test09", | ||
args: args{ | ||
diskType: apistructs.VolumeTypeNAS, | ||
vendor: apistructs.CSIVendorHuawei, | ||
}, | ||
want: apistructs.HuaweiNASSC, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "test10", | ||
args: args{ | ||
diskType: "XXXX", | ||
vendor: apistructs.CSIVendorAlibaba, | ||
}, | ||
want: "", | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := VolumeTypeToSCName(tt.args.diskType, tt.args.vendor) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("VolumeTypeToSCName() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if got != tt.want { | ||
t.Errorf("VolumeTypeToSCName() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |