|
| 1 | +package io.javaoperatorsdk.operator; |
| 2 | + |
| 3 | +import java.time.Duration; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | +import org.junit.jupiter.api.Timeout; |
| 7 | + |
| 8 | +import io.fabric8.kubernetes.api.model.ConfigMap; |
| 9 | +import io.fabric8.kubernetes.client.ConfigBuilder; |
| 10 | +import io.fabric8.kubernetes.client.KubernetesClient; |
| 11 | +import io.fabric8.kubernetes.client.KubernetesClientBuilder; |
| 12 | +import io.javaoperatorsdk.operator.api.reconciler.Context; |
| 13 | +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; |
| 14 | +import io.javaoperatorsdk.operator.api.reconciler.Reconciler; |
| 15 | +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; |
| 16 | + |
| 17 | +class InformerErrorHandlerStartIT { |
| 18 | + /** |
| 19 | + * Test showcases that the operator starts even if there is no access right for some resource. |
| 20 | + */ |
| 21 | + @Test |
| 22 | + @Timeout(5) |
| 23 | + void operatorStart() { |
| 24 | + KubernetesClient client = new KubernetesClientBuilder() |
| 25 | + .withConfig(new ConfigBuilder() |
| 26 | + .withImpersonateUsername("user-with-no-rights") |
| 27 | + .build()) |
| 28 | + .build(); |
| 29 | + |
| 30 | + Operator operator = new Operator(o -> o |
| 31 | + .withKubernetesClient(client) |
| 32 | + .withStopOnInformerErrorDuringStartup(false) |
| 33 | + .withCacheSyncTimeout(Duration.ofSeconds(2))); |
| 34 | + operator.register(new ConfigMapReconciler()); |
| 35 | + operator.start(); |
| 36 | + } |
| 37 | + |
| 38 | + @ControllerConfiguration |
| 39 | + public static class ConfigMapReconciler implements Reconciler<ConfigMap> { |
| 40 | + @Override |
| 41 | + public UpdateControl<ConfigMap> reconcile(ConfigMap resource, Context<ConfigMap> context) |
| 42 | + throws Exception { |
| 43 | + return UpdateControl.noUpdate(); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | +} |
0 commit comments