Skip to content

Commit 6f5d369

Browse files
committed
Merge branch 'AbhiK_tcps_bugfixes' into 'master'
Bugfixes related to TCPS changes See merge request rac-docker-dev/oracle-database-operator!221
2 parents d5f3eee + aa37794 commit 6f5d369

File tree

8 files changed

+120
-20
lines changed

8 files changed

+120
-20
lines changed

apis/database/v1alpha1/pdb_webhook.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
3838

3939
/* MODIFIED (MM/DD/YY)
4040
** rcitton 07/14/22 - 33822886
41-
*/
42-
43-
41+
*/
42+
4443
package v1alpha1
4544

4645
import (

apis/database/v1alpha1/singleinstancedatabase_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ type SingleInstanceDatabaseStatus struct {
177177
// +kubebuilder:printcolumn:JSONPath=".status.releaseUpdate",name="Version",type="string"
178178
// +kubebuilder:printcolumn:JSONPath=".status.connectString",name="Connect Str",type="string"
179179
// +kubebuilder:printcolumn:JSONPath=".status.tcpsConnectString",name="TCPS Connect Str",type="string"
180-
// +kubebuilder:printcolumn:JSONPath=".status.tcpsPdbConnectString",name="TCPS Pdb Connect Str",type="string", priority=1
181180
// +kubebuilder:printcolumn:JSONPath=".status.pdbConnectString",name="Pdb Connect Str",type="string",priority=1
181+
// +kubebuilder:printcolumn:JSONPath=".status.tcpsPdbConnectString",name="TCPS Pdb Connect Str",type="string", priority=1
182182
// +kubebuilder:printcolumn:JSONPath=".status.oemExpressUrl",name="Oem Express Url",type="string"
183183

184184
// SingleInstanceDatabase is the Schema for the singleinstancedatabases API

apis/database/v1alpha1/singleinstancedatabase_webhook.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ func (r *SingleInstanceDatabase) ValidateCreate() error {
254254
field.Invalid(field.NewPath("spec").Child("tcpsListenerPort"), r.Spec.TcpsListenerPort,
255255
"listenerPort and tcpsListenerPort can not be equal."))
256256
}
257+
if r.Spec.EnableTCPS && r.Spec.TcpsListenerPort == 0 && r.Spec.ListenerPort == 1522 {
258+
allErrs = append(allErrs,
259+
field.Invalid(field.NewPath("spec").Child("listenerPort"), r.Spec.ListenerPort,
260+
"listenerPort can not be 1522 as the default port for tcpsListenerPort is 1522."))
261+
}
257262

258263
// Certificate Renew Duration Validation
259264
if r.Spec.TcpsCertRenewInterval != "" {

commons/database/constants.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,22 @@ const ClientWalletUpdate string = "sed -i -e 's/HOST.*$/HOST=%s)/g' -e 's/PORT.*
498498

499499
// TCPS clientWallet location
500500
const ClientWalletLocation string = "/opt/oracle/oradata/clientWallet/%s"
501+
502+
// Service Patch Payloads
503+
// Three port payload: one OEM express, one TCP and one TCPS port
504+
const ThreePortPayload string = "{\"spec\": { \"ports\": [{\"name\": \"xmldb\", \"port\": 5500, \"protocol\": \"TCP\"},{%s},{%s}]}}"
505+
506+
// Two port payload: one OEM express, one TCP/TCPS port
507+
const TwoPortPayload string = "{\"spec\": { \"ports\": [{\"name\": \"xmldb\", \"port\": 5500, \"protocol\": \"TCP\"},{%s}]}}"
508+
509+
// Payload section for listener port
510+
const LsnrPort string = "\"name\": \"listener\", \"protocol\": \"TCP\", \"port\": %d"
511+
512+
// Payload section for listener node port
513+
const LsnrNodePort string = "\"name\": \"listener\", \"protocol\": \"TCP\", \"port\": 1521, \"nodePort\": %d"
514+
515+
// Payload section for TCPS port
516+
const TcpsPort string = "\"name\": \"listener-tcps\", \"protocol\": \"TCP\", \"port\": %d"
517+
518+
// Payload section for TCPS node port
519+
const TcpsNodePort string = "\"name\": \"listener-tcps\", \"protocol\": \"TCP\", \"port\": 1522, \"nodePort\": %d"

commons/database/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,6 @@ func PatchService(config *rest.Config, namespace string, ctx context.Context, re
686686

687687
// Trying to patch the service resource using Strategic Merge strategy
688688
log.Info("Patching the service", "Service", svcName)
689-
_, err = client.CoreV1().Services(namespace).Patch(ctx, svcName, types.StrategicMergePatchType, []byte(payload), metav1.PatchOptions{})
689+
_, err = client.CoreV1().Services(namespace).Patch(ctx, svcName, types.MergePatchType, []byte(payload), metav1.PatchOptions{})
690690
return err
691691
}

config/crd/bases/database.oracle.com_singleinstancedatabases.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ spec:
3636
- jsonPath: .status.tcpsConnectString
3737
name: TCPS Connect Str
3838
type: string
39-
- jsonPath: .status.tcpsPdbConnectString
40-
name: TCPS Pdb Connect Str
41-
priority: 1
42-
type: string
4339
- jsonPath: .status.pdbConnectString
4440
name: Pdb Connect Str
4541
priority: 1
4642
type: string
43+
- jsonPath: .status.tcpsPdbConnectString
44+
name: TCPS Pdb Connect Str
45+
priority: 1
46+
type: string
4747
- jsonPath: .status.oemExpressUrl
4848
name: Oem Express Url
4949
type: string

controllers/database/singleinstancedatabase_controller.go

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,31 +1127,108 @@ func (r *SingleInstanceDatabaseReconciler) createOrReplaceSVC(ctx context.Contex
11271127
}
11281128

11291129
deleteSvc := false
1130-
if extSvc.Spec.Type != extSvcType || len(extSvc.Spec.Ports) != requiredPorts {
1130+
patchSvc := false
1131+
if extSvc.Spec.Type != extSvcType {
11311132
deleteSvc = true
11321133
} else {
1133-
// Match for the ports
1134-
if (m.Spec.ListenerPort != 0 && svcPort != targetPorts[1]) || (m.Spec.TcpsListenerPort != 0 && tcpsSvcPort != targetPorts[len(targetPorts)-1]) {
1135-
deleteSvc = true
1134+
// Conditions to determine whether to patch or not
1135+
if len(extSvc.Spec.Ports) != requiredPorts {
1136+
patchSvc = true
11361137
}
1137-
if m.Spec.ListenerPort == 0 && m.Spec.TcpsListenerPort == 0 {
1138-
if (m.Spec.EnableTCPS && extSvc.Spec.Ports[1].TargetPort.IntVal != dbcommons.CONTAINER_TCPS_PORT) ||
1139-
(!m.Spec.EnableTCPS && extSvc.Spec.Ports[1].TargetPort.IntVal != dbcommons.CONTAINER_LISTENER_PORT) {
1140-
deleteSvc = true
1138+
1139+
if (m.Spec.ListenerPort != 0 && svcPort != targetPorts[1]) || (m.Spec.EnableTCPS && m.Spec.TcpsListenerPort != 0 && tcpsSvcPort != targetPorts[len(targetPorts)-1]) {
1140+
patchSvc = true
1141+
}
1142+
1143+
if m.Spec.LoadBalancer {
1144+
if m.Spec.EnableTCPS {
1145+
if m.Spec.TcpsListenerPort == 0 && tcpsSvcPort != targetPorts[len(targetPorts)-1] {
1146+
patchSvc = true
1147+
}
1148+
} else {
1149+
if m.Spec.ListenerPort == 0 && svcPort != targetPorts[1] {
1150+
patchSvc = true
1151+
}
1152+
}
1153+
} else {
1154+
if m.Spec.EnableTCPS {
1155+
if m.Spec.TcpsListenerPort == 0 && tcpsSvcPort != extSvc.Spec.Ports[len(targetPorts)-1].TargetPort.IntVal {
1156+
patchSvc = true
1157+
}
1158+
} else {
1159+
if m.Spec.ListenerPort == 0 && svcPort != extSvc.Spec.Ports[1].TargetPort.IntVal {
1160+
patchSvc = true
1161+
}
11411162
}
11421163
}
11431164
}
11441165

11451166
if deleteSvc {
11461167
// Deleting th service
11471168
log.Info("Deleting service", "name", extSvcName)
1148-
err := r.Delete(ctx, extSvc)
1169+
// Setting GracePeriodSeconds to 0 for instant deletion
1170+
delOpts := &client.DeleteOptions{}
1171+
var gracePeriod client.GracePeriodSeconds = 0
1172+
gracePeriod.ApplyToDelete(delOpts)
1173+
1174+
err := r.Delete(ctx, extSvc, delOpts)
11491175
if err != nil {
11501176
r.Log.Error(err, "Failed to delete service", "name", extSvcName)
11511177
return requeueN, err
11521178
}
11531179
isExtSvcFound = false
11541180
}
1181+
1182+
if patchSvc {
1183+
// Reset connect strings whenever patching happens
1184+
m.Status.Status = dbcommons.StatusUpdating
1185+
m.Status.ConnectString = dbcommons.ValueUnavailable
1186+
m.Status.PdbConnectString = dbcommons.ValueUnavailable
1187+
m.Status.OemExpressUrl = dbcommons.ValueUnavailable
1188+
m.Status.TcpsConnectString = dbcommons.ValueUnavailable
1189+
m.Status.TcpsPdbConnectString = dbcommons.ValueUnavailable
1190+
1191+
// Payload formation for patching the service
1192+
var payload string
1193+
if m.Spec.LoadBalancer {
1194+
if m.Spec.EnableTCPS {
1195+
if m.Spec.ListenerPort != 0 {
1196+
payload = fmt.Sprintf(dbcommons.ThreePortPayload, fmt.Sprintf(dbcommons.LsnrPort, svcPort), fmt.Sprintf(dbcommons.TcpsPort, tcpsSvcPort))
1197+
} else {
1198+
payload = fmt.Sprintf(dbcommons.TwoPortPayload, fmt.Sprintf(dbcommons.TcpsPort, tcpsSvcPort))
1199+
}
1200+
} else {
1201+
payload = fmt.Sprintf(dbcommons.TwoPortPayload, fmt.Sprintf(dbcommons.LsnrPort, svcPort))
1202+
}
1203+
} else {
1204+
if m.Spec.EnableTCPS {
1205+
if m.Spec.ListenerPort != 0 && m.Spec.TcpsListenerPort != 0 {
1206+
payload = fmt.Sprintf(dbcommons.ThreePortPayload, fmt.Sprintf(dbcommons.LsnrNodePort, svcPort), fmt.Sprintf(dbcommons.TcpsNodePort, tcpsSvcPort))
1207+
} else if m.Spec.ListenerPort != 0 {
1208+
payload = fmt.Sprintf(dbcommons.ThreePortPayload, fmt.Sprintf(dbcommons.LsnrNodePort, svcPort), fmt.Sprintf(dbcommons.TcpsPort, tcpsSvcPort))
1209+
} else if m.Spec.TcpsListenerPort != 0 {
1210+
payload = fmt.Sprintf(dbcommons.TwoPortPayload, fmt.Sprintf(dbcommons.TcpsNodePort, tcpsSvcPort))
1211+
} else {
1212+
payload = fmt.Sprintf(dbcommons.TwoPortPayload, fmt.Sprintf(dbcommons.TcpsPort, tcpsSvcPort))
1213+
}
1214+
} else {
1215+
if m.Spec.ListenerPort != 0 {
1216+
payload = fmt.Sprintf(dbcommons.TwoPortPayload, fmt.Sprintf(dbcommons.LsnrNodePort, svcPort))
1217+
} else {
1218+
payload = fmt.Sprintf(dbcommons.TwoPortPayload, fmt.Sprintf(dbcommons.LsnrPort, svcPort))
1219+
}
1220+
}
1221+
}
1222+
1223+
//Attemp Service Pathcing
1224+
log.Info("Patching the service", "Service.Name", extSvc.Name, "payload", payload)
1225+
err := dbcommons.PatchService(r.Config, m.Namespace, ctx, req, extSvcName, payload)
1226+
if err != nil {
1227+
log.Error(err, "Failed to patch Service")
1228+
}
1229+
//Requeue once after patching
1230+
return requeueY, err
1231+
}
11551232
}
11561233

11571234
if !isExtSvcFound {

docs/sidb/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ To obtain a quick database status, use the following command as an example:
6363
```sh
6464
$ kubectl get singleinstancedatabase sidb-sample
6565

66-
NAME EDITION STATUS VERSION CONNECT STR OEM EXPRESS URL
67-
sidb-sample Enterprise Healthy 19.3.0.0.0 10.0.25.54:1521/ORCLCDB https://10.0.25.54:5500/em
66+
NAME EDITION STATUS VERSION CONNECT STR TCPS CONNECT STR OEM EXPRESS URL
67+
sidb-sample Enterprise Healthy 19.3.0.0.0 10.0.25.54:1521/ORCL1 Unavailable https://10.0.25.54:5500/em
6868
```
6969

7070
#### Detailed Status

0 commit comments

Comments
 (0)