Skip to content

Commit c614050

Browse files
authored
Merge pull request #68 from IshaanDesai45/bugfix-issue_67
Bugfix issue 67
2 parents 2123de1 + 8e49ed7 commit c614050

File tree

3 files changed

+49
-41
lines changed

3 files changed

+49
-41
lines changed

commons/database/constants.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ const DataguardBrokerAddDBMaxAvailabilityCMD string = "ADD DATABASE ${ORACLE_SID
212212
"(CONNECT_DATA=(SERVICE_NAME=${ORACLE_SID}_DGMGRL)(INSTANCE_NAME=${ORACLE_SID})(SERVER=DEDICATED)))';" +
213213
"\nENABLE CONFIGURATION;"
214214

215-
const RemoveStandbyDBFromDGConfgCMD string = "DISABLE DATABASE ${ORACLE_SID};" +
216-
"\nREMOVE DATABASE ${ORACLE_SID};"
215+
const RemoveStandbyDBFromDGConfgCMD string = "DISABLE DATABASE ${ORACLE_SID};" +
216+
"\nREMOVE DATABASE ${ORACLE_SID};"
217217

218218
const DBShowConfigCMD string = "SHOW CONFIGURATION;"
219219

@@ -506,7 +506,7 @@ const SetApexUsers string = "\numask 177" +
506506
"\numask 022"
507507

508508
// Get Sid, Pdbname, Edition for prebuilt db
509-
const GetSidPdbEditionCMD string = "echo $ORACLE_SID,$ORACLE_PDB,$ORACLE_EDITION,Edition;"
509+
const GetSidPdbEditionCMD string = "echo $ORACLE_SID,$ORACLE_PDB,$ORACLE_EDITION;"
510510

511511
// Command to enable TCPS as a formatted string. The parameter would be the port at which TCPS is enabled.
512512
const EnableTcpsCMD string = "$ORACLE_BASE/$CONFIG_TCPS_FILE"

commons/database/utils.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -507,23 +507,23 @@ func GetDatabaseRole(readyPod corev1.Pod, r client.Reader,
507507

508508
func GetDatabaseOpenMode(readyPod corev1.Pod, r client.Reader,
509509
config *rest.Config, ctx context.Context, req ctrl.Request, edition string) (string, error) {
510-
log := ctrllog.FromContext(ctx).WithValues("GetDatabaseOpenMode",req.NamespacedName)
510+
log := ctrllog.FromContext(ctx).WithValues("GetDatabaseOpenMode", req.NamespacedName)
511511

512-
out,err := ExecCommand(r, config, readyPod.Name, readyPod.Namespace, "", ctx, req, false, "bash", "-c",
513-
fmt.Sprintf("echo -e \"%s\" | %s",GetDBOpenMode,SQLPlusCLI))
514-
if err != nil {
515-
return "",err
516-
}
517-
log.Info(out)
518-
if !strings.Contains(out, "no rows selected") && !strings.Contains(out, "ORA-") {
519-
out1 := strings.Replace(out, " ", "_", -1)
520-
// filtering output and storing databse_role in "database_role"
521-
databaseOpenMode := strings.Fields(out1)[2]
522-
// first 2 values in the slice will be column name(DATABASE_ROLE) and a seperator(--------------) .
523-
return databaseOpenMode, nil
524-
}
525-
return "", errors.New("database open mode is nil")
512+
out, err := ExecCommand(r, config, readyPod.Name, readyPod.Namespace, "", ctx, req, false, "bash", "-c",
513+
fmt.Sprintf("echo -e \"%s\" | %s", GetDBOpenMode, SQLPlusCLI))
514+
if err != nil {
515+
return "", err
516+
}
517+
log.Info(out)
518+
if !strings.Contains(out, "no rows selected") && !strings.Contains(out, "ORA-") {
519+
out1 := strings.Replace(out, " ", "_", -1)
520+
// filtering output and storing databse_role in "database_role"
521+
databaseOpenMode := strings.Fields(out1)[2]
522+
// first 2 values in the slice will be column name(DATABASE_ROLE) and a seperator(--------------) .
523+
return databaseOpenMode, nil
526524
}
525+
return "", errors.New("database open mode is nil")
526+
}
527527

528528
// Returns true if any of the pod in 'pods' is with pod.Status.Phase == phase
529529
func IsAnyPodWithStatus(pods []corev1.Pod, phase corev1.PodPhase) (bool, corev1.Pod) {
@@ -590,29 +590,29 @@ func GetNodeIp(r client.Reader, ctx context.Context, req ctrl.Request) string {
590590
}
591591

592592
// GetSidPdbEdition to display sid, pdbname, edition in ConnectionString
593-
func GetSidPdbEdition(r client.Reader, config *rest.Config, ctx context.Context, req ctrl.Request) (string, string, string) {
593+
func GetSidPdbEdition(r client.Reader, config *rest.Config, ctx context.Context, req ctrl.Request) (string, string, string, error) {
594594

595-
log := ctrllog.FromContext(ctx).WithValues("GetNodeIp", req.NamespacedName)
595+
log := ctrllog.FromContext(ctx).WithValues("GetSidbPdbEdition", req.NamespacedName)
596596

597597
readyPod, _, _, _, err := FindPods(r, "", "", req.Name, req.Namespace, ctx, req)
598598
if err != nil {
599599
log.Error(err, err.Error())
600-
return "", "", ""
600+
return "", "", "", fmt.Errorf("error while fetching ready pod %s : \n %s", readyPod.Name, err.Error())
601601
}
602602
if readyPod.Name != "" {
603603
out, err := ExecCommand(r, config, readyPod.Name, readyPod.Namespace, "",
604604
ctx, req, false, "bash", "-c", GetSidPdbEditionCMD)
605605
if err != nil {
606606
log.Error(err, err.Error())
607-
return "", "", ""
608-
}
609-
splitstr := strings.Split(out, ",")
610-
if len(splitstr) == 4 {
611-
return splitstr[0], splitstr[1], splitstr[2]
607+
return "", "", "", err
612608
}
609+
log.Info("GetSidPdbEditionCMD output \n" + out)
610+
splitstr := strings.Split((strings.TrimSpace(out)), ",")
611+
return splitstr[0], splitstr[1], splitstr[2], nil
613612
}
614-
615-
return "", "", ""
613+
err = errors.New("ready pod name is nil")
614+
log.Error(err, err.Error())
615+
return "", "", "", err
616616
}
617617

618618
// Get Datapatch Status

controllers/database/singleinstancedatabase_controller.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,22 +167,22 @@ func (r *SingleInstanceDatabaseReconciler) Reconcile(ctx context.Context, req ct
167167
return result, nil
168168
}
169169

170-
// Service creation
171-
result, err = r.createOrReplaceSVC(ctx, req, singleInstanceDatabase)
170+
// PVC Creation
171+
result, err = r.createOrReplacePVC(ctx, req, singleInstanceDatabase)
172172
if result.Requeue {
173173
r.Log.Info("Reconcile queued")
174174
return result, nil
175175
}
176176

177-
// PVC Creation
178-
result, err = r.createOrReplacePVC(ctx, req, singleInstanceDatabase)
177+
// POD creation
178+
result, err = r.createOrReplacePods(singleInstanceDatabase, cloneFromDatabase, referredPrimaryDatabase, ctx, req)
179179
if result.Requeue {
180180
r.Log.Info("Reconcile queued")
181181
return result, nil
182182
}
183183

184-
// POD creation
185-
result, err = r.createOrReplacePods(singleInstanceDatabase, cloneFromDatabase, referredPrimaryDatabase, ctx, req)
184+
// Service creation
185+
result, err = r.createOrReplaceSVC(ctx, req, singleInstanceDatabase)
186186
if result.Requeue {
187187
r.Log.Info("Reconcile queued")
188188
return result, nil
@@ -280,6 +280,7 @@ func (r *SingleInstanceDatabaseReconciler) Reconcile(ctx context.Context, req ct
280280

281281
// If LoadBalancer = true , ensure Connect String is updated
282282
if singleInstanceDatabase.Status.ConnectString == dbcommons.ValueUnavailable {
283+
r.Log.Info("Connect string not available for the database " + singleInstanceDatabase.Name)
283284
return requeueY, nil
284285
}
285286

@@ -1494,17 +1495,24 @@ func (r *SingleInstanceDatabaseReconciler) createOrReplaceSVC(ctx context.Contex
14941495
extSvc = svc
14951496
}
14961497

1497-
pdbName := strings.ToUpper(m.Spec.Pdbname)
1498-
sid := m.Spec.Sid
1498+
var sid, pdbName string
1499+
var getSidPdbEditionErr error
14991500
if m.Spec.Image.PrebuiltDB {
1500-
edition := ""
1501-
sid, pdbName, edition = dbcommons.GetSidPdbEdition(r, r.Config, ctx, req)
1502-
if sid == "" || pdbName == "" || edition == "" {
1503-
return requeueN, nil
1501+
r.Log.Info("Initiliazing database sid, pdb, edition for prebuilt database")
1502+
var edition string
1503+
sid, pdbName, edition, getSidPdbEditionErr = dbcommons.GetSidPdbEdition(r, r.Config, ctx, ctrl.Request{NamespacedName: types.NamespacedName{Namespace: m.Namespace, Name: m.Name}})
1504+
if getSidPdbEditionErr != nil {
1505+
return requeueY, getSidPdbEditionErr
15041506
}
1507+
r.Log.Info(fmt.Sprintf("Prebuilt database: %s has SID : %s, PDB : %s, EDITION: %s", m.Name, sid, pdbName, edition))
15051508
m.Status.Edition = cases.Title(language.English).String(edition)
15061509
}
1507-
1510+
if sid == "" {
1511+
sid = strings.ToUpper(m.Spec.Sid)
1512+
}
1513+
if pdbName == "" {
1514+
pdbName = strings.ToUpper(m.Spec.Pdbname)
1515+
}
15081516
if m.Spec.LoadBalancer {
15091517
m.Status.ClusterConnectString = extSvc.Name + "." + extSvc.Namespace + ":" + fmt.Sprint(extSvc.Spec.Ports[1].Port) + "/" + strings.ToUpper(sid)
15101518
if len(extSvc.Status.LoadBalancer.Ingress) > 0 {

0 commit comments

Comments
 (0)