Skip to content

Commit a1f53ee

Browse files
committed
fix: workspace config not found
Signed-off-by: Oleksii Kurinnyi <[email protected]>
1 parent d3f3594 commit a1f53ee

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

controllers/cleanupcronjob/cleanupcronjob_controller.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,25 @@ func (r *CleanupCronJobReconciler) Reconcile(ctx context.Context, req ctrl.Reque
163163
return ctrl.Result{}, client.IgnoreNotFound(err)
164164
}
165165

166-
cleanupConfig := dwOperatorConfig.Config.Workspace.CleanupCronJob
167-
log = log.WithValues("CleanupCronJob", cleanupConfig)
168-
169-
if cleanupConfig == nil {
170-
log.Info("DevWorkspaceOperatorConfig does not have cleanup configuration, stopping cron schedler and skipping reconciliation")
166+
if dwOperatorConfig.Config == nil {
167+
log.Info("DevWorkspaceOperatorConfig does not have config, stopping cron scheduler and skipping reconciliation")
171168
r.stopCron(log)
172169
return ctrl.Result{}, nil
173170
}
171+
if dwOperatorConfig.Config.Workspace == nil {
172+
log.Info("DevWorkspaceOperatorConfig does not have workspace config, stopping cron scheduler and skipping reconciliation")
173+
r.stopCron(log)
174+
return ctrl.Result{}, nil
175+
}
176+
if dwOperatorConfig.Config.Workspace.CleanupCronJob == nil {
177+
log.Info("DevWorkspaceOperatorConfig does not have cleanup configuration, stopping cron scheduler and skipping reconciliation")
178+
r.stopCron(log)
179+
return ctrl.Result{}, nil
180+
}
181+
182+
cleanupConfig := dwOperatorConfig.Config.Workspace.CleanupCronJob
183+
log = log.WithValues("CleanupCronJob", cleanupConfig)
184+
174185
if cleanupConfig.Enable == nil || !*cleanupConfig.Enable {
175186
log.Info("DevWorkspace pruning is disabled, stopping cron scheduler and skipping reconciliation")
176187
r.stopCron(log)

controllers/cleanupcronjob/cleanupcronjob_controller_test.go

+30-2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,34 @@ var _ = Describe("CleanupCronJobReconciler", func() {
148148
Expect(reconciler.cron.Entries()).To(BeEmpty())
149149
})
150150

151+
It("Should not start cron if dwOperatorConfig.Config is nil", func() {
152+
dwoc := &controllerv1alpha1.DevWorkspaceOperatorConfig{
153+
ObjectMeta: metav1.ObjectMeta{Name: nameNamespace.Name, Namespace: nameNamespace.Namespace},
154+
Config: nil,
155+
}
156+
Expect(fakeClient.Create(ctx, dwoc)).To(Succeed())
157+
158+
result, err := reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: nameNamespace})
159+
Expect(err).ToNot(HaveOccurred())
160+
Expect(result).To(Equal(ctrl.Result{}))
161+
Expect(reconciler.cron.Entries()).To(BeEmpty())
162+
})
163+
164+
It("Should not start cron if dwOperatorConfig.Config.Workspace is nil", func() {
165+
dwoc := &controllerv1alpha1.DevWorkspaceOperatorConfig{
166+
ObjectMeta: metav1.ObjectMeta{Name: nameNamespace.Name, Namespace: nameNamespace.Namespace},
167+
Config: &controllerv1alpha1.OperatorConfiguration{
168+
Workspace: nil,
169+
},
170+
}
171+
Expect(fakeClient.Create(ctx, dwoc)).To(Succeed())
172+
173+
result, err := reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: nameNamespace})
174+
Expect(err).ToNot(HaveOccurred())
175+
Expect(result).To(Equal(ctrl.Result{}))
176+
Expect(reconciler.cron.Entries()).To(BeEmpty())
177+
})
178+
151179
It("Should not start cron if received event from different namespace", func() {
152180
dwoc := &controllerv1alpha1.DevWorkspaceOperatorConfig{
153181
ObjectMeta: metav1.ObjectMeta{Name: nameNamespace.Name, Namespace: "other-namespace"},
@@ -185,7 +213,7 @@ var _ = Describe("CleanupCronJobReconciler", func() {
185213
Expect(reconciler.cron.Entries()).To(BeEmpty())
186214
})
187215

188-
It("Should do not start cron if pruning is disabled", func() {
216+
It("Should not start cron if pruning is disabled", func() {
189217
enabled := false
190218
dwoc := &controllerv1alpha1.DevWorkspaceOperatorConfig{
191219
ObjectMeta: metav1.ObjectMeta{Name: nameNamespace.Name, Namespace: nameNamespace.Namespace},
@@ -205,7 +233,7 @@ var _ = Describe("CleanupCronJobReconciler", func() {
205233
Expect(reconciler.cron.Entries()).To(BeEmpty())
206234
})
207235

208-
It("Should do not start cron if schedule is missing", func() {
236+
It("Should not start cron if schedule is missing", func() {
209237
enabled := true
210238
dwoc := &controllerv1alpha1.DevWorkspaceOperatorConfig{
211239
ObjectMeta: metav1.ObjectMeta{Name: nameNamespace.Name, Namespace: nameNamespace.Namespace},

0 commit comments

Comments
 (0)