1111import java .io .ByteArrayOutputStream ;
1212import java .io .IOException ;
1313import java .io .InputStream ;
14+ import java .net .URL ;
1415import java .time .Duration ;
15- import java .util .Base64 ;
16- import java .util .List ;
17- import java .util .Map ;
18- import java .util .Objects ;
19- import java .util .Optional ;
16+ import java .util .*;
17+ import java .util .concurrent .TimeUnit ;
2018import java .util .function .Function ;
2119import java .util .function .Supplier ;
2220import java .util .stream .Collectors ;
4543import com .github .dockerjava .api .DockerClient ;
4644import com .github .dockerjava .api .command .InspectContainerResponse ;
4745
48- import io .fabric8 .kubernetes .api .model .HasMetadata ;
46+ import io .fabric8 .kubernetes .api .model .*;
47+ import io .fabric8 .kubernetes .api .model .apps .Deployment ;
48+ import io .fabric8 .kubernetes .api .model .apps .ReplicaSet ;
49+ import io .fabric8 .kubernetes .api .model .apps .StatefulSet ;
4950import io .fabric8 .kubernetes .client .*;
51+ import io .fabric8 .kubernetes .client .Config ;
5052import io .quarkus .deployment .Feature ;
5153import io .quarkus .deployment .IsDevServicesSupportedByLaunchMode ;
5254import io .quarkus .deployment .annotations .BuildProducer ;
@@ -196,10 +198,7 @@ public void applyManifests(
196198 .withConfig (Config .fromKubeconfig (kubernetesDevServiceInfoBuildItem .getKubeConfig ()))
197199 .build ()) {
198200 for (String manifestPath : manifests .get ()) {
199- // Load the manifest from the resources directory
200- InputStream manifestStream = Thread .currentThread ()
201- .getContextClassLoader ()
202- .getResourceAsStream (manifestPath );
201+ InputStream manifestStream = getManifestStream (manifestPath );
203202
204203 if (manifestStream == null ) {
205204 log .errorf ("Could not find manifest file in resources: %s" , manifestPath );
@@ -210,11 +209,25 @@ public void applyManifests(
210209 try {
211210 // A single manifest file may contain multiple resources to deploy
212211 List <HasMetadata > resources = client .load (manifestStream ).items ();
212+ List <HasMetadata > resourcesWithReadiness = new ArrayList <>();
213213
214214 if (resources .isEmpty ()) {
215215 log .warnf ("No resources found in manifest: %s" , manifestPath );
216216 } else {
217- resources .forEach (resource -> client .resource (resource ).create ());
217+ resources .forEach (resource -> {
218+ client .resource (resource ).create ();
219+
220+ if (isReadinessApplicable (resource )) {
221+ resourcesWithReadiness .add (resource );
222+ }
223+ });
224+
225+ resourcesWithReadiness .forEach (resource -> {
226+ log .info ("Waiting for " + resource .getClass ().getSimpleName () + " "
227+ + resource .getMetadata ().getName ()
228+ + " to be ready..." );
229+ client .resource (resource ).waitUntilReady (60 , TimeUnit .SECONDS );
230+ });
218231 }
219232 } catch (Exception ex ) {
220233 log .errorf ("Failed to deploy manifest %s: %s" , manifestPath , ex .getMessage ());
@@ -228,6 +241,29 @@ public void applyManifests(
228241 }
229242 }
230243
244+ private boolean isReadinessApplicable (HasMetadata item ) {
245+ return (item instanceof Deployment ||
246+ item instanceof io .fabric8 .kubernetes .api .model .extensions .Deployment ||
247+ item instanceof ReplicaSet ||
248+ item instanceof Pod ||
249+ item instanceof ReplicationController ||
250+ item instanceof Endpoints ||
251+ item instanceof Node ||
252+ item instanceof StatefulSet );
253+ }
254+
255+ private InputStream getManifestStream (String manifestPath ) throws IOException {
256+ if (manifestPath .startsWith ("http://" ) || manifestPath .startsWith ("https://" )) {
257+ // Option 1: The manifest is a URL, in which case we download it
258+ return new URL (manifestPath ).openStream ();
259+ } else {
260+ // Option 2: The manifest is a file in the resources directory
261+ return Thread .currentThread ()
262+ .getContextClassLoader ()
263+ .getResourceAsStream (manifestPath );
264+ }
265+ }
266+
231267 private void shutdownCluster () {
232268 if (devService != null && devService .isOwner ()) {
233269 try {
0 commit comments