-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from stakater/reconcile-bug-fix
Fixed repetitive reconciliation issue on users
- Loading branch information
Showing
8 changed files
with
89 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ bin | |
*.swo | ||
*~ | ||
.local | ||
testbin | ||
testbin | ||
.vscode |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package controllers | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
@@ -84,13 +85,13 @@ var _ = Describe("ChannelController", func() { | |
}) | ||
|
||
It("should set error condition when user does not exists", func() { | ||
|
||
_ = util.CreateChannel(channelName, true, "", "", []string{"[email protected]"}, ns) | ||
emailList := []string{"[email protected]"} | ||
_ = util.CreateChannel(channelName, true, "", "", emailList, ns) | ||
channel := util.GetChannel(channelName, ns) | ||
|
||
Expect(len(channel.Status.Conditions)).To(Equal(1)) | ||
Expect(channel.Status.Conditions[0].Reason).To(Equal("Failed")) | ||
Expect(channel.Status.Conditions[0].Message).To(Equal("users_not_found")) | ||
Expect(channel.Status.Conditions[0].Message).To(Equal(fmt.Sprintf("Error fetching user by Email %s", emailList[0]))) | ||
}) | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package slack | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stakater/slack-operator/pkg/slack/mock" | ||
|
@@ -78,12 +79,14 @@ func TestSlackService_ArchiveChannel_shouldThrowError_whenChannelNotFound(t *tes | |
|
||
func TestSlackService_InviteUsers_shouldSendUserInvites_whenUserExists(t *testing.T) { | ||
s := NewMockService(log) | ||
err := s.InviteUsers(mock.PublicConversationID, []string{mock.ExistingUserEmail}) | ||
assert.NoError(t, err) | ||
errs := s.InviteUsers(mock.PublicConversationID, []string{mock.ExistingUserEmail}) | ||
assert.Equal(t, 0, len(errs)) | ||
} | ||
|
||
func TestSlackService_InviteUsers_shouldThowError_whenUserDoesNotExists(t *testing.T) { | ||
s := NewMockService(log) | ||
err := s.InviteUsers(mock.PublicConversationID, []string{"[email protected]"}) | ||
assert.EqualError(t, err, "users_not_found") | ||
emailList := []string{"[email protected]"} | ||
errs := s.InviteUsers(mock.PublicConversationID, emailList) | ||
assert.Equal(t, 1, len(errs)) | ||
assert.EqualError(t, errs[0], fmt.Sprintf("Error fetching user by Email %s", emailList[0])) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package pkgutil | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/stakater/slack-operator/pkg/config" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
|
||
k8sClient "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
reconcilerUtil "github.com/stakater/operator-utils/util/reconciler" | ||
slackv1alpha1 "github.com/stakater/slack-operator/api/v1alpha1" | ||
) | ||
|
||
// MapErrorListToError maps multiple errors into a single error | ||
func MapErrorListToError(errs []error) error { | ||
|
||
if len(errs) == 0 { | ||
return nil | ||
} | ||
|
||
errMsg := []string{} | ||
for _, err := range errs { | ||
errMsg = append(errMsg, err.Error()) | ||
} | ||
|
||
return fmt.Errorf(strings.Join(errMsg, "\n")) | ||
} | ||
|
||
func ManageError(ctx context.Context, client k8sClient.Client, channelInstance *slackv1alpha1.Channel, issue error) (ctrl.Result, error) { | ||
|
||
// Base object for patch, which patches using the merge-patch strategy with the given object as base. | ||
channelInstancePatchBase := k8sClient.MergeFrom(channelInstance.DeepCopy()) | ||
|
||
// Update status | ||
channelInstance.Status.Conditions = []metav1.Condition{ | ||
{ | ||
Type: "ReconcileError", | ||
LastTransitionTime: metav1.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), time.Now().Hour(), time.Now().Minute(), 0, 0, time.Now().Location()), | ||
Message: issue.Error(), | ||
Reason: reconcilerUtil.FailedReason, | ||
Status: metav1.ConditionTrue, | ||
}, | ||
} | ||
|
||
// Patch status | ||
err := client.Status().Patch(ctx, channelInstance, channelInstancePatchBase) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
return reconcilerUtil.RequeueAfter(config.ErrorRequeueTime) | ||
} |