@@ -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 {
0 commit comments