Skip to content

Add DNS lookup plugin #1080

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

Open
wants to merge 1 commit 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
6 changes: 6 additions & 0 deletions config/network-problem-monitor.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
"reason": "ConntrackFull",
"path": "./config/plugin/network_problem.sh",
"timeout": "3s"
},
{
"type": "temporary",
"reason": "DNSUnreachable",
"path": "./config/plugin/dns_problem.sh",
"timeout": "3s"
}
]
}
24 changes: 24 additions & 0 deletions config/plugin/dns_problem.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# This plugin checks for dns network issues.

readonly OK=0
readonly NONOK=1
readonly UNKNOWN=2

readonly KUBERNETES_SERVICE='kubernetes.default'

# Check getent command is present
if ! command -v getent >/dev/null; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getent seems the most common tool available in a host, but do we want to use hosts or nslookup just in case getent is not available?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I picked it since I assumed it would be the most available. I could change the logic to fall back to other tools, if getent isn't available?
May be in this order:

  1. getent
  2. host
  3. nslookup

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be good to know what install each tool in debian and red hat per example, I think gerent comes as part as libc so that makes it pretty common

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using containers, and I don't know if that's a good idea:

Red Hat:

adrian@Adrians-MacBook-Pro:~$ docker run redhat/ubi10 getent hosts example.com
2600:1406:bc00:53::b81e:94c8 example.com
2600:1406:bc00:53::b81e:94ce example.com
2600:1408:ec00:36::1736:7f24 example.com
2600:1408:ec00:36::1736:7f31 example.com
2600:1406:3a00:21::173e:2e65 example.com
2600:1406:3a00:21::173e:2e66 example.com
adrian@Adrians-MacBook-Pro:~$ docker run redhat/ubi10 host example.com
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: exec: "host": executable file not found in $PATH

Run 'docker run --help' for more information
adrian@Adrians-MacBook-Pro:~$ docker run redhat/ubi10 nslookup example.com
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: exec: "nslookup": executable file not found in $PATH

Run 'docker run --help' for more information

Debian:

adrian@Adrians-MacBook-Pro:~$ docker run debian:latest getent hosts example.com
2600:1406:bc00:53::b81e:94c8 example.com
2600:1406:bc00:53::b81e:94ce example.com
2600:1408:ec00:36::1736:7f24 example.com
2600:1408:ec00:36::1736:7f31 example.com
2600:1406:3a00:21::173e:2e65 example.com
2600:1406:3a00:21::173e:2e66 example.com
adrian@Adrians-MacBook-Pro:~$ docker run debian:latest host example.com
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: exec: "host": executable file not found in $PATH

Run 'docker run --help' for more information
adrian@Adrians-MacBook-Pro:~$ docker run debian:latest nslookup example.com
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: exec: "nslookup": executable file not found in $PATH

Run 'docker run --help' for more information

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems getent is the way to go

echo "Could not find 'getent' - require getent"
exit $UNKNOWN
fi

# Return success if a DNS lookup to the Kubernetes host is successful
if getent hosts "${KUBERNETES_SERVICE}" >/dev/null; then
echo "DNS lookup to ${KUBERNETES_SERVICE} is working"
exit $OK
else
echo "DNS lookup to ${KUBERNETES_SERVICE} is not working"
exit $NONOK
fi