9
9
import java .util .function .UnaryOperator ;
10
10
import java .util .stream .Collectors ;
11
11
12
+ import org .slf4j .Logger ;
13
+ import org .slf4j .LoggerFactory ;
14
+
15
+ import io .fabric8 .kubernetes .api .model .Event ;
12
16
import io .fabric8 .kubernetes .api .model .HasMetadata ;
13
17
import io .fabric8 .kubernetes .api .model .apiextensions .v1 .*;
14
18
import io .fabric8 .kubernetes .api .model .networking .v1 .*;
15
19
import io .fabric8 .kubernetes .client .KubernetesClient ;
20
+ import io .fabric8 .kubernetes .client .KubernetesClientTimeoutException ;
21
+ import io .fabric8 .kubernetes .client .utils .KubernetesSerialization ;
16
22
17
23
import static io .javaoperatorsdk .webhook .sample .commons .AdmissionControllers .VALIDATION_TARGET_LABEL ;
18
24
import static io .javaoperatorsdk .webhook .sample .commons .ConversionControllers .CONVERSION_PATH ;
19
25
20
26
public class Utils {
21
27
22
- public static final int SPIN_UP_GRACE_PERIOD = 120 ;
28
+ private static final Logger log = LoggerFactory . getLogger ( Utils . class ) ;
23
29
30
+ public static final int SPIN_UP_GRACE_PERIOD = 180 ;
24
31
25
32
public static void applyAndWait (KubernetesClient client , String path ) {
26
33
applyAndWait (client , path , null );
@@ -41,11 +48,25 @@ public static void applyAndWait(KubernetesClient client, InputStream is) {
41
48
42
49
public static void applyAndWait (KubernetesClient client , List <HasMetadata > resources ,
43
50
UnaryOperator <HasMetadata > transformer ) {
44
- if (transformer != null ) {
45
- resources = resources .stream ().map (transformer ).collect (Collectors .toList ());
51
+ try {
52
+ if (transformer != null ) {
53
+ resources = resources .stream ().map (transformer ).collect (Collectors .toList ());
54
+ }
55
+ client .resourceList (resources ).createOrReplace ();
56
+ client .resourceList (resources ).waitUntilReady (5 , TimeUnit .MINUTES );
57
+ } catch (KubernetesClientTimeoutException e ) {
58
+ log .info ("Timed out resource list: {}" , client .resourceList (resources ).get ());
59
+ var deployment = client .resourceList (resources ).get ().stream ()
60
+ .filter (r -> r .getKind ().equals ("Deployment" )).findFirst ().orElseThrow ();
61
+ log .info ("Deployment:\n {} \n " ,
62
+ new KubernetesSerialization ().asYaml (deployment ));
63
+
64
+ client .v1 ().events ().inNamespace (deployment .getMetadata ().getNamespace ()).list ().getItems ()
65
+ .stream ()
66
+ .map (Event ::getMessage )
67
+ .forEach (ev -> log .info ("Event: {}" , new KubernetesSerialization ().asYaml (ev )));
68
+ throw e ;
46
69
}
47
- client .resourceList (resources ).createOrReplace ();
48
- client .resourceList (resources ).waitUntilReady (3 , TimeUnit .MINUTES );
49
70
}
50
71
51
72
public static void applyAndWait (KubernetesClient client , InputStream is ,
0 commit comments