Skip to content

Commit

Permalink
[#303]fix-Failed_to_get_the_dns_service_IP_list
Browse files Browse the repository at this point in the history
  • Loading branch information
carryaimp committed Nov 6, 2023
1 parent 8f17d25 commit a533252
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/agentDnsServer/appDnsServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ func SetupAppDnsServer(rootLogger *zap.Logger, tlsCert, tlsKey string) {
if err != nil {
logger.Sugar().Fatalf("failed get kube dns service,err: %v", err)
}

// If the ip address list is empty, the corresponding service does not exist or the selected label is incorrect
if len(dnsServiceIPs) == 0 {
logger.Sugar().Fatalf("failed get kube dns service: %v", "the corresponding service does not exist or the selected label is incorrect")
}

logger.Sugar().Infof("kube dns service %s ", dnsServiceIPs)
coreDnsAddr = fmt.Sprintf("%s:53", dnsServiceIPs[0])
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/k8ObjManager/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package k8sObjManager
import (
"context"
"fmt"
"github.com/kdoctor-io/kdoctor/pkg/types"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -98,9 +99,11 @@ func (nm *k8sObjManager) ListServicesDnsIP(ctx context.Context) ([]string, error
serviceList := new(corev1.ServiceList)
var err error
var result []string

label := map[string]string{
"k8s-app": "kube-dns",
types.AgentConfig.DnsServiceSelectLabelKey: types.AgentConfig.DnsServiceSelectLabelValue,
}

ListOption := &client.ListOptions{
Namespace: "kube-system",
LabelSelector: labels.SelectorFromSet(label),
Expand Down
6 changes: 6 additions & 0 deletions pkg/types/agent_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var AgentEnvMapping = []EnvMapping{
{"ENV_CLUSTER_DNS_DOMAIN", "cluster.local", &AgentConfig.ClusterDnsDomain},
{"ENV_LOCAL_NODE_IP", "", &AgentConfig.LocalNodeIP},
{"ENV_LOCAL_NODE_NAME", "", &AgentConfig.LocalNodeName},
{"DNS_SERVICE_SELECT_LABEL_KEY", "kubernetes.io/name", &AgentConfig.DnsServiceSelectLabelKey},
{"DNS_SERVICE_SELECT_LABEL_VALUE", "CoreDNS", &AgentConfig.DnsServiceSelectLabelValue},
}

type AgentConfigStruct struct {
Expand All @@ -51,6 +53,10 @@ type AgentConfigStruct struct {
LocalNodeIP string
LocalNodeName string

// dns selector label
DnsServiceSelectLabelKey string
DnsServiceSelectLabelValue string

EnableAggregateAgentReport bool
DirPathAgentReport string
CleanAgedReportInMinute int32
Expand Down

0 comments on commit a533252

Please sign in to comment.