@@ -46,14 +46,65 @@ const (
4646 SemeruGenerationLabelNameSuffix = "/semeru-compiler-generation"
4747 StatusReferenceSemeruGeneration = "semeruGeneration"
4848 StatusReferenceSemeruInstancesCompleted = "semeruInstancesCompleted"
49+ SemeruContainerName = "compiler"
4950)
5051
51- // Create the Deployment and Service objects for a Semeru Compiler used by a Websphere Liberty Application
52- func (r * ReconcileWebSphereLiberty ) reconcileSemeruCompiler (wlva * wlv1.WebSphereLibertyApplication ) (error , string , bool ) {
53- compilerMeta := metav1.ObjectMeta {
52+ func getCompilerMeta (wlva * wlv1.WebSphereLibertyApplication ) metav1.ObjectMeta {
53+ return metav1.ObjectMeta {
5454 Name : getSemeruCompilerNameWithGeneration (wlva ),
5555 Namespace : wlva .GetNamespace (),
5656 }
57+ }
58+
59+ func getSemeruDeploymentContainer (deploy * appsv1.Deployment ) (corev1.Container , error ) {
60+ for _ , container := range deploy .Spec .Template .Spec .Containers {
61+ if container .Name == SemeruContainerName {
62+ return container , nil
63+ }
64+ }
65+ return corev1.Container {}, fmt .Errorf ("could not find the Semeru Deployment container" )
66+ }
67+
68+ // Returns true if the semeru health port configuration has changed otherwise false
69+ func (r * ReconcileWebSphereLiberty ) upgradeSemeruHealthPorts (inputMeta metav1.ObjectMeta , wlva * wlv1.WebSphereLibertyApplication ) bool {
70+ var healthPort int32 = 38600
71+ if wlva .GetSemeruCloudCompiler ().GetHealth () != nil {
72+ healthPort = * wlva .GetSemeruCloudCompiler ().GetHealth ().GetPort ()
73+ }
74+ semeruDeployment := & appsv1.Deployment {ObjectMeta : inputMeta }
75+ if r .GetClient ().Get (context .TODO (), types.NamespacedName {Name : semeruDeployment .Name , Namespace : semeruDeployment .Namespace }, semeruDeployment ) == nil {
76+ container , err := getSemeruDeploymentContainer (semeruDeployment )
77+ if err != nil {
78+ return false
79+ }
80+ if healthPort == 38400 && len (container .Ports ) > 1 {
81+ return true
82+ }
83+ containsHealthPort := false
84+ for _ , port := range container .Ports {
85+ if port .ContainerPort == healthPort {
86+ containsHealthPort = true
87+ }
88+ }
89+ if ! containsHealthPort {
90+ return true
91+ }
92+ }
93+ return false
94+ }
95+
96+ // Create the Deployment and Service objects for a Semeru Compiler used by a Websphere Liberty Application
97+ func (r * ReconcileWebSphereLiberty ) reconcileSemeruCompiler (wlva * wlv1.WebSphereLibertyApplication ) (error , string , bool ) {
98+ compilerMeta := getCompilerMeta (wlva )
99+
100+ // check for any diffs that require generation changes
101+ if r .isSemeruEnabled (wlva ) {
102+ upgradeRequired := r .upgradeSemeruHealthPorts (compilerMeta , wlva )
103+ if upgradeRequired {
104+ createNewSemeruGeneration (wlva ) // update generation
105+ compilerMeta = getCompilerMeta (wlva ) // adjust compilerMeta to reference the new generation
106+ }
107+ }
57108
58109 currentGeneration := getGeneration (wlva )
59110
@@ -255,6 +306,8 @@ func (r *ReconcileWebSphereLiberty) deleteCompletedSemeruInstances(wlva *wlv1.We
255306}
256307
257308func (r * ReconcileWebSphereLiberty ) reconcileSemeruDeployment (wlva * wlv1.WebSphereLibertyApplication , deploy * appsv1.Deployment ) {
309+ var port int32 = 38400
310+ var healthPort int32 = 38600
258311 deploy .Labels = getLabels (wlva )
259312 deploy .Spec .Strategy .Type = appsv1 .RecreateDeploymentStrategyType
260313
@@ -276,11 +329,20 @@ func (r *ReconcileWebSphereLiberty) reconcileSemeruDeployment(wlva *wlv1.WebSphe
276329 limitsMemory := getQuantityFromLimitsOrDefault (instanceResources , corev1 .ResourceMemory , "1200Mi" )
277330 limitsCPU := getQuantityFromLimitsOrDefault (instanceResources , corev1 .ResourceCPU , "2000m" )
278331
332+ if semeruCloudCompiler .GetHealth () != nil {
333+ healthPort = * semeruCloudCompiler .GetHealth ().GetPort ()
334+ }
335+ var portIntOrStr intstr.IntOrString
336+ if healthPort == port {
337+ portIntOrStr = intstr .FromInt32 (port )
338+ } else {
339+ portIntOrStr = intstr .FromString (fmt .Sprintf ("%d-tcp" , healthPort ))
340+ }
279341 // Liveness probe
280342 livenessProbe := corev1.Probe {
281343 ProbeHandler : corev1.ProbeHandler {
282344 TCPSocket : & corev1.TCPSocketAction {
283- Port : intstr . FromInt ( 38400 ) ,
345+ Port : portIntOrStr ,
284346 },
285347 },
286348 InitialDelaySeconds : 10 ,
@@ -291,7 +353,7 @@ func (r *ReconcileWebSphereLiberty) reconcileSemeruDeployment(wlva *wlv1.WebSphe
291353 readinessProbe := corev1.Probe {
292354 ProbeHandler : corev1.ProbeHandler {
293355 TCPSocket : & corev1.TCPSocketAction {
294- Port : intstr . FromInt ( 38400 ) ,
356+ Port : portIntOrStr ,
295357 },
296358 },
297359 InitialDelaySeconds : 5 ,
@@ -301,6 +363,22 @@ func (r *ReconcileWebSphereLiberty) reconcileSemeruDeployment(wlva *wlv1.WebSphe
301363 semeruPodMatchLabels := map [string ]string {
302364 "app.kubernetes.io/instance" : getSemeruCompilerNameWithGeneration (wlva ),
303365 }
366+ containerPorts := make ([]corev1.ContainerPort , 0 )
367+ containerPorts = append (containerPorts , corev1.ContainerPort {
368+ ContainerPort : port ,
369+ Protocol : corev1 .ProtocolTCP ,
370+ })
371+
372+ healthProbesFlag := ""
373+ if healthPort != port {
374+ healthProbesFlag = " -XX:+JITServerHealthProbes" + fmt .Sprintf (" -XX:JITServerHealthProbePort=%d" , healthPort )
375+ containerPorts [0 ].Name = fmt .Sprintf ("%d-tcp" , port )
376+ containerPorts = append (containerPorts , corev1.ContainerPort {
377+ Name : fmt .Sprintf ("%d-tcp" , healthPort ),
378+ ContainerPort : healthPort ,
379+ Protocol : corev1 .ProtocolTCP ,
380+ })
381+ }
304382 deploy .Spec .Template = corev1.PodTemplateSpec {
305383 ObjectMeta : metav1.ObjectMeta {
306384 Labels : getLabels (wlva ),
@@ -333,16 +411,11 @@ func (r *ReconcileWebSphereLiberty) reconcileSemeruDeployment(wlva *wlv1.WebSphe
333411 },
334412 Containers : []corev1.Container {
335413 {
336- Name : "compiler" ,
414+ Name : SemeruContainerName ,
337415 Image : wlva .Status .GetImageReference (),
338416 ImagePullPolicy : * wlva .GetPullPolicy (),
339417 Command : []string {"jitserver" },
340- Ports : []corev1.ContainerPort {
341- {
342- ContainerPort : 38400 ,
343- Protocol : corev1 .ProtocolTCP ,
344- },
345- },
418+ Ports : containerPorts ,
346419 Resources : corev1.ResourceRequirements {
347420 Requests : corev1.ResourceList {
348421 corev1 .ResourceMemory : requestsMemory ,
@@ -356,6 +429,7 @@ func (r *ReconcileWebSphereLiberty) reconcileSemeruDeployment(wlva *wlv1.WebSphe
356429 Env : []corev1.EnvVar {
357430 {Name : "OPENJ9_JAVA_OPTIONS" , Value : "-XX:+JITServerLogConnections" +
358431 " -XX:+JITServerShareROMClasses" +
432+ healthProbesFlag +
359433 " -XX:JITServerSSLKey=/etc/x509/certs/tls.key" +
360434 " -XX:JITServerSSLCert=/etc/x509/certs/tls.crt" },
361435 },
@@ -413,16 +487,34 @@ func (r *ReconcileWebSphereLiberty) reconcileSemeruDeployment(wlva *wlv1.WebSphe
413487
414488func reconcileSemeruService (svc * corev1.Service , wlva * wlv1.WebSphereLibertyApplication ) {
415489 var port int32 = 38400
490+ var healthPort int32 = 38600
416491 var timeout int32 = 86400
417492 svc .Labels = getLabels (wlva )
418493 svc .Spec .Selector = getSelectors (wlva )
419494 utils .CustomizeServiceAnnotations (svc , wlva .GetDisableTopologyRouting ())
420- if len (svc .Spec .Ports ) == 0 {
495+ numPorts := len (svc .Spec .Ports )
496+ if numPorts == 0 {
421497 svc .Spec .Ports = append (svc .Spec .Ports , corev1.ServicePort {})
422498 }
499+
423500 svc .Spec .Ports [0 ].Protocol = corev1 .ProtocolTCP
424501 svc .Spec .Ports [0 ].Port = port
425502 svc .Spec .Ports [0 ].TargetPort = intstr .FromInt (int (port ))
503+ if wlva .GetSemeruCloudCompiler ().GetHealth () != nil {
504+ healthPort = * wlva .GetSemeruCloudCompiler ().GetHealth ().GetPort ()
505+ }
506+ if healthPort != port {
507+ numPorts = len (svc .Spec .Ports )
508+ if numPorts == 1 {
509+ svc .Spec .Ports = append (svc .Spec .Ports , corev1.ServicePort {})
510+ }
511+ svc .Spec .Ports [0 ].Name = fmt .Sprintf ("%d-tcp" , port )
512+ svc .Spec .Ports [0 ].TargetPort = intstr .FromString (fmt .Sprintf ("%d-tcp" , port ))
513+ svc .Spec .Ports [1 ].Name = fmt .Sprintf ("%d-tcp" , healthPort )
514+ svc .Spec .Ports [1 ].Protocol = corev1 .ProtocolTCP
515+ svc .Spec .Ports [1 ].Port = healthPort
516+ svc .Spec .Ports [1 ].TargetPort = intstr .FromString (fmt .Sprintf ("%d-tcp" , healthPort ))
517+ }
426518 svc .Spec .SessionAffinity = corev1 .ServiceAffinityClientIP
427519 svc .Spec .SessionAffinityConfig = & corev1.SessionAffinityConfig {
428520 ClientIP : & corev1.ClientIPConfig {
@@ -585,14 +677,13 @@ func (r *ReconcileWebSphereLiberty) getSemeruJavaOptions(instance *wlv1.WebSpher
585677 certificateLocation = "/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt"
586678 }
587679 jitServerAddress := instance .Status .SemeruCompiler .ServiceHostname
588- jitSeverOptions := fmt .Sprintf ("-XX:+UseJITServer -XX:+JITServerLogConnections -XX:JITServerAddress=%v -XX:JITServerSSLRootCerts=%v" ,
589- jitServerAddress , certificateLocation )
680+ jitServerOptions := fmt .Sprintf ("-XX:+UseJITServer -XX:+JITServerLogConnections -XX:JITServerAddress=%v -XX:JITServerSSLRootCerts=%v" , jitServerAddress , certificateLocation )
590681
591682 args := []string {
592683 "/bin/bash" ,
593684 "-c" ,
594- "export OPENJ9_JAVA_OPTIONS=\" $OPENJ9_JAVA_OPTIONS " + jitSeverOptions +
595- "\" && export OPENJ9_RESTORE_JAVA_OPTIONS=\" $OPENJ9_RESTORE_JAVA_OPTIONS " + jitSeverOptions +
685+ "export OPENJ9_JAVA_OPTIONS=\" $OPENJ9_JAVA_OPTIONS " + jitServerOptions +
686+ "\" && export OPENJ9_RESTORE_JAVA_OPTIONS=\" $OPENJ9_RESTORE_JAVA_OPTIONS " + jitServerOptions +
596687 "\" && server run" ,
597688 }
598689 return args
0 commit comments