Skip to content

Commit afacdec

Browse files
committed
Fix typos and clean code
Signed-off-by: Ales Raszka <[email protected]>
1 parent cbc61d8 commit afacdec

File tree

5 files changed

+30
-38
lines changed

5 files changed

+30
-38
lines changed

controllers/backupcronjob/backupcronjob_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func (r *BackupCronJobReconciler) stopCron(log logr.Logger) {
210210
func (r *BackupCronJobReconciler) executeBackupSync(ctx context.Context, dwOperatorConfig *controllerv1alpha1.DevWorkspaceOperatorConfig, log logr.Logger) error {
211211
log.Info("Executing backup sync for all DevWorkspaces")
212212

213-
registyAuthSecret, err := r.getRegistryAuthSecret(ctx, dwOperatorConfig, log)
213+
registryAuthSecret, err := r.getRegistryAuthSecret(ctx, dwOperatorConfig, log)
214214
if err != nil {
215215
log.Error(err, "Failed to get registry auth secret for backup job")
216216
return err
@@ -239,7 +239,7 @@ func (r *BackupCronJobReconciler) executeBackupSync(ctx context.Context, dwOpera
239239
continue
240240
}
241241

242-
if err := r.createBackupJob(&dw, ctx, dwOperatorConfig, registyAuthSecret, log); err != nil {
242+
if err := r.createBackupJob(&dw, ctx, dwOperatorConfig, registryAuthSecret, log); err != nil {
243243
log.Error(err, "Failed to create backup Job for DevWorkspace", "id", dwID)
244244
continue
245245
}
@@ -310,7 +310,7 @@ func (r *BackupCronJobReconciler) createBackupJob(
310310
workspace *dw.DevWorkspace,
311311
ctx context.Context,
312312
dwOperatorConfig *controllerv1alpha1.DevWorkspaceOperatorConfig,
313-
registyAuthSecret *corev1.Secret,
313+
registryAuthSecret *corev1.Secret,
314314
log logr.Logger,
315315
) error {
316316
dwID := workspace.Status.DevWorkspaceId
@@ -407,8 +407,8 @@ func (r *BackupCronJobReconciler) createBackupJob(
407407
},
408408
},
409409
}
410-
if registyAuthSecret != nil {
411-
secret, err := r.copySecret(workspace, ctx, registyAuthSecret, log)
410+
if registryAuthSecret != nil {
411+
secret, err := r.copySecret(workspace, ctx, registryAuthSecret, log)
412412
if err != nil {
413413
return err
414414
}

controllers/backupcronjob/backupcronjob_controller_test.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
111111
Enable: pointer.Bool(true),
112112
Schedule: "* * * * *",
113113
Registry: &controllerv1alpha1.RegistryConfig{
114-
Path: "fake-registy",
114+
Path: "fake-registry",
115115
},
116116
},
117117
},
@@ -138,7 +138,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
138138
Enable: &enabled,
139139
Schedule: schedule,
140140
Registry: &controllerv1alpha1.RegistryConfig{
141-
Path: "fake-registy",
141+
Path: "fake-registry",
142142
},
143143
},
144144
},
@@ -163,7 +163,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
163163
Enable: &enabled,
164164
Schedule: schedule1,
165165
Registry: &controllerv1alpha1.RegistryConfig{
166-
Path: "fake-registy",
166+
Path: "fake-registry",
167167
},
168168
},
169169
},
@@ -199,7 +199,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
199199
Enable: &enabled,
200200
Schedule: schedule,
201201
Registry: &controllerv1alpha1.RegistryConfig{
202-
Path: "fake-registy",
202+
Path: "fake-registry",
203203
},
204204
},
205205
},
@@ -223,7 +223,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
223223
})
224224

225225
Context("executeBackupSync", func() {
226-
It("creates a Job for a DevWorkspace stopped with no previsou backup", func() {
226+
It("creates a Job for a DevWorkspace stopped with no previous backup", func() {
227227
enabled := true
228228
schedule := "* * * * *"
229229
dwoc := &controllerv1alpha1.DevWorkspaceOperatorConfig{
@@ -234,7 +234,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
234234
Enable: &enabled,
235235
Schedule: schedule,
236236
Registry: &controllerv1alpha1.RegistryConfig{
237-
Path: "fake-registy",
237+
Path: "fake-registry",
238238
},
239239
},
240240
},
@@ -267,7 +267,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
267267
Enable: &enabled,
268268
Schedule: schedule,
269269
Registry: &controllerv1alpha1.RegistryConfig{
270-
Path: "fake-registy",
270+
Path: "fake-registry",
271271
},
272272
},
273273
},
@@ -302,7 +302,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
302302
Enable: &enabled,
303303
Schedule: schedule,
304304
Registry: &controllerv1alpha1.RegistryConfig{
305-
Path: "fake-registy",
305+
Path: "fake-registry",
306306
},
307307
},
308308
},
@@ -321,7 +321,7 @@ var _ = Describe("BackupCronJobReconciler", func() {
321321
Expect(jobList.Items).To(HaveLen(0))
322322
})
323323

324-
It("creates a Job for a DevWorkspace stopped with no previsou backup and auth registry", func() {
324+
It("creates a Job for a DevWorkspace stopped with no previous backup and auth registry", func() {
325325
enabled := true
326326
schedule := "* * * * *"
327327
dwoc := &controllerv1alpha1.DevWorkspaceOperatorConfig{
@@ -393,14 +393,12 @@ func createDevWorkspace(name, namespace string, started bool, lastTransitionTime
393393
}
394394

395395
func createAuthSecret(name, namespace string, data map[string][]byte) *corev1.Secret {
396-
{
397-
return &corev1.Secret{
398-
ObjectMeta: metav1.ObjectMeta{
399-
Name: name,
400-
Namespace: namespace,
401-
},
402-
Data: data,
403-
}
396+
return &corev1.Secret{
397+
ObjectMeta: metav1.ObjectMeta{
398+
Name: name,
399+
Namespace: namespace,
400+
},
401+
Data: data,
404402
}
405403
}
406404

controllers/backupcronjob/rbac.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ const (
3131
)
3232

3333
func (r *BackupCronJobReconciler) ensureJobRunnerRBAC(ctx context.Context, workspace *dw.DevWorkspace) error {
34-
const (
35-
roleName = "devworkspace-job-runner-role"
36-
rbName = "devworkspace-job-runner-rolebinding"
37-
)
38-
3934
sa := &corev1.ServiceAccount{
4035
ObjectMeta: metav1.ObjectMeta{Name: JobRunnerSAName + "-" + workspace.Status.DevWorkspaceId, Namespace: workspace.Namespace, Labels: map[string]string{
4136
constants.DevWorkspaceIDLabel: workspace.Status.DevWorkspaceId,

pkg/config/defaults.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ var defaultConfig = &v1alpha1.OperatorConfiguration{
8585
BackupCronJob: &v1alpha1.BackupCronJobConfig{
8686
Enable: pointer.Bool(false),
8787
Schedule: "0 0 1 * *",
88-
Registry: &v1alpha1.RegistryConfig{
89-
Path: "sample.com",
90-
},
9188
},
9289
// Do not declare a default value for this field.
9390
// Setting a default leads to an endless reconcile loop when UserNamespacesSupport is disabled,

pkg/config/sync.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -441,14 +441,16 @@ func mergeConfig(from, to *controller.OperatorConfiguration) {
441441
if from.Workspace.BackupCronJob.Schedule != "" {
442442
to.Workspace.BackupCronJob.Schedule = from.Workspace.BackupCronJob.Schedule
443443
}
444-
if to.Workspace.BackupCronJob.Registry == nil {
445-
to.Workspace.BackupCronJob.Registry = &controller.RegistryConfig{}
446-
}
447-
if from.Workspace.BackupCronJob.Registry.Path != "" {
448-
to.Workspace.BackupCronJob.Registry.Path = from.Workspace.BackupCronJob.Registry.Path
449-
}
450-
if from.Workspace.BackupCronJob.Registry.AuthSecret != "" {
451-
to.Workspace.BackupCronJob.Registry.AuthSecret = from.Workspace.BackupCronJob.Registry.AuthSecret
444+
if from.Workspace.BackupCronJob.Registry != nil {
445+
if to.Workspace.BackupCronJob.Registry == nil {
446+
to.Workspace.BackupCronJob.Registry = &controller.RegistryConfig{}
447+
}
448+
if from.Workspace.BackupCronJob.Registry.Path != "" {
449+
to.Workspace.BackupCronJob.Registry.Path = from.Workspace.BackupCronJob.Registry.Path
450+
}
451+
if from.Workspace.BackupCronJob.Registry.AuthSecret != "" {
452+
to.Workspace.BackupCronJob.Registry.AuthSecret = from.Workspace.BackupCronJob.Registry.AuthSecret
453+
}
452454
}
453455
}
454456

0 commit comments

Comments
 (0)