-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Fix service discovery bug in kubernetes-extensions
#19139
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
Show all changes
16 commits
Select commit
Hold shift + click to select a range
dbe34a8
Potential fix
capistrant e539452
self review iteration
capistrant cb71279
minor fixes
capistrant fcce511
clarify why remapping modified to added is safe
capistrant 474c33f
Add more info about how readiness probes come into play for k8s disco…
capistrant 23af381
more comment and log cleanup
capistrant 1340130
Fix doc spelling
capistrant 23f557e
refactor to make reasoning about new behavior more easy
capistrant 27cefc1
Merge branch 'master' into k8s-discovery-bug
capistrant f8f057b
Merge branch 'master' into k8s-discovery-bug
capistrant 106fe38
change example in docs to new readiness probe
capistrant 5ca2069
Fix tests file
capistrant d2f7c1b
Merge branch 'master' into k8s-discovery-bug
capistrant 0a9b72f
Some doc sharpening
capistrant 4e1db73
add some common k8s language to spelling
capistrant 818bffc
Address review comments on log noiseness and javadocs
capistrant 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
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
107 changes: 107 additions & 0 deletions
107
...etes-extensions/src/test/java/org/apache/druid/k8s/discovery/DefaultK8sApiClientTest.java
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,107 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.druid.k8s.discovery; | ||
|
|
||
| import io.kubernetes.client.openapi.models.V1ContainerStatus; | ||
| import io.kubernetes.client.openapi.models.V1Pod; | ||
| import io.kubernetes.client.openapi.models.V1PodStatus; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
|
|
||
| public class DefaultK8sApiClientTest | ||
| { | ||
| @Test | ||
| public void testIsPodReady_nullStatus() | ||
| { | ||
| V1Pod pod = new V1Pod(); | ||
| Assertions.assertFalse(DefaultK8sApiClient.isPodReady(pod)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsPodReady_nullContainerStatuses() | ||
| { | ||
| V1Pod pod = new V1Pod(); | ||
| pod.setStatus(new V1PodStatus()); | ||
| Assertions.assertFalse(DefaultK8sApiClient.isPodReady(pod)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsPodReady_emptyContainerStatuses() | ||
| { | ||
| V1Pod pod = new V1Pod(); | ||
| V1PodStatus status = new V1PodStatus(); | ||
| status.setContainerStatuses(Collections.emptyList()); | ||
| pod.setStatus(status); | ||
| Assertions.assertFalse(DefaultK8sApiClient.isPodReady(pod)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsPodReady_allContainersReady() | ||
| { | ||
| V1Pod pod = new V1Pod(); | ||
| V1PodStatus status = new V1PodStatus(); | ||
| V1ContainerStatus cs = new V1ContainerStatus(); | ||
| cs.setReady(true); | ||
| status.setContainerStatuses(Collections.singletonList(cs)); | ||
| pod.setStatus(status); | ||
| Assertions.assertTrue(DefaultK8sApiClient.isPodReady(pod)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsPodReady_containerNotReady() | ||
| { | ||
| V1Pod pod = new V1Pod(); | ||
| V1PodStatus status = new V1PodStatus(); | ||
| V1ContainerStatus cs = new V1ContainerStatus(); | ||
| cs.setReady(false); | ||
| status.setContainerStatuses(Collections.singletonList(cs)); | ||
| pod.setStatus(status); | ||
| Assertions.assertFalse(DefaultK8sApiClient.isPodReady(pod)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsPodReady_mixedContainerReadiness() | ||
| { | ||
| V1Pod pod = new V1Pod(); | ||
| V1PodStatus status = new V1PodStatus(); | ||
| V1ContainerStatus cs1 = new V1ContainerStatus(); | ||
| cs1.setReady(true); | ||
| V1ContainerStatus cs2 = new V1ContainerStatus(); | ||
| cs2.setReady(false); | ||
| status.setContainerStatuses(Arrays.asList(cs1, cs2)); | ||
| pod.setStatus(status); | ||
| Assertions.assertFalse(DefaultK8sApiClient.isPodReady(pod)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsPodReady_containerReadyNull() | ||
| { | ||
| V1Pod pod = new V1Pod(); | ||
| V1PodStatus status = new V1PodStatus(); | ||
| V1ContainerStatus cs = new V1ContainerStatus(); | ||
| // ready is null (not set) | ||
| status.setContainerStatuses(Collections.singletonList(cs)); | ||
| pod.setStatus(status); | ||
| Assertions.assertFalse(DefaultK8sApiClient.isPodReady(pod)); | ||
| } | ||
| } |
Oops, something went wrong.
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.
This class used to be a relatively thin layer over k8s watches, now there's remapping and synthetic events going on. The javadoc of this class should make clear that it's not meant to be a thin layer over k8s watches, it's meant to be aligned with the needs of service discovery.