Skip to content

Commit 1df0e69

Browse files
committed
Handle success conditions
1 parent cec5cb4 commit 1df0e69

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

controllers/channel_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ func (r *ChannelReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
5959
// Request object not found, could have been deleted after reconcile request.
6060
// Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
6161
// Return and don't requeue
62-
return ctrl.Result{}, nil
62+
return reconcilerUtil.DoNotRequeue()
6363
}
6464
// Error reading channel, requeue
65-
return ctrl.Result{}, err
65+
return reconcilerUtil.RequeueWithError(err)
6666
}
6767

6868
isChannelMarkedToBeDeleted := channel.GetDeletionTimestamp() != nil
@@ -104,7 +104,7 @@ func (r *ChannelReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
104104
err = r.Status().Update(ctx, channel)
105105
if err != nil {
106106
log.Error(err, "Failed to update Channel status")
107-
return ctrl.Result{}, err
107+
return reconcilerUtil.ManageError(r.Client, channel, err, true)
108108
}
109109
return r.updateSlackChannel(ctx, channel)
110110
}
@@ -147,7 +147,7 @@ func (r *ChannelReconciler) updateSlackChannel(ctx context.Context, channel *sla
147147
return reconcilerUtil.ManageError(r.Client, channel, err, false)
148148
}
149149

150-
return ctrl.Result{}, nil
150+
return reconcilerUtil.ManageSuccess(r.Client, channel)
151151
}
152152

153153
func (r *ChannelReconciler) finalizeChannel(req ctrl.Request, channel *slackv1alpha1.Channel) (ctrl.Result, error) {

controllers/channel_controller_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ var _ = Describe("ChannelController", func() {
2929
_ = util.CreateChannel(channelName, false, "", "", []string{}, ns)
3030
channel := util.GetChannel(channelName, ns)
3131

32-
Expect(channel.Status.Conditions).To(BeNil())
3332
Expect(channel.Status.ID).To(Equal(slackMock.PublicConversationID))
33+
Expect(len(channel.Status.Conditions)).To(Equal(1))
34+
Expect(channel.Status.Conditions[0].Reason).To(Equal(status.ConditionReason("Successful")))
3435
})
3536

3637
It("should set error condition if channel with same name already exists", func() {
@@ -49,8 +50,9 @@ var _ = Describe("ChannelController", func() {
4950
_ = util.CreateChannel(channelName, true, "", "", []string{}, ns)
5051
channel := util.GetChannel(channelName, ns)
5152

52-
Expect(channel.Status.Conditions).To(BeNil())
5353
Expect(channel.Status.ID).To(Equal(slackMock.PrivateConversationID))
54+
Expect(len(channel.Status.Conditions)).To(Equal(1))
55+
Expect(channel.Status.Conditions[0].Reason).To(Equal(status.ConditionReason("Successful")))
5456
})
5557
})
5658

@@ -61,8 +63,9 @@ var _ = Describe("ChannelController", func() {
6163
_ = util.CreateChannel(channelName, true, "", description, []string{}, ns)
6264
channel := util.GetChannel(channelName, ns)
6365

64-
Expect(channel.Status.Conditions).To(BeNil())
6566
Expect(channel.Spec.Description).To(Equal(description))
67+
Expect(len(channel.Status.Conditions)).To(Equal(1))
68+
Expect(channel.Status.Conditions[0].Reason).To(Equal(status.ConditionReason("Successful")))
6669
})
6770
})
6871

@@ -73,18 +76,20 @@ var _ = Describe("ChannelController", func() {
7376
_ = util.CreateChannel(channelName, true, topic, "", []string{}, ns)
7477
channel := util.GetChannel(channelName, ns)
7578

76-
Expect(channel.Status.Conditions).To(BeNil())
7779
Expect(channel.Spec.Topic).To(Equal(topic))
80+
Expect(len(channel.Status.Conditions)).To(Equal(1))
81+
Expect(channel.Status.Conditions[0].Reason).To(Equal(status.ConditionReason("Successful")))
7882
})
7983
})
8084

8185
Context("With user emails", func() {
82-
It("should not set error condition when user exists", func() {
86+
It("should set success condition when user exists", func() {
8387

8488
_ = util.CreateChannel(channelName, true, "", "", []string{mock.ExistingUserEmail}, ns)
8589
channel := util.GetChannel(channelName, ns)
8690

87-
Expect(channel.Status.Conditions).To(BeNil())
91+
Expect(len(channel.Status.Conditions)).To(Equal(1))
92+
Expect(channel.Status.Conditions[0].Reason).To(Equal(status.ConditionReason("Successful")))
8893
})
8994

9095
It("should set error condition when user does not exists", func() {
@@ -121,8 +126,10 @@ var _ = Describe("ChannelController", func() {
121126

122127
updatedChannel := util.GetChannel(channelName, ns)
123128

124-
Expect(channel.Status.Conditions).To(BeNil())
125129
Expect(updatedChannel.Spec.Name).To(Equal(newName))
130+
131+
Expect(len(channel.Status.Conditions)).To(Equal(1))
132+
Expect(channel.Status.Conditions[0].Reason).To(Equal(status.ConditionReason("Successful")))
126133
})
127134
})
128135
})
@@ -133,8 +140,9 @@ var _ = Describe("ChannelController", func() {
133140
_ = util.CreateChannel(channelName, false, "", "", []string{}, ns)
134141
channel := util.GetChannel(channelName, ns)
135142

136-
Expect(channel.Status.Conditions).To(BeNil())
137143
Expect(channel.Status.ID).ToNot(BeEmpty())
144+
Expect(len(channel.Status.Conditions)).To(Equal(1))
145+
Expect(channel.Status.Conditions[0].Reason).To(Equal(status.ConditionReason("Successful")))
138146

139147
util.DeleteChannel(channelName, ns)
140148

0 commit comments

Comments
 (0)