Skip to content

Commit 87af075

Browse files
authored
Revert "Stop reporting fake Ready status in WLM based on AD annotation" (#37722)
1 parent 68e3ce1 commit 87af075

File tree

8 files changed

+22
-37
lines changed

8 files changed

+22
-37
lines changed

comp/core/autodiscovery/listeners/container.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ import (
2626
)
2727

2828
const (
29-
newIdentifierLabel = "com.datadoghq.ad.check.id"
30-
legacyIdentifierLabel = "com.datadoghq.sd.check.id"
31-
tolerateUnreadyAnnotation = "ad.datadoghq.com/tolerate-unready"
29+
newIdentifierLabel = "com.datadoghq.ad.check.id"
30+
legacyIdentifierLabel = "com.datadoghq.sd.check.id"
3231
)
3332

3433
// ContainerListener listens to container creation through a subscription to the
@@ -130,7 +129,7 @@ func (l *ContainerListener) createContainerService(entity workloadmeta.Entity) {
130129

131130
if pod != nil {
132131
svc.hosts = map[string]string{"pod": pod.IP}
133-
svc.ready = pod.Ready || shouldSkipPodReadiness(pod)
132+
svc.ready = pod.Ready
134133

135134
svc.metricsExcluded = l.IsExcluded(
136135
containers.MetricsFilter,
@@ -229,11 +228,3 @@ func computeContainerServiceIDs(entity string, image string, labels map[string]s
229228
}
230229
return ids
231230
}
232-
233-
func shouldSkipPodReadiness(pod *workloadmeta.KubernetesPod) bool {
234-
tolerate, ok := pod.Annotations[tolerateUnreadyAnnotation]
235-
if !ok {
236-
return false
237-
}
238-
return tolerate == "true"
239-
}

comp/core/autodiscovery/listeners/container_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ func TestCreateContainerService(t *testing.T) {
144144
Annotations: map[string]string{
145145
fmt.Sprintf("ad.datadoghq.com/%s.exclude", kubernetesContainer.Name): `false`,
146146
fmt.Sprintf("ad.datadoghq.com/%s.exclude", kubernetesExcludedContainer.Name): `true`,
147-
tolerateUnreadyAnnotation: `true`,
148147
},
149148
},
150149
Containers: []workloadmeta.OrchestratorContainer{
@@ -294,7 +293,7 @@ func TestCreateContainerService(t *testing.T) {
294293
},
295294
hosts: map[string]string{"pod": pod.IP},
296295
ports: []ContainerPort{},
297-
ready: true,
296+
ready: pod.Ready,
298297
},
299298
},
300299
},

comp/core/autodiscovery/listeners/kubelet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (l *KubeletListener) createContainerService(
160160
svc := &service{
161161
entity: container,
162162
tagsHash: l.tagger.GetEntityHash(types.NewEntityID(types.ContainerID, container.ID), types.ChecksConfigCardinality),
163-
ready: pod.Ready || shouldSkipPodReadiness(pod),
163+
ready: pod.Ready,
164164
ports: ports,
165165
extraConfig: map[string]string{
166166
"pod_name": pod.Name,

comp/core/autodiscovery/listeners/kubelet_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ func TestKubeletCreateContainerService(t *testing.T) {
141141

142142
podWithMetricsExcludeAnnotation := podWithAnnotations.DeepCopy().(*workloadmeta.KubernetesPod)
143143
podWithMetricsExcludeAnnotation.Annotations[fmt.Sprintf("ad.datadoghq.com/%s.metrics_exclude", containerName)] = `true`
144-
podWithMetricsExcludeAnnotation.Annotations[tolerateUnreadyAnnotation] = `true`
145144

146145
podWithLogsExcludeAnnotation := podWithAnnotations.DeepCopy().(*workloadmeta.KubernetesPod)
147146
podWithLogsExcludeAnnotation.Annotations[fmt.Sprintf("ad.datadoghq.com/%s.logs_exclude", containerName)] = `true`
@@ -473,7 +472,6 @@ func TestKubeletCreateContainerService(t *testing.T) {
473472
},
474473
metricsExcluded: true,
475474
tagger: taggerComponent,
476-
ready: true,
477475
},
478476
},
479477
},

comp/core/workloadmeta/collectors/util/kubernetes_resource_parsers/pod.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ func (p podParser) Parse(obj interface{}) workloadmeta.Entity {
4242
})
4343
}
4444

45+
var ready bool
46+
for _, condition := range pod.Status.Conditions {
47+
if condition.Type == corev1.PodReady {
48+
if condition.Status == corev1.ConditionTrue {
49+
ready = true
50+
}
51+
break
52+
}
53+
}
54+
4555
var pvcNames []string
4656
for _, volume := range pod.Spec.Volumes {
4757
if volume.PersistentVolumeClaim != nil {
@@ -96,7 +106,7 @@ func (p podParser) Parse(obj interface{}) workloadmeta.Entity {
96106
Phase: string(pod.Status.Phase),
97107
Owners: owners,
98108
PersistentVolumeClaimNames: pvcNames,
99-
Ready: isPodReady(pod),
109+
Ready: ready,
100110
IP: pod.Status.PodIP,
101111
PriorityClass: pod.Spec.PriorityClassName,
102112
QOSClass: string(pod.Status.QOSClass),
@@ -105,18 +115,3 @@ func (p podParser) Parse(obj interface{}) workloadmeta.Entity {
105115
Containers: containersList,
106116
}
107117
}
108-
109-
// Should be aligned with pkg/util/kubernetes/kubelet/kubelet.go
110-
// (Except the static pods that should go away as fixed long time ago)
111-
func isPodReady(pod *corev1.Pod) bool {
112-
if pod.Status.Phase != corev1.PodRunning {
113-
return false
114-
}
115-
116-
for _, condition := range pod.Status.Conditions {
117-
if condition.Type == corev1.PodReady {
118-
return condition.Status == corev1.ConditionTrue
119-
}
120-
}
121-
return false
122-
}

comp/core/workloadmeta/collectors/util/kubernetes_resource_parsers/pod_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This product includes software developed at Datadog (https://www.datadoghq.com/).
44
// Copyright 2016-present Datadog, Inc.
55

6-
//go:build kubeapiserver
6+
//go:build kubeapiserver && test
77

88
package kubernetesresourceparsers
99

pkg/util/kubernetes/kubelet/kubelet.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,8 @@ func (ku *KubeUtil) GetPodForContainerID(ctx context.Context, containerID string
371371
return pod, nil
372372
}
373373

374-
// Error is not nil
375374
// Retry with cache invalidation
376-
if errors.IsNotFound(err) {
375+
if err != nil && errors.IsNotFound(err) {
377376
log.Debugf("Cannot get container %q: %s, retrying without cache...", containerID, err)
378377
pods, err = ku.ForceGetLocalPodList(ctx)
379378
if err != nil {
@@ -507,6 +506,9 @@ func IsPodReady(pod *Pod) bool {
507506
return false
508507
}
509508

509+
if tolerate, ok := pod.Metadata.Annotations[unreadyAnnotation]; ok && tolerate == "true" {
510+
return true
511+
}
510512
for _, status := range pod.Status.Conditions {
511513
if status.Type == "Ready" && status.Status == "True" {
512514
return true

pkg/util/kubernetes/kubelet/podwatcher_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (suite *PodwatcherTestSuite) TestPodWatcherComputeChangesInConditions() {
113113
require.Nil(suite.T(), err)
114114
require.Len(suite.T(), changes, 2)
115115
assert.Equal(suite.T(), "nginx", changes[0].Spec.Containers[0].Name)
116-
require.False(suite.T(), IsPodReady(changes[0]))
116+
require.True(suite.T(), IsPodReady(changes[0]))
117117
}
118118

119119
func (suite *PodwatcherTestSuite) TestPodWatcherWithInitContainers() {

0 commit comments

Comments
 (0)