├── .gitignore ├── LICENSE.md ├── README.adoc ├── configuration └── settings.xml ├── pom.xml └── src ├── main ├── java │ └── io │ │ └── fabric8 │ │ └── quickstarts │ │ └── camel │ │ └── Application.java ├── jkube │ └── deployment.yml └── resources │ ├── application.properties │ ├── logback.xml │ └── spring │ └── camel-context.xml └── test └── java └── io └── fabric8 └── tests └── integration ├── KubernetesIntegrationKT.java └── support ├── KubernetesTestConfig.java ├── KubernetesTestDeployer.java ├── KubernetesTestSetup.java └── KubernetesTestUtil.java /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .idea 3 | *.iml 4 | *.im 5 | *.ipr 6 | *.iws 7 | overlays 8 | .DS_Store 9 | .settings 10 | *.swp 11 | *.log 12 | .project 13 | .classpath 14 | *.fmd 15 | .cache 16 | dependency-reduced-pom.xml 17 | .vagrant/ 18 | .vscode/ -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = Spring-Boot Camel QuickStart 2 | 3 | This example demonstrates how you can use Apache Camel with Spring Boot 4 | based on a https://github.com/fabric8io/base-images#java-base-images['fabric8 Java base image']. 5 | 6 | The quickstart uses Spring Boot to configure a little application that includes a Camel 7 | route that triggers a message every 5th second, and routes the message to a log. 8 | 9 | The application utilizes the Spring http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/ImportResource.html[`@ImportResource`] annotation to load a Camel Context definition via a _src/main/resources/spring/camel-context.xml_ file on the classpath. 10 | 11 | IMPORTANT: This quickstart can run in 2 modes: standalone on your machine and on Kubernetes / OpenShift Cluster. Quickstart requires Java 8 or Java 11 (`fuse-java-openshift-jdk11-rhel8` image is used to build in Java 11). 12 | 13 | == Deployment options 14 | 15 | You can run this quickstart in the following modes: 16 | 17 | * Kubernetes / Single-node OpenShift cluster 18 | * Standalone on your machine 19 | 20 | The most effective way to run this quickstart is to deploy and run the project on OpenShift. 21 | 22 | For more details about running this quickstart on a single-node OpenShift cluster, CI/CD deployments, as well as the rest of the runtime, see the link:http://appdev.openshift.io/docs/spring-boot-runtime.html[Spring Boot Runtime Guide]. 23 | 24 | == Running the Quickstart on a single-node Kubernetes/OpenShift cluster 25 | 26 | IMPORTANT: You need to run this example on Container Development Kit 3.3 or OpenShift 3.7. 27 | Both of these products have suitable Fuse images pre-installed. 28 | If you run it in an environment where those images are not preinstalled follow the steps described in <>. 29 | 30 | A single-node Kubernetes/OpenShift cluster provides you with access to a cloud environment that is similar to a production environment. 31 | 32 | If you have a single-node Kubernetes/OpenShift cluster, such as Minishift or the Red Hat Container Development Kit, link:http://appdev.openshift.io/docs/minishift-installation.html[installed and running], you can deploy your quickstart there. 33 | 34 | 35 | . Log in to your OpenShift cluster: 36 | + 37 | [source,bash,options="nowrap",subs="attributes+"] 38 | ---- 39 | $ oc login -u developer -p developer 40 | ---- 41 | 42 | . Create a new OpenShift project for the quickstart: 43 | + 44 | [source,bash,options="nowrap",subs="attributes+"] 45 | ---- 46 | $ oc new-project MY_PROJECT_NAME 47 | ---- 48 | 49 | . Change the directory to the folder that contains the extracted quickstart application (for example, `my_openshift/spring-boot-camel`) : 50 | + 51 | or 52 | + 53 | [source,bash,options="nowrap",subs="attributes+"] 54 | ---- 55 | $ cd my_openshift/spring-boot-camel 56 | ---- 57 | 58 | . Build and deploy the project to the OpenShift cluster: 59 | + 60 | [source,bash,options="nowrap",subs="attributes+"] 61 | ---- 62 | $ mvn clean -DskipTests oc:deploy -Popenshift 63 | ---- 64 | 65 | . In your browser, navigate to the `MY_PROJECT_NAME` project in the OpenShift console. 66 | Wait until you can see that the pod for the `spring-boot-camel` has started up. 67 | 68 | . On the project's `Overview` page, navigate to the details page deployment of the `spring-boot-camel` application: `https://OPENSHIFT_IP_ADDR:8443/console/project/MY_PROJECT_NAME/browse/rc/spring-boot-camel-NUMBER_OF_DEPLOYMENT?tab=details`. 69 | 70 | . Switch to tab `Logs` and then see the messages sent by Camel. 71 | 72 | [#single-node-without-preinstalled-images] 73 | === Running the Quickstart on a single-node Kubernetes/OpenShift cluster without preinstalled images 74 | 75 | A single-node Kubernetes/OpenShift cluster provides you with access to a cloud environment that is similar to a production environment. 76 | 77 | If you have a single-node Kubernetes/OpenShift cluster, such as Minishift or the Red Hat Container Development Kit, link:http://appdev.openshift.io/docs/minishift-installation.html[installed and running], you can deploy your quickstart there. 78 | 79 | 80 | . Log in to your OpenShift cluster: 81 | + 82 | [source,bash,options="nowrap",subs="attributes+"] 83 | ---- 84 | $ oc login -u developer -p developer 85 | ---- 86 | 87 | . Create a new OpenShift project for the quickstart: 88 | + 89 | [source,bash,options="nowrap",subs="attributes+"] 90 | ---- 91 | $ oc new-project MY_PROJECT_NAME 92 | ---- 93 | 94 | . Configure Red Hat Container Registry authentication (if it is not configured). 95 | Follow https://access.redhat.com/documentation/en-us/red_hat_fuse/7.13/html-single/fuse_on_openshift_guide/index#configure-container-registry[documentation]. 96 | 97 | . Import base images in your newly created project (MY_PROJECT_NAME): 98 | + 99 | [source,bash,options="nowrap",subs="attributes+"] 100 | ---- 101 | $ oc import-image fuse-java-openshift:1.13 --from=registry.redhat.io/fuse7/fuse-java-openshift-rhel8:1.13 --confirm 102 | ---- 103 | 104 | . Change the directory to the folder that contains the extracted quickstart application (for example, `my_openshift/spring-boot-camel`) : 105 | + 106 | or 107 | + 108 | [source,bash,options="nowrap",subs="attributes+"] 109 | ---- 110 | $ cd my_openshift/spring-boot-camel 111 | ---- 112 | 113 | . Build and deploy the project to the OpenShift cluster: 114 | + 115 | [source,bash,options="nowrap",subs="attributes+"] 116 | ---- 117 | $ mvn clean -DskipTests oc:deploy -Popenshift -Djkube.generator.fromMode=istag -Djkube.generator.from=MY_PROJECT_NAME/fuse-java-openshift:1.13 118 | ---- 119 | 120 | . In your browser, navigate to the `MY_PROJECT_NAME` project in the OpenShift console. 121 | Wait until you can see that the pod for the `spring-boot-camel` has started up. 122 | 123 | . On the project's `Overview` page, navigate to the details page deployment of the `spring-boot-camel` application: `https://OPENSHIFT_IP_ADDR:8443/console/project/MY_PROJECT_NAME/browse/pods/spring-boot-camel-xml-NUMBER_OF_DEPLOYMENT?tab=details`. 124 | 125 | . Switch to tab `Logs` and then see the messages sent by Camel. 126 | 127 | == Integration Testing 128 | 129 | The example includes a Kubernetes Integration Test. 130 | Once the container image has been built and deployed in Kubernetes, the integration test can be run with: 131 | 132 | [source,bash,options="nowrap",subs="attributes+"] 133 | ---- 134 | mvn test -Dtest=*KT 135 | ---- 136 | 137 | The test is disabled by default and has to be enabled using `-Dtest`. 138 | 139 | == Running the quickstart standalone on your machine 140 | To run this quickstart as a standalone project on your local machine: 141 | 142 | . Download the project and extract the archive on your local filesystem. 143 | . Build the project: 144 | + 145 | [source,bash,options="nowrap",subs="attributes+"] 146 | ---- 147 | $ cd PROJECT_DIR 148 | $ mvn clean package 149 | ---- 150 | . Run the service: 151 | 152 | + 153 | [source,bash,options="nowrap",subs="attributes+"] 154 | ---- 155 | $ mvn spring-boot:run 156 | ---- 157 | . See the messages sent by Camel. 158 | -------------------------------------------------------------------------------- /configuration/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | fusesource.repo 32 | 33 | 34 | maven.central 35 | Maven Central 36 | https://repo1.maven.org/maven2 37 | 38 | false 39 | 40 | 41 | true 42 | never 43 | 44 | 45 | 46 | redhat.ga 47 | Red Hat General Availability Repository 48 | https://maven.repository.redhat.com/ga 49 | 50 | false 51 | 52 | 53 | true 54 | never 55 | 56 | 57 | 58 | redhat.earlyaccess 59 | Red Hat General Early Access Repository 60 | https://maven.repository.redhat.com/earlyaccess 61 | 62 | false 63 | 64 | 65 | true 66 | never 67 | 68 | 69 | 70 | fusesource.m2 71 | FuseSource Community Release Repository 72 | https://repo.fusesource.com/nexus/content/groups/public 73 | 74 | false 75 | 76 | 77 | true 78 | never 79 | 80 | 81 | 82 | fusesource.ea 83 | FuseSource Community Early Access Release Repository 84 | https://repo.fusesource.com/nexus/content/groups/ea 85 | 86 | false 87 | 88 | 89 | true 90 | never 91 | 92 | 93 | 94 | 95 | 96 | maven.central 97 | Maven Central 98 | https://repo1.maven.org/maven2 99 | 100 | false 101 | 102 | 103 | true 104 | never 105 | 106 | 107 | 108 | redhat.ga 109 | Red Hat General Availability Repository 110 | https://maven.repository.redhat.com/ga 111 | 112 | false 113 | 114 | 115 | true 116 | never 117 | 118 | 119 | 120 | redhat.earlyaccess 121 | Red Hat General Early Access Repository 122 | https://maven.repository.redhat.com/earlyaccess 123 | 124 | false 125 | 126 | 127 | true 128 | never 129 | 130 | 131 | 132 | fusesource.m2 133 | FuseSource Community Release Repository 134 | https://repo.fusesource.com/nexus/content/groups/public 135 | 136 | false 137 | 138 | 139 | true 140 | never 141 | 142 | 143 | 144 | fusesource.ea 145 | FuseSource Community Early Access Release Repository 146 | https://repo.fusesource.com/nexus/content/groups/ea 147 | 148 | false 149 | 150 | 151 | true 152 | never 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | fusesource.repo 161 | 162 | 163 | 164 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 4.0.0 23 | 24 | io.fabric8.quickstarts 25 | spring-boot-camel 26 | 1.0-SNAPSHOT 27 | 28 | Fabric8 :: Quickstarts :: Spring-Boot :: Camel 29 | Spring Boot example running a Camel route 30 | 31 | 32 | UTF-8 33 | UTF-8 34 | 35 | 36 | 7.12.0.fuse-7_12_0-00016-redhat-00001 37 | 1.13 38 | 39 | 40 | 3.7.0 41 | 2.22.2 42 | 43 | 44 | 45 | 46 | 47 | org.jboss.redhat-fuse 48 | fuse-springboot-bom 49 | ${fuse.bom.version} 50 | pom 51 | import 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-starter-actuator 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-starter-web 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-starter-tomcat 70 | 71 | 72 | 73 | 74 | org.springframework.boot 75 | spring-boot-starter-undertow 76 | 77 | 78 | 79 | org.apache.camel 80 | camel-spring-boot-starter 81 | 82 | 83 | 84 | 85 | 86 | 87 | io.fabric8 88 | kubernetes-model 89 | test 90 | 91 | 92 | 93 | io.fabric8 94 | kubernetes-client 95 | test 96 | 97 | 98 | 99 | io.fabric8 100 | openshift-client 101 | 4.6.2 102 | test 103 | 104 | 105 | 106 | junit 107 | junit 108 | test 109 | 110 | 111 | 112 | 113 | spring-boot:run 114 | 115 | 116 | 117 | org.apache.maven.plugins 118 | maven-compiler-plugin 119 | ${maven-compiler-plugin.version} 120 | 121 | 1.8 122 | 1.8 123 | 124 | 125 | 126 | org.apache.maven.plugins 127 | maven-surefire-plugin 128 | ${maven-surefire-plugin.version} 129 | true 130 | 131 | 3 132 | 133 | **/*KT.java 134 | 135 | 136 | 137 | 138 | 139 | org.jboss.redhat-fuse 140 | spring-boot-maven-plugin 141 | ${fuse.bom.version} 142 | 143 | 144 | 145 | repackage 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | openshift 157 | 158 | registry.redhat.io/fuse7/fuse-java-openshift-rhel8:${docker.image.version} 159 | 160 | 161 | 162 | 163 | org.jboss.redhat-fuse 164 | openshift-maven-plugin 165 | ${fuse.bom.version} 166 | 167 | 168 | 169 | resource 170 | build 171 | apply 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | com.company 181 | Red_Hat 182 | 183 | 184 | rht.prod_name 185 | Red_Hat_Integration 186 | 187 | 188 | rht.prod_ver 189 | 7.13.0 190 | 191 | 192 | rht.comp 193 | spring-boot-camel 194 | 195 | 196 | rht.comp_ver 197 | ${fuse.bom.version} 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | java11 209 | 210 | registry.redhat.io/fuse7/fuse-java-openshift-jdk11-rhel8:${docker.image.version} 211 | 212 | 213 | [11,17) 214 | 215 | 216 | 217 | java17 218 | 219 | registry.redhat.io/fuse7/fuse-java-openshift-jdk17-rhel8:${docker.image.version} 220 | 221 | 222 | [17,) 223 | 224 | 225 | 226 | 227 | 228 | 229 | redhat-ga-repository 230 | https://maven.repository.redhat.com/ga 231 | 232 | true 233 | 234 | 235 | false 236 | 237 | 238 | 239 | redhat-ea-repository 240 | https://maven.repository.redhat.com/earlyaccess/all 241 | 242 | true 243 | 244 | 245 | false 246 | 247 | 248 | 249 | 250 | 251 | 252 | redhat-ga-repository 253 | https://maven.repository.redhat.com/ga 254 | 255 | true 256 | 257 | 258 | false 259 | 260 | 261 | 262 | redhat-ea-repository 263 | https://maven.repository.redhat.com/earlyaccess/all 264 | 265 | true 266 | 267 | 268 | false 269 | 270 | 271 | 272 | 273 | -------------------------------------------------------------------------------- /src/main/java/io/fabric8/quickstarts/camel/Application.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2005-2016 Red Hat, Inc. 3 | * 4 | * Red Hat licenses this file to you under the Apache License, version 5 | * 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | package io.fabric8.quickstarts.camel; 17 | 18 | import org.apache.camel.builder.RouteBuilder; 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.context.annotation.ImportResource; 22 | 23 | /** 24 | * A spring-boot application that includes a Camel route builder to setup the Camel routes 25 | */ 26 | @SpringBootApplication 27 | @ImportResource({"classpath:spring/camel-context.xml"}) 28 | public class Application extends RouteBuilder { 29 | 30 | // must have a main method spring-boot can run 31 | public static void main(String[] args) { 32 | SpringApplication.run(Application.class, args); 33 | } 34 | 35 | @Override 36 | public void configure() throws Exception { 37 | from("timer://foo?period=5000") 38 | .setBody().constant("Hello World") 39 | .log(">>> ${body}"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/jkube/deployment.yml: -------------------------------------------------------------------------------- 1 | spec: 2 | template: 3 | spec: 4 | containers: 5 | - 6 | resources: 7 | requests: 8 | cpu: "0.2" 9 | memory: 256Mi 10 | limits: 11 | cpu: "1.0" 12 | memory: 256Mi 13 | env: 14 | - name: SPRING_APPLICATION_JSON 15 | value: '{"server":{"undertow":{"io-threads":1, "worker-threads":2 }}}' 16 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.config=classpath:logback.xml 2 | 3 | # the options from org.apache.camel.spring.boot.CamelConfigurationProperties can be configured here 4 | camel.springboot.name=MyCamel 5 | 6 | # lets listen on all ports to ensure we can be invoked from the pod IP 7 | server.address=0.0.0.0 8 | management.address=0.0.0.0 9 | 10 | # lets use a different management port in case you need to listen to HTTP requests on 8080 11 | management.server.port=8081 12 | 13 | # disable all management enpoints except health 14 | management.endpoints.enabled-by-default=false 15 | management.endpoint.health.enabled=true -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/main/resources/spring/camel-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 18 | 19 | -------------------------------------------------------------------------------- /src/test/java/io/fabric8/tests/integration/KubernetesIntegrationKT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005-2016 Red Hat, Inc. 3 | * 4 | * Red Hat licenses this file to you under the Apache License, version 5 | * 2.0 (the "License"); you may not use this file except in compliance 6 | * with the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 | * implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | package io.fabric8.tests.integration; 18 | 19 | import io.fabric8.kubernetes.api.model.Pod; 20 | import io.fabric8.kubernetes.api.model.PodList; 21 | import io.fabric8.kubernetes.client.KubernetesClient; 22 | import io.fabric8.tests.integration.support.KubernetesTestConfig; 23 | import io.fabric8.tests.integration.support.KubernetesTestSetup; 24 | import org.junit.Assert; 25 | import org.junit.Test; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | import java.util.concurrent.TimeUnit; 30 | 31 | import static io.fabric8.tests.integration.support.KubernetesTestConfig.createConfig; 32 | 33 | public class KubernetesIntegrationKT { 34 | 35 | private static Logger LOG = LoggerFactory.getLogger(KubernetesIntegrationKT.class); 36 | 37 | 38 | @Test 39 | public void testAppProvisionsRunningPods() { 40 | KubernetesTestConfig config = createConfig(); 41 | KubernetesTestSetup testSetup = new KubernetesTestSetup(config); 42 | 43 | try { 44 | testSetup.setUp(); 45 | KubernetesClient client = config.getClient(); 46 | PodList podList = client.pods().inNamespace(config.getNamespace()).list(); 47 | 48 | if (podList.getItems().isEmpty()) { 49 | Assert.fail("No pods found in namespace "+ config.getNamespace()); 50 | } 51 | 52 | for (Pod pod : podList.getItems()) { 53 | try { 54 | if (!pod.getMetadata().getName().endsWith("build") && !pod.getMetadata().getName().endsWith("deploy")) { 55 | client.resource(pod) 56 | .inNamespace(config.getNamespace()) 57 | .waitUntilReady(config.getKubernetesTimeout(), TimeUnit.SECONDS); 58 | LOG.info("Pod {} is in state: {}",pod.getMetadata().getName(),pod.getStatus().getPhase()); 59 | } 60 | } catch (InterruptedException e) { 61 | Assert.fail("Timeout reached waiting for pod " + pod.getMetadata().getName()); 62 | } 63 | } 64 | } finally { 65 | testSetup.tearDown(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/io/fabric8/tests/integration/support/KubernetesTestConfig.java: -------------------------------------------------------------------------------- 1 | package io.fabric8.tests.integration.support; 2 | 3 | import io.fabric8.kubernetes.client.Config; 4 | import io.fabric8.kubernetes.client.ConfigBuilder; 5 | import io.fabric8.kubernetes.client.DefaultKubernetesClient; 6 | import io.fabric8.kubernetes.client.KubernetesClient; 7 | import org.xml.sax.SAXException; 8 | 9 | import javax.xml.parsers.ParserConfigurationException; 10 | import javax.xml.xpath.XPathExpressionException; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | import java.nio.file.Files; 14 | import java.nio.file.Paths; 15 | import java.util.HashMap; 16 | import java.util.List; 17 | import java.util.Map; 18 | import java.util.Optional; 19 | import java.util.Properties; 20 | import java.util.UUID; 21 | import java.util.function.Predicate; 22 | import java.util.regex.Pattern; 23 | import java.util.stream.Collectors; 24 | import java.util.stream.Stream; 25 | 26 | import static io.fabric8.tests.integration.support.KubernetesTestUtil.*; 27 | import static io.fabric8.tests.integration.support.KubernetesTestUtil.failNotDeployed; 28 | import static io.fabric8.tests.integration.support.KubernetesTestUtil.getArrayListStringProperty; 29 | import static io.fabric8.tests.integration.support.KubernetesTestUtil.getArtifactId; 30 | import static io.fabric8.tests.integration.support.KubernetesTestUtil.getBooleanProperty; 31 | import static io.fabric8.tests.integration.support.KubernetesTestUtil.getIntProperty; 32 | import static io.fabric8.tests.integration.support.KubernetesTestUtil.getResourceFileAsStream; 33 | import static io.fabric8.tests.integration.support.KubernetesTestUtil.getStringProperty; 34 | import static io.fabric8.tests.integration.support.KubernetesTestUtil.isNullOrEmpty; 35 | import static java.util.Collections.singletonMap; 36 | import static java.util.Objects.nonNull; 37 | 38 | 39 | public class KubernetesTestConfig { 40 | 41 | 42 | public static final String NAMESPACE_USE_CURRENT = "kt.namespace.use.current"; 43 | public static final String NAMESPACE_TO_USE = "kt.namespace.use.existing"; 44 | public static final String NAMESPACE_DESTROY_ENABLED = "kt.namespace.destroy.enabled"; 45 | public static final String NAMESPACE_PREFIX = "kt.namespace.prefix"; 46 | public static final String RESOUCE_FILE_PATH = "kt.resource.file.path"; 47 | public static final String KUBERNETES_MASTER = "kubernetes.master"; 48 | public static final String KUBERNETES_USERNAME = "kubernetes.username"; 49 | public static final String KUBERNETES_PASSWORD = "kubernetes.password"; 50 | public static final String KUBERNETES_TIMEOUT = "kubernetes.timeout"; 51 | 52 | public static final int DEFAULT_KUBERNETES_TIMEOUT = 300; 53 | public static final String ENV_DEPENDENCIES = "kt.env.dependencies"; 54 | public static final String DEFAULT_NAMESPACE_PREFIX = "ktest"; 55 | 56 | public static final String TARGET_DIR_PATH = System.getProperty("basedir", ".") + "/target"; 57 | public static final String DEFAULT_RESOUCE_FILE_PATH = TARGET_DIR_PATH + "/classes/META-INF/jkube/openshift.yml"; 58 | 59 | public static final String TEST_PROPERTIES_FILE = "kubernetesTest.properties"; 60 | 61 | 62 | private final Properties systemPropertiesVars = System.getProperties(); 63 | 64 | private boolean shouldDestroyNamespace = false; 65 | 66 | private boolean useExistingNamespace = true; 67 | 68 | private String namespace; 69 | 70 | private String resourceFilePath; 71 | 72 | private String imageStreamFilePath; 73 | 74 | private List dependencies; 75 | 76 | private String kubernetesMaster; 77 | 78 | private String kubernetesUsername; 79 | 80 | private String kubernetesPassword; 81 | 82 | private KubernetesClient kubeClient; 83 | 84 | private int kubernetesTimeout; 85 | 86 | private String mainNamespace; 87 | 88 | private Map ktestLabels = singletonMap("scope","ktest"); 89 | 90 | private KubernetesTestConfig() { 91 | } 92 | 93 | public static KubernetesTestConfig createConfig() { 94 | KubernetesTestConfig config = new KubernetesTestConfig(); 95 | config.loadConfiguration(); 96 | return config; 97 | } 98 | 99 | public KubernetesClient getClient() { 100 | if (kubeClient == null) { 101 | if (isNullOrEmpty(kubernetesMaster)) { 102 | kubeClient = new DefaultKubernetesClient(); 103 | }else { 104 | Config config = new ConfigBuilder() 105 | .withMasterUrl(kubernetesMaster) 106 | .withUsername(kubernetesUsername) 107 | .withPassword(kubernetesPassword) 108 | .build(); 109 | kubeClient = new DefaultKubernetesClient(config); 110 | } 111 | } 112 | return kubeClient; 113 | } 114 | 115 | private void loadConfiguration() { 116 | 117 | Properties prop = new Properties(); 118 | 119 | try (InputStream input = getResourceFileAsStream(TEST_PROPERTIES_FILE)) { 120 | // load a properties file 121 | if(nonNull(input)) { 122 | prop.load(input); 123 | } 124 | } catch (IOException e) { 125 | throw new RuntimeException(e); 126 | } 127 | 128 | prop.putAll(systemPropertiesVars); 129 | 130 | Map testConfig = prop.entrySet().stream().collect( 131 | Collectors.toMap( 132 | e -> String.valueOf(e.getKey()), 133 | e -> String.valueOf(e.getValue()), 134 | (prev, next) -> next, 135 | HashMap::new) 136 | ); 137 | String artifactId = null; 138 | try{ 139 | artifactId = getArtifactId(); 140 | } catch (XPathExpressionException | ParserConfigurationException |IOException| SAXException e) { 141 | failNotDeployed(); 142 | } 143 | 144 | namespace = generateNamespaceName(testConfig); 145 | 146 | resourceFilePath = getStringProperty(RESOUCE_FILE_PATH, testConfig, DEFAULT_RESOUCE_FILE_PATH); 147 | 148 | imageStreamFilePath = TARGET_DIR_PATH + "/" + artifactId + "-is.yml" ; 149 | 150 | dependencies = getArrayListStringProperty(ENV_DEPENDENCIES, testConfig); 151 | 152 | kubernetesMaster = getStringProperty(KUBERNETES_MASTER, testConfig, null); 153 | 154 | kubernetesUsername = getStringProperty(KUBERNETES_USERNAME, testConfig, null); 155 | 156 | kubernetesPassword = getStringProperty(KUBERNETES_PASSWORD, testConfig, null); 157 | 158 | kubernetesTimeout = getIntProperty(KUBERNETES_TIMEOUT,testConfig,DEFAULT_KUBERNETES_TIMEOUT); 159 | 160 | shouldDestroyNamespace = getBooleanProperty(NAMESPACE_DESTROY_ENABLED, testConfig, true); 161 | 162 | mainNamespace = extractMainNamespaceName(imageStreamFilePath); 163 | } 164 | 165 | 166 | private String generateNamespaceName(Map config) { 167 | String sessionId = UUID.randomUUID().toString().split("-")[0]; 168 | String namespace = getBooleanProperty(NAMESPACE_USE_CURRENT, config, false) 169 | ? new ConfigBuilder().build().getNamespace() 170 | : getStringProperty(NAMESPACE_TO_USE, config, null); 171 | if (isNullOrEmpty(namespace)) { 172 | namespace = getStringProperty(NAMESPACE_PREFIX, config, DEFAULT_NAMESPACE_PREFIX) + "-" + sessionId; 173 | shouldDestroyNamespace = true; 174 | useExistingNamespace = false; 175 | } 176 | return namespace; 177 | } 178 | 179 | private String extractMainNamespaceName(String imageStreamFilePath){ 180 | Pattern pattern = Pattern.compile("\\s*\"namespace\"\\s*:\\s*\"[a-z0-9]([-a-z0-9]*[a-z0-9])?\".*"); 181 | Predicate namespacePredicate = pattern.asPredicate(); 182 | 183 | Optional mainNamespace = Optional.empty(); 184 | 185 | try (Stream stream = Files.lines(Paths.get(imageStreamFilePath))) { 186 | mainNamespace = stream 187 | .filter(namespacePredicate) 188 | .map(x->pattern.matcher(x).group(1)).findFirst(); 189 | }catch (IOException e) { 190 | failNotDeployed(); 191 | } 192 | return mainNamespace.orElseGet(() -> new DefaultKubernetesClient().getNamespace()); 193 | } 194 | 195 | 196 | // Getter 197 | 198 | 199 | public String getNamespace() { 200 | return namespace; 201 | } 202 | 203 | public String getResourceFilePath() { 204 | return resourceFilePath; 205 | } 206 | 207 | public List getDependencies() { 208 | return dependencies; 209 | } 210 | 211 | public boolean isUseExistingNamespace() { 212 | return useExistingNamespace; 213 | } 214 | 215 | public boolean isShouldDestroyNamespace() { 216 | return shouldDestroyNamespace; 217 | } 218 | 219 | public int getKubernetesTimeout() { 220 | return kubernetesTimeout; 221 | } 222 | 223 | public Map getKtestLabels() { 224 | return ktestLabels; 225 | } 226 | 227 | public String getImageStreamFilePath() { 228 | return imageStreamFilePath; 229 | } 230 | 231 | public String getMainNamespace() { 232 | return mainNamespace; 233 | } 234 | } -------------------------------------------------------------------------------- /src/test/java/io/fabric8/tests/integration/support/KubernetesTestDeployer.java: -------------------------------------------------------------------------------- 1 | package io.fabric8.tests.integration.support; 2 | 3 | import io.fabric8.kubernetes.api.model.HasMetadata; 4 | import io.fabric8.kubernetes.api.model.Namespace; 5 | import io.fabric8.kubernetes.api.model.NamespaceBuilder; 6 | import io.fabric8.kubernetes.api.model.Pod; 7 | import io.fabric8.kubernetes.api.model.rbac.RoleBinding; 8 | import io.fabric8.kubernetes.api.model.rbac.RoleBindingBuilder; 9 | import io.fabric8.kubernetes.api.model.rbac.Subject; 10 | import io.fabric8.kubernetes.api.model.rbac.SubjectBuilder; 11 | import io.fabric8.kubernetes.client.KubernetesClient; 12 | import io.fabric8.kubernetes.client.KubernetesClientException; 13 | import io.fabric8.kubernetes.client.Watch; 14 | import io.fabric8.kubernetes.client.Watcher; 15 | import io.fabric8.openshift.api.model.ImageLookupPolicy; 16 | import io.fabric8.openshift.api.model.ImageStream; 17 | import org.slf4j.Logger; 18 | import org.slf4j.LoggerFactory; 19 | 20 | import java.io.FileInputStream; 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | import java.util.Arrays; 24 | import java.util.List; 25 | import java.util.concurrent.CountDownLatch; 26 | import java.util.concurrent.TimeUnit; 27 | import java.util.function.Predicate; 28 | import java.util.stream.Collectors; 29 | 30 | import static io.fabric8.tests.integration.support.KubernetesTestUtil.failNotDeployed; 31 | import static io.fabric8.tests.integration.support.KubernetesTestUtil.isNotNullOrEmpty; 32 | import static io.fabric8.tests.integration.support.KubernetesTestUtil.isNullOrEmpty; 33 | import static java.util.concurrent.TimeUnit.SECONDS; 34 | 35 | public class KubernetesTestDeployer { 36 | 37 | private final static Logger LOG = LoggerFactory.getLogger(KubernetesTestDeployer.class); 38 | 39 | private final static Predicate supportReadiness = 40 | resource -> Arrays.asList("Node", "Deployment", "ReplicaSet", "StatefulSet", "Pod", "DeploymentConfig", "ReplicationController") 41 | .contains(resource.getKind()); 42 | 43 | private static final Predicate podStatusPhasePredicate = pod -> pod.getStatus().getPhase().equals("Succeeded") 44 | || pod.getStatus().getPhase().equals("Failed"); 45 | 46 | 47 | public static void deploy(KubernetesClient client, KubernetesTestConfig config) { 48 | createNamespace(client, config); 49 | 50 | // deploy dependencies 51 | if (isNotNullOrEmpty(config.getDependencies())) { 52 | LOG.info("Deploy dependencies from file {}", config.getImageStreamFilePath()); 53 | for (String dependency : config.getDependencies()) { 54 | deployFromFile(client, config, dependency); 55 | } 56 | } 57 | 58 | String sourceNamespace = config.getMainNamespace(); 59 | LOG.info("Deploy RoleBinding "); 60 | createRoleBinding(client, sourceNamespace, config); 61 | LOG.info("Deploy ImageStreams from file {}", config.getImageStreamFilePath()); 62 | createImageStream(client, config); 63 | // deploy resources 64 | LOG.info("Deploy resources from file {}", config.getResourceFilePath()); 65 | deployFromFile(client, config, config.getResourceFilePath()); 66 | } 67 | 68 | 69 | private static void deployFromFile(KubernetesClient client, KubernetesTestConfig config, String resourcesFilePath) { 70 | if (isNullOrEmpty(resourcesFilePath)) { 71 | failNotDeployed(); 72 | } 73 | LOG.info("Loading resources file: " + resourcesFilePath); 74 | List resourceList = null; 75 | 76 | try (InputStream resources = new FileInputStream(resourcesFilePath)) { 77 | resourceList = client.load(resources).get(); 78 | } catch (IOException e) { 79 | LOG.error("Problem loading resources file {}", resourcesFilePath); 80 | failNotDeployed(); 81 | } 82 | 83 | List deployedResourceList = client.resourceList(resourceList) 84 | .inNamespace(config.getNamespace()) 85 | .createOrReplace(); 86 | 87 | LOG.info("Waiting for reources to be ready"); 88 | deployedResourceList.stream() 89 | .filter(supportReadiness) 90 | .forEach(resource -> { 91 | try { 92 | client.resource(resource) 93 | .inNamespace(config.getNamespace()) 94 | .waitUntilReady(config.getKubernetesTimeout(), SECONDS); 95 | } catch (InterruptedException e) { 96 | LOG.error("Timeout reached waiting for "+resource.getKind()+" with name "+resource.getMetadata().getName()+" to be ready"); 97 | failNotDeployed(); 98 | } 99 | }); 100 | LOG.info("Reources are ready Now"); 101 | } 102 | 103 | private static void createRoleBinding(KubernetesClient client, String sourceNamespace, KubernetesTestConfig config) { 104 | 105 | String targetNamespace = config.getNamespace(); 106 | 107 | Subject subject = new SubjectBuilder() 108 | .withName("default") 109 | .withKind("ServiceAccount") 110 | .withNamespace(targetNamespace) 111 | .build(); 112 | 113 | RoleBindingBuilder roleBindingBuilder = new RoleBindingBuilder(); 114 | RoleBinding roleBinding = roleBindingBuilder 115 | .withKind("RoleBinding") 116 | .withApiVersion("rbac.authorization.k8s.io/v1") 117 | .withNewMetadata() 118 | .withName("ktest-system:image-puller") 119 | .withNamespace(sourceNamespace) 120 | .withLabels(config.getKtestLabels()) 121 | .endMetadata() 122 | .withSubjects(subject) 123 | .withNewRoleRef() 124 | .withApiGroup("rbac.authorization.k8s.io") 125 | .withKind("ClusterRole") 126 | .withName("system:image-puller") 127 | .endRoleRef() 128 | .build(); 129 | 130 | client.rbac().roleBindings().inNamespace(sourceNamespace).createOrReplace(roleBinding); 131 | } 132 | 133 | private static void createNamespace(KubernetesClient client, KubernetesTestConfig config) { 134 | if (config.isUseExistingNamespace()) { 135 | return; 136 | } 137 | Namespace ns = new NamespaceBuilder().withNewMetadata().withName(config.getNamespace()).endMetadata().build(); 138 | client.namespaces().create(ns); 139 | LOG.info("Namespace " + config.getNamespace() + " created."); 140 | } 141 | 142 | 143 | public static void deleteNamespace(KubernetesClient 144 | client, KubernetesTestConfig config) { 145 | final CountDownLatch isWatchClosed = new CountDownLatch(1); 146 | Watch watch = client.namespaces().withName(config.getNamespace()).watch(new Watcher() { 147 | @Override 148 | public void eventReceived(Action action, Namespace resource) { 149 | if (action.equals(Action.DELETED)) { 150 | LOG.debug("Deleted event for namespace {} received", config.getNamespace()); 151 | isWatchClosed.countDown(); 152 | } 153 | } 154 | @Override 155 | public void onClose(KubernetesClientException cause) { 156 | isWatchClosed.countDown(); 157 | } 158 | }); 159 | try { 160 | if (config.isShouldDestroyNamespace()) { 161 | client.namespaces().withName(config.getNamespace()).delete(); 162 | LOG.info("Waiting for namespace deletion " + config.getNamespace() + " ..."); 163 | isWatchClosed.await(config.getKubernetesTimeout(), TimeUnit.SECONDS); 164 | LOG.info("Namespace - " + config.getNamespace() + " deleted."); 165 | } 166 | } catch (InterruptedException e) { 167 | isWatchClosed.countDown(); 168 | watch.close(); 169 | throw new RuntimeException("Timeout reached while waiting for namespace deletion."); 170 | } 171 | } 172 | 173 | private static void createImageStream(KubernetesClient client, KubernetesTestConfig config) { 174 | try (InputStream imageStreamFile = new FileInputStream(config.getImageStreamFilePath())) { 175 | List result = client.load(imageStreamFile).get(); 176 | result = result.stream().peek( 177 | x -> { 178 | if (x instanceof ImageStream) { 179 | ((ImageStream) x).getSpec() 180 | .setLookupPolicy(new ImageLookupPolicy(true)); 181 | } 182 | } 183 | ).collect(Collectors.toList()); 184 | 185 | client.resourceList(result) 186 | .inNamespace(config.getNamespace()) 187 | .createOrReplace(); 188 | } catch (IOException e) { 189 | failNotDeployed(); 190 | } 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /src/test/java/io/fabric8/tests/integration/support/KubernetesTestSetup.java: -------------------------------------------------------------------------------- 1 | package io.fabric8.tests.integration.support; 2 | 3 | import io.fabric8.kubernetes.client.KubernetesClient; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | public class KubernetesTestSetup { 8 | 9 | protected static Logger LOG = LoggerFactory.getLogger(KubernetesTestSetup.class); 10 | 11 | private KubernetesTestConfig config; 12 | 13 | private KubernetesClient client; 14 | 15 | public KubernetesTestSetup(KubernetesTestConfig config) { 16 | this.config = config; 17 | this.client = config.getClient(); 18 | } 19 | 20 | public void setUp() { 21 | LOG.info("Doing setup..."); 22 | KubernetesTestDeployer.deploy(client, config); 23 | LOG.info("setup done."); 24 | } 25 | 26 | public void tearDown() { 27 | LOG.info("Doing teardown..."); 28 | if(config.isShouldDestroyNamespace()) { 29 | KubernetesTestDeployer.deleteNamespace(client, config); 30 | client.rbac() 31 | .roleBindings() 32 | .inNamespace(config.getMainNamespace()) 33 | .withLabels(config.getKtestLabels()) 34 | .delete(); 35 | }else{ 36 | LOG.info("Nothing to do!"); 37 | } 38 | LOG.info("Teardown done."); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/io/fabric8/tests/integration/support/KubernetesTestUtil.java: -------------------------------------------------------------------------------- 1 | package io.fabric8.tests.integration.support; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.w3c.dom.Document; 6 | import org.w3c.dom.Node; 7 | import org.xml.sax.SAXException; 8 | 9 | import javax.xml.parsers.DocumentBuilder; 10 | import javax.xml.parsers.DocumentBuilderFactory; 11 | import javax.xml.parsers.ParserConfigurationException; 12 | import javax.xml.xpath.XPath; 13 | import javax.xml.xpath.XPathConstants; 14 | import javax.xml.xpath.XPathExpression; 15 | import javax.xml.xpath.XPathExpressionException; 16 | import javax.xml.xpath.XPathFactory; 17 | import java.io.File; 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | import java.util.Arrays; 21 | import java.util.Collection; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | public class KubernetesTestUtil { 26 | 27 | protected static Logger LOG = LoggerFactory.getLogger(KubernetesTestUtil.class); 28 | 29 | 30 | public static boolean isNullOrEmpty(String s) { 31 | return s == null || s.isEmpty(); 32 | } 33 | 34 | public static boolean isNullOrEmpty(Collection s) { 35 | return s == null || s.isEmpty(); 36 | } 37 | 38 | 39 | public static boolean isNullOrEmpty(Object [] s) { 40 | return s == null || s.length == 0; 41 | } 42 | 43 | public static boolean isNotNullOrEmpty(String s) { 44 | return !isNullOrEmpty(s); 45 | } 46 | 47 | public static boolean isNotNullOrEmpty(Collection s) { 48 | return !isNullOrEmpty(s); 49 | } 50 | 51 | public static InputStream getResourceFileAsStream(String fileName) { 52 | return KubernetesTestUtil.class.getClassLoader().getResourceAsStream(fileName); 53 | } 54 | 55 | public static void failNotDeployed(){ 56 | String errorMessage = "Error loading resource file. Be sure to run `mvn oc:deploy` before running this integration test."; 57 | LOG.error(errorMessage); 58 | throw new RuntimeException(errorMessage); 59 | } 60 | 61 | public static String getStringProperty(String name, Map map) { 62 | return getStringProperty(name, map, null); 63 | } 64 | public static String getStringProperty(String name, Map map, String defaultValue) { 65 | if (map.containsKey(name) && isNotNullOrEmpty(map.get(name))) { 66 | defaultValue = map.get(name); 67 | } 68 | return defaultValue; 69 | } 70 | 71 | public static List getArrayListStringProperty(String name, Map map) { 72 | if (map.containsKey(name) && isNotNullOrEmpty(map.get(name))) { 73 | return Arrays.asList(map.get(name).split(",")); 74 | } 75 | return null; 76 | } 77 | 78 | public static int getIntProperty(String name, Map map, int defaultValue) { 79 | if (map.containsKey(name) && isNotNullOrEmpty(map.get(name))) { 80 | return Integer.parseInt(map.get(name)); 81 | } 82 | return defaultValue; 83 | } 84 | 85 | public static Boolean getBooleanProperty(String name, Map map, Boolean defaultValue) { 86 | if (map.containsKey(name) && isNotNullOrEmpty(map.get(name))) { 87 | defaultValue = Boolean.parseBoolean(map.get(name)); 88 | } 89 | return defaultValue; 90 | } 91 | 92 | public static String getArtifactId() throws ParserConfigurationException, IOException, SAXException, XPathExpressionException { 93 | 94 | DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); 95 | domFactory.setNamespaceAware(true); 96 | 97 | DocumentBuilder builder = domFactory.newDocumentBuilder(); 98 | Document doc = builder.parse(new File("./pom.xml")); 99 | XPath xpath = XPathFactory.newInstance().newXPath(); 100 | 101 | XPathExpression expr = xpath.compile("/*[local-name() = 'project']/*[local-name() = 'artifactId']/text()"); 102 | Node result = (Node) expr.evaluate(doc, XPathConstants.NODE); 103 | String artifactId = result.getTextContent(); 104 | LOG.info("Detected artifactId: {}", artifactId); 105 | return artifactId; 106 | } 107 | 108 | } 109 | --------------------------------------------------------------------------------