Skip to content

Commit 4876e14

Browse files
IshaanDesai45yunus-qureshi
authored andcommitted
23c Free support and Dataguard Controller enhancements
1 parent eadd47f commit 4876e14

File tree

5 files changed

+63
-21
lines changed

5 files changed

+63
-21
lines changed

config/samples/sidb/singleinstancedatabase_free.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ spec:
2222

2323
## Database image details
2424
image:
25+
## Oracle Database Free is only supported from DB version 23.2 onwards
2526
pullFrom: container-registry.oracle.com/database/free:latest
2627
prebuiltDB: true
2728

config/samples/sidb/singleinstancedatabase_secrets.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ stringData:
4242

4343
---
4444

45-
## Prebuilt-Database Admin password secret
45+
## Oracle Database Free Admin password secret
4646
apiVersion: v1
4747
kind: Secret
4848
metadata:

controllers/database/dataguardbroker_controller.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,21 @@ func (r *DataguardBrokerReconciler) setupDataguardBrokerConfiguration(m *dbapi.D
355355
sidbReadyPod corev1.Pod, adminPassword string, ctx context.Context, req ctrl.Request) ctrl.Result {
356356
log := r.Log.WithValues("setupDataguardBrokerConfiguration", req.NamespacedName)
357357

358+
databases, _, err := dbcommons.GetDatabasesInDgConfig(sidbReadyPod, r, r.Config, ctx, req)
359+
dbSet := make(map[string]struct{})
360+
if err != nil {
361+
if err.Error() != "databases in DG config is nil" {
362+
return requeueY
363+
}
364+
}
365+
if len(databases) > 0 {
366+
log.Info("Databases in DG config are :")
367+
for i := 0; i < len(databases); i++ {
368+
log.Info(strings.Split(databases[i], ":")[0])
369+
dbSet[strings.ToUpper(strings.Split(databases[i], ":")[0])] = struct{}{}
370+
}
371+
}
372+
358373
for i := 0; i < len(m.Spec.StandbyDatabaseRefs); i++ {
359374

360375
standbyDatabase := &dbapi.SingleInstanceDatabase{}
@@ -369,6 +384,12 @@ func (r *DataguardBrokerReconciler) setupDataguardBrokerConfiguration(m *dbapi.D
369384
log.Error(err, err.Error())
370385
return requeueY
371386
}
387+
_, ok := dbSet[standbyDatabase.Status.Sid]
388+
if ok {
389+
log.Info("A database with the same SID is already configured in the DG")
390+
r.Recorder.Eventf(m, corev1.EventTypeWarning, "Spec Error", "A database with the same SID " + standbyDatabase.Status.Sid + " is already configured in the DG")
391+
continue
392+
}
372393

373394
// Check if dataguard broker is already configured for the standby database
374395
if standbyDatabase.Status.DgBrokerConfigured {

controllers/database/singleinstancedatabase_controller.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,17 +2037,27 @@ func (r *SingleInstanceDatabaseReconciler) validateDBReadiness(m *dbapi.SingleIn
20372037
m.Status.ReleaseUpdate = version
20382038
}
20392039
}
2040-
oemSupport, err := isOEMSupported(r,m.Status.ReleaseUpdate)
2040+
dbMajorVersion, err := strconv.Atoi(strings.Split(m.Status.ReleaseUpdate,".")[0])
20412041
if err != nil {
20422042
r.Log.Error(err, err.Error())
20432043
return requeueY, readyPod, err
20442044
}
2045-
if oemSupport {
2046-
m.Status.OemExpressUrl = oemExpressUrl
2047-
} else {
2045+
r.Log.Info("DB Major Version is " + strconv.Itoa(dbMajorVersion))
2046+
// Validating that free edition of the database is only supported from database 23c onwards
2047+
if (m.Spec.Edition == "free" && dbMajorVersion < 23){
2048+
r.Log.Info("Oracle Database Free is only supported from version 23c onwards")
2049+
r.Recorder.Eventf(m, corev1.EventTypeWarning, "Spec Error", "Oracle Database Free is only supported from version 23c onwards")
2050+
m.Status.Status = dbcommons.StatusError
2051+
return requeueN, readyPod, errors.New("Oracle Database Free is only supported from version 23c onwards")
2052+
}
2053+
// Checking if OEM is supported in the provided Database version
2054+
if (dbMajorVersion >= 23 ) {
20482055
m.Status.OemExpressUrl = dbcommons.ValueUnavailable
2056+
} else {
2057+
m.Status.OemExpressUrl = oemExpressUrl
20492058
}
20502059

2060+
20512061
if strings.ToUpper(m.Status.Role) == "PRIMARY" && m.Status.DatafilesPatched != "true" {
20522062
eventReason := "Datapatch Pending"
20532063
eventMsg := "datapatch execution pending"
@@ -2623,6 +2633,13 @@ func (r *SingleInstanceDatabaseReconciler) updateORDSStatus(m *dbapi.SingleInsta
26232633
func (r *SingleInstanceDatabaseReconciler) manageSingleInstanceDatabaseDeletion(req ctrl.Request, ctx context.Context,
26242634
m *dbapi.SingleInstanceDatabase) (ctrl.Result, error) {
26252635
log := r.Log.WithValues("manageSingleInstanceDatabaseDeletion", req.NamespacedName)
2636+
2637+
log.Info("DG broker is configured with the DB " + m.Status.Sid + " : " + strconv.FormatBool(m.Status.DgBrokerConfigured))
2638+
if (m.Status.DgBrokerConfigured){
2639+
log.Info("Database cannot be deleted as it is present in a DataGuard Broker configuration")
2640+
r.Recorder.Eventf(m, corev1.EventTypeWarning, "Deleting", "Database cannot be deleted as it is present in a DataGuard Broker configuration")
2641+
return requeueN,nil
2642+
}
26262643

26272644
// Check if the SingleInstanceDatabase instance is marked to be deleted, which is
26282645
// indicated by the deletion timestamp being set.
@@ -3105,19 +3122,3 @@ func SetupStandbyDatabase(r *SingleInstanceDatabaseReconciler, stdby *dbapi.Sing
31053122

31063123
return nil
31073124
}
3108-
3109-
3110-
func isOEMSupported (r *SingleInstanceDatabaseReconciler,version string) (bool,error) {
3111-
majorVersion, err := strconv.Atoi(strings.Split(version,".")[0])
3112-
r.Log.Info("majorVersion of database is " + strconv.Itoa(majorVersion))
3113-
if err != nil {
3114-
return false,err
3115-
}
3116-
if majorVersion > 21{
3117-
r.Log.Info("major Version " + strconv.Itoa(majorVersion) + " is greater that 21 so OEM Express is not supported")
3118-
return false,nil
3119-
} else {
3120-
r.Log.Info("major Version " + strconv.Itoa(majorVersion) + " is lesser than equal to 21 so OEM Express is supported")
3121-
return true,nil
3122-
}
3123-
}

docs/sidb/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Oracle Database Operator for Kubernetes (`OraOperator`) includes the Single Inst
2626
* [Creating an Oracle Data Guard Configuration](#creating-an-oracle-data-guard-configuration)
2727
* [Creating a Standby Database](#creating-a-standby-database)
2828
* [Setup DataGuardBroker Configuration for a Single Instance Database](#setup-dataguardbroker-configuration-for-a-single-instance-database)
29+
* [Delete a standby database with dataguard broker configured](#delete-a-standby-database-with-dataguard-broker-configured)
2930
* [OracleRestDataService Resource](#oraclerestdataservice-resource)
3031
* [REST Enable a Database](#rest-enable-a-database)
3132
* [Provision ORDS](#provision-ords)
@@ -756,6 +757,24 @@ $ kubectl delete dataguardbroker dgbroker-sample
756757

757758
**NOTE :** You can only delete DataGuard broker when role of `.spec.primaryDatabaseRef` is PRIMARY
758759

760+
### Delete a standby database with dataguard broker configured
761+
762+
To delete a standby database in a dataguard configuration, delete the dataguardbroker resource first followed by the standby database
763+
764+
#### Delete DataguardBroker Resource
765+
```sh
766+
$ kubectl delete dataguardbroker dgbroker-sample
767+
768+
dataguardbroker.database.oracle.com/dgbroker-sample deleted
769+
```
770+
771+
#### Delete Standby Database
772+
```sh
773+
$ kubectl delete singleinstancedatabase stdby-1
774+
775+
singleinstancedatabase.database.oracle.com "stdby-1" deleted
776+
```
777+
759778
## OracleRestDataService Resource
760779

761780
The Oracle Database Operator creates the `OracleRestDataService` as a custom resource. We will refer `OracleRestDataService` as ORDS from now onwards. Creating ORDS as a custom resource enables the RESTful API access to the Oracle Database in K8s and enables it to be managed as a native Kubernetes object.

0 commit comments

Comments
 (0)