Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ type Config struct {
// Patterns are compiled from IgnoreLogPatterns after populating
// IgnoreLogPatterns configuration
IgnoreLogPatternsCompiled []*regexp.Regexp

// IgnoreNodeReasons is an optional list of node reasons for which alerting should be skipped
IgnoreNodeReasons []string `yaml:"ignoreNodeReasons"`
}

// App confing struct
Expand Down
57 changes: 57 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,60 @@ func TestGetCompiledIgnorePatterns(t *testing.T) {

assert.NotNil(err)
}

func TestIgnoreNodeReasonsLoading(t *testing.T) {
assert := assert.New(t)

defer os.Unsetenv("CONFIG_FILE")
defer os.RemoveAll("config.yaml")

os.Setenv("CONFIG_FILE", "config.yaml")

n := Config{
IgnoreNodeReasons: []string{"NotReady", "KubeletNotReady", "custom-reason"},
}
yamlData, _ := yaml.Marshal(&n)
os.WriteFile("config.yaml", yamlData, 0644)

cfg, _ := LoadConfig()
assert.NotNil(cfg)
assert.Equal([]string{"NotReady", "KubeletNotReady", "custom-reason"}, cfg.IgnoreNodeReasons)
}

func TestIgnoreNodeReasonsEmpty(t *testing.T) {
assert := assert.New(t)

defer os.Unsetenv("CONFIG_FILE")
defer os.RemoveAll("config.yaml")

os.Setenv("CONFIG_FILE", "config.yaml")

n := Config{
IgnoreNodeReasons: []string{},
}
yamlData, _ := yaml.Marshal(&n)
os.WriteFile("config.yaml", yamlData, 0644)

cfg, _ := LoadConfig()
assert.NotNil(cfg)
assert.Equal([]string{}, cfg.IgnoreNodeReasons)
}

func TestIgnoreNodeReasonsSpecialChars(t *testing.T) {
assert := assert.New(t)

defer os.Unsetenv("CONFIG_FILE")
defer os.RemoveAll("config.yaml")

os.Setenv("CONFIG_FILE", "config.yaml")

n := Config{
IgnoreNodeReasons: []string{"reason-1", "reason_2", "reason.with.dot", "reason/with/slash"},
}
yamlData, _ := yaml.Marshal(&n)
os.WriteFile("config.yaml", yamlData, 0644)

cfg, _ := LoadConfig()
assert.NotNil(cfg)
assert.Equal([]string{"reason-1", "reason_2", "reason.with.dot", "reason/with/slash"}, cfg.IgnoreNodeReasons)
}
8 changes: 7 additions & 1 deletion handler/processNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package handler

import (
"fmt"

"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -28,6 +27,13 @@ func (h *handler) ProcessNode(eventType string, obj runtime.Object) {
if c.Type == corev1.NodeReady {
if c.Status == corev1.ConditionFalse && !h.memory.HasNode(node.Name) {
logrus.Printf("node %s is not ready: %s", node.Name, c.Reason)
// Skip alert if Reason is in IgnoreNodeReasons
for _, ignoreReason := range h.config.IgnoreNodeReasons {
if c.Reason == ignoreReason {
logrus.Printf("Skipping Notify for node %s due to ignored reason: %s", node.Name, c.Reason)
return
}
}
h.alertManager.Notify(fmt.Sprintf("Node %s is not ready: %s - %s",
node.Name,
c.Reason,
Expand Down