Skip to content

Commit 7df3fbf

Browse files
committed
Merge branch 'mmalvezz' into 'master'
Add changes to pdb controller + usecase02 See merge request rac-docker-dev/oracle-database-operator!235
2 parents b171222 + 3fefa26 commit 7df3fbf

File tree

9 files changed

+887
-7
lines changed

9 files changed

+887
-7
lines changed

controllers/database/pdb_controller.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ func (r *PDBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
229229
err = r.getPDBState(ctx, req, pdb)
230230
case pdbPhaseMap:
231231
err = r.mapPDB(ctx, req, pdb)
232-
case pdbPhaseFail:
233-
err = r.mapPDB(ctx, req, pdb)
232+
case pdbPhaseFail:
233+
err = r.mapPDB(ctx, req, pdb)
234234
default:
235235
log.Info("DEFAULT:", "Name", pdb.Name, "Phase", phase, "Status", strconv.FormatBool(pdb.Status.Status))
236236
return requeueN, nil
@@ -904,12 +904,24 @@ func (r *PDBReconciler) modifyPDB(ctx context.Context, req ctrl.Request, pdb *db
904904
return err
905905
}
906906

907-
// To prevent Reconcile from Modifying again whenever the Operator gets re-started
908-
modOption := pdb.Spec.PDBState + "-" + pdb.Spec.ModifyOption
909-
if pdb.Status.ModifyOption == modOption {
907+
if pdb.Status.OpenMode == "READ WRITE" && pdb.Spec.PDBState == "OPEN" && pdb.Spec.ModifyOption == "READ WRITE" {
908+
/* Database is already open no action required */
909+
return nil
910+
}
911+
912+
if pdb.Status.OpenMode == "MOUNTED" && pdb.Spec.PDBState == "CLOSE" && pdb.Spec.ModifyOption == "IMMEDIATE" {
913+
/* Database is already close no action required */
910914
return nil
911915
}
912916

917+
// To prevent Reconcile from Modifying again whenever the Operator gets re-started
918+
/*
919+
modOption := pdb.Spec.PDBState + "-" + pdb.Spec.ModifyOption
920+
if pdb.Status.ModifyOption == modOption {
921+
return nil
922+
}
923+
*/
924+
913925
cdb, err := r.getCDBResource(ctx, req, pdb)
914926
if err != nil {
915927
return err
@@ -919,6 +931,8 @@ func (r *PDBReconciler) modifyPDB(ctx context.Context, req ctrl.Request, pdb *db
919931
"state": pdb.Spec.PDBState,
920932
"modifyOption": pdb.Spec.ModifyOption,
921933
"getScript": strconv.FormatBool(*(pdb.Spec.GetScript))}
934+
log.Info("MODIFY PDB", "pdb.Spec.PDBState=", pdb.Spec.PDBState, "pdb.Spec.ModifyOption=", pdb.Spec.ModifyOption)
935+
log.Info("PDB STATUS OPENMODE", "pdb.Status.OpenMode=", pdb.Status.OpenMode)
922936

923937
pdbName := pdb.Spec.PDBName
924938
url := "https://" + pdb.Spec.CDBResName + "-ords:" + strconv.Itoa(cdb.Spec.ORDSPort) + "/ords/_/db-api/latest/database/pdbs/" + pdbName + "/status"
@@ -973,8 +987,8 @@ func (r *PDBReconciler) getPDBState(ctx context.Context, req ctrl.Request, pdb *
973987

974988
if err != nil {
975989
pdb.Status.OpenMode = "UNKNOWN"
976-
pdb.Status.Msg = "CHECK PDB STATUS"
977-
pdb.Status.Status = false
990+
pdb.Status.Msg = "CHECK PDB STATUS"
991+
pdb.Status.Status = false
978992
return err
979993
}
980994

@@ -985,6 +999,13 @@ func (r *PDBReconciler) getPDBState(ctx context.Context, req ctrl.Request, pdb *
985999

9861000
pdb.Status.OpenMode = objmap["open_mode"].(string)
9871001

1002+
if pdb.Status.OpenMode == "READ WRITE" {
1003+
err := r.mapPDB(ctx, req, pdb)
1004+
if err != nil {
1005+
log.Info("Fail to Map resource getting PDB state")
1006+
}
1007+
}
1008+
9881009
log.Info("Successfully obtained PDB state", "PDB Name", pdb.Spec.PDBName, "State", objmap["open_mode"].(string))
9891010
return nil
9901011
}
@@ -1036,6 +1057,10 @@ func (r *PDBReconciler) mapPDB(ctx context.Context, req ctrl.Request, pdb *dbapi
10361057
pdb.Status.ConnString = cdb.Spec.DBTnsurl
10371058
}
10381059

1060+
if err := r.Status().Update(ctx, pdb); err != nil {
1061+
log.Error(err, "Failed to update status for :"+pdb.Name, "err", err.Error())
1062+
}
1063+
10391064
log.Info("Successfully mapped PDB to Kubernetes resource", "PDB Name", pdb.Spec.PDBName)
10401065
return nil
10411066
}

docs/multitenant/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
# Oracle Multitenant Database Controller
66

7+
> <span style="color:red"> WARNING: Examples with https are located in the usecases directories </span>
8+
79
CDBs and PDBs are the part of the Oracle Database's [Multitenant Architecture](https://docs.oracle.com/en/database/oracle/oracle-database/21/multi/introduction-to-the-multitenant-architecture.html#GUID-AB84D6C9-4BBE-4D36-992F-2BB85739329F). The Multitenant Database Controller is a feature of Oracle DB Operator for Kubernetes (OraOperator) which helps to manage the life cycle of Pluggable Databases (PDBs) in an Oracle Container Database(CDB).
810

911
The target CDB (for which the PDB life cycle management is needed) can be running on an multitenant machine and to manage its PDBs, the Oracle DB Operator can run on an multitenant Kubernetes system (For Example: [Oracle Linux Cloud Native Environment or OLCNE](https://docs.oracle.com/en/operating-systems/olcne/)).

0 commit comments

Comments
 (0)