Skip to content

Commit

Permalink
fix(storage): add s3 swift
Browse files Browse the repository at this point in the history
Signed-off-by: cndoit18 <cndoit18@outlook.com>
  • Loading branch information
cndoit18 authored and bitsf committed Jun 30, 2021
1 parent db72477 commit 241271d
Show file tree
Hide file tree
Showing 6 changed files with 438 additions and 20 deletions.
135 changes: 120 additions & 15 deletions apis/goharbor.io/v1alpha3/harborcluster_conversion.go
Expand Up @@ -253,16 +253,14 @@ func Convert_v1alpha3_RedisSpec_To_v1beta1_CacheSpec(src *RedisSpec, dst *v1beta
func Convert_v1alpha3_HarborStorageImageChartStorageSpec_To_v1beta1_Storage(src *HarborStorageImageChartStorageSpec, dst *v1beta1.Storage) { // nolint
if src.FileSystem != nil {
dst.Kind = "FileSystem"
dst.Spec = v1beta1.StorageSpec{
FileSystem: &v1beta1.FileSystemSpec{
HarborStorageImageChartStorageFileSystemSpec: v1beta1.HarborStorageImageChartStorageFileSystemSpec{
RegistryPersistentVolume: v1beta1.HarborStorageRegistryPersistentVolumeSpec{
HarborStoragePersistentVolumeSpec: v1beta1.HarborStoragePersistentVolumeSpec{
PersistentVolumeClaimVolumeSource: src.FileSystem.RegistryPersistentVolume.PersistentVolumeClaimVolumeSource,
Prefix: src.FileSystem.RegistryPersistentVolume.Prefix,
},
MaxThreads: src.FileSystem.RegistryPersistentVolume.MaxThreads,
dst.Spec.FileSystem = &v1beta1.FileSystemSpec{
HarborStorageImageChartStorageFileSystemSpec: v1beta1.HarborStorageImageChartStorageFileSystemSpec{
RegistryPersistentVolume: v1beta1.HarborStorageRegistryPersistentVolumeSpec{
HarborStoragePersistentVolumeSpec: v1beta1.HarborStoragePersistentVolumeSpec{
PersistentVolumeClaimVolumeSource: src.FileSystem.RegistryPersistentVolume.PersistentVolumeClaimVolumeSource,
Prefix: src.FileSystem.RegistryPersistentVolume.Prefix,
},
MaxThreads: src.FileSystem.RegistryPersistentVolume.MaxThreads,
},
},
}
Expand All @@ -274,6 +272,57 @@ func Convert_v1alpha3_HarborStorageImageChartStorageSpec_To_v1beta1_Storage(src
}
}
}

if src.S3 != nil {
dst.Kind = "S3"
dst.Spec.S3 = &v1beta1.S3Spec{
HarborStorageImageChartStorageS3Spec: v1beta1.HarborStorageImageChartStorageS3Spec{
RegistryStorageDriverS3Spec: v1beta1.RegistryStorageDriverS3Spec{
AccessKey: src.S3.AccessKey,
SecretKeyRef: src.S3.SecretKeyRef,
Region: src.S3.Region,
RegionEndpoint: src.S3.RegionEndpoint,
Bucket: src.S3.Bucket,
RootDirectory: src.S3.RootDirectory,
StorageClass: src.S3.StorageClass,
KeyID: src.S3.KeyID,
Encrypt: src.S3.Encrypt,
SkipVerify: src.S3.SkipVerify,
CertificateRef: src.S3.CertificateRef,
Secure: src.S3.Secure,
V4Auth: src.S3.V4Auth,
ChunkSize: src.S3.ChunkSize,
},
},
}
}

if src.Swift != nil {
dst.Kind = "Swift"
dst.Spec.Swift = &v1beta1.SwiftSpec{
HarborStorageImageChartStorageSwiftSpec: v1beta1.HarborStorageImageChartStorageSwiftSpec{
RegistryStorageDriverSwiftSpec: v1beta1.RegistryStorageDriverSwiftSpec{
AuthURL: src.Swift.AuthURL,
Username: src.Swift.Username,
PasswordRef: src.Swift.PasswordRef,
Region: src.Swift.Region,
Container: src.Swift.Container,
Tenant: src.Swift.Tenant,
TenantID: src.Swift.TenantID,
Domain: src.Swift.Domain,
DomainID: src.Swift.DomainID,
TrustID: src.Swift.TrustID,
InsecureSkipVerify: src.Swift.InsecureSkipVerify,
ChunkSize: src.Swift.ChunkSize,
Prefix: src.Swift.Prefix,
SecretKeyRef: src.Swift.SecretKeyRef,
AccessKey: src.Swift.AccessKey,
AuthVersion: src.Swift.AuthVersion,
EndpointType: src.Swift.EndpointType,
},
},
}
}
}

func Convert_v1alpha3_Storage_To_v1beta1_Storage(src *Storage, dst *v1beta1.Storage) { // nolint
Expand Down Expand Up @@ -400,13 +449,24 @@ func Convert_v1beta1_HarborClusterSpec_To_v1alpha3_HarborClusterSpec(src *v1beta
Convert_v1beta1_Cache_To_v1alpha3_Cache(&src.Cache, dst.InClusterCache)
}

if src.Storage.Kind == "FileSystem" && src.Storage.Spec.FileSystem != nil {
if dst.ImageChartStorage == nil {
dst.ImageChartStorage = &HarborStorageImageChartStorageSpec{}
}
if dst.ImageChartStorage == nil {
dst.ImageChartStorage = &HarborStorageImageChartStorageSpec{}
}

Convert_v1beta1_FileSystemSpec_To_v1alpha3_HarborStorageImageChartStorage(src.Storage.Spec.FileSystem, dst.ImageChartStorage)
} else if src.Storage.Kind == "MinIO" {
switch src.Storage.Kind {
case "FileSystem":
if src.Storage.Spec.FileSystem != nil {
Convert_v1beta1_FileSystemSpec_To_v1alpha3_HarborStorageImageChartStorage(src.Storage.Spec.FileSystem, dst.ImageChartStorage)
}
case "S3":
if src.Storage.Spec.S3 != nil {
Convert_v1beta1_S3Spec_To_v1alpha3_HarborStorageImageChartStorage(src.Storage.Spec.S3, dst.ImageChartStorage)
}
case "Swift":
if src.Storage.Spec.Swift != nil {
Convert_v1beta1_SwiftSpec_To_v1alpha3_HarborStorageImageChartStorage(src.Storage.Spec.Swift, dst.ImageChartStorage)
}
case "MinIO":
if dst.InClusterStorage == nil {
dst.InClusterStorage = &Storage{}
}
Expand All @@ -431,6 +491,51 @@ func Convert_v1beta1_HarborClusterSpec_To_v1alpha3_HarborClusterSpec(src *v1beta
Convert_v1beta1_EmbeddedHarborSpec_To_v1alpha3_HarborSpec(&src.EmbeddedHarborSpec, &dst.HarborSpec)
}

func Convert_v1beta1_S3Spec_To_v1alpha3_HarborStorageImageChartStorage(src *v1beta1.S3Spec, dst *HarborStorageImageChartStorageSpec) { // nolint
dst.S3 = &HarborStorageImageChartStorageS3Spec{
RegistryStorageDriverS3Spec: RegistryStorageDriverS3Spec{
AccessKey: src.AccessKey,
SecretKeyRef: src.SecretKeyRef,
Region: src.Region,
RegionEndpoint: src.RegionEndpoint,
Bucket: src.Bucket,
RootDirectory: src.RootDirectory,
StorageClass: src.StorageClass,
KeyID: src.KeyID,
Encrypt: src.Encrypt,
SkipVerify: src.SkipVerify,
CertificateRef: src.CertificateRef,
Secure: src.Secure,
V4Auth: src.V4Auth,
ChunkSize: src.ChunkSize,
},
}
}

func Convert_v1beta1_SwiftSpec_To_v1alpha3_HarborStorageImageChartStorage(src *v1beta1.SwiftSpec, dst *HarborStorageImageChartStorageSpec) { // nolint
dst.Swift = &HarborStorageImageChartStorageSwiftSpec{
RegistryStorageDriverSwiftSpec: RegistryStorageDriverSwiftSpec{
AuthURL: src.AuthURL,
Username: src.Username,
PasswordRef: src.PasswordRef,
Region: src.Region,
Container: src.Container,
Tenant: src.Tenant,
TenantID: src.TenantID,
Domain: src.Domain,
DomainID: src.DomainID,
TrustID: src.TrustID,
InsecureSkipVerify: src.InsecureSkipVerify,
ChunkSize: src.ChunkSize,
Prefix: src.Prefix,
SecretKeyRef: src.SecretKeyRef,
AccessKey: src.AccessKey,
AuthVersion: src.AuthVersion,
EndpointType: src.EndpointType,
},
}
}

func Convert_v1beta1_EmbeddedHarborSpec_To_v1alpha3_HarborSpec(src *v1beta1.EmbeddedHarborSpec, dst *HarborSpec) { // nolint
dst.ExternalURL = src.ExternalURL
dst.InternalTLS = HarborInternalTLSSpec{
Expand Down
16 changes: 14 additions & 2 deletions apis/goharbor.io/v1beta1/harborcluster_types.go
Expand Up @@ -196,7 +196,7 @@ type ZlandoPostgreSQLSpec struct {

type Storage struct {
// Kind of which storage service to be used. Only support MinIO now.
// +kubebuilder:validation:Enum={MinIO,FileSystem}
// +kubebuilder:validation:Enum={MinIO,S3,Swift,FileSystem}
Kind string `json:"kind"`

Spec StorageSpec `json:"spec"`
Expand All @@ -207,8 +207,12 @@ type StorageSpec struct {
// inCluster options.
// +kubebuilder:validation:Optional
MinIO *MinIOSpec `json:"minIO,omitempty"`

// +kubebuilder:validation:Optional
FileSystem *FileSystemSpec `json:"fileSystem,omitempty"`
// +kubebuilder:validation:Optional
S3 *S3Spec `json:"s3,omitempty"`
// +kubebuilder:validation:Optional
Swift *SwiftSpec `json:"swift,omitempty"`
}

// StorageRedirectSpec defines if the redirection is disabled.
Expand All @@ -224,6 +228,14 @@ type FileSystemSpec struct {
HarborStorageImageChartStorageFileSystemSpec `json:",inline"`
}

type S3Spec struct {
HarborStorageImageChartStorageS3Spec `json:",inline"`
}

type SwiftSpec struct {
HarborStorageImageChartStorageSwiftSpec `json:",inline"`
}

type MinIOSpec struct {
harbormetav1.ImageSpec `json:",inline"`

Expand Down
42 changes: 42 additions & 0 deletions apis/goharbor.io/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 241271d

Please sign in to comment.