|
2 | 2 |
|
3 | 3 | import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
|
4 | 4 | import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusUpdateControl;
|
| 5 | +import io.javaoperatorsdk.operator.sample.customresource.WebPage; |
| 6 | +import io.javaoperatorsdk.operator.sample.customresource.WebPageStatus; |
5 | 7 |
|
6 | 8 | import static io.javaoperatorsdk.operator.ReconcilerUtils.loadYaml;
|
7 | 9 |
|
8 | 10 | public class Utils {
|
9 | 11 |
|
10 | 12 | private Utils() {}
|
11 | 13 |
|
12 |
| - static WebPageStatus createStatus(String configMapName) { |
| 14 | + public static WebPageStatus createStatus(String configMapName) { |
13 | 15 | WebPageStatus status = new WebPageStatus();
|
14 | 16 | status.setHtmlConfigMap(configMapName);
|
15 | 17 | status.setAreWeGood(true);
|
16 | 18 | status.setErrorMessage(null);
|
17 | 19 | return status;
|
18 | 20 | }
|
19 | 21 |
|
20 |
| - static String configMapName(WebPage nginx) { |
| 22 | + public static String configMapName(WebPage nginx) { |
21 | 23 | return nginx.getMetadata().getName() + "-html";
|
22 | 24 | }
|
23 | 25 |
|
24 |
| - static String deploymentName(WebPage nginx) { |
| 26 | + public static String deploymentName(WebPage nginx) { |
25 | 27 | return nginx.getMetadata().getName();
|
26 | 28 | }
|
27 | 29 |
|
28 |
| - static String serviceName(WebPage webPage) { |
| 30 | + public static String serviceName(WebPage webPage) { |
29 | 31 | return webPage.getMetadata().getName();
|
30 | 32 | }
|
31 | 33 |
|
32 |
| - static ErrorStatusUpdateControl<WebPage> handleError(WebPage resource, Exception e) { |
| 34 | + public static ErrorStatusUpdateControl<WebPage> handleError(WebPage resource, Exception e) { |
33 | 35 | resource.getStatus().setErrorMessage("Error: " + e.getMessage());
|
34 | 36 | return ErrorStatusUpdateControl.updateStatus(resource);
|
35 | 37 | }
|
36 | 38 |
|
37 |
| - static void simulateErrorIfRequested(WebPage webPage) throws ErrorSimulationException { |
| 39 | + public static void simulateErrorIfRequested(WebPage webPage) throws ErrorSimulationException { |
38 | 40 | if (webPage.getSpec().getHtml().contains("error")) {
|
39 | 41 | // special case just to showcase error if doing a demo
|
40 | 42 | throw new ErrorSimulationException("Simulating error");
|
41 | 43 | }
|
42 | 44 | }
|
43 | 45 |
|
44 |
| - static boolean isValidHtml(WebPage webPage) { |
| 46 | + public static boolean isValidHtml(WebPage webPage) { |
45 | 47 | // very dummy html validation
|
46 | 48 | var lowerCaseHtml = webPage.getSpec().getHtml().toLowerCase();
|
47 | 49 | return lowerCaseHtml.contains("<html>") && lowerCaseHtml.contains("</html>");
|
48 | 50 | }
|
49 | 51 |
|
50 |
| - static WebPage setInvalidHtmlErrorMessage(WebPage webPage) { |
| 52 | + public static WebPage setInvalidHtmlErrorMessage(WebPage webPage) { |
51 | 53 | if (webPage.getStatus() == null) {
|
52 | 54 | webPage.setStatus(new WebPageStatus());
|
53 | 55 | }
|
54 | 56 | webPage.getStatus().setErrorMessage("Invalid html.");
|
55 | 57 | return webPage;
|
56 | 58 | }
|
57 | 59 |
|
58 |
| - static Ingress makeDesiredIngress(WebPage webPage) { |
| 60 | + public static Ingress makeDesiredIngress(WebPage webPage) { |
59 | 61 | Ingress ingress = loadYaml(Ingress.class, Utils.class, "ingress.yaml");
|
60 | 62 | ingress.getMetadata().setName(webPage.getMetadata().getName());
|
61 | 63 | ingress.getMetadata().setNamespace(webPage.getMetadata().getNamespace());
|
|
0 commit comments