Skip to content

Commit 4cb48ce

Browse files
committed
Reapply "remove leftoever impossible to reach kubelet logs due to getHostAliases"
This reverts commit 86af906.
1 parent 86af906 commit 4cb48ce

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

pkg/util/cloudproviders/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ go_library(
1010
importpath = "github.com/DataDog/datadog-agent/pkg/util/cloudproviders",
1111
visibility = ["//visibility:public"],
1212
deps = [
13+
"//pkg/config/helper",
1314
"//pkg/config/setup",
1415
"//pkg/util/cloudproviders/alibaba",
1516
"//pkg/util/cloudproviders/azure",

pkg/util/cloudproviders/cloudproviders.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"sync"
1313
"time"
1414

15+
"github.com/DataDog/datadog-agent/pkg/config/helper"
1516
configsetup "github.com/DataDog/datadog-agent/pkg/config/setup"
1617
"github.com/DataDog/datadog-agent/pkg/util/hostname/validate"
1718
"github.com/DataDog/datadog-agent/pkg/util/kubelet"
@@ -134,16 +135,34 @@ var (
134135
hostAliasLogOnce = true
135136
)
136137

138+
// kubeletDependentHostAliasDetectors are the host-alias detectors that route through
139+
// the shared kubelet client singleton. Cluster Checks Runners are Deployment
140+
// replicas, not DaemonSets, so they are never colocated with a node's kubelet and can
141+
// never reach it.
142+
var kubeletDependentHostAliasDetectors = map[string]bool{
143+
"kubelet": true,
144+
kubernetes.CloudProviderName: true,
145+
}
146+
137147
// GetHostAliases returns the hostname aliases and the name of the possible cloud providers
138148
func GetHostAliases(ctx context.Context) ([]string, string) {
139149
aliases := []string{}
140150
cloudprovider := ""
151+
isCLCRunner := helper.IsCLCRunner(configsetup.Datadog())
141152

142153
// cloud providers endpoints can take a few seconds to answer. We're using a WaitGroup to call all of them
143154
// concurrently since GetHostAliases is called during the agent startup and is blocking.
144155
var wg sync.WaitGroup
145156

146157
for _, hostAliasesDetector := range hostAliasesDetectors {
158+
if isCLCRunner && kubeletDependentHostAliasDetectors[hostAliasesDetector.name] {
159+
// Skip probing the kubelet client singleton: it can never succeed on a
160+
// CCR and would otherwise trigger its exponential-backoff retrier and
161+
// its "Impossible to reach Kubelet" warning for no benefit.
162+
log.Debugf("Skipping %s Host Alias: Agent is a Cluster Checks Runner and has no reachable local Kubelet", hostAliasesDetector.name)
163+
continue
164+
}
165+
147166
wg.Add(1)
148167
go func(hostAliasesDetector cloudProviderAliasesDetector) {
149168
defer wg.Done()

pkg/util/cloudproviders/cloudproviders_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,55 @@ func TestCloudProviderAliases(t *testing.T) {
6464
assert.Contains(t, []string{"detector1", "detector3"}, cloudprovider)
6565
}
6666

67+
// TestCloudProviderAliasesSkipsKubeletDependentDetectorsOnCLCRunner ensures
68+
// that GetHostAliases never invokes the "kubelet" or "kubernetes" detectors
69+
// on a Cluster Checks Runner, since CCRs are Deployment replicas (not
70+
// DaemonSets) and can never reach a local kubelet.
71+
func TestCloudProviderAliasesSkipsKubeletDependentDetectorsOnCLCRunner(t *testing.T) {
72+
origDetectors := hostAliasesDetectors
73+
defer func() { hostAliasesDetectors = origDetectors }()
74+
75+
config := configmock.New(t)
76+
config.SetInTest("clc_runner_enabled", true)
77+
config.SetInTest("config_providers", []map[string]interface{}{{"name": "clusterchecks"}})
78+
79+
kubeletCalled := false
80+
kubernetesDetectorCalled := false
81+
otherDetectorCalled := false
82+
83+
hostAliasesDetectors = []cloudProviderAliasesDetector{
84+
{
85+
name: "kubelet",
86+
callback: func(_ context.Context) ([]string, error) {
87+
kubeletCalled = true
88+
return []string{"kubelet-alias"}, nil
89+
},
90+
},
91+
{
92+
name: "kubernetes",
93+
callback: func(_ context.Context) ([]string, error) {
94+
kubernetesDetectorCalled = true
95+
return []string{"kubernetes-alias"}, nil
96+
},
97+
},
98+
{
99+
name: "other",
100+
isCloudEnv: true,
101+
callback: func(_ context.Context) ([]string, error) {
102+
otherDetectorCalled = true
103+
return []string{"other-alias"}, nil
104+
},
105+
},
106+
}
107+
108+
aliases, cloudprovider := GetHostAliases(context.TODO())
109+
assert.False(t, kubeletCalled, "kubelet host alias detector should be skipped on a Cluster Checks Runner")
110+
assert.False(t, kubernetesDetectorCalled, "kubernetes host alias detector should be skipped on a Cluster Checks Runner")
111+
assert.True(t, otherDetectorCalled, "non-kubelet-dependent host alias detectors should still run on a Cluster Checks Runner")
112+
assert.Equal(t, []string{"other-alias"}, aliases)
113+
assert.Equal(t, "other", cloudprovider)
114+
}
115+
67116
func TestCloudProviderHostCCRID(t *testing.T) {
68117
origDetectors := hostCCRIDDetectors
69118
defer func() { hostCCRIDDetectors = origDetectors }()

0 commit comments

Comments
 (0)