Skip to content

Commit

Permalink
support aliyun oss storage
Browse files Browse the repository at this point in the history
Signed-off-by: Ziming Zhang <zziming@vmware.com>
  • Loading branch information
bitsf committed Dec 6, 2022
1 parent 4bfa15a commit 9c19b15
Show file tree
Hide file tree
Showing 14 changed files with 767 additions and 13 deletions.
20 changes: 20 additions & 0 deletions apis/goharbor.io/v1beta1/chartmuseum_types.go
Expand Up @@ -161,6 +161,26 @@ type ChartMuseumChartStorageDriverSpec struct {

// +kubebuilder:validation:Optional
Gcs *ChartMuseumChartStorageDriverGcsSpec `json:"gcs,omitempty"`

// +kubebuilder:validation:Optional
Oss *ChartMuseumChartStorageDriverOssSpec `json:"oss,omitempty"`
}

type ChartMuseumChartStorageDriverOssSpec struct {
// +kubebuilder:validation:Required
Endpoint string `json:"endpoint"`

// +kubebuilder:validation:Required
AccessKeyID string `json:"accessKeyID"`

// +kubebuilder:validation:Required
AccessSecretRef string `json:"accessSecretRef"`

// +kubebuilder:validation:Required
Bucket string `json:"bucket"`

// +kubebuilder:validation:Optional
PathPrefix string `json:"pathPrefix,omitempty"`
}

type ChartMuseumChartStorageDriverGcsSpec struct {
Expand Down
44 changes: 44 additions & 0 deletions apis/goharbor.io/v1beta1/harbor_types.go
Expand Up @@ -509,6 +509,11 @@ type HarborStorageImageChartStorageSpec struct {
// An implementation of the storagedriver.StorageDriver interface which uses Google Cloud for object storage.
// See https://docs.docker.com/registry/storage-drivers/gcs/
Gcs *HarborStorageImageChartStorageGcsSpec `json:"gcs,omitempty"`

// +kubebuilder:validation:Optional
// An implementation of the storagedriver.StorageDriver interface which uses Alibaba Cloud for object storage.
// See https://docs.docker.com/registry/storage-drivers/oss/
Oss *HarborStorageImageChartStorageOssSpec `json:"oss,omitempty"`
}

type HarborStorageJobServiceStorageSpec struct {
Expand Down Expand Up @@ -536,6 +541,7 @@ const (
FileSystemDriverName = "filesystem"
AzureDriverName = "azure"
GcsDriverName = "gcs"
OssDriverName = "oss"
)

func (r *HarborStorageImageChartStorageSpec) ProviderName() string {
Expand All @@ -555,6 +561,10 @@ func (r *HarborStorageImageChartStorageSpec) ProviderName() string {
return GcsDriverName
}

if r.Oss != nil {
return OssDriverName
}

return FileSystemDriverName
}

Expand Down Expand Up @@ -585,6 +595,10 @@ func (r *HarborStorageImageChartStorageSpec) Validate() error {
found++
}

if r.Oss != nil {
found++
}

switch found {
case 0:
return ErrNoStorageConfiguration
Expand Down Expand Up @@ -616,6 +630,36 @@ type HarborStorageImageChartStorageAzureSpec struct {
RegistryStorageDriverAzureSpec `json:",inline"`
}

type HarborStorageImageChartStorageOssSpec struct {
RegistryStorageDriverOssSpec `json:",inline"`
}

func (r *HarborStorageImageChartStorageOssSpec) ChartMuseum() *ChartMuseumChartStorageDriverOssSpec {
return &ChartMuseumChartStorageDriverOssSpec{
Endpoint: r.getEndpoint(),
AccessKeyID: r.AccessKeyID,
AccessSecretRef: r.AccessSecretRef,
Bucket: r.Bucket,
PathPrefix: r.PathPrefix,
}
}

func (r *HarborStorageImageChartStorageOssSpec) Registry() *RegistryStorageDriverOssSpec {
return &r.RegistryStorageDriverOssSpec
}

func (r *HarborStorageImageChartStorageOssSpec) getEndpoint() string {
if r.Endpoint != "" {
return r.Endpoint
}

if r.Internal {
return fmt.Sprintf("%s-internal.aliyuncs.com", r.Region)
}

return fmt.Sprintf("%s.aliyuncs.com", r.Region)
}

type HarborStorageImageChartStorageGcsSpec struct {
RegistryStorageDriverGcsSpec `json:",inline"`
}
Expand Down
9 changes: 8 additions & 1 deletion apis/goharbor.io/v1beta1/harborcluster_types.go
Expand Up @@ -11,6 +11,7 @@ import (
const (
KindDatabaseZlandoPostgreSQL = "Zlando/PostgreSQL"
KindDatabasePostgreSQL = "PostgreSQL"
KindStorageOss = "Oss"
KindStorageGcs = "Gcs"
KindStorageAzure = "Azure"
KindStorageMinIO = "MinIO"
Expand Down Expand Up @@ -216,7 +217,7 @@ type ZlandoPostgreSQLSpec struct {

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

Spec StorageSpec `json:"spec"`
Expand All @@ -237,6 +238,8 @@ type StorageSpec struct {
Azure *AzureSpec `json:"azure,omitempty"`
// +kubebuilder:validation:Optional
Gcs *GcsSpec `json:"gcs,omitempty"`
// +kubebuilder:validation:Optional
Oss *OssSpec `json:"oss,omitempty"`
// Determine if the redirection of minio storage is disabled.
// +kubebuilder:validation:Optional
Redirect *StorageRedirectSpec `json:"redirect,omitempty"`
Expand Down Expand Up @@ -267,6 +270,10 @@ type GcsSpec struct {
HarborStorageImageChartStorageGcsSpec `json:",inline"`
}

type OssSpec struct {
HarborStorageImageChartStorageOssSpec `json:",inline"`
}

type SwiftSpec struct {
HarborStorageImageChartStorageSwiftSpec `json:",inline"`
}
Expand Down
20 changes: 19 additions & 1 deletion apis/goharbor.io/v1beta1/harborcluster_webhook.go
Expand Up @@ -52,41 +52,54 @@ func (harborcluster *HarborCluster) Default() { //nolint:funlen

switch harborcluster.Spec.Storage.Kind {
case KindStorageFileSystem:
harborcluster.Spec.Storage.Spec.Oss = nil
harborcluster.Spec.Storage.Spec.Gcs = nil
harborcluster.Spec.Storage.Spec.Azure = nil
harborcluster.Spec.Storage.Spec.S3 = nil
harborcluster.Spec.Storage.Spec.Swift = nil
harborcluster.Spec.Storage.Spec.MinIO = nil
case KindStorageS3:
harborcluster.Spec.Storage.Spec.Oss = nil
harborcluster.Spec.Storage.Spec.Gcs = nil
harborcluster.Spec.Storage.Spec.Azure = nil
harborcluster.Spec.Storage.Spec.FileSystem = nil
harborcluster.Spec.Storage.Spec.Swift = nil
harborcluster.Spec.Storage.Spec.MinIO = nil
case KindStorageSwift:
harborcluster.Spec.Storage.Spec.Oss = nil
harborcluster.Spec.Storage.Spec.Gcs = nil
harborcluster.Spec.Storage.Spec.Azure = nil
harborcluster.Spec.Storage.Spec.S3 = nil
harborcluster.Spec.Storage.Spec.FileSystem = nil
harborcluster.Spec.Storage.Spec.MinIO = nil
case KindStorageMinIO:
harborcluster.Spec.Storage.Spec.Oss = nil
harborcluster.Spec.Storage.Spec.Gcs = nil
harborcluster.Spec.Storage.Spec.Azure = nil
harborcluster.Spec.Storage.Spec.S3 = nil
harborcluster.Spec.Storage.Spec.Swift = nil
harborcluster.Spec.Storage.Spec.FileSystem = nil
case KindStorageAzure:
harborcluster.Spec.Storage.Spec.Oss = nil
harborcluster.Spec.Storage.Spec.Gcs = nil
harborcluster.Spec.Storage.Spec.S3 = nil
harborcluster.Spec.Storage.Spec.Swift = nil
harborcluster.Spec.Storage.Spec.FileSystem = nil
harborcluster.Spec.Storage.Spec.MinIO = nil
case KindStorageGcs:
harborcluster.Spec.Storage.Spec.Oss = nil
harborcluster.Spec.Storage.Spec.Azure = nil
harborcluster.Spec.Storage.Spec.S3 = nil
harborcluster.Spec.Storage.Spec.Swift = nil
harborcluster.Spec.Storage.Spec.FileSystem = nil
harborcluster.Spec.Storage.Spec.MinIO = nil
case KindStorageOss:
harborcluster.Spec.Storage.Spec.Azure = nil
harborcluster.Spec.Storage.Spec.S3 = nil
harborcluster.Spec.Storage.Spec.Swift = nil
harborcluster.Spec.Storage.Spec.FileSystem = nil
harborcluster.Spec.Storage.Spec.MinIO = nil
harborcluster.Spec.Storage.Spec.Gcs = nil
}
}

Expand Down Expand Up @@ -176,7 +189,7 @@ func (harborcluster *HarborCluster) validate(old *HarborCluster) error {
return apierrors.NewInvalid(schema.GroupKind{Group: GroupVersion.Group, Kind: "HarborCluster"}, harborcluster.Name, allErrs)
}

func (harborcluster *HarborCluster) validateStorage() *field.Error { //nolint:gocognit
func (harborcluster *HarborCluster) validateStorage() *field.Error { //nolint:funlen,gocognit
// in cluster storage has high priority
fp := field.NewPath("spec").Child("storage").Child("spec")

Expand Down Expand Up @@ -206,6 +219,11 @@ func (harborcluster *HarborCluster) validateStorage() *field.Error { //nolint:go
return required(fp.Child("gcs"))
}

if harborcluster.Spec.Storage.Kind == KindStorageOss && harborcluster.Spec.Storage.Spec.Oss == nil {
// Invalid and not acceptable
return required(fp.Child("oss"))
}

if harborcluster.Spec.Storage.Kind == KindStorageFileSystem && harborcluster.Spec.Storage.Spec.FileSystem == nil {
// Invalid and not acceptable
return required(fp.Child("fileSystem"))
Expand Down
48 changes: 48 additions & 0 deletions apis/goharbor.io/v1beta1/registry_types.go
Expand Up @@ -617,6 +617,11 @@ type RegistryStorageDriverSpec struct {
// An implementation of the storagedriver.StorageDriver interface which uses Google Cloud for object storage.
// https://docs.docker.com/registry/storage-drivers/gcs/
Gcs *RegistryStorageDriverGcsSpec `json:"gcs,omitempty"`

// +kubebuilder:validation:Optional
// An implementation of the storagedriver.StorageDriver interface which uses Alibaba Cloud for object storage.
// https://docs.docker.com/registry/storage-drivers/oss/
Oss *RegistryStorageDriverOssSpec `json:"oss,omitempty"`
}

func (r *RegistryStorageDriverSpec) Validate() error {
Expand Down Expand Up @@ -646,6 +651,10 @@ func (r *RegistryStorageDriverSpec) Validate() error {
found++
}

if r.Oss != nil {
found++
}

switch found {
case 0:
return ErrNoStorageConfiguration
Expand Down Expand Up @@ -686,6 +695,45 @@ type RegistryStorageDriverAzureSpec struct {
PathPrefix string `json:"pathPrefix,omitempty"`
}

type RegistryStorageDriverOssSpec struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:Pattern="oss-.*"
Region string `json:"region"`

// +kubebuilder:validation:Required
AccessKeyID string `json:"accessKeyID"`

// +kubebuilder:validation:Required
AccessSecretRef string `json:"accessSecretRef"`

// +kubebuilder:validation:Required
Bucket string `json:"bucket"`

// +kubebuilder:validation:Optional
PathPrefix string `json:"pathPrefix,omitempty"`

// +kubebuilder:validation:Optional
Endpoint string `json:"endpoint,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=false
Internal bool `json:"internal,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=false
// Specifies whether the registry stores the image in encrypted format or not. A boolean value.
Encrypt bool `json:"encrypt,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=true
Secure *bool `json:"secure,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=5242880
// The Oss API requires multipart upload chunks to be at least 5MB.
ChunkSize int64 `json:"chunksize,omitempty"`
}

type RegistryStorageDriverGcsSpec struct {
// +kubebuilder:validation:Required
// The base64 encoded json file which contains the key
Expand Down

0 comments on commit 9c19b15

Please sign in to comment.