-
Notifications
You must be signed in to change notification settings - Fork 789
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
720 additions
and
34 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
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,27 @@ | ||
package configs | ||
|
||
import "github.com/spf13/pflag" | ||
|
||
type FilePersistenceConfig struct { | ||
FilePersistenceType string `json:"file_persistence_type"` | ||
FilePersistenceAccessKeyID string `json:"file_persistence_access_key_id"` | ||
FilePersistenceSecretAccessKey string `json:"file_persistence_secret_access_key"` | ||
FilePersistenceRegion string `json:"file_persistence_region"` | ||
FilePersistenceZoneID string `json:"file_persistence_zone_id"` | ||
FilePersistenceVpcID string `json:"file_persistence_vpc_id"` | ||
FilePersistenceSubnetID string `json:"file_persistence_subnet_id"` | ||
FilePersistencePermissionGroupID string `json:"file_persistence_permission_group_id"` | ||
FilePersistenceEnable string `json:"file_persistence_enable"` | ||
} | ||
|
||
func AddFilePersistenceFlags(fs *pflag.FlagSet, fpc *FilePersistenceConfig) { | ||
fs.StringVar(&fpc.FilePersistenceType, "file-persistence-type", "volcengine", "volcengine、aliyun or tencentcloud") | ||
fs.StringVar(&fpc.FilePersistenceAccessKeyID, "file-persistence-access-key-id", "", "access key id") | ||
fs.StringVar(&fpc.FilePersistenceSecretAccessKey, "file-persistence-secret-access-key", "", "secret access key") | ||
fs.StringVar(&fpc.FilePersistenceRegion, "file-persistence-region", "cn-shanghai", "region") | ||
fs.StringVar(&fpc.FilePersistenceZoneID, "file-persistence-zone-id", "cn-shanghai-b", "zone id") | ||
fs.StringVar(&fpc.FilePersistenceVpcID, "file-persistence-vpc-id", "", "file persistence vpc id") | ||
fs.StringVar(&fpc.FilePersistenceSubnetID, "file-persistence-subnet-id", "", "file persistence subnet id") | ||
fs.StringVar(&fpc.FilePersistencePermissionGroupID, "file-persistence-permission-group-id", "", "file persistence permission group id") | ||
fs.StringVar(&fpc.FilePersistenceEnable, "file-persistence-enable", "open", "open or close") | ||
} |
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
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
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,103 @@ | ||
package filepersistence | ||
|
||
import ( | ||
"context" | ||
"github.com/goodrain/rainbond/config/configs" | ||
storagev1 "k8s.io/api/storage/v1" | ||
) | ||
|
||
// FileSystem represents a file storage system | ||
type FileSystem struct { | ||
ID string | ||
Name string | ||
Status string | ||
ProtocolType string | ||
StorageType string | ||
FileSystemType string | ||
ZoneID string | ||
Region string | ||
Size int64 | ||
} | ||
|
||
// CreateFileSystemOptions contains options for creating a file system | ||
type CreateFileSystemOptions struct { | ||
Name string | ||
ProtocolType string | ||
StorageType string | ||
FileSystemType string | ||
VpcID string | ||
VSwitchID string | ||
SecurityGroup string | ||
Description string | ||
Size int64 | ||
} | ||
|
||
// CreateStorageClassOptions contains options for creating a storage class | ||
type CreateStorageClassOptions struct { | ||
Name string | ||
ReclaimPolicy string | ||
VolumeBindingMode string | ||
Parameters map[string]string | ||
} | ||
|
||
type InterfaceFilePersistence interface { | ||
FindFileSystem(ctx context.Context, name string) (*FileSystem, error) | ||
CreateFileSystem(ctx context.Context, opts *CreateFileSystemOptions) (string, error) | ||
CreateStorageClass(ctx context.Context, fs *FileSystem, opts *CreateStorageClassOptions) (*storagev1.StorageClass, error) | ||
} | ||
|
||
// ComponentFilePersistence - | ||
type ComponentFilePersistence struct { | ||
FilePersistenceCli InterfaceFilePersistence | ||
FilePersistenceConfig *configs.FilePersistenceConfig | ||
} | ||
|
||
var defaultFilePersistenceComponent *ComponentFilePersistence | ||
|
||
// New - | ||
func New() *ComponentFilePersistence { | ||
fpConfig := configs.Default().FilePersistenceConfig | ||
defaultFilePersistenceComponent = &ComponentFilePersistence{ | ||
FilePersistenceConfig: fpConfig, | ||
} | ||
return defaultFilePersistenceComponent | ||
} | ||
|
||
// Start - | ||
func (s *ComponentFilePersistence) Start(ctx context.Context) error { | ||
var fpCli InterfaceFilePersistence | ||
switch s.FilePersistenceConfig.FilePersistenceType { | ||
case "volcengine": | ||
fpCli = &VolcengineProvider{ | ||
config: &VolcengineConfig{ | ||
AccessKey: s.FilePersistenceConfig.FilePersistenceAccessKeyID, | ||
SecretKey: s.FilePersistenceConfig.FilePersistenceSecretAccessKey, | ||
Region: s.FilePersistenceConfig.FilePersistenceRegion, | ||
ZoneID: s.FilePersistenceConfig.FilePersistenceZoneID, | ||
VpcID: s.FilePersistenceConfig.FilePersistenceVpcID, | ||
SubnetID: s.FilePersistenceConfig.FilePersistenceSubnetID, | ||
PermissionGroupID: s.FilePersistenceConfig.FilePersistencePermissionGroupID, | ||
}, | ||
} | ||
} | ||
s.FilePersistenceCli = fpCli | ||
return nil | ||
} | ||
|
||
// CloseHandle - | ||
func (s *ComponentFilePersistence) CloseHandle() { | ||
} | ||
|
||
// Default - | ||
func Default() *ComponentFilePersistence { | ||
return defaultFilePersistenceComponent | ||
} | ||
|
||
type SrcFile interface { | ||
Read([]byte) (int, error) | ||
} | ||
|
||
// DstFile 目标文件接口 | ||
type DstFile interface { | ||
Write([]byte) (int, error) | ||
} |
Oops, something went wrong.