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

[#303]fix-Failed_to_get_the_dns_service_IP_list #306

Merged
Merged
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 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},
{"ENV_DNS_SERVICE_SELECT_LABEL_KEY", "kubernetes.io/name", &AgentConfig.DnsServiceSelectLabelKey},
{"ENV_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
Loading