-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚀 support storage to avoid duplicate notifications (#20)
* support storage to avoid duplicate notifications * update configs
- Loading branch information
Showing
16 changed files
with
141 additions
and
28 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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
|
@@ -7,5 +7,4 @@ alert: | |
discord: | ||
webhook: "" | ||
namespaces: | ||
- default | ||
|
||
- default |
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 |
---|---|---|
|
@@ -20,5 +20,3 @@ data: | |
webhook: <webhook_url> | ||
namespaces: | ||
- <optional_namespace> | ||
: |
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
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,65 @@ | ||
package storage | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type memory struct { | ||
smap sync.Map | ||
} | ||
|
||
// NewMemory returns new Memory object | ||
func NewMemory() Storage { | ||
return &memory{ | ||
smap: sync.Map{}, | ||
} | ||
} | ||
|
||
// AddPodContainer attaches container to pod to mark it has an error | ||
func (m *memory) AddPodContainer(podKey, containerKey string) { | ||
if v, ok := m.smap.Load(podKey); ok { | ||
containers := v.(map[string]bool) | ||
containers[containerKey] = true | ||
|
||
m.smap.Store(podKey, containers) | ||
return | ||
} | ||
m.smap.Store(podKey, map[string]bool{containerKey: true}) | ||
} | ||
|
||
// Delete deletes pod with all its containers | ||
func (m *memory) DelPod(key string) { | ||
logrus.Info("del called: " + key) | ||
|
||
m.smap.Delete(key) | ||
} | ||
|
||
// DelPodContainer detaches container from pod to mark error is resolved | ||
func (m *memory) DelPodContainer(podKey, containerKey string) { | ||
v, ok := m.smap.Load(podKey) | ||
if !ok { | ||
return | ||
} | ||
|
||
containers := v.(map[string]bool) | ||
delete(containers, containerKey) | ||
|
||
m.smap.Store(podKey, containers) | ||
} | ||
|
||
// HasPodContainer checks if container is attached to given pod or not | ||
func (m *memory) HasPodContainer(podKey, containerKey string) bool { | ||
v, ok := m.smap.Load(podKey) | ||
if !ok { | ||
return false | ||
} | ||
|
||
containers := v.(map[string]bool) | ||
if _, ok := containers[containerKey]; ok { | ||
return true | ||
} | ||
|
||
return false | ||
} |
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,8 @@ | ||
package storage | ||
|
||
type Storage interface { | ||
AddPodContainer(podKey, containerKey string) | ||
DelPodContainer(podKey, containerKey string) | ||
DelPod(podKey string) | ||
HasPodContainer(podKey, containerKey string) bool | ||
} |
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