Skip to content

Commit 2e99b7e

Browse files
committed
Per workspace backup SA
A SA is created for every backup workspace to avoid ownership conflict. Signed-off-by: Ales Raszka <[email protected]>
1 parent c4a958c commit 2e99b7e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

controllers/backupcronjob/backupcronjob_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func (r *BackupCronJobReconciler) createBackupJob(
347347
Spec: batchv1.JobSpec{
348348
Template: corev1.PodTemplateSpec{
349349
Spec: corev1.PodSpec{
350-
ServiceAccountName: JobRunnerSAName,
350+
ServiceAccountName: JobRunnerSAName + "-" + workspace.Status.DevWorkspaceId,
351351
RestartPolicy: corev1.RestartPolicyNever,
352352
SecurityContext: &corev1.PodSecurityContext{
353353
FSGroup: ptr.To[int64](0),

controllers/backupcronjob/rbac.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (r *BackupCronJobReconciler) ensureJobRunnerRBAC(ctx context.Context, works
3737
)
3838

3939
sa := &corev1.ServiceAccount{
40-
ObjectMeta: metav1.ObjectMeta{Name: JobRunnerSAName, Namespace: workspace.Namespace, Labels: map[string]string{
40+
ObjectMeta: metav1.ObjectMeta{Name: JobRunnerSAName + "-" + workspace.Status.DevWorkspaceId, Namespace: workspace.Namespace, Labels: map[string]string{
4141
constants.DevWorkspaceIDLabel: workspace.Status.DevWorkspaceId,
4242
constants.DevWorkspaceWatchSecretLabel: "true",
4343
}},
@@ -47,6 +47,7 @@ func (r *BackupCronJobReconciler) ensureJobRunnerRBAC(ctx context.Context, works
4747
if err := controllerutil.SetControllerReference(workspace, sa, r.Scheme); err != nil {
4848
return err
4949
}
50+
5051
if _, err := controllerutil.CreateOrUpdate(ctx, r.Client, sa, func() error { return nil }); err != nil {
5152
return fmt.Errorf("ensuring ServiceAccount: %w", err)
5253
}

0 commit comments

Comments
 (0)