7
7
import io .apicurio .registry .operator .api .v1 .ApicurioRegistry3Spec ;
8
8
import io .apicurio .registry .operator .api .v1 .spec .AppSpec ;
9
9
import io .apicurio .registry .operator .api .v1 .spec .StudioUiSpec ;
10
+ import io .apicurio .registry .operator .api .v1 .spec .TLSSpec ;
10
11
import io .apicurio .registry .operator .api .v1 .spec .UiSpec ;
11
- import io .apicurio .registry .operator .status .ValidationErrorConditionManager ;
12
12
import io .apicurio .registry .operator .status .StatusManager ;
13
+ import io .apicurio .registry .operator .status .ValidationErrorConditionManager ;
14
+ import io .apicurio .registry .operator .utils .SecretKeyRefTool ;
13
15
import io .fabric8 .kubernetes .api .model .*;
14
16
import io .fabric8 .kubernetes .api .model .apps .Deployment ;
15
17
import io .fabric8 .kubernetes .api .model .apps .DeploymentSpec ;
23
25
import java .util .Map ;
24
26
import java .util .Optional ;
25
27
26
- import static io .apicurio .registry .operator .Constants .DEFAULT_REPLICAS ;
27
- import static io .apicurio .registry .operator .api .v1 .ContainerNames .*;
28
+ import static io .apicurio .registry .operator .Constants .*;
29
+ import static io .apicurio .registry .operator .api .v1 .ContainerNames .REGISTRY_APP_CONTAINER_NAME ;
30
+ import static io .apicurio .registry .operator .api .v1 .ContainerNames .REGISTRY_UI_CONTAINER_NAME ;
31
+ import static io .apicurio .registry .operator .api .v1 .ContainerNames .STUDIO_UI_CONTAINER_NAME ;
28
32
import static io .apicurio .registry .operator .resource .Labels .getSelectorLabels ;
29
33
import static io .apicurio .registry .operator .resource .app .AppDeploymentResource .getContainerFromPodTemplateSpec ;
30
34
import static io .apicurio .registry .operator .utils .Mapper .YAML_MAPPER ;
@@ -56,19 +60,43 @@ public Deployment getDefaultAppDeployment(ApicurioRegistry3 primary) {
56
60
.map (AppSpec ::getReplicas ).orElse (DEFAULT_REPLICAS ),
57
61
ofNullable (primary .getSpec ()).map (ApicurioRegistry3Spec ::getApp )
58
62
.map (AppSpec ::getPodTemplateSpec ).orElse (null )); // TODO:
63
+
64
+ var readinessProbe = DEFAULT_READINESS_PROBE ;
65
+ var livenessProbe = DEFAULT_LIVENESS_PROBE ;
66
+ var containerPort = List .of (new ContainerPortBuilder ().withName ("http" ).withProtocol ("TCP" ).withContainerPort (8080 ).build ());
67
+
68
+ Optional <TLSSpec > tlsSpec = ofNullable (primary .getSpec ())
69
+ .map (ApicurioRegistry3Spec ::getApp )
70
+ .map (AppSpec ::getTls );
71
+
72
+ if (tlsSpec .isPresent ()) {
73
+ var keystore = new SecretKeyRefTool (tlsSpec .map (TLSSpec ::getKeystoreSecretRef )
74
+ .orElse (null ), "keystore" );
75
+
76
+ var keystorePassword = new SecretKeyRefTool (tlsSpec .map (TLSSpec ::getKeystorePasswordSecretRef )
77
+ .orElse (null ), "password" );
78
+
79
+ if (keystore .isValid () && keystorePassword .isValid ()) {
80
+ readinessProbe = TLS_DEFAULT_READINESS_PROBE ;
81
+ livenessProbe = TLS_DEFAULT_LIVENESS_PROBE ;
82
+ containerPort = List .of (new ContainerPortBuilder ().withName ("https" ).withProtocol ("TCP" ).withContainerPort (8443 ).build ());
83
+ }
84
+ }
85
+
59
86
// Replicas
60
87
mergeDeploymentPodTemplateSpec (
61
88
COMPONENT_APP_SPEC_FIELD_NAME ,
62
89
primary ,
63
90
r .getSpec ().getTemplate (),
64
91
REGISTRY_APP_CONTAINER_NAME ,
65
92
Configuration .getAppImage (),
66
- List . of ( new ContainerPortBuilder (). withName ( "http" ). withProtocol ( "TCP" ). withContainerPort ( 8080 ). build ()) ,
67
- new ProbeBuilder (). withHttpGet ( new HTTPGetActionBuilder (). withPath ( "/health/ready" ). withPort ( new IntOrString ( 8080 )). withScheme ( "HTTP" ). build ()). build () ,
68
- new ProbeBuilder (). withHttpGet ( new HTTPGetActionBuilder (). withPath ( "/health/live" ). withPort ( new IntOrString ( 8080 )). withScheme ( "HTTP" ). build ()). build () ,
93
+ containerPort ,
94
+ readinessProbe ,
95
+ livenessProbe ,
69
96
Map .of ("cpu" , new Quantity ("500m" ), "memory" , new Quantity ("512Mi" )),
70
97
Map .of ("cpu" , new Quantity ("1" ), "memory" , new Quantity ("1Gi" ))
71
98
);
99
+
72
100
addDefaultLabels (r .getMetadata ().getLabels (), primary , COMPONENT_APP );
73
101
addSelectorLabels (r .getSpec ().getSelector ().getMatchLabels (), primary , COMPONENT_APP );
74
102
addDefaultLabels (r .getSpec ().getTemplate ().getMetadata ().getLabels (), primary , COMPONENT_APP );
@@ -106,7 +134,7 @@ public Deployment getDefaultStudioUIDeployment(ApicurioRegistry3 primary) {
106
134
.map (StudioUiSpec ::getReplicas ).orElse (DEFAULT_REPLICAS ),
107
135
ofNullable (primary .getSpec ()).map (ApicurioRegistry3Spec ::getStudioUi )
108
136
.map (StudioUiSpec ::getPodTemplateSpec ).orElse (null )); // TODO:
109
- // Replicas
137
+ // Replicas
110
138
mergeDeploymentPodTemplateSpec (
111
139
COMPONENT_STUDIO_UI_SPEC_FIELD_NAME ,
112
140
primary ,
@@ -126,7 +154,7 @@ public Deployment getDefaultStudioUIDeployment(ApicurioRegistry3 primary) {
126
154
}
127
155
128
156
private static Deployment initDefaultDeployment (ApicurioRegistry3 primary , String componentId ,
129
- int replicas , PodTemplateSpec pts ) {
157
+ int replicas , PodTemplateSpec pts ) {
130
158
var r = new Deployment ();
131
159
r .setMetadata (new ObjectMeta ());
132
160
r .getMetadata ().setNamespace (primary .getMetadata ().getNamespace ());
@@ -137,7 +165,8 @@ private static Deployment initDefaultDeployment(ApicurioRegistry3 primary, Strin
137
165
r .getSpec ().setSelector (new LabelSelector ());
138
166
if (pts != null ) {
139
167
r .getSpec ().setTemplate (pts );
140
- } else {
168
+ }
169
+ else {
141
170
r .getSpec ().setTemplate (new PodTemplateSpec ());
142
171
}
143
172
return r ;
@@ -179,8 +208,8 @@ private static void mergeDeploymentPodTemplateSpec(
179
208
if (c .getEnv () != null && !c .getEnv ().isEmpty ()) {
180
209
StatusManager .get (primary ).getConditionManager (ValidationErrorConditionManager .class )
181
210
.recordError ("""
182
- Field spec.%s.podTemplateSpec.spec.containers[name = %s].env must be empty. \
183
- Use spec.%s.env to configure environment variables.""" , componentFieldName , containerName , componentFieldName );
211
+ Field spec.%s.podTemplateSpec.spec.containers[name = %s].env must be empty. \
212
+ Use spec.%s.env to configure environment variables.""" , componentFieldName , containerName , componentFieldName );
184
213
}
185
214
if (c .getPorts () == null ) {
186
215
c .setPorts (new ArrayList <>());
@@ -269,7 +298,7 @@ public PodDisruptionBudget getDefaultStudioUIPodDisruptionBudget(ApicurioRegistr
269
298
}
270
299
271
300
private <T extends HasMetadata > T getDefaultResource (ApicurioRegistry3 primary , Class <T > klass ,
272
- String resourceType , String component ) {
301
+ String resourceType , String component ) {
273
302
var r = deserialize ("/k8s/default/" + component + "." + resourceType + ".yaml" , klass );
274
303
r .getMetadata ().setNamespace (primary .getMetadata ().getNamespace ());
275
304
r .getMetadata ().setName (primary .getMetadata ().getName () + "-" + component + "-" + resourceType );
@@ -320,15 +349,17 @@ private void addSelectorLabels(Map<String, String> labels, ApicurioRegistry3 pri
320
349
public static <T > T deserialize (String path , Class <T > klass ) {
321
350
try {
322
351
return YAML_MAPPER .readValue (load (path ), klass );
323
- } catch (JsonProcessingException ex ) {
352
+ }
353
+ catch (JsonProcessingException ex ) {
324
354
throw new OperatorException ("Could not deserialize resource: " + path , ex );
325
355
}
326
356
}
327
357
328
358
public static <T > T deserialize (String path , Class <T > klass , ClassLoader classLoader ) {
329
359
try {
330
360
return YAML_MAPPER .readValue (load (path , classLoader ), klass );
331
- } catch (JsonProcessingException ex ) {
361
+ }
362
+ catch (JsonProcessingException ex ) {
332
363
throw new OperatorException ("Could not deserialize resource: " + path , ex );
333
364
}
334
365
}
@@ -340,7 +371,8 @@ public static String load(String path) {
340
371
public static String load (String path , ClassLoader classLoader ) {
341
372
try (var stream = classLoader .getResourceAsStream (path )) {
342
373
return new String (stream .readAllBytes (), Charset .defaultCharset ());
343
- } catch (Exception ex ) {
374
+ }
375
+ catch (Exception ex ) {
344
376
throw new OperatorException ("Could not read resource: " + path , ex );
345
377
}
346
378
}
0 commit comments