Skip to content

fix: special IT failing test case #1836

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 5 commits into from
Mar 28, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.time.Duration;

import org.junit.jupiter.api.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
Expand Down Expand Up @@ -34,7 +36,7 @@
/**
* The test relies on a special api server configuration: "min-request-timeout" to have a very low
* value (in case want to try with minikube use: "minikube start
* --extra-config=apiserver.min-request-timeout=3")
* --extra-config=apiserver.min-request-timeout=1")
*
* <p>
* This is important when tests are affected by permission changes, since the watch permissions are
Expand All @@ -45,16 +47,19 @@
* The test ends with "ITS" (Special) since it needs to run separately from other ITs
* </p>
*/
@EnableKubeAPIServer(apiServerFlags = {"--min-request-timeout", "3"})
@EnableKubeAPIServer(apiServerFlags = {"--min-request-timeout", "1"})
class InformerRelatedBehaviorITS {

private static final Logger log = LoggerFactory.getLogger(InformerRelatedBehaviorITS.class);

public static final String TEST_RESOURCE_NAME = "test1";
public static final String ADDITIONAL_NAMESPACE_SUFFIX = "-additional";

KubernetesClient adminClient = new KubernetesClientBuilder().build();
InformerRelatedBehaviorTestReconciler reconciler;
String actualNamespace;
String additionalNamespace;
Operator operator;
volatile boolean replacementStopHandlerCalled = false;

@BeforeEach
Expand All @@ -72,8 +77,11 @@ void beforeEach(TestInfo testInfo) {

@AfterEach
void cleanup() {
adminClient.resource(testCustomResource()).delete();
if (operator != null) {
operator.stop(Duration.ofSeconds(1));
}
adminClient.resource(dependentConfigMap()).delete();
adminClient.resource(testCustomResource()).delete();
}

@Test
Expand All @@ -90,7 +98,7 @@ void startsUpWhenNoPermissionToCustomResource() {
adminClient.resource(testCustomResource()).createOrReplace();
setNoCustomResourceAccess();

var operator = startOperator(false);
operator = startOperator(false);
assertNotReconciled();
assertRuntimeInfoNoCRPermission(operator);

Expand All @@ -106,7 +114,7 @@ void startsUpWhenNoPermissionToSecondaryResource() {
adminClient.resource(testCustomResource()).createOrReplace();
setNoConfigMapAccess();

var operator = startOperator(false);
operator = startOperator(false);
assertNotReconciled();
assertRuntimeInfoForSecondaryPermission(operator);

Expand All @@ -120,7 +128,7 @@ void startsUpIfNoPermissionToOneOfTwoNamespaces() {
adminClient.resource(namespace(additionalNamespace)).createOrReplace();

addRoleBindingsToTestNamespaces();
var operator = startOperator(false, false, actualNamespace, additionalNamespace);
operator = startOperator(false, false, actualNamespace, additionalNamespace);
assertInformerNotWatchingForAdditionalNamespace(operator);

adminClient.resource(testCustomResource()).createOrReplace();
Expand Down Expand Up @@ -151,17 +159,18 @@ private void assertInformerNotWatchingForAdditionalNamespace(Operator operator)
assertThat(configMapHealthIndicator.isWatching()).isFalse();
}


@Test
void resilientForLoosingPermissionForCustomResource() {
setFullResourcesAccess();
startOperator(true);
operator = startOperator(true);
setNoCustomResourceAccess();

waitForWatchReconnect();

adminClient.resource(testCustomResource()).createOrReplace();

assertNotReconciled();

setFullResourcesAccess();
assertReconciled();
}
Expand Down Expand Up @@ -210,7 +219,7 @@ void notExitingWithDefaultStopHandlerIfErrorHappensOnStartup() {

private static void waitForWatchReconnect() {
try {
Thread.sleep(6000);
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import java.util.concurrent.atomic.AtomicInteger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.fabric8.kubernetes.client.KubernetesClient;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent;
import io.javaoperatorsdk.operator.processing.event.ResourceID;
import io.javaoperatorsdk.operator.support.TestExecutionInfoProvider;

@ControllerConfiguration(
Expand All @@ -18,6 +22,9 @@
public class InformerRelatedBehaviorTestReconciler
implements Reconciler<InformerRelatedBehaviorTestCustomResource>, TestExecutionInfoProvider {

private static final Logger log =
LoggerFactory.getLogger(InformerRelatedBehaviorTestReconciler.class);

public static final String INFORMER_RELATED_BEHAVIOR_TEST_RECONCILER =
"InformerRelatedBehaviorTestReconciler";
public static final String CONFIG_MAP_DEPENDENT_RESOURCE = "ConfigMapDependentResource";
Expand All @@ -30,6 +37,7 @@ public UpdateControl<InformerRelatedBehaviorTestCustomResource> reconcile(
InformerRelatedBehaviorTestCustomResource resource,
Context<InformerRelatedBehaviorTestCustomResource> context) {
numberOfExecutions.addAndGet(1);
log.info("Reconciled for: {}", ResourceID.fromResource(resource));
return UpdateControl.noUpdate();
}

Expand Down