Skip to content

Commit

Permalink
fix webhook with azure field
Browse files Browse the repository at this point in the history
Signed-off-by: soulseen <zhuxiaoyang1996@gmail.com>
  • Loading branch information
soulseen authored and bitsf committed Nov 8, 2021
1 parent 7c279ce commit 3e675aa
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 1 deletion.
7 changes: 7 additions & 0 deletions apis/goharbor.io/v1beta1/harbor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ type HarborStorageImageChartStorageSpec struct {
// An implementation of the storagedriver.StorageDriver interface that uses OpenStack Swift for object storage.
// See: https://docs.docker.com/registry/storage-drivers/swift/
Swift *HarborStorageImageChartStorageSwiftSpec `json:"swift,omitempty"`

// +kubebuilder:validation:Optional
Azure *HarborStorageImageChartStorageAzureSpec `json:"azure,omitempty"`
}

type HarborStorageTrivyStorageSpec struct {
Expand Down Expand Up @@ -537,6 +540,10 @@ func (r *HarborStorageImageChartStorageSpec) Validate() error {
found++
}

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

switch found {
case 0:
return ErrNoStorageConfiguration
Expand Down
3 changes: 2 additions & 1 deletion apis/goharbor.io/v1beta1/harborcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
const (
KindDatabaseZlandoPostgreSQL = "Zlando/PostgreSQL"
KindDatabasePostgreSQL = "PostgreSQL"
KindStorageAzure = "Azure"
KindStorageMinIO = "MinIO"
KindStorageSwift = "Swift"
KindStorageS3 = "S3"
Expand Down Expand Up @@ -211,7 +212,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}
// +kubebuilder:validation:Enum={MinIO,S3,Swift,FileSystem,Azure}
Kind string `json:"kind"`

Spec StorageSpec `json:"spec"`
Expand Down
14 changes: 14 additions & 0 deletions apis/goharbor.io/v1beta1/harborcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,30 @@ func (harborcluster *HarborCluster) Default() {

switch harborcluster.Spec.Storage.Kind {
case KindStorageFileSystem:
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.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.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.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.S3 = nil
harborcluster.Spec.Storage.Spec.Swift = nil
harborcluster.Spec.Storage.Spec.FileSystem = nil
harborcluster.Spec.Storage.Spec.MinIO = nil
}
}

Expand Down Expand Up @@ -154,6 +163,11 @@ func (harborcluster *HarborCluster) validateStorage() *field.Error {
return required(fp.Child("swift"))
}

if harborcluster.Spec.Storage.Kind == KindStorageAzure && harborcluster.Spec.Storage.Spec.Azure == nil {
// Invalid and not acceptable
return required(fp.Child("azure"))
}

if harborcluster.Spec.Storage.Kind == KindStorageFileSystem && harborcluster.Spec.Storage.Spec.FileSystem == nil {
// Invalid and not acceptable
return required(fp.Child("fileSystem"))
Expand Down
6 changes: 6 additions & 0 deletions apis/goharbor.io/v1beta1/registry_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ type RegistryStorageDriverSpec struct {
// An implementation of the storagedriver.StorageDriver interface that uses OpenStack Swift for object storage.
// See: https://docs.docker.com/registry/storage-drivers/swift/
Swift *RegistryStorageDriverSwiftSpec `json:"swift,omitempty"`

Azure *RegistryStorageDriverAzureSpec `json:"azure,omitempty"`
}

func (r *RegistryStorageDriverSpec) Validate() error {
Expand All @@ -625,6 +627,10 @@ func (r *RegistryStorageDriverSpec) Validate() error {
found++
}

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

switch found {
case 0:
return ErrNoStorageConfiguration
Expand Down
10 changes: 10 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.

31 changes: 31 additions & 0 deletions charts/harbor-operator/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7543,6 +7543,7 @@ spec:
- S3
- Swift
- FileSystem
- Azure
type: string
spec:
description: the spec of Storage.
Expand Down Expand Up @@ -10599,6 +10600,21 @@ spec:
type: string
imageChartStorage:
properties:
azure:
properties:
accountkeyRef:
type: string
accountname:
type: string
baseURL:
default: core.windows.net
type: string
container:
type: string
pathPrefix:
default: /azure/harbor/charts
type: string
type: object
filesystem:
description: 'FileSystem is an implementation of the storagedriver.StorageDriver interface which uses the local filesystem. The local filesystem can be a remote volume. See: https://docs.docker.com/registry/storage-drivers/filesystem/'
properties:
Expand Down Expand Up @@ -19890,6 +19906,21 @@ spec:
type: object
driver:
properties:
azure:
properties:
accountkeyRef:
type: string
accountname:
type: string
baseURL:
default: core.windows.net
type: string
container:
type: string
pathPrefix:
default: /azure/harbor/charts
type: string
type: object
filesystem:
description: 'FileSystem is an implementation of the storagedriver.StorageDriver interface which uses the local filesystem. The local filesystem can be a remote volume. See: https://docs.docker.com/registry/storage-drivers/filesystem/'
properties:
Expand Down
31 changes: 31 additions & 0 deletions manifests/cluster/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7562,6 +7562,7 @@ spec:
- S3
- Swift
- FileSystem
- Azure
type: string
spec:
description: the spec of Storage.
Expand Down Expand Up @@ -10623,6 +10624,21 @@ spec:
type: string
imageChartStorage:
properties:
azure:
properties:
accountkeyRef:
type: string
accountname:
type: string
baseURL:
default: core.windows.net
type: string
container:
type: string
pathPrefix:
default: /azure/harbor/charts
type: string
type: object
filesystem:
description: 'FileSystem is an implementation of the storagedriver.StorageDriver interface which uses the local filesystem. The local filesystem can be a remote volume. See: https://docs.docker.com/registry/storage-drivers/filesystem/'
properties:
Expand Down Expand Up @@ -19929,6 +19945,21 @@ spec:
type: object
driver:
properties:
azure:
properties:
accountkeyRef:
type: string
accountname:
type: string
baseURL:
default: core.windows.net
type: string
container:
type: string
pathPrefix:
default: /azure/harbor/charts
type: string
type: object
filesystem:
description: 'FileSystem is an implementation of the storagedriver.StorageDriver interface which uses the local filesystem. The local filesystem can be a remote volume. See: https://docs.docker.com/registry/storage-drivers/filesystem/'
properties:
Expand Down
31 changes: 31 additions & 0 deletions manifests/harbor/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7562,6 +7562,7 @@ spec:
- S3
- Swift
- FileSystem
- Azure
type: string
spec:
description: the spec of Storage.
Expand Down Expand Up @@ -10623,6 +10624,21 @@ spec:
type: string
imageChartStorage:
properties:
azure:
properties:
accountkeyRef:
type: string
accountname:
type: string
baseURL:
default: core.windows.net
type: string
container:
type: string
pathPrefix:
default: /azure/harbor/charts
type: string
type: object
filesystem:
description: 'FileSystem is an implementation of the storagedriver.StorageDriver interface which uses the local filesystem. The local filesystem can be a remote volume. See: https://docs.docker.com/registry/storage-drivers/filesystem/'
properties:
Expand Down Expand Up @@ -19929,6 +19945,21 @@ spec:
type: object
driver:
properties:
azure:
properties:
accountkeyRef:
type: string
accountname:
type: string
baseURL:
default: core.windows.net
type: string
container:
type: string
pathPrefix:
default: /azure/harbor/charts
type: string
type: object
filesystem:
description: 'FileSystem is an implementation of the storagedriver.StorageDriver interface which uses the local filesystem. The local filesystem can be a remote volume. See: https://docs.docker.com/registry/storage-drivers/filesystem/'
properties:
Expand Down
Loading

0 comments on commit 3e675aa

Please sign in to comment.