Skip to content

Commit

Permalink
more changes in dnstest answer
Browse files Browse the repository at this point in the history
  • Loading branch information
joshisumit committed Jul 12, 2020
1 parent 0133ada commit a04e279
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
8 changes: 0 additions & 8 deletions cmd/corefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type corednsPatchValue struct {
Data *corefileValue `json:"data"`
}

type corefileValue struct {
Corefile string `json:"Corefile"`
}

func getCorefile(ns string) (string, error) {
api := Clientset.CoreV1()

Expand Down
11 changes: 8 additions & 3 deletions cmd/dnsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type DnsTestResultForDomain struct {
DomainName string `json:"domain"`
Server string `json:"server"`
Result string `json:"result"`
Answer []net.IP `json:"answer"`
Answer []string `json:"answer"`
}

type Dnstest struct {
Expand All @@ -56,6 +56,7 @@ func lookupIP(host string, server []string) *DnsTestResultForDomain {
resolver.RetryTimes = 3

//Perform each DNS query for 3 times
answer := make([]string, 0)
for i := 1; i <= 3; i++ {
log.Infof("DNS query: %s Servers: %v", host, srv)
ip, err := resolver.LookupHost(host)
Expand All @@ -65,9 +66,13 @@ func lookupIP(host string, server []string) *DnsTestResultForDomain {
continue
}
s++
log.Infof("Answer: %s A %s", host, ip)
}

for _, ipaddr := range ip {
answer = append(answer, ipaddr.String())
}
log.Infof("Answer: %s A %s %v", host, ip, answer)

log.Debugf("success: %d fail: %d domain: %s Servers: %s", s, f, host, srv)
if f > 0 {
log.Errorf("DNS query failed %d times", f)
Expand All @@ -77,7 +82,7 @@ func lookupIP(host string, server []string) *DnsTestResultForDomain {
result = "success"
}

testres.DomainName, testres.Server, testres.Result, testres.Answer = host, srv[0], result, ip
testres.DomainName, testres.Server, testres.Result, testres.Answer = host, srv[0], result, answer

return &testres
}
6 changes: 3 additions & 3 deletions cmd/verify-configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (cd *Coredns) testDNS() {

//2. Match nameserver in /etc/resolv.conf with ClusterIP ->it should match
//from the nameserver IP -> check its coredns or nodeLocalDNSCache
dnstest.Description = "tests the DNS queries against ClusterIP and two Coredns Pod IPs"
dnstest.Description = "tests the internal and external DNS queries against ClusterIP and two Coredns Pod IPs"

if rc.Nameserver[0] == cd.ClusterIP {
log.Infof("Pod's nameserver is matching to ClusterIP: %s", rc.Nameserver[0])
Expand Down Expand Up @@ -168,9 +168,9 @@ func (cd *Coredns) testDNS() {
}
}
if successCount != len(dnstest.DnsTestResultForDomains) {
dnstest.DnsResolution = "Failed"
dnstest.DnsResolution = "failed"
}
dnstest.DnsResolution = "Success"
dnstest.DnsResolution = "success"

cd.Dnstest = *dnstest
//cd.Dnstest = success
Expand Down
18 changes: 6 additions & 12 deletions pkg/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,10 @@ import (
const (
maxRetries = 10
resourceID = "resource-id"
resourceKey = "key"
tagKeyMatchValue = "kubernetes.io/cluster/"
)

type ec2MetdataClient struct {
//instanceIdentityDocument ec2metadata.EC2InstanceIdentityDocument
client ec2metadata.EC2Metadata
}

type ec2Client struct {
//client ec2.EC2
ec2ServiceClient ec2iface.EC2API
}

Expand All @@ -50,7 +43,7 @@ type ClusterInfo struct {
ClusterName string `json:"clusterName"`
ClusterSGID string `json:"clusterSecurityGroup"`
TagList []map[string]string `json:"tagList,omitempty"`
InstanceIdentityDocument ec2metadata.EC2InstanceIdentityDocument `json:"instanceDetails"`
InstanceIdentityDocument ec2metadata.EC2InstanceIdentityDocument `json:"-"`
ClusterDetails *eks.Cluster `json:"-"`
}

Expand Down Expand Up @@ -214,7 +207,7 @@ func (w *ClusterInfo) getClusterDetails(clusterName string, region string) (*eks

// getSecurityGrupRules returns SG rules based on sg-id or sg-name
func getSecurityGrupRules(sgFilter string, region string) (*ec2.SecurityGroup, error) {
ec2Client, err := newEC2Client(region)
ec2Client, _ := newEC2Client(region)
fmt.Printf("EC2 Client: %v %T\n\n", ec2Client, ec2Client)

//input := &ec2.DescribeSecurityGroupsInput{}
Expand Down Expand Up @@ -300,7 +293,7 @@ func verifyClusterSGRules(clusterSGID string, region string) (bool, bool, error)
// requires IAM policy
func verifyNaclRules(region string, vpcid string) (bool, error) {

ec2Client, err := newEC2Client(region)
ec2Client, _ := newEC2Client(region)

// NetworkAclIds: []*string{
//aws.String("acl-5fb85d36"),
Expand Down Expand Up @@ -413,11 +406,12 @@ func DiscoverClusterInfo() (*ClusterInfo, error) {
log.Infof("Fetching Clustername...")
clusterName, err := ec2Client.getClusterName(wkr1.InstanceIdentityDocument.InstanceID)
if err != nil {
log.Errorf(`Error finding required tag "kubernetes.io/cluster/clusterName" on EC2 instance : `, err)
log.Errorf("Error finding required tag %q on EC2 instance: %v", "kubernetes.io/cluster/clusterName", err)
return nil, err
}
wkr.ClusterName = clusterName
log.Infof("Clustername is :%v", clusterName)
wkr.Region = region
log.Infof("Clustername is: %v", clusterName)

log.Infof("Fetching SGs attached to an EC2 instance")
sgID, err := wkr.getAttachedSG()
Expand Down

0 comments on commit a04e279

Please sign in to comment.