Skip to content

Commit

Permalink
update storage config
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 3e675aa commit c9d380d
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 135 deletions.
5 changes: 5 additions & 0 deletions apis/goharbor.io/v1beta1/harbor_types.go
Expand Up @@ -507,6 +507,7 @@ const (
S3DriverName = "s3"
SwiftDriverName = "swift"
FileSystemDriverName = "filesystem"
AzureDriverName = "azure"
)

func (r *HarborStorageImageChartStorageSpec) ProviderName() string {
Expand All @@ -518,6 +519,10 @@ func (r *HarborStorageImageChartStorageSpec) ProviderName() string {
return SwiftDriverName
}

if r.Azure != nil {
return AzureDriverName
}

return FileSystemDriverName
}

Expand Down
1 change: 1 addition & 0 deletions apis/goharbor.io/v1beta1/registry_types.go
Expand Up @@ -605,6 +605,7 @@ type RegistryStorageDriverSpec struct {
// See: https://docs.docker.com/registry/storage-drivers/swift/
Swift *RegistryStorageDriverSwiftSpec `json:"swift,omitempty"`

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

Expand Down
7 changes: 7 additions & 0 deletions config/config/assets/registry-config.yaml.tmpl
Expand Up @@ -138,6 +138,13 @@ storage:
{{- end }}
{{- end }}

{{- if .Spec.Storage.Driver.Azure }}
azure:
accountname: {{ .Spec.Storage.Driver.Azure.AccountName | quote }}
container: {{ .Spec.Storage.Driver.Azure.Container | quote }}
realm: {{ .Spec.Storage.Driver.Azure.BaseURL | quote }}
{{- end }}

{{- if .Spec.Storage.Driver.Swift }}
swift:
username: {{ .Spec.Storage.Driver.Swift.Username | quote }}
Expand Down
12 changes: 12 additions & 0 deletions controllers/goharbor/harbor/storage.go
Expand Up @@ -20,6 +20,12 @@ func (r *Reconciler) ChartMuseumStorage(ctx context.Context, harbor *goharborv1.
}
}

if harbor.Spec.ImageChartStorage.Azure != nil {
return goharborv1.ChartMuseumChartStorageDriverSpec{
Azure: harbor.Spec.ImageChartStorage.Azure.ChartMuseum(),
}
}

prefix := ""
pvc := &harbor.Spec.ImageChartStorage.FileSystem.RegistryPersistentVolume.PersistentVolumeClaimVolumeSource

Expand Down Expand Up @@ -87,6 +93,12 @@ func (r *Reconciler) RegistryStorage(ctx context.Context, harbor *goharborv1.Har
}
}

if harbor.Spec.ImageChartStorage.Azure != nil {
return goharborv1.RegistryStorageDriverSpec{
Azure: harbor.Spec.ImageChartStorage.Azure.Registry(),
}
}

return goharborv1.RegistryStorageDriverSpec{
FileSystem: &goharborv1.RegistryStorageDriverFilesystemSpec{
VolumeSource: corev1.VolumeSource{
Expand Down
22 changes: 22 additions & 0 deletions controllers/goharbor/registry/deployments.go
Expand Up @@ -361,6 +361,24 @@ func (r *Reconciler) ApplySwiftStorageEnvs(ctx context.Context, registry *goharb
return nil
}

func (r *Reconciler) ApplyAzureStorageEnvs(ctx context.Context, registry *goharborv1.Registry, deploy *appsv1.Deployment) error {
regContainer := &deploy.Spec.Template.Spec.Containers[registryContainerIndex]

regContainer.Env = append(regContainer.Env, corev1.EnvVar{
Name: "REGISTRY_STORAGE_AZURE_ACCOUNTKEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
Key: harbormetav1.SharedSecretKey,
LocalObjectReference: corev1.LocalObjectReference{
Name: registry.Spec.Storage.Driver.Azure.AccountKeyRef,
},
},
},
})

return nil
}

func (r *Reconciler) ApplyInMemoryStorageEnvs(ctx context.Context, registry *goharborv1.Registry, deploy *appsv1.Deployment) error {
regContainer := &deploy.Spec.Template.Spec.Containers[registryContainerIndex]

Expand All @@ -383,6 +401,10 @@ func (r *Reconciler) ApplyStorageConfiguration(ctx context.Context, registry *go
return r.ApplySwiftStorageEnvs(ctx, registry, deploy)
}

if registry.Spec.Storage.Driver.Azure != nil {
return r.ApplyAzureStorageEnvs(ctx, registry, deploy)
}

if registry.Spec.Storage.Driver.FileSystem != nil {
return r.ApplyFilesystemStorageEnvs(ctx, registry, deploy)
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/cluster/deployment.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manifests/harbor/deployment.yaml

Large diffs are not rendered by default.

133 changes: 0 additions & 133 deletions manifests/samples/zxy_test.yaml

This file was deleted.

5 changes: 5 additions & 0 deletions pkg/cluster/controllers/harbor/harbor.go
Expand Up @@ -157,6 +157,11 @@ func (harbor *Controller) getHarborCR(ctx context.Context, harborcluster *goharb
harborcluster.Spec.Storage.Spec.Swift.HarborStorageImageChartStorageSwiftSpec.DeepCopy()
}

if harborcluster.Spec.Storage.Spec.Azure != nil {
harborCR.Spec.ImageChartStorage.Azure =
harborcluster.Spec.Storage.Spec.Azure.HarborStorageImageChartStorageAzureSpec.DeepCopy()
}

if harborcluster.Spec.Database.Spec.PostgreSQL != nil {
harborCR.Spec.Database =
harborcluster.Spec.Database.Spec.PostgreSQL.HarborDatabaseSpec.DeepCopy()
Expand Down

0 comments on commit c9d380d

Please sign in to comment.