This repository has been archived by the owner on Jun 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to check if the dns is ready (#81)
* readiness: add a way to check if the dns is ready * dns: include a prometheus counter
- Loading branch information
1 parent
a7d20c4
commit 24008b0
Showing
311 changed files
with
40,671 additions
and
96 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 was deleted.
Oops, something went wrong.
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,74 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2018 Datadog, Inc. | ||
|
||
package run | ||
|
||
import ( | ||
"fmt" | ||
"github.com/golang/glog" | ||
"github.com/miekg/dns" | ||
"os/exec" | ||
"strings" | ||
"time" | ||
) | ||
|
||
func (r *Runtime) applyManifests() error { | ||
if r.state.IsKubectlApplied() { | ||
glog.V(5).Infof("Kubectl is already applied") | ||
return nil | ||
} | ||
glog.Infof("Calling kubectl apply -f %s ...", r.env.GetManifestsPathToApply()) | ||
b, err := exec.Command(r.env.GetHyperkubePath(), "kubectl", "--kubeconfig", r.env.GetKubeconfigInsecurePath(), "apply", "-f", r.env.GetManifestsPathToApply()).CombinedOutput() | ||
output := string(b) | ||
if err != nil { | ||
glog.Errorf("Cannot apply manifests %v:\n%s", err, output) | ||
return err | ||
} | ||
glog.V(2).Infof("Successfully applied manifests:\n%s", output) | ||
r.state.SetKubectlApplied() | ||
return nil | ||
} | ||
|
||
func (r *Runtime) checkInClusterDNS() error { | ||
if r.dnsQueriesForReadiness == nil { | ||
glog.V(2).Infof("No dns query supplied for readiness condition, skipping") | ||
return nil | ||
} | ||
c := dns.Client{Timeout: time.Millisecond * 500} | ||
for _, query := range r.dnsQueriesForReadiness { | ||
if !strings.HasSuffix(query, ".") { | ||
// dns: domain must be fully qualified | ||
query = query + "." | ||
} | ||
dnsMessage := &dns.Msg{} | ||
dnsMessage.SetQuestion(query, dns.TypeA) | ||
resp, _, err := c.Exchange(dnsMessage, r.env.GetDNSClusterIP()+":53") | ||
if err != nil { | ||
glog.V(4).Infof("Cannot run DNS query: %v", err) | ||
// err message can be like: | ||
// - read udp 192.168.1.12:60449->192.168.254.2:53: i/o timeout | ||
// - write udp 192.168.1.12:42766->192.168.254.2:53: write: operation not permitted | ||
i := strings.Index(err.Error(), "->") | ||
if i == -1 { | ||
// log all messages if the basic parsing failed, | ||
// this is not ideal but enough for this use case | ||
i = 0 | ||
glog.Warningf("DNS error: %v, this is blocking the readiness", err) | ||
} | ||
r.state.SetDNSLastError(fmt.Sprintf("query %s %s", query, err.Error()[i:])) | ||
return err | ||
} | ||
if len(resp.Answer) == 0 { | ||
r.state.SetDNSLastError("No DNS results for " + query) | ||
return err | ||
} | ||
var dnsResults []string | ||
for _, ans := range resp.Answer { | ||
dnsResults = append(dnsResults, strings.Replace(ans.String(), "\t", " ", -1)) | ||
} | ||
glog.V(2).Infof("DNS query: %s", strings.Join(dnsResults, " ")) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.