Skip to content

[Backport 7.67.x] Revert "Stop reporting fake Ready status in WLM based on AD annotation" #37737

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

Merged
merged 1 commit into from
Jun 10, 2025
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
15 changes: 3 additions & 12 deletions comp/core/autodiscovery/listeners/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import (
)

const (
newIdentifierLabel = "com.datadoghq.ad.check.id"
legacyIdentifierLabel = "com.datadoghq.sd.check.id"
tolerateUnreadyAnnotation = "ad.datadoghq.com/tolerate-unready"
newIdentifierLabel = "com.datadoghq.ad.check.id"
legacyIdentifierLabel = "com.datadoghq.sd.check.id"
)

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

if pod != nil {
svc.hosts = map[string]string{"pod": pod.IP}
svc.ready = pod.Ready || shouldSkipPodReadiness(pod)
svc.ready = pod.Ready

svc.metricsExcluded = l.IsExcluded(
containers.MetricsFilter,
Expand Down Expand Up @@ -229,11 +228,3 @@ func computeContainerServiceIDs(entity string, image string, labels map[string]s
}
return ids
}

func shouldSkipPodReadiness(pod *workloadmeta.KubernetesPod) bool {
tolerate, ok := pod.Annotations[tolerateUnreadyAnnotation]
if !ok {
return false
}
return tolerate == "true"
}
3 changes: 1 addition & 2 deletions comp/core/autodiscovery/listeners/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ func TestCreateContainerService(t *testing.T) {
Annotations: map[string]string{
fmt.Sprintf("ad.datadoghq.com/%s.exclude", kubernetesContainer.Name): `false`,
fmt.Sprintf("ad.datadoghq.com/%s.exclude", kubernetesExcludedContainer.Name): `true`,
tolerateUnreadyAnnotation: `true`,
},
},
Containers: []workloadmeta.OrchestratorContainer{
Expand Down Expand Up @@ -294,7 +293,7 @@ func TestCreateContainerService(t *testing.T) {
},
hosts: map[string]string{"pod": pod.IP},
ports: []ContainerPort{},
ready: true,
ready: pod.Ready,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion comp/core/autodiscovery/listeners/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (l *KubeletListener) createContainerService(
svc := &service{
entity: container,
tagsHash: l.tagger.GetEntityHash(types.NewEntityID(types.ContainerID, container.ID), types.ChecksConfigCardinality),
ready: pod.Ready || shouldSkipPodReadiness(pod),
ready: pod.Ready,
ports: ports,
extraConfig: map[string]string{
"pod_name": pod.Name,
Expand Down
2 changes: 0 additions & 2 deletions comp/core/autodiscovery/listeners/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func TestKubeletCreateContainerService(t *testing.T) {

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

podWithLogsExcludeAnnotation := podWithAnnotations.DeepCopy().(*workloadmeta.KubernetesPod)
podWithLogsExcludeAnnotation.Annotations[fmt.Sprintf("ad.datadoghq.com/%s.logs_exclude", containerName)] = `true`
Expand Down Expand Up @@ -473,7 +472,6 @@ func TestKubeletCreateContainerService(t *testing.T) {
},
metricsExcluded: true,
tagger: taggerComponent,
ready: true,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ func (p podParser) Parse(obj interface{}) workloadmeta.Entity {
})
}

var ready bool
for _, condition := range pod.Status.Conditions {
if condition.Type == corev1.PodReady {
if condition.Status == corev1.ConditionTrue {
ready = true
}
break
}
}

var pvcNames []string
for _, volume := range pod.Spec.Volumes {
if volume.PersistentVolumeClaim != nil {
Expand Down Expand Up @@ -96,7 +106,7 @@ func (p podParser) Parse(obj interface{}) workloadmeta.Entity {
Phase: string(pod.Status.Phase),
Owners: owners,
PersistentVolumeClaimNames: pvcNames,
Ready: isPodReady(pod),
Ready: ready,
IP: pod.Status.PodIP,
PriorityClass: pod.Spec.PriorityClassName,
QOSClass: string(pod.Status.QOSClass),
Expand All @@ -105,18 +115,3 @@ func (p podParser) Parse(obj interface{}) workloadmeta.Entity {
Containers: containersList,
}
}

// Should be aligned with pkg/util/kubernetes/kubelet/kubelet.go
// (Except the static pods that should go away as fixed long time ago)
func isPodReady(pod *corev1.Pod) bool {
if pod.Status.Phase != corev1.PodRunning {
return false
}

for _, condition := range pod.Status.Conditions {
if condition.Type == corev1.PodReady {
return condition.Status == corev1.ConditionTrue
}
}
return false
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//go:build kubeapiserver
//go:build kubeapiserver && test

package kubernetesresourceparsers

Expand Down
6 changes: 4 additions & 2 deletions pkg/util/kubernetes/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,8 @@ func (ku *KubeUtil) GetPodForContainerID(ctx context.Context, containerID string
return pod, nil
}

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

if tolerate, ok := pod.Metadata.Annotations[unreadyAnnotation]; ok && tolerate == "true" {
return true
}
for _, status := range pod.Status.Conditions {
if status.Type == "Ready" && status.Status == "True" {
return true
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/kubernetes/kubelet/podwatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (suite *PodwatcherTestSuite) TestPodWatcherComputeChangesInConditions() {
require.Nil(suite.T(), err)
require.Len(suite.T(), changes, 2)
assert.Equal(suite.T(), "nginx", changes[0].Spec.Containers[0].Name)
require.False(suite.T(), IsPodReady(changes[0]))
require.True(suite.T(), IsPodReady(changes[0]))
}

func (suite *PodwatcherTestSuite) TestPodWatcherWithInitContainers() {
Expand Down