Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
manirajv06 committed Jul 20, 2023
1 parent 95d4d90 commit 64a9714
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
7 changes: 2 additions & 5 deletions pkg/appmgmt/general/podevent_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package general

import (
"fmt"
"sync"

"go.uber.org/zap"
Expand Down Expand Up @@ -135,11 +136,7 @@ func (p *PodEventHandler) addPod(pod *v1.Pod, eventSource EventSource) interface
zap.String("app user", app.GetUser()),
zap.String("submitted by", appMeta.User))
events.GetRecorder().Eventf(pod.DeepCopy(), nil, v1.EventTypeWarning,
"Rejecting the application because already application exists with different user",
"Please try submitting a application by same user",
"SingleUserPerApplication has been configured to true. So rejecting the application because it has been submitted by different user. "+
"Either you can disable the check by not setting SingleUserPerApplication or try submitting a application by same use. "+
"By default, SingleUserPerApplication is false")
fmt.Sprintf("Rejecting pod because application ID %s belongs to a different user", appMeta.ApplicationID), "", "")
return nil
}
managedApp = app
Expand Down
13 changes: 5 additions & 8 deletions pkg/appmgmt/general/podevent_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,24 +168,21 @@ func TestSingleUserPerApplication(t *testing.T) {
// submit the same app with different user
am.AddPod(pod)

message := "Rejecting the application because already application exists with different user"
reason := "SingleUserPerApplication has been configured to true. So rejecting the application because it has been submitted by different user. " +
"Either you can disable the check by not setting SingleUserPerApplication or try submitting a application by same use. " +
"By default, SingleUserPerApplication is false"
message := "Rejecting pod because application ID " + appID + " belongs to a different user"

// ensure there is no event
err := utils.WaitForCondition(func() bool {
for {
select {
case event := <-recorder.Events:
if strings.Contains(event, reason) && strings.Contains(event, message) {
if strings.Contains(event, message) {
return true
}
default:
return false
}
}
}, 50*time.Millisecond, 20*time.Millisecond)
}, 50*time.Millisecond, time.Second)
assert.Error(t, err, "timeout waiting for condition")

// set SingleUserPerApplication to true
Expand All @@ -201,14 +198,14 @@ func TestSingleUserPerApplication(t *testing.T) {
for {
select {
case event := <-recorder.Events:
if strings.Contains(event, reason) && strings.Contains(event, message) {
if strings.Contains(event, message) {
return true
}
default:
return false
}
}
}, 50*time.Millisecond, 20*time.Millisecond)
}, 50*time.Millisecond, time.Second)
assert.NilError(t, err, "event should have been emitted")
}

Expand Down

0 comments on commit 64a9714

Please sign in to comment.