|
3 | 3 | import java.util.Map; |
4 | 4 | import java.util.concurrent.ConcurrentHashMap; |
5 | 5 |
|
6 | | -import io.javaoperatorsdk.operator.processing.expiration.Expiration; |
7 | | -import io.javaoperatorsdk.operator.processing.expiration.RetryExpiration; |
8 | 6 | import org.slf4j.Logger; |
9 | 7 | import org.slf4j.LoggerFactory; |
10 | 8 |
|
|
14 | 12 | import io.javaoperatorsdk.operator.api.reconciler.Context; |
15 | 13 | import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; |
16 | 14 | import io.javaoperatorsdk.operator.processing.GroupVersionKind; |
| 15 | +import io.javaoperatorsdk.operator.processing.expiration.Expiration; |
17 | 16 | import io.javaoperatorsdk.operator.processing.expiration.ExpirationExecution; |
| 17 | +import io.javaoperatorsdk.operator.processing.expiration.RetryExpiration; |
18 | 18 | import io.javaoperatorsdk.operator.processing.retry.GenericRetry; |
19 | 19 | import io.javaoperatorsdk.operator.processing.retry.Retry; |
20 | 20 |
|
21 | 21 | public class CRDPresentActivationCondition implements Condition<HasMetadata, HasMetadata> { |
22 | 22 |
|
23 | 23 | private static final Logger log = LoggerFactory.getLogger(CRDPresentActivationCondition.class); |
24 | 24 |
|
| 25 | + public static final int DEFAULT_EXPIRATION_INITIAL_INTERVAL = 1000; |
| 26 | + public static final int DEFAULT_EXPIRATION_INTERVAL_MULTIPLIER = 4; |
| 27 | + public static final int DEFAULT_EXPIRATION_MAX_RETRY_ATTEMPTS = 10; |
| 28 | + |
25 | 29 | /** |
26 | | - * |
27 | | - * */ |
28 | | - public static Retry DEFAULT_EXPIRATION_RETRY = new GenericRetry().setInitialInterval(2000) |
29 | | - .setIntervalMultiplier(2) |
30 | | - .setMaxAttempts(10); |
| 30 | + * The idea behind default expiration is that on cluster start there might be different phases |
| 31 | + * when CRDs and controllers are added. For a few times it will be checked if the target CRD is |
| 32 | + * not present, after it will just use the cached state. |
| 33 | + */ |
| 34 | + public static Retry DEFAULT_EXPIRATION_RETRY = |
| 35 | + new GenericRetry().setInitialInterval(DEFAULT_EXPIRATION_INITIAL_INTERVAL) |
| 36 | + .setIntervalMultiplier(DEFAULT_EXPIRATION_INTERVAL_MULTIPLIER) |
| 37 | + .setMaxAttempts(DEFAULT_EXPIRATION_MAX_RETRY_ATTEMPTS); |
31 | 38 |
|
32 | 39 | private final Map<GroupVersionKind, CRDCheckState> crdPresenceCache = new ConcurrentHashMap<>(); |
33 | 40 |
|
@@ -55,14 +62,15 @@ public boolean isMet(DependentResource<HasMetadata, HasMetadata> dependentResour |
55 | 62 | // in case of parallel execution it is only refreshed once |
56 | 63 | synchronized (crdCheckState) { |
57 | 64 | if (crdCheckState.getExpiration().isExpired()) { |
58 | | - refreshCache(crdCheckState,gvk, context.getClient()); |
| 65 | + refreshCache(crdCheckState, gvk, context.getClient()); |
59 | 66 | } |
60 | 67 | } |
61 | 68 | return crdPresenceCache.get(gvk).getCrdPresent(); |
62 | 69 | } |
63 | 70 |
|
64 | | - private void refreshCache(CRDCheckState crdCheckState, GroupVersionKind gvk, KubernetesClient client) { |
65 | | - |
| 71 | + private void refreshCache(CRDCheckState crdCheckState, GroupVersionKind gvk, |
| 72 | + KubernetesClient client) { |
| 73 | + log.debug("Refreshing cache for gvk: {}", gvk); |
66 | 74 | boolean found = client.resources(CustomResourceDefinition.class).list().getItems() |
67 | 75 | .stream().anyMatch(crd -> crd.getSpec().getNames().getKind().equals(gvk.getKind()) |
68 | 76 | && crd.getSpec().getGroup().equals(gvk.getGroup())); |
|
0 commit comments