Skip to content

Commit

Permalink
chore: optionally use a service account name
Browse files Browse the repository at this point in the history
  • Loading branch information
shadracnicholas committed Oct 14, 2024
1 parent bbe6190 commit cfd1cc0
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 21 deletions.
1 change: 1 addition & 0 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
9 changes: 7 additions & 2 deletions 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 Down Expand Up @@ -122,12 +122,17 @@ func AdminDeployment(store *v1.Store) *appsv1.Deployment {
ImagePullSecrets: store.Spec.Container.ImagePullSecrets,
RestartPolicy: store.Spec.Container.RestartPolicy,
Containers: containers,
ServiceAccountName: util.GetServiceAccountName(store),
SecurityContext: store.Spec.Container.SecurityContext,
},
},
},
}

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

return deployment
}

func GetAdminDeploymentName(store *v1.Store) string {
Expand Down
9 changes: 7 additions & 2 deletions 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 @@ -123,12 +123,17 @@ func StorefrontDeployment(store *v1.Store) *appsv1.Deployment {
ImagePullSecrets: store.Spec.Container.ImagePullSecrets,
RestartPolicy: store.Spec.Container.RestartPolicy,
Containers: containers,
ServiceAccountName: util.GetServiceAccountName(store),
SecurityContext: store.Spec.Container.SecurityContext,
},
},
},
}

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

return deployment
}

func GetStorefrontDeploymentName(store *v1.Store) string {
Expand Down
9 changes: 7 additions & 2 deletions 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 @@ -105,12 +105,17 @@ func WorkerDeployment(store *v1.Store) *appsv1.Deployment {
ImagePullSecrets: store.Spec.Container.ImagePullSecrets,
RestartPolicy: store.Spec.Container.RestartPolicy,
Containers: containers,
ServiceAccountName: util.GetServiceAccountName(store),
SecurityContext: store.Spec.Container.SecurityContext,
},
},
},
}

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

return deployment
}

func GetWorkerDeploymentName(store *v1.Store) string {
Expand Down
9 changes: 7 additions & 2 deletions 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 All @@ -99,12 +99,17 @@ func MigrationJob(store *v1.Store) *batchv1.Job {
ImagePullSecrets: store.Spec.Container.ImagePullSecrets,
RestartPolicy: "Never",
Containers: containers,
ServiceAccountName: util.GetServiceAccountName(store),
SecurityContext: store.Spec.Container.SecurityContext,
},
},
},
}

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

return job
}

func MigrateJobName(store *v1.Store) string {
Expand Down
9 changes: 7 additions & 2 deletions 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 All @@ -102,12 +102,17 @@ func SetupJob(store *v1.Store) *batchv1.Job {
ImagePullSecrets: store.Spec.Container.ImagePullSecrets,
RestartPolicy: "Never",
Containers: containers,
ServiceAccountName: util.GetServiceAccountName(store),
SecurityContext: store.Spec.Container.SecurityContext,
},
},
},
}

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

return job
}

func GetSetupJobName(store *v1.Store) string {
Expand Down
11 changes: 0 additions & 11 deletions internal/util/serviceaccount.go

This file was deleted.

0 comments on commit cfd1cc0

Please sign in to comment.