-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #2514: SharedIndexInformer watches only pods of its own namespace…
… when run in the cluster
- Loading branch information
1 parent
579d972
commit 77f74db
Showing
17 changed files
with
495 additions
and
274 deletions.
There are no files selected for viewing
This file contains 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
77 changes: 53 additions & 24 deletions
77
kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/OperationContext.java
Large diffs are not rendered by default.
Oops, something went wrong.
50 changes: 25 additions & 25 deletions
50
...c/main/java/io/fabric8/kubernetes/client/dsl/internal/CustomResourceOperationContext.java
Large diffs are not rendered by default.
Oops, something went wrong.
86 changes: 43 additions & 43 deletions
86
...s-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/PodOperationContext.java
Large diffs are not rendered by default.
Oops, something went wrong.
48 changes: 24 additions & 24 deletions
48
...ient/src/main/java/io/fabric8/kubernetes/client/dsl/internal/RollingOperationContext.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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
116 changes: 116 additions & 0 deletions
116
...etes-client/src/test/java/io/fabric8/kubernetes/client/dsl/base/OperationContextTest.java
This file contains 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,116 @@ | ||
package io.fabric8.kubernetes.client.dsl.base; | ||
|
||
import io.fabric8.kubernetes.api.model.DeletionPropagation; | ||
import io.fabric8.kubernetes.api.model.batch.Job; | ||
import io.fabric8.kubernetes.api.model.batch.JobBuilder; | ||
import io.fabric8.kubernetes.client.Config; | ||
import okhttp3.OkHttpClient; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.util.Collections; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.when; | ||
|
||
class OperationContextTest { | ||
private OkHttpClient okHttpClient; | ||
private Config config; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
this.okHttpClient = Mockito.mock(OkHttpClient.class, Mockito.RETURNS_DEEP_STUBS); | ||
this.config = Mockito.mock(Config.class, Mockito.RETURNS_DEEP_STUBS); | ||
} | ||
|
||
|
||
@Test | ||
void testNamespaceIsSetFromGlobalConfiguration() { | ||
// Given | ||
OperationContext operationContext = new OperationContext(); | ||
when(config.getNamespace()).thenReturn("namespace-from-config"); | ||
|
||
// When | ||
operationContext = operationContext | ||
.withConfig(config); | ||
|
||
// Then | ||
assertNotNull(operationContext); | ||
assertTrue(operationContext.isNamespaceFromGlobalConfig()); | ||
assertEquals("namespace-from-config", operationContext.getNamespace()); | ||
} | ||
|
||
@Test | ||
void testNamespaceIsSetFromOperationContext() { | ||
// Given | ||
OperationContext operationContext = new OperationContext(); | ||
when(config.getNamespace()).thenReturn("namespace-from-config"); | ||
|
||
// When | ||
operationContext = operationContext | ||
.withNamespace("operation-namespace") | ||
.withConfig(config); | ||
|
||
// Then | ||
assertNotNull(operationContext); | ||
assertFalse(operationContext.isNamespaceFromGlobalConfig()); | ||
assertEquals("operation-namespace", operationContext.getNamespace()); | ||
} | ||
|
||
@Test | ||
void testCompeteOperationContext() { | ||
// Given | ||
OperationContext operationContext = new OperationContext(); | ||
|
||
// When | ||
operationContext = operationContext.withNamespace("operation-namespace") | ||
.withName("operand-name") | ||
.withConfig(config) | ||
.withApiGroupName("batch") | ||
.withApiGroupVersion("v1") | ||
.withOkhttpClient(okHttpClient) | ||
.withPlural("jobs") | ||
.withItem(new JobBuilder().withNewMetadata().withName("testItem").endMetadata().build()) | ||
.withCascading(false) | ||
.withLabels(Collections.singletonMap("test", "labels")) | ||
.withLabelsIn(Collections.singletonMap("test", new String[]{"labelsIn1", "labelsIn2"})) | ||
.withLabelsNot(Collections.singletonMap("test", new String[]{"labelsNot"})) | ||
.withLabelsNotIn(Collections.singletonMap("test", new String[]{"labelsNotIn"})) | ||
.withFields(Collections.singletonMap("test", "field")) | ||
.withFieldsNot(Collections.singletonMap("test", new String[]{"fieldsNot"})) | ||
.withResourceVersion("234343") | ||
.withReloadingFromServer(false) | ||
.withGracePeriodSeconds(0) | ||
.withPropagationPolicy(DeletionPropagation.BACKGROUND) | ||
.withWatchRetryInitialBackoffMillis(0) | ||
.withWatchRetryBackoffMultiplier(1.0F); | ||
|
||
// Then | ||
assertNotNull(operationContext); | ||
assertEquals("operation-namespace", operationContext.getNamespace()); | ||
assertEquals("operand-name", operationContext.getName()); | ||
assertEquals("batch", operationContext.getApiGroupName()); | ||
assertEquals("v1", operationContext.getApiGroupVersion()); | ||
assertEquals("jobs", operationContext.getPlural()); | ||
assertNotNull(operationContext.getItem()); | ||
assertTrue(operationContext.getItem() instanceof Job); | ||
assertFalse(operationContext.getCascading()); | ||
assertEquals("labels", operationContext.getLabels().get("test")); | ||
assertArrayEquals(new String[]{"labelsIn1", "labelsIn2"}, operationContext.getLabelsIn().get("test")); | ||
assertArrayEquals(new String[]{"labelsNot"}, operationContext.getLabelsNot().get("test")); | ||
assertArrayEquals(new String[]{"labelsNotIn"}, operationContext.getLabelsNotIn().get("test")); | ||
assertEquals("field", operationContext.getFields().get("test")); | ||
assertArrayEquals(new String[]{ "fieldsNot"}, operationContext.getFieldsNot().get("test")); | ||
assertEquals("234343", operationContext.getResourceVersion()); | ||
assertFalse(operationContext.getReloadingFromServer()); | ||
assertEquals(0, operationContext.getGracePeriodSeconds()); | ||
assertEquals(DeletionPropagation.BACKGROUND, operationContext.getPropagationPolicy()); | ||
assertEquals(0, operationContext.getWatchRetryInitialBackoffMillis()); | ||
assertEquals(1.0F, operationContext.getWatchRetryBackoffMultiplier()); | ||
} | ||
} |
This file contains 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 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
Oops, something went wrong.