Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: access key and secret key can be empty if role is used #53

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions api/v1/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (s *Store) getBlackfire() []corev1.EnvVar {
// TODO: Minio should use bucketname before URL. So we have public.domain.com see:
// https://min.io/docs/minio/linux/administration/object-management.html#minio-object-management-path-virtual-access
func (s *Store) getStorage() []corev1.EnvVar {
return []corev1.EnvVar{
envVars := []corev1.EnvVar{
{
Name: "K8S_FILESYSTEM_PUBLIC_BUCKET",
Value: s.Spec.S3Storage.PublicBucketName,
Expand All @@ -207,7 +207,10 @@ func (s *Store) getStorage() []corev1.EnvVar {
Name: "K8S_FILESYSTEM_ENDPOINT",
Value: s.Spec.S3Storage.EndpointURL,
},
{
}

if s.Spec.S3Storage.AccessKeyRef.Name != "" {
envVars = append(envVars, corev1.EnvVar{
Name: "AWS_ACCESS_KEY_ID",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
Expand All @@ -217,8 +220,11 @@ func (s *Store) getStorage() []corev1.EnvVar {
Key: s.Spec.S3Storage.AccessKeyRef.Key,
},
},
},
{
})
}

if s.Spec.S3Storage.SecretAccessKeyRef.Key != "" {
envVars = append(envVars, corev1.EnvVar{
Name: "AWS_SECRET_ACCESS_KEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
Expand All @@ -228,8 +234,10 @@ func (s *Store) getStorage() []corev1.EnvVar {
Key: s.Spec.S3Storage.SecretAccessKeyRef.Key,
},
},
},
})
}

return envVars
}

func (s *Store) GetEnv() []corev1.EnvVar {
Expand Down
5 changes: 3 additions & 2 deletions api/v1/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type StoreSpec struct {
Otel OtelSpec `json:"otel,omitempty"`
FPM FPMSpec `json:"fpm,omitempty"`
HorizontalPodAutoscaler HPASpec `json:"horizontalPodAutoscaler,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`

// +kubebuilder:default=false
DisableChecks bool `json:"disableChecks,omitempty"`
Expand Down Expand Up @@ -233,8 +234,8 @@ type S3Storage struct {
PublicBucketName string `json:"publicBucketName"`
Region string `json:"region,omitempty"`

AccessKeyRef SecretRef `json:"accessKeyRef"`
SecretAccessKeyRef SecretRef `json:"secretAccessKeyRef"`
AccessKeyRef SecretRef `json:"accessKeyRef,omitempty"`
SecretAccessKeyRef SecretRef `json:"secretAccessKeyRef,omitempty"`
}

type DatabaseSpec struct {
Expand Down
9 changes: 8 additions & 1 deletion internal/deployment/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func AdminDeployment(store *v1.Store) *appsv1.Deployment {
Resources: store.Spec.Container.Resources,
})

return &appsv1.Deployment{
deployment := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
APIVersion: "apps/v1",
Expand All @@ -93,6 +93,7 @@ func AdminDeployment(store *v1.Store) *appsv1.Deployment {
Spec: appsv1.DeploymentSpec{
ProgressDeadlineSeconds: &store.Spec.Container.ProgressDeadlineSeconds,
Replicas: &store.Spec.Container.Replicas,

Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": appName,
Expand Down Expand Up @@ -126,6 +127,12 @@ func AdminDeployment(store *v1.Store) *appsv1.Deployment {
},
},
}

if store.Spec.ServiceAccountName != "" {
deployment.Spec.Template.Spec.ServiceAccountName = store.Spec.ServiceAccountName
}

return deployment
}

func GetAdminDeploymentName(store *v1.Store) string {
Expand Down
8 changes: 7 additions & 1 deletion internal/deployment/storefront.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func StorefrontDeployment(store *v1.Store) *appsv1.Deployment {
Resources: store.Spec.Container.Resources,
})

return &appsv1.Deployment{
deployment := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
APIVersion: "apps/v1",
Expand Down Expand Up @@ -128,6 +128,12 @@ func StorefrontDeployment(store *v1.Store) *appsv1.Deployment {
},
},
}

if store.Spec.ServiceAccountName != "" {
deployment.Spec.Template.Spec.ServiceAccountName = store.Spec.ServiceAccountName
}

return deployment
}

func GetStorefrontDeploymentName(store *v1.Store) string {
Expand Down
8 changes: 7 additions & 1 deletion internal/deployment/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func WorkerDeployment(store *v1.Store) *appsv1.Deployment {
Resources: store.Spec.Container.Resources,
})

return &appsv1.Deployment{
deployment := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
APIVersion: "apps/v1",
Expand Down Expand Up @@ -110,6 +110,12 @@ func WorkerDeployment(store *v1.Store) *appsv1.Deployment {
},
},
}

if store.Spec.ServiceAccountName != "" {
deployment.Spec.Template.Spec.ServiceAccountName = store.Spec.ServiceAccountName
}

return deployment
}

func GetWorkerDeploymentName(store *v1.Store) string {
Expand Down
8 changes: 7 additions & 1 deletion internal/job/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func MigrationJob(store *v1.Store) *batchv1.Job {
Env: store.GetEnv(),
})

return &batchv1.Job{
job := &batchv1.Job{
TypeMeta: metav1.TypeMeta{
Kind: "Job",
APIVersion: "batch/v1"},
Expand Down Expand Up @@ -104,6 +104,12 @@ func MigrationJob(store *v1.Store) *batchv1.Job {
},
},
}

if store.Spec.ServiceAccountName != "" {
job.Spec.Template.Spec.ServiceAccountName = store.Spec.ServiceAccountName
}

return job
}

func MigrateJobName(store *v1.Store) string {
Expand Down
8 changes: 7 additions & 1 deletion internal/job/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func SetupJob(store *v1.Store) *batchv1.Job {
Env: envs,
})

return &batchv1.Job{
job := &batchv1.Job{
TypeMeta: metav1.TypeMeta{
Kind: "Job",
APIVersion: "batch/v1",
Expand Down Expand Up @@ -107,6 +107,12 @@ func SetupJob(store *v1.Store) *batchv1.Job {
},
},
}

if store.Spec.ServiceAccountName != "" {
job.Spec.Template.Spec.ServiceAccountName = store.Spec.ServiceAccountName
}

return job
}

func GetSetupJobName(store *v1.Store) string {
Expand Down
Loading