Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Ignore specific errors for given pods #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ func (c *Controller) handlePod(pod *v1.Pod) error {
if err != nil {
return err
}

if isIgnoredErrorForPod(pod.Name, containerLogs) {
continue
}

if containerLogs == "" {
containerLogs = "• No Logs Before Restart\n"
} else {
Expand Down
2 changes: 2 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ spec:
value: {{ .Values.watchedPodNamePrefixes | quote}}
- name: IGNORED_POD_NAME_PREFIXES
value: {{ .Values.ignoredPodNamePrefixes | quote}}
- name: IGNORED_ERRORS_FOR_POD_NAME_PREFIXES
value: {{ .Values.ignoredErrorsForPodNamePrefixes | quote}}
- name: IGNORE_RESTARTS_WITH_EXIT_CODE_ZERO
value: {{ .Values.ignoreRestartsWithExitCodeZero | quote}}
- name: SLACK_WEBHOOK_URL
Expand Down
4 changes: 4 additions & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ ignoredNamespaces: ""
# A set of pod name prefixes to be ignored. This should be provided as a comma-separated list or a regular expression.
ignoredPodNamePrefixes: ""

# A json map with specific errors to ignore from specific pods
# {"podName": ["error 1", "error 2"]}
ignoredErrorsForPodNamePrefixes: ""

# A set of namespaces to be watched. This should be provided as a comma-separated list or a regular expression.
watchedNamespaces: ""
# A set of pod name prefixes to be watched. This should be provided as a comma-separated list or a regular expression.
Expand Down
28 changes: 28 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"encoding/json"
"os"
"regexp"
"sort"
Expand Down Expand Up @@ -60,6 +61,33 @@ func isIgnoredPod(name string) bool {
return false
}

func isIgnoredErrorForPod(podName string, errorLog string) bool {
ignoredErrorsForPodNamePrefixesEnv := os.Getenv("IGNORED_ERRORS_FOR_POD_NAME_PREFIXES")
if ignoredErrorsForPodNamePrefixesEnv == "" {
return false
}

podErrorsMap := make(map[string][]interface{})
err := json.Unmarshal([]byte(ignoredErrorsForPodNamePrefixesEnv), &podErrorsMap)
if err != nil {
klog.Infof("Failed to load IGNORED_ERRORS_FOR_POD_NAME_PREFIXES with error: %s", err)
return false
}

for key, errors := range podErrorsMap {
if strings.HasPrefix(podName, key) {
for _, ignoredError := range errors {
if strings.Contains(errorLog, ignoredError.(string)) {
klog.Infof("Ignore: pod %s has ignored error: %s\n", podName, ignoredError)
return true
}
}
}
}

return false
}

func isWatchedNamespace(namespace string) bool {
watchedNamespacesEnv := os.Getenv("WATCHED_NAMESPACES")
if watchedNamespacesEnv == "" {
Expand Down