Skip to content

Commit

Permalink
retry policy in some commands for knative installation
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor Graziano authored and vitorz committed Mar 31, 2023
1 parent b2a8c6d commit 0c89805
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@
<artifactId>failsafe-okhttp</artifactId>
<version>${failsafe-version}</version>
</dependency>
<dependency>
<groupId>dev.failsafe</groupId>
<artifactId>failsafe</artifactId>
<version>${failsafe-version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
6 changes: 6 additions & 0 deletions system-x/services/knative/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
<version>1.0-SNAPSHOT</version>
<name>TNB :: System-X :: Services :: Knative</name>

<dependencies>
<dependency>
<groupId>dev.failsafe</groupId>
<artifactId>failsafe</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@

import com.google.auto.service.AutoService;

import java.io.IOException;
import java.time.Duration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cz.xtf.core.openshift.helpers.ResourceParsers;
import dev.failsafe.Failsafe;
import dev.failsafe.FailsafeException;
import dev.failsafe.RetryPolicy;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.client.KubernetesClientTimeoutException;
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext;

@AutoService(Knative.class)
Expand Down Expand Up @@ -83,12 +87,17 @@ public void create() {

// Create eventing and serving custom resource
try {
OpenshiftClient.get().customResource(EVENTING_CTX).inNamespace(EVENTING_NAMESPACE)
.createOrReplace(createCr("KnativeEventing", EVENTING_CR_NAME, EVENTING_NAMESPACE));
OpenshiftClient.get().customResource(SERVING_CTX).inNamespace(SERVING_NAMESPACE)
.createOrReplace(createCr("KnativeServing", SERVING_CR_NAME, SERVING_NAMESPACE));
} catch (IOException e) {
fail("Unable to create custom resources: ", e);
RetryPolicy<Void> retryPolicy = RetryPolicy.<Void>builder()
.handle(KubernetesClientTimeoutException.class)
.withDelay(Duration.ofSeconds(5))
.withMaxRetries(3)
.build();
Failsafe.with(retryPolicy).run(() -> OpenshiftClient.get().customResource(EVENTING_CTX).inNamespace(EVENTING_NAMESPACE)
.createOrReplace(createCr("KnativeEventing", EVENTING_CR_NAME, EVENTING_NAMESPACE)));
Failsafe.with(retryPolicy).run(() -> OpenshiftClient.get().customResource(SERVING_CTX).inNamespace(SERVING_NAMESPACE)
.createOrReplace(createCr("KnativeServing", SERVING_CR_NAME, SERVING_NAMESPACE)));
} catch (FailsafeException e) {
fail("Unable to create custom resources: ", e.getCause());
}
}

Expand Down

0 comments on commit 0c89805

Please sign in to comment.