diff --git a/apis/goharbor.io/v1beta1/harborcluster_types.go b/apis/goharbor.io/v1beta1/harborcluster_types.go index 8a23bcbc9..27735b300 100644 --- a/apis/goharbor.io/v1beta1/harborcluster_types.go +++ b/apis/goharbor.io/v1beta1/harborcluster_types.go @@ -179,6 +179,10 @@ type RedisServer struct { // +kubebuilder:validation:Optional // Storage is the size of the redis storage. Storage string `json:"storage,omitempty"` + + // +kubebuilder:validation:Optional + // ServiceAccountName is the service account name of the redis server. + ServiceAccountName string `json:"serviceAccountName,omitempty"` } type Database struct { diff --git a/manifests/cluster/deployment.yaml b/manifests/cluster/deployment.yaml index 4b4558c3e..3372cdffa 100644 --- a/manifests/cluster/deployment.yaml +++ b/manifests/cluster/deployment.yaml @@ -9745,6 +9745,10 @@ spec: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' type: object type: object + serviceAccountName: + description: ServiceAccountName is the service account + name of the redis server. + type: string storage: description: Storage is the size of the redis storage. type: string diff --git a/manifests/harbor/deployment.yaml b/manifests/harbor/deployment.yaml index 3f5a669b7..1bdde8388 100644 --- a/manifests/harbor/deployment.yaml +++ b/manifests/harbor/deployment.yaml @@ -9745,6 +9745,10 @@ spec: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' type: object type: object + serviceAccountName: + description: ServiceAccountName is the service account + name of the redis server. + type: string storage: description: Storage is the size of the redis storage. type: string diff --git a/pkg/cluster/controllers/cache/resource_manager.go b/pkg/cluster/controllers/cache/resource_manager.go index 8c1ce439f..0ceb2c7f6 100644 --- a/pkg/cluster/controllers/cache/resource_manager.go +++ b/pkg/cluster/controllers/cache/resource_manager.go @@ -107,9 +107,10 @@ func (rm *redisResourceManager) GetCacheCR(ctx context.Context, harborcluster *g Spec: pvc.Spec, }, }, - Image: image, - ImagePullPolicy: rm.getImagePullPolicy(ctx, harborcluster), - ImagePullSecrets: rm.getImagePullSecrets(ctx, harborcluster), + Image: image, + ImagePullPolicy: rm.getImagePullPolicy(ctx, harborcluster), + ImagePullSecrets: rm.getImagePullSecrets(ctx, harborcluster), + ServiceAccountName: rm.getServiceAccountName(ctx, harborcluster), }, Sentinel: redisOp.SentinelSettings{ Replicas: int32(rm.GetClusterServerReplica()), @@ -242,3 +243,11 @@ func (rm *redisResourceManager) getImagePullSecrets(_ context.Context, harborclu return nil } + +func (rm *redisResourceManager) getServiceAccountName(_ context.Context, harborcluster *goharborv1.HarborCluster) string { + if rm.cluster.Spec.Cache.Spec.RedisFailover != nil && rm.cluster.Spec.Cache.Spec.RedisFailover.Server != nil { + return harborcluster.Spec.Cache.Spec.RedisFailover.Server.ServiceAccountName + } + + return "" +}