Skip to content

Commit 1ec77d6

Browse files
committed
Implement GetManagedPort()
1 parent de5574d commit 1ec77d6

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

api/v1/webspherelibertyapplication_types.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,16 @@ func (cr *WebSphereLibertyApplication) GetManageTLS() *bool {
929929
return cr.Spec.ManageTLS
930930
}
931931

932+
func (cr *WebSphereLibertyApplication) GetManagedPort() int {
933+
if cr.GetService() != nil && cr.GetService().GetPort() != 0 {
934+
return int(cr.GetService().GetPort())
935+
}
936+
if cr.GetManageTLS() == nil || *cr.GetManageTLS() {
937+
return 9443
938+
}
939+
return 9080
940+
}
941+
932942
// GetEnv returns slice of environment variables
933943
func (cr *WebSphereLibertyApplication) GetEnv() []corev1.EnvVar {
934944
return cr.Spec.Env
@@ -1452,12 +1462,7 @@ func (cr *WebSphereLibertyApplication) Initialize() {
14521462
}
14531463

14541464
if cr.Spec.Service.Port == 0 {
1455-
if cr.Spec.ManageTLS == nil || *cr.Spec.ManageTLS {
1456-
cr.Spec.Service.Port = 9443
1457-
1458-
} else {
1459-
cr.Spec.Service.Port = 9080
1460-
}
1465+
cr.Spec.Service.Port = int32(cr.GetManagedPort())
14611466
}
14621467

14631468
// If TargetPorts on Serviceports are not set, default them to the Port value in the CR

utils/utils.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828

2929
"math/rand/v2"
3030

31+
"github.com/application-stacks/runtime-component-operator/common"
32+
3133
wlv1 "github.com/WASdev/websphere-liberty-operator/api/v1"
3234
rcoutils "github.com/application-stacks/runtime-component-operator/utils"
3335
routev1 "github.com/openshift/api/route/v1"
@@ -1153,7 +1155,7 @@ func patchFileBasedProbe(defaultProbe *corev1.Probe, instanceProbe *corev1.Probe
11531155
defaultProbe = getOrInitProbe(defaultProbe)
11541156
instanceProbe = getOrInitProbe(instanceProbe)
11551157
isExecConfigured := instanceProbe.Exec != nil // this flag allows the user to override the ExecAction object to bring their own custom file-based health check
1156-
instanceProbe = rcoutils.CustomizeProbeDefaults(instanceProbe, defaultProbe)
1158+
instanceProbe = common.CustomizeProbeDefaults(instanceProbe, defaultProbe)
11571159
if !isExecConfigured {
11581160
configureFileBasedProbeExec(instanceProbe, scriptName, probeFile)
11591161
}
@@ -1186,14 +1188,15 @@ func customizeFileBasedProbes(appContainer *corev1.Container, instance *wlv1.Web
11861188
if appContainer == nil {
11871189
return
11881190
}
1189-
if instance.Spec.Probes.WebSphereLibertyApplicationProbes.Startup != nil {
1190-
appContainer.StartupProbe = patchFileBasedProbe(instance.Spec.Probes.WebSphereLibertyApplicationProbes.GetDefaultStartupProbe(instance), instance.Spec.Probes.Startup, StartupProbeFileBasedScriptName, StartupProbeFileName)
1191+
probes := instance.Spec.Probes.WebSphereLibertyApplicationProbes
1192+
if probes.Startup != nil {
1193+
appContainer.StartupProbe = patchFileBasedProbe(probes.GetDefaultStartupProbe(instance), probes.GetStartupProbe(), StartupProbeFileBasedScriptName, StartupProbeFileName)
11911194
}
1192-
if instance.Spec.Probes.WebSphereLibertyApplicationProbes.Liveness != nil {
1193-
appContainer.LivenessProbe = patchFileBasedProbe(instance.Spec.Probes.WebSphereLibertyApplicationProbes.GetDefaultLivenessProbe(instance), instance.Spec.Probes.Liveness, LivenessProbeFileBasedScriptName, LivenessProbeFileName)
1195+
if probes.Liveness != nil {
1196+
appContainer.LivenessProbe = patchFileBasedProbe(probes.GetDefaultLivenessProbe(instance), probes.GetLivenessProbe(), LivenessProbeFileBasedScriptName, LivenessProbeFileName)
11941197
}
1195-
if instance.Spec.Probes.WebSphereLibertyApplicationProbes.Readiness != nil {
1196-
appContainer.ReadinessProbe = patchFileBasedProbe(instance.Spec.Probes.WebSphereLibertyApplicationProbes.GetDefaultReadinessProbe(instance), instance.Spec.Probes.Readiness, ReadinessProbeFileBasedScriptName, ReadinessProbeFileName)
1198+
if probes.Readiness != nil {
1199+
appContainer.ReadinessProbe = patchFileBasedProbe(probes.GetDefaultReadinessProbe(instance), probes.GetReadinessProbe(), ReadinessProbeFileBasedScriptName, ReadinessProbeFileName)
11971200
}
11981201
}
11991202

0 commit comments

Comments
 (0)