diff --git a/api/v1/webspherelibertyapplication_types.go b/api/v1/webspherelibertyapplication_types.go index 05583173..942f0aa8 100644 --- a/api/v1/webspherelibertyapplication_types.go +++ b/api/v1/webspherelibertyapplication_types.go @@ -100,7 +100,7 @@ type WebSphereLibertyApplicationSpec struct { Resources *corev1.ResourceRequirements `json:"resources,omitempty"` // +operator-sdk:csv:customresourcedefinitions:order=15,type=spec,displayName="Probes" - Probes *WebSphereLibertyApplicationProbes `json:"probes,omitempty"` + Probes *WebSphereLibertyApplicationProbesConfig `json:"probes,omitempty"` // +operator-sdk:csv:customresourcedefinitions:order=16,type=spec,displayName="Deployment" Deployment *WebSphereLibertyApplicationDeployment `json:"deployment,omitempty"` @@ -289,6 +289,26 @@ type WebSphereLibertyApplicationServiceAccount struct { SkipPullSecretValidation *bool `json:"skipPullSecretValidation,omitempty"` } +type WebSphereLibertyApplicationProbesConfig struct { + WebSphereLibertyApplicationProbes `json:",inline"` + + // Inspects the container filesystem to return health checks based upon files generated by the Liberty runtime. Only supported on Liberty version 25.0.0.6-beta or higher. + // +operator-sdk:csv:customresourcedefinitions:order=100,type=spec,displayName="Enable File Based",xDescriptors="urn:alm:descriptor:com.tectonic.ui:booleanSwitch" + EnableFileBased *bool `json:"enableFileBased,omitempty"` + + // The Liberty container directory used to track file-based health checks for the 'live', 'ready', and 'started' files. Only used when .spec.probes.enableFiledBased is set to true. Defaults to /output/health. + // +operator-sdk:csv:customresourcedefinitions:order=101,type=spec,displayName="File Directory",xDescriptors="urn:alm:descriptor:com.tectonic.ui:text" + FileDirectory *string `json:"fileDirectory,omitempty"` + + // The interval at which the Liberty runtime queries to update the file-based health check files. The value is a number followed by an optional time unit of ms for milliseconds or s for seconds. Only used when .spec.probes.enableFiledBased is set to true. Defaults to 5s. + // +operator-sdk:csv:customresourcedefinitions:order=102,type=spec,displayName="Check Interval",xDescriptors="urn:alm:descriptor:com.tectonic.ui:text" + CheckInterval *string `json:"checkInterval,omitempty"` + + // The interval at which the Liberty runtime will query until an UP status is resolved and the health check file is created. The value is a number followed by an optional time unit of ms for milliseconds or s for seconds. If no time unit is specified for a value, the value is in milliseconds by default. Only used when .spec.probes.enableFiledBased is set to true. Defaults to 100ms. + // +operator-sdk:csv:customresourcedefinitions:order=103,type=spec,displayName="Startup Check Interval",xDescriptors="urn:alm:descriptor:com.tectonic.ui:text" + StartupCheckInterval *string `json:"startupCheckInterval,omitempty"` +} + // Define health checks on application container to determine whether it is alive or ready to receive traffic type WebSphereLibertyApplicationProbes struct { // Periodic probe of container liveness. Container will be restarted if the probe fails. diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 752dd9c4..3d6a7e99 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -587,6 +587,32 @@ func (in *WebSphereLibertyApplicationProbes) DeepCopy() *WebSphereLibertyApplica return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *WebSphereLibertyApplicationProbesConfig) DeepCopyInto(out *WebSphereLibertyApplicationProbesConfig) { + *out = *in + in.WebSphereLibertyApplicationProbes.DeepCopyInto(&out.WebSphereLibertyApplicationProbes) + if in.EnableFileBased != nil { + in, out := &in.EnableFileBased, &out.EnableFileBased + *out = new(bool) + **out = **in + } + if in.FileDirectory != nil { + in, out := &in.FileDirectory, &out.FileDirectory + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WebSphereLibertyApplicationProbesConfig. +func (in *WebSphereLibertyApplicationProbesConfig) DeepCopy() *WebSphereLibertyApplicationProbesConfig { + if in == nil { + return nil + } + out := new(WebSphereLibertyApplicationProbesConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *WebSphereLibertyApplicationRoute) DeepCopyInto(out *WebSphereLibertyApplicationRoute) { *out = *in @@ -883,7 +909,7 @@ func (in *WebSphereLibertyApplicationSpec) DeepCopyInto(out *WebSphereLibertyApp } if in.Probes != nil { in, out := &in.Probes, &out.Probes - *out = new(WebSphereLibertyApplicationProbes) + *out = new(WebSphereLibertyApplicationProbesConfig) (*in).DeepCopyInto(*out) } if in.Deployment != nil { diff --git a/bundle/manifests/ibm-websphere-liberty.clusterserviceversion.yaml b/bundle/manifests/ibm-websphere-liberty.clusterserviceversion.yaml index 87011f72..aee27161 100644 --- a/bundle/manifests/ibm-websphere-liberty.clusterserviceversion.yaml +++ b/bundle/manifests/ibm-websphere-liberty.clusterserviceversion.yaml @@ -67,7 +67,7 @@ metadata: capabilities: Auto Pilot categories: Application Runtime containerImage: icr.io/cpopen/websphere-liberty-operator:daily - createdAt: "2025-09-08T02:59:31Z" + createdAt: "2025-10-02T17:16:23Z" description: Deploy and manage containerized Liberty applications features.operators.openshift.io/disconnected: "true" olm.skipRange: '>=1.0.0 <1.5.0' @@ -612,6 +612,13 @@ spec: Application Server Network Deployment' displayName: Edition path: license.edition + - description: Inspects the container filesystem to return health checks based + upon files generated by the Liberty runtime. Only supported on Liberty version + 25.0.0.6-beta or higher. + displayName: Enable File Based + path: probes.enableFileBased + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:booleanSwitch - description: 'Entitlement source for the product. Defaults to Standalone. Other options: IBM Enterprise Application Runtimes, IBM Cloud Pak for Applications Advanced, IBM Cloud Pak for Applications Standard, IBM WebSphere Hybrid @@ -620,12 +627,27 @@ spec: Standard instead.' displayName: Product Entitlement Source path: license.productEntitlementSource + - description: The Liberty container directory used to track file-based health + checks for the 'live', 'ready', and 'started' files. Only used when .spec.probes.enableFiledBased + is set to true. Defaults to /output/health. + displayName: File Directory + path: probes.fileDirectory + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:text - description: Deprecated. Charge metric code is now automatically determined based on the specified product edition and entitlement source. displayName: Metric path: license.metric x-descriptors: - urn:alm:descriptor:com.tectonic.ui:hidden + - description: The interval at which the Liberty runtime queries to update the + file-based health check files. The value is a number followed by an optional + time unit of ms for milliseconds or s for seconds. Only used when .spec.probes.enableFiledBased + is set to true. Defaults to 5s. + displayName: Check Interval + path: probes.checkInterval + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:text - description: |- I represent that the software in the above-referenced application container includes the IBM Program referenced below and I accept the terms of the license agreement corresponding to the version of IBM Program in the application container by setting this value to true. See https://ibm.biz/was-license for the license agreements applicable to this IBM Program @@ -633,6 +655,16 @@ spec: path: license.accept x-descriptors: - urn:alm:descriptor:com.tectonic.ui:checkbox + - description: The interval at which the Liberty runtime will query until an + UP status is resolved and the health check file is created. The value is + a number followed by an optional time unit of ms for milliseconds or s for + seconds. If no time unit is specified for a value, the value is in milliseconds + by default. Only used when .spec.probes.enableFiledBased is set to true. + Defaults to 100ms. + displayName: Startup Check Interval + path: probes.startupCheckInterval + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:text - description: Determines whether the access token that is provided in the request is used for authentication. displayName: Access Token Required diff --git a/bundle/manifests/liberty.websphere.ibm.com_webspherelibertyapplications.yaml b/bundle/manifests/liberty.websphere.ibm.com_webspherelibertyapplications.yaml index 14da7a34..9121a4f0 100644 --- a/bundle/manifests/liberty.websphere.ibm.com_webspherelibertyapplications.yaml +++ b/bundle/manifests/liberty.websphere.ibm.com_webspherelibertyapplications.yaml @@ -4403,9 +4403,25 @@ spec: type: object type: object probes: - description: Define health checks on application container to determine - whether it is alive or ready to receive traffic properties: + checkInterval: + description: The interval at which the Liberty runtime queries + to update the file-based health check files. The value is a + number followed by an optional time unit of ms for milliseconds + or s for seconds. Only used when .spec.probes.enableFiledBased + is set to true. Defaults to 5s. + type: string + enableFileBased: + description: Inspects the container filesystem to return health + checks based upon files generated by the Liberty runtime. Only + supported on Liberty version 25.0.0.6-beta or higher. + type: boolean + fileDirectory: + description: The Liberty container directory used to track file-based + health checks for the 'live', 'ready', and 'started' files. + Only used when .spec.probes.enableFiledBased is set to true. + Defaults to /output/health. + type: string liveness: description: Periodic probe of container liveness. Container will be restarted if the probe fails. @@ -4866,6 +4882,15 @@ spec: format: int32 type: integer type: object + startupCheckInterval: + description: The interval at which the Liberty runtime will query + until an UP status is resolved and the health check file is + created. The value is a number followed by an optional time + unit of ms for milliseconds or s for seconds. If no time unit + is specified for a value, the value is in milliseconds by default. + Only used when .spec.probes.enableFiledBased is set to true. + Defaults to 100ms. + type: string type: object pullPolicy: description: Policy for pulling container images. Defaults to IfNotPresent. diff --git a/config/crd/bases/liberty.websphere.ibm.com_webspherelibertyapplications.yaml b/config/crd/bases/liberty.websphere.ibm.com_webspherelibertyapplications.yaml index 02d1cfcc..2f754f68 100644 --- a/config/crd/bases/liberty.websphere.ibm.com_webspherelibertyapplications.yaml +++ b/config/crd/bases/liberty.websphere.ibm.com_webspherelibertyapplications.yaml @@ -4399,9 +4399,25 @@ spec: type: object type: object probes: - description: Define health checks on application container to determine - whether it is alive or ready to receive traffic properties: + checkInterval: + description: The interval at which the Liberty runtime queries + to update the file-based health check files. The value is a + number followed by an optional time unit of ms for milliseconds + or s for seconds. Only used when .spec.probes.enableFiledBased + is set to true. Defaults to 5s. + type: string + enableFileBased: + description: Inspects the container filesystem to return health + checks based upon files generated by the Liberty runtime. Only + supported on Liberty version 25.0.0.6-beta or higher. + type: boolean + fileDirectory: + description: The Liberty container directory used to track file-based + health checks for the 'live', 'ready', and 'started' files. + Only used when .spec.probes.enableFiledBased is set to true. + Defaults to /output/health. + type: string liveness: description: Periodic probe of container liveness. Container will be restarted if the probe fails. @@ -4862,6 +4878,15 @@ spec: format: int32 type: integer type: object + startupCheckInterval: + description: The interval at which the Liberty runtime will query + until an UP status is resolved and the health check file is + created. The value is a number followed by an optional time + unit of ms for milliseconds or s for seconds. If no time unit + is specified for a value, the value is in milliseconds by default. + Only used when .spec.probes.enableFiledBased is set to true. + Defaults to 100ms. + type: string type: object pullPolicy: description: Policy for pulling container images. Defaults to IfNotPresent. diff --git a/config/manifests/bases/ibm-websphere-liberty.clusterserviceversion.yaml b/config/manifests/bases/ibm-websphere-liberty.clusterserviceversion.yaml index 6419638c..87879f98 100644 --- a/config/manifests/bases/ibm-websphere-liberty.clusterserviceversion.yaml +++ b/config/manifests/bases/ibm-websphere-liberty.clusterserviceversion.yaml @@ -548,6 +548,13 @@ spec: Application Server Network Deployment' displayName: Edition path: license.edition + - description: Inspects the container filesystem to return health checks based + upon files generated by the Liberty runtime. Only supported on Liberty version + 25.0.0.6-beta or higher. + displayName: Enable File Based + path: probes.enableFileBased + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:booleanSwitch - description: 'Entitlement source for the product. Defaults to Standalone. Other options: IBM Enterprise Application Runtimes, IBM Cloud Pak for Applications Advanced, IBM Cloud Pak for Applications Standard, IBM WebSphere Hybrid @@ -556,12 +563,27 @@ spec: Standard instead.' displayName: Product Entitlement Source path: license.productEntitlementSource + - description: The Liberty container directory used to track file-based health + checks for the 'live', 'ready', and 'started' files. Only used when .spec.probes.enableFiledBased + is set to true. Defaults to /output/health. + displayName: File Directory + path: probes.fileDirectory + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:text - description: Deprecated. Charge metric code is now automatically determined based on the specified product edition and entitlement source. displayName: Metric path: license.metric x-descriptors: - urn:alm:descriptor:com.tectonic.ui:hidden + - description: The interval at which the Liberty runtime queries to update the + file-based health check files. The value is a number followed by an optional + time unit of ms for milliseconds or s for seconds. Only used when .spec.probes.enableFiledBased + is set to true. Defaults to 5s. + displayName: Check Interval + path: probes.checkInterval + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:text - description: |- I represent that the software in the above-referenced application container includes the IBM Program referenced below and I accept the terms of the license agreement corresponding to the version of IBM Program in the application container by setting this value to true. See https://ibm.biz/was-license for the license agreements applicable to this IBM Program @@ -569,6 +591,16 @@ spec: path: license.accept x-descriptors: - urn:alm:descriptor:com.tectonic.ui:checkbox + - description: The interval at which the Liberty runtime will query until an + UP status is resolved and the health check file is created. The value is + a number followed by an optional time unit of ms for milliseconds or s for + seconds. If no time unit is specified for a value, the value is in milliseconds + by default. Only used when .spec.probes.enableFiledBased is set to true. + Defaults to 100ms. + displayName: Startup Check Interval + path: probes.startupCheckInterval + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:text - description: Determines whether the access token that is provided in the request is used for authentication. displayName: Access Token Required diff --git a/go.mod b/go.mod index f91cb616..cb17f565 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.25 require ( github.com/OpenLiberty/open-liberty-operator v0.8.1-0.20250905223351-5f5935cfd434 - github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20250902185901-28fab0958c43 + github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20250924191244-78a168608ead github.com/cert-manager/cert-manager v1.16.5 github.com/go-logr/logr v1.4.2 github.com/openshift/api v0.0.0-20230928134114-673ed0cfc7f1 diff --git a/go.sum b/go.sum index 3ba50c47..bf49226b 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ github.com/OpenLiberty/open-liberty-operator v0.8.1-0.20250905223351-5f5935cfd43 github.com/OpenLiberty/open-liberty-operator v0.8.1-0.20250905223351-5f5935cfd434/go.mod h1:WQFReKJqTX+dE6TkzFF+CqjR7EeS0UMCg7a8/UVlrn8= github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20250902185901-28fab0958c43 h1:LKDWp8yhFzvnqKjPCzbPi/VzQAG6nj4wFnS7zD27lOs= github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20250902185901-28fab0958c43/go.mod h1:Hs5AbE9J+rLM34IAc75X7dtxnrzFg2AvG1XYLcX/ApU= +github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20250924191244-78a168608ead h1:/bnhC3edZUrByFy+NCh4P+Y6Nhk3D1Q5hoM7c80ECtM= +github.com/application-stacks/runtime-component-operator v1.0.0-20220602-0850.0.20250924191244-78a168608ead/go.mod h1:Hs5AbE9J+rLM34IAc75X7dtxnrzFg2AvG1XYLcX/ApU= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= diff --git a/internal/controller/webspherelibertyapplication_controller.go b/internal/controller/webspherelibertyapplication_controller.go index 244c0601..a7c01f62 100644 --- a/internal/controller/webspherelibertyapplication_controller.go +++ b/internal/controller/webspherelibertyapplication_controller.go @@ -548,6 +548,7 @@ func (r *ReconcileWebSphereLiberty) Reconcile(ctx context.Context, request ctrl. statefulSet := &appsv1.StatefulSet{ObjectMeta: defaultMeta} err = r.CreateOrUpdate(statefulSet, instance, func() error { oputils.CustomizeStatefulSet(statefulSet, instance) + lutils.CustomizeFileBasedProbes(&statefulSet.Spec.Template, instance) oputils.CustomizePodSpec(&statefulSet.Spec.Template, instance) oputils.CustomizePersistence(statefulSet, instance) if err := lutils.CustomizeLibertyEnv(&statefulSet.Spec.Template, instance, r.GetClient()); err != nil { @@ -646,6 +647,7 @@ func (r *ReconcileWebSphereLiberty) Reconcile(ctx context.Context, request ctrl. deploy := &appsv1.Deployment{ObjectMeta: defaultMeta} err = r.CreateOrUpdate(deploy, instance, func() error { oputils.CustomizeDeployment(deploy, instance) + lutils.CustomizeFileBasedProbes(&deploy.Spec.Template, instance) oputils.CustomizePodSpec(&deploy.Spec.Template, instance) if err := lutils.CustomizeLibertyEnv(&deploy.Spec.Template, instance, r.GetClient()); err != nil { reqLogger.Error(err, "Failed to reconcile Liberty env, error: "+err.Error()) diff --git a/internal/deploy/kubectl/websphereliberty-app-crd.yaml b/internal/deploy/kubectl/websphereliberty-app-crd.yaml index 37726936..e604fa39 100644 --- a/internal/deploy/kubectl/websphereliberty-app-crd.yaml +++ b/internal/deploy/kubectl/websphereliberty-app-crd.yaml @@ -4402,9 +4402,25 @@ spec: type: object type: object probes: - description: Define health checks on application container to determine - whether it is alive or ready to receive traffic properties: + checkInterval: + description: The interval at which the Liberty runtime queries + to update the file-based health check files. The value is a + number followed by an optional time unit of ms for milliseconds + or s for seconds. Only used when .spec.probes.enableFiledBased + is set to true. Defaults to 5s. + type: string + enableFileBased: + description: Inspects the container filesystem to return health + checks based upon files generated by the Liberty runtime. Only + supported on Liberty version 25.0.0.6-beta or higher. + type: boolean + fileDirectory: + description: The Liberty container directory used to track file-based + health checks for the 'live', 'ready', and 'started' files. + Only used when .spec.probes.enableFiledBased is set to true. + Defaults to /output/health. + type: string liveness: description: Periodic probe of container liveness. Container will be restarted if the probe fails. @@ -4865,6 +4881,15 @@ spec: format: int32 type: integer type: object + startupCheckInterval: + description: The interval at which the Liberty runtime will query + until an UP status is resolved and the health check file is + created. The value is a number followed by an optional time + unit of ms for milliseconds or s for seconds. If no time unit + is specified for a value, the value is in milliseconds by default. + Only used when .spec.probes.enableFiledBased is set to true. + Defaults to 100ms. + type: string type: object pullPolicy: description: Policy for pulling container images. Defaults to IfNotPresent. diff --git a/internal/deploy/kustomize/daily/base/websphere-liberty-crd.yaml b/internal/deploy/kustomize/daily/base/websphere-liberty-crd.yaml index 37726936..e604fa39 100644 --- a/internal/deploy/kustomize/daily/base/websphere-liberty-crd.yaml +++ b/internal/deploy/kustomize/daily/base/websphere-liberty-crd.yaml @@ -4402,9 +4402,25 @@ spec: type: object type: object probes: - description: Define health checks on application container to determine - whether it is alive or ready to receive traffic properties: + checkInterval: + description: The interval at which the Liberty runtime queries + to update the file-based health check files. The value is a + number followed by an optional time unit of ms for milliseconds + or s for seconds. Only used when .spec.probes.enableFiledBased + is set to true. Defaults to 5s. + type: string + enableFileBased: + description: Inspects the container filesystem to return health + checks based upon files generated by the Liberty runtime. Only + supported on Liberty version 25.0.0.6-beta or higher. + type: boolean + fileDirectory: + description: The Liberty container directory used to track file-based + health checks for the 'live', 'ready', and 'started' files. + Only used when .spec.probes.enableFiledBased is set to true. + Defaults to /output/health. + type: string liveness: description: Periodic probe of container liveness. Container will be restarted if the probe fails. @@ -4865,6 +4881,15 @@ spec: format: int32 type: integer type: object + startupCheckInterval: + description: The interval at which the Liberty runtime will query + until an UP status is resolved and the health check file is + created. The value is a number followed by an optional time + unit of ms for milliseconds or s for seconds. If no time unit + is specified for a value, the value is in milliseconds by default. + Only used when .spec.probes.enableFiledBased is set to true. + Defaults to 100ms. + type: string type: object pullPolicy: description: Policy for pulling container images. Defaults to IfNotPresent. diff --git a/utils/utils.go b/utils/utils.go index c02d1c7d..b830a4be 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -76,6 +76,14 @@ const LocalPasswordEncryptionKeyRootName = "wlo-wlp-password-encryption-key" const EncryptionKeyXMLFileName = "encryptionKey.xml" const EncryptionKeyMountXMLFileName = "encryptionKeyMount.xml" +// File-based probe constants +const StartupProbeFileBasedScriptName = "startupHealthCheck.sh" +const LivenessProbeFileBasedScriptName = "livenessHealthCheck.sh" +const ReadinessProbeFileBasedScriptName = "readinessHealthCheck.sh" +const StartupProbeFileName = "started" +const LivenessProbeFileName = "live" +const ReadinessProbeFileName = "ready" + const ( productChargedContainersKey string = "productChargedContainers" productIDKey string = "productID" @@ -351,6 +359,28 @@ func CustomizeLibertyEnv(pts *corev1.PodTemplateSpec, la *wlv1.WebSphereLibertyA ) } + if isFileBasedProbesEnabled(la) { + checkInterval := "5s" + startupCheckInterval := "100ms" + if la.Spec.Probes != nil { + if la.Spec.Probes.CheckInterval != nil && len(*la.Spec.Probes.CheckInterval) > 0 { + // Lightly guard against user setting checkInterval to 0, 0ms, or 0s because isFileBasedProbesEnabled() returned true + configCheckInterval := *la.Spec.Probes.CheckInterval + if configCheckInterval != "0" && configCheckInterval != "0ms" && configCheckInterval != "0s" { + checkInterval = configCheckInterval + } + } + if la.Spec.Probes.StartupCheckInterval != nil && len(*la.Spec.Probes.StartupCheckInterval) > 0 { + startupCheckInterval = *la.Spec.Probes.StartupCheckInterval + } + } + + targetEnv = append(targetEnv, + corev1.EnvVar{Name: "MP_HEALTH_CHECK_INTERVAL", Value: checkInterval}, + corev1.EnvVar{Name: "MP_HEALTH_STARTUP_CHECK_INTERVAL", Value: startupCheckInterval}, + ) + } + // If manageTLS is true or not set, and SEC_IMPORT_K8S_CERTS is not set then default it to "true" if la.GetManageTLS() == nil || *la.GetManageTLS() { targetEnv = append(targetEnv, corev1.EnvVar{Name: "SEC_IMPORT_K8S_CERTS", Value: "true"}) @@ -1041,6 +1071,92 @@ func CustomizeLibertyFileMountXML(mountingPasswordKeySecret *corev1.Secret, moun return nil } +func isFileBasedProbesEnabled(instance *wlv1.WebSphereLibertyApplication) bool { + return instance.Spec.Probes != nil && instance.Spec.Probes.EnableFileBased != nil && *instance.Spec.Probes.EnableFileBased +} + +func clearFileBasedProbe(probe *corev1.Probe) *corev1.Probe { + if probe != nil && probe.Exec != nil && len(probe.Exec.Command) == 3 { + scriptCmd := probe.Exec.Command[2] + if strings.HasPrefix(scriptCmd, StartupProbeFileBasedScriptName) || + strings.HasPrefix(scriptCmd, LivenessProbeFileBasedScriptName) || + strings.HasPrefix(scriptCmd, ReadinessProbeFileBasedScriptName) { + probe = &corev1.Probe{} + } + } + return probe +} + +func configureFileBasedProbeExec(instance *wlv1.WebSphereLibertyApplication, probe *corev1.Probe, scriptName string, probeFile string) { + probe = getProbeWithoutHandlers(probe) // remove any preset handlers configured to this probe + probesConfig := instance.Spec.Probes + cmdList := []string{scriptName} + if scriptName == StartupProbeFileBasedScriptName { + // Set timeout seconds for the startup probe + timeoutSeconds := int32(1) + if probe.TimeoutSeconds > 0 { + timeoutSeconds = probe.TimeoutSeconds + } + cmdList = append(cmdList, fmt.Sprintf("-t %d", timeoutSeconds)) + } else { + // Set period seconds for all other probes + periodSeconds := int32(10) + if probe.PeriodSeconds > 0 { + periodSeconds = probe.PeriodSeconds + } + cmdList = append(cmdList, fmt.Sprintf("-p %d", periodSeconds)) + } + if probesConfig.FileDirectory != nil && len(*probesConfig.FileDirectory) > 0 { + fileDirectory := strings.TrimRight(*probesConfig.FileDirectory, "/") + if len(fileDirectory) > 0 { + cmdList = append(cmdList, fmt.Sprintf("-f %s/%s", fileDirectory, probeFile)) + } + } + probe.Exec = &corev1.ExecAction{ + Command: []string{"/bin/sh", "-c", strings.Join(cmdList, FlagDelimiterSpace)}, + } +} + +func getProbeWithoutHandlers(probe *corev1.Probe) *corev1.Probe { + probe = getOrInitProbe(probe) + probe.ProbeHandler = corev1.ProbeHandler{} + return probe +} + +func getOrInitProbe(probe *corev1.Probe) *corev1.Probe { + if probe == nil { + return &corev1.Probe{} + } + return probe +} + +func patchFileBasedProbe(instance *wlv1.WebSphereLibertyApplication, defaultProbe *corev1.Probe, instanceProbe *corev1.Probe, scriptName string, probeFile string) *corev1.Probe { + defaultProbe = getOrInitProbe(defaultProbe) + instanceProbe = getOrInitProbe(instanceProbe) + isExecConfigured := instanceProbe.Exec != nil + instanceProbe = rcoutils.CustomizeProbeDefaults(instanceProbe, defaultProbe) + if !isExecConfigured { + configureFileBasedProbeExec(instance, instanceProbe, scriptName, probeFile) + } + return instanceProbe +} + +func CustomizeFileBasedProbes(pts *corev1.PodTemplateSpec, instance *wlv1.WebSphereLibertyApplication) { + if !isFileBasedProbesEnabled(instance) { + if instance.Spec.Probes == nil { + return + } + // Reset probe if file-based settings were previously configured + instance.Spec.Probes.Startup = clearFileBasedProbe(instance.Spec.Probes.Startup) + instance.Spec.Probes.Liveness = clearFileBasedProbe(instance.Spec.Probes.Liveness) + instance.Spec.Probes.Readiness = clearFileBasedProbe(instance.Spec.Probes.Readiness) + return + } + instance.Spec.Probes.Startup = patchFileBasedProbe(instance, instance.Spec.Probes.WebSphereLibertyApplicationProbes.GetDefaultStartupProbe(instance), instance.Spec.Probes.Startup, StartupProbeFileBasedScriptName, StartupProbeFileName) + instance.Spec.Probes.Liveness = patchFileBasedProbe(instance, instance.Spec.Probes.WebSphereLibertyApplicationProbes.GetDefaultLivenessProbe(instance), instance.Spec.Probes.Liveness, LivenessProbeFileBasedScriptName, LivenessProbeFileName) + instance.Spec.Probes.Readiness = patchFileBasedProbe(instance, instance.Spec.Probes.WebSphereLibertyApplicationProbes.GetDefaultReadinessProbe(instance), instance.Spec.Probes.Readiness, ReadinessProbeFileBasedScriptName, ReadinessProbeFileName) +} + // Converts a file name into a lowercase word separated string // Example: managedLTPASecret.xml -> managed-ltpa-secret-xml func parseMountName(fileName string) string {