-
Notifications
You must be signed in to change notification settings - Fork 0
fix(dns): don't emit ClusterDNSDown when clusterDomains empty (unmasks pod probe) #29
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package network | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/supporttools/node-doctor/pkg/types" | ||
| ) | ||
|
|
||
| // newFailureTrackingMonitor builds a minimal DNSMonitor sufficient to exercise | ||
| // updateFailureTracking with the given cluster domains. | ||
| func newFailureTrackingMonitor(clusterDomains []string) *DNSMonitor { | ||
| return &DNSMonitor{ | ||
| config: &DNSMonitorConfig{ | ||
| ClusterDomains: clusterDomains, | ||
| FailureCountThreshold: 3, | ||
| SuccessRateTracking: &SuccessRateConfig{Enabled: false, WindowSize: 10}, | ||
| }, | ||
| clusterSuccessTracker: NewRingBuffer(10), | ||
| externalSuccessTracker: NewRingBuffer(10), | ||
| } | ||
| } | ||
|
|
||
| func hasConditionType(s *types.Status, condType string) bool { | ||
| for _, c := range s.Conditions { | ||
| if c.Type == condType { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // TestClusterDNSDownNotEmittedWhenClusterDomainsEmpty verifies the fix for the | ||
| // two-monitor conflict: when clusterDomains is empty (in-agent cluster check disabled | ||
| // because a hostNetwork agent can't resolve ClusterIP cluster records), the DNS monitor | ||
| // must NOT emit ClusterDNSDown — otherwise its unconditional False would mask the | ||
| // pod-network cluster-dns-pod monitor's True. | ||
| func TestClusterDNSDownNotEmittedWhenClusterDomainsEmpty(t *testing.T) { | ||
| m := newFailureTrackingMonitor(nil) // no cluster domains | ||
|
|
||
| // Even a "healthy" cluster result must not emit ClusterDNSDown. | ||
| s := types.NewStatus("test-dns") | ||
| m.updateFailureTracking(true, true, s) | ||
| if hasConditionType(s, "ClusterDNSDown") { | ||
| t.Errorf("ClusterDNSDown must NOT be emitted when clusterDomains is empty, got conditions: %+v", s.Conditions) | ||
| } | ||
|
|
||
| // Even repeated cluster "failures" must not emit ClusterDNSDown when disabled. | ||
| for i := 0; i < 5; i++ { | ||
| s = types.NewStatus("test-dns") | ||
| m.updateFailureTracking(false, true, s) | ||
| } | ||
| if hasConditionType(s, "ClusterDNSDown") { | ||
| t.Errorf("ClusterDNSDown must NOT be emitted when clusterDomains is empty even after failures, got: %+v", s.Conditions) | ||
| } | ||
|
|
||
| // ExternalDNSDown is unaffected — still emitted (False on healthy external). | ||
| if !hasConditionType(s, "ExternalDNSDown") { | ||
| t.Errorf("ExternalDNSDown should still be emitted regardless of clusterDomains") | ||
| } | ||
| } | ||
|
|
||
| // TestClusterDNSDownEmittedWhenClusterDomainsSet verifies the normal path still works: | ||
| // with cluster domains configured, the DNS monitor owns ClusterDNSDown as before. | ||
| func TestClusterDNSDownEmittedWhenClusterDomainsSet(t *testing.T) { | ||
| m := newFailureTrackingMonitor([]string{"kubernetes.default.svc.cluster.local"}) | ||
|
|
||
| // Healthy -> ClusterDNSDown=False. | ||
| s := types.NewStatus("test-dns") | ||
| m.updateFailureTracking(true, true, s) | ||
| if !hasCondition(s, "ClusterDNSDown", types.ConditionFalse, "ClusterDNSResolved") { | ||
| t.Errorf("expected ClusterDNSDown=False when clusterDomains set and healthy, got: %+v", s.Conditions) | ||
| } | ||
|
|
||
| // Repeated failures past threshold -> ClusterDNSDown=True. | ||
| for i := 0; i < 3; i++ { | ||
| s = types.NewStatus("test-dns") | ||
| m.updateFailureTracking(false, true, s) | ||
| } | ||
| if !hasCondition(s, "ClusterDNSDown", types.ConditionTrue, "RepeatedClusterDNSFailures") { | ||
| t.Errorf("expected ClusterDNSDown=True after threshold failures, got: %+v", s.Conditions) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
clusterDomains: []and the pod monitor is not enabled/running, this guard stops the DNS monitor from writingClusterDNSDownat all. ExistingNodeDoctorClusterDNSDown=Truevalues are preserved on startup becauseretiredDNSConditionTypesdoes not include it (pkg/exporters/kubernetes/condition_manager.go:237), and the Kubernetes exporter only updates conditions present in each status, so an upgrade or config reload from a failing cluster-domain check to disabled cluster checks leaves the old True condition latched indefinitely instead of clearing/removing it. Please either remove/clear the condition when disabling the in-agent check or ensure another owner is configured before suppressing both True and False writes.Useful? React with 👍 / 👎.