Skip to content

feat: update pod status logic #214

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 7 commits into from
Jun 4, 2025
Merged

Conversation

obs-gh-alexlew
Copy link
Collaborator

Description

OB-XXX Please explain the changes you made here.

Checklist

  • Created tests which fail without the change (if possible)
  • Extended the README / documentation, if necessary

Copy link

@orca-security-us orca-security-us bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

@obs-gh-alexlew obs-gh-alexlew changed the title feat: update logic to match new printer logic feat: update pod status logic Jun 2, 2025
@obs-gh-alexlew
Copy link
Collaborator Author

tested in my sandbox instance and things look reasonable

Comment on lines +50 to +54
if condition.Type != v1.PodInitialized {
continue
}

return condition.Status == v1.ConditionTrue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change this to

Suggested change
if condition.Type != v1.PodInitialized {
continue
}
return condition.Status == v1.ConditionTrue
if condition.Type == v1.PodInitialized && condition.Status == v1.ConditionTrue {
return true
}

to match hasPodReadyCondition

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumping this one

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually just helper code I copied from the same kubectl code, if its semantically the same i'd prefer to leave it in case that helper code changes in the future as well it'll be easier to copy/compare

Comment on lines 131 to 136
case isRestartableInitContainer(initContainers[container.Name]) &&
container.Started != nil && *container.Started:
if container.Ready {
readyContainers++
}
continue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in the switch statement? It could skip the default case and miss setting the reason there.

Comment on lines 81 to 86
restarts := 0
restartableInitContainerRestarts := 0
totalContainers := len(pod.Spec.Containers)
readyContainers := 0
lastRestartDate := metav1.NewTime(time.Time{})
lastRestartableInitContainerRestartDate := metav1.NewTime(time.Time{})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of these new variables don't seem to be used for anything; is this coming in a follow up?

},
},
// { // Tests that we don't override/drop other facets computed in OTTL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you replace these deleted tests with new ones?

Comment on lines 79 to 82
restarts := 0
restartableInitContainerRestarts := 0
totalContainers := len(pod.Spec.Containers)
readyContainers := 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still looks like these four variables are unused.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so here's the logic in datadog agent https://github.com/DataDog/datadog-agent/blob/7d47d25899c025c8b3e5ba91e488fa0f97f7a275/pkg/collector/corechecks/cluster/orchestrator/transformers/k8s/pod.go#L220 they also only use status but kept the rest of the logic so that they can just copy paste it over

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think the argument for taking it out is that its unnecessary computation / more efficient which i agree with but its a slight preference vs. way better imo

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I'm happy with where you landed!

If we need to change it again, I think it could be more clear to have a helper that returns all values and is very explicitly full copy/paste. Then we could call that and extra only what we want

Comment on lines +50 to +54
if condition.Type != v1.PodInitialized {
continue
}

return condition.Status == v1.ConditionTrue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumping this one

Comment on lines 79 to 82
restarts := 0
restartableInitContainerRestarts := 0
totalContainers := len(pod.Spec.Containers)
readyContainers := 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I'm happy with where you landed!

If we need to change it again, I think it could be more clear to have a helper that returns all values and is very explicitly full copy/paste. Then we could call that and extra only what we want

@obs-gh-alexlew obs-gh-alexlew merged commit d1dbf1e into main Jun 4, 2025
12 checks passed
@obs-gh-alexlew obs-gh-alexlew deleted the alew/update-status-logic branch June 4, 2025 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants