Skip to content

Commit 90561b6

Browse files
committed
Merge branch 'mmalvezz' into 'master'
bug 34836177 See merge request rac-docker-dev/oracle-database-operator!234
2 parents b3bf5d5 + 7c6ca30 commit 90561b6

File tree

2 files changed

+76
-63
lines changed

2 files changed

+76
-63
lines changed

controllers/database/cdb_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const CDBFinalizer = "database.oracle.com/CDBfinalizer"
108108
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
109109
func (r *CDBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
110110

111-
log := r.Log.WithValues("onpremdboperator", req.NamespacedName)
111+
log := r.Log.WithValues("multitenantoperator", req.NamespacedName)
112112
log.Info("Reconcile requested")
113113

114114
reconcilePeriod := r.Interval * time.Second
@@ -449,10 +449,10 @@ func (r *CDBReconciler) createPodSpec(cdb *dbapi.CDB) corev1.PodSpec {
449449
Name: "ORACLE_HOST",
450450
Value: cdb.Spec.DBServer,
451451
},
452-
{
453-
Name: "DBTNSURL",
454-
Value: cdb.Spec.DBTnsurl,
455-
},
452+
{
453+
Name: "DBTNSURL",
454+
Value: cdb.Spec.DBTnsurl,
455+
},
456456
{
457457
Name: "TLSCRT",
458458
Value: cdb.Spec.CDBTlsCrt.Secret.Key,

controllers/database/pdb_controller.go

Lines changed: 71 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const PDBFinalizer = "database.oracle.com/PDBfinalizer"
121121

122122
var tdePassword string
123123
var tdeSecret string
124-
124+
var floodcontrol bool = false
125125

126126
//+kubebuilder:rbac:groups=database.oracle.com,resources=pdbs,verbs=get;list;watch;create;update;patch;delete
127127
//+kubebuilder:rbac:groups=database.oracle.com,resources=pdbs/status,verbs=get;update;patch
@@ -137,7 +137,7 @@ var tdeSecret string
137137
// For more details, check Reconcile and its Result here:
138138
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
139139
func (r *PDBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
140-
log := r.Log.WithValues("onpremdboperator", req.NamespacedName)
140+
log := r.Log.WithValues("multitenantoperator", req.NamespacedName)
141141
log.Info("Reconcile requested")
142142

143143
reconcilePeriod := r.Interval * time.Second
@@ -229,6 +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)
232234
default:
233235
log.Info("DEFAULT:", "Name", pdb.Name, "Phase", phase, "Status", strconv.FormatBool(pdb.Status.Status))
234236
return requeueN, nil
@@ -243,7 +245,7 @@ func (r *PDBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
243245
}
244246

245247
log.Info("Reconcile completed")
246-
return requeueN, nil
248+
return requeueY, nil
247249
}
248250

249251
/*************************************************
@@ -448,11 +450,11 @@ func (r *PDBReconciler) callAPI(ctx context.Context, req ctrl.Request, pdb *dbap
448450
}
449451

450452
caCert := secret.Data[pdb.Spec.PDBTlsCat.Secret.Key]
451-
/*
452-
r.Recorder.Eventf(pdb, corev1.EventTypeWarning, "ORDSINFO", string(rsaKeyPEM))
453-
r.Recorder.Eventf(pdb, corev1.EventTypeWarning, "ORDSINFO", string(rsaCertPEM))
454-
r.Recorder.Eventf(pdb, corev1.EventTypeWarning, "ORDSINFO", string(caCert))
455-
*/
453+
/*
454+
r.Recorder.Eventf(pdb, corev1.EventTypeWarning, "ORDSINFO", string(rsaKeyPEM))
455+
r.Recorder.Eventf(pdb, corev1.EventTypeWarning, "ORDSINFO", string(rsaCertPEM))
456+
r.Recorder.Eventf(pdb, corev1.EventTypeWarning, "ORDSINFO", string(caCert))
457+
*/
456458

457459
certificate, err := tls.X509KeyPair([]byte(rsaCertPEM), []byte(rsaKeyPEM))
458460
if err != nil {
@@ -535,18 +537,28 @@ func (r *PDBReconciler) callAPI(ctx context.Context, req ctrl.Request, pdb *dbap
535537
if resp.StatusCode == 404 {
536538
pdb.Status.ConnString = ""
537539
pdb.Status.Msg = pdb.Spec.PDBName + " not found"
540+
538541
} else {
539-
pdb.Status.Msg = "ORDS Error - HTTP Status Code:" + strconv.Itoa(resp.StatusCode)
542+
if floodcontrol == false {
543+
pdb.Status.Msg = "ORDS Error - HTTP Status Code:" + strconv.Itoa(resp.StatusCode)
544+
}
545+
}
546+
547+
if floodcontrol == false {
548+
log.Info("ORDS Error - HTTP Status Code :"+strconv.Itoa(resp.StatusCode), "Err", string(bb))
540549
}
541-
log.Info("ORDS Error - HTTP Status Code :"+strconv.Itoa(resp.StatusCode), "Err", string(bb))
542550

543551
var apiErr ORDSError
544552
json.Unmarshal([]byte(bb), &apiErr)
545-
r.Recorder.Eventf(pdb, corev1.EventTypeWarning, "ORDSError", "Failed: %s", apiErr.Message)
553+
if floodcontrol == false {
554+
r.Recorder.Eventf(pdb, corev1.EventTypeWarning, "ORDSError", "Failed: %s", apiErr.Message)
555+
}
546556
//fmt.Printf("%+v", apiErr)
547557
//fmt.Println(string(bb))
558+
floodcontrol = true
548559
return "", errors.New("ORDS Error")
549560
}
561+
floodcontrol = false
550562

551563
defer resp.Body.Close()
552564

@@ -589,9 +601,8 @@ func (r *PDBReconciler) createPDB(ctx context.Context, req ctrl.Request, pdb *db
589601
log := r.Log.WithValues("createPDB", req.NamespacedName)
590602

591603
var err error
592-
var tdePassword string
593-
var tdeSecret string
594-
604+
var tdePassword string
605+
var tdeSecret string
595606

596607
cdb, err := r.getCDBResource(ctx, req, pdb)
597608
if err != nil {
@@ -620,17 +631,17 @@ func (r *PDBReconciler) createPDB(ctx context.Context, req ctrl.Request, pdb *db
620631
"getScript": strconv.FormatBool(*(pdb.Spec.GetScript))}
621632

622633
if *(pdb.Spec.TDEImport) {
623-
tdePassword, err = r.getSecret(ctx, req, pdb, pdb.Spec.TDEPassword.Secret.SecretName, pdb.Spec.TDEPassword.Secret.Key)
634+
tdePassword, err = r.getSecret(ctx, req, pdb, pdb.Spec.TDEPassword.Secret.SecretName, pdb.Spec.TDEPassword.Secret.Key)
624635
if err != nil {
625636
return err
626637
}
627-
tdeSecret, err = r.getSecret(ctx, req, pdb, pdb.Spec.TDESecret.Secret.SecretName, pdb.Spec.TDESecret.Secret.Key)
638+
tdeSecret, err = r.getSecret(ctx, req, pdb, pdb.Spec.TDESecret.Secret.SecretName, pdb.Spec.TDESecret.Secret.Key)
628639
if err != nil {
629640
return err
630641
}
631642

632-
tdeSecret = tdeSecret[:len(tdeSecret)-1]
633-
tdePassword = tdeSecret[:len(tdePassword)-1]
643+
tdeSecret = tdeSecret[:len(tdeSecret)-1]
644+
tdePassword = tdeSecret[:len(tdePassword)-1]
634645
values["tdePassword"] = tdePassword
635646
values["tdeKeystorePath"] = pdb.Spec.TDEKeystorePath
636647
values["tdeSecret"] = tdeSecret
@@ -652,12 +663,12 @@ func (r *PDBReconciler) createPDB(ctx context.Context, req ctrl.Request, pdb *db
652663

653664
r.Recorder.Eventf(pdb, corev1.EventTypeNormal, "Created", "PDB '%s' created successfully", pdb.Spec.PDBName)
654665

655-
if cdb.Spec.DBServer != "" {
656-
pdb.Status.ConnString = cdb.Spec.DBServer + ":" + strconv.Itoa(cdb.Spec.DBPort) + "/" + pdb.Spec.PDBName
657-
} else {
658-
pdb.Status.ConnString = cdb.Spec.DBTnsurl
659-
}
660-
666+
if cdb.Spec.DBServer != "" {
667+
pdb.Status.ConnString = cdb.Spec.DBServer + ":" + strconv.Itoa(cdb.Spec.DBPort) + "/" + pdb.Spec.PDBName
668+
} else {
669+
pdb.Status.ConnString = cdb.Spec.DBTnsurl
670+
}
671+
661672
log.Info("Created PDB Resource", "PDB Name", pdb.Spec.PDBName)
662673
r.getPDBState(ctx, req, pdb)
663674
return nil
@@ -711,12 +722,11 @@ func (r *PDBReconciler) clonePDB(ctx context.Context, req ctrl.Request, pdb *dba
711722

712723
r.Recorder.Eventf(pdb, corev1.EventTypeNormal, "Created", "PDB '%s' cloned successfully", pdb.Spec.PDBName)
713724

714-
if cdb.Spec.DBServer != "" {
715-
pdb.Status.ConnString = cdb.Spec.DBServer + ":" + strconv.Itoa(cdb.Spec.DBPort) + "/" + pdb.Spec.PDBName
716-
} else {
717-
pdb.Status.ConnString = cdb.Spec.DBTnsurl
718-
}
719-
725+
if cdb.Spec.DBServer != "" {
726+
pdb.Status.ConnString = cdb.Spec.DBServer + ":" + strconv.Itoa(cdb.Spec.DBPort) + "/" + pdb.Spec.PDBName
727+
} else {
728+
pdb.Status.ConnString = cdb.Spec.DBTnsurl
729+
}
720730

721731
log.Info("Cloned PDB successfully", "Source PDB Name", pdb.Spec.SrcPDBName, "Clone PDB Name", pdb.Spec.PDBName)
722732
r.getPDBState(ctx, req, pdb)
@@ -731,8 +741,8 @@ func (r *PDBReconciler) plugPDB(ctx context.Context, req ctrl.Request, pdb *dbap
731741
log := r.Log.WithValues("plugPDB", req.NamespacedName)
732742

733743
var err error
734-
var tdePassword string
735-
var tdeSecret string
744+
var tdePassword string
745+
var tdeSecret string
736746

737747
cdb, err := r.getCDBResource(ctx, req, pdb)
738748
if err != nil {
@@ -763,9 +773,9 @@ func (r *PDBReconciler) plugPDB(ctx context.Context, req ctrl.Request, pdb *dbap
763773
if err != nil {
764774
return err
765775
}
766-
767-
tdeSecret = tdeSecret[:len(tdeSecret)-1]
768-
tdePassword = tdeSecret[:len(tdePassword)-1]
776+
777+
tdeSecret = tdeSecret[:len(tdeSecret)-1]
778+
tdePassword = tdeSecret[:len(tdePassword)-1]
769779
values["tdePassword"] = tdePassword
770780
values["tdeKeystorePath"] = pdb.Spec.TDEKeystorePath
771781
values["tdeSecret"] = tdeSecret
@@ -790,11 +800,11 @@ func (r *PDBReconciler) plugPDB(ctx context.Context, req ctrl.Request, pdb *dbap
790800

791801
r.Recorder.Eventf(pdb, corev1.EventTypeNormal, "Created", "PDB '%s' plugged successfully", pdb.Spec.PDBName)
792802

793-
if cdb.Spec.DBServer != "" {
794-
pdb.Status.ConnString = cdb.Spec.DBServer + ":" + strconv.Itoa(cdb.Spec.DBPort) + "/" + pdb.Spec.PDBName
795-
} else {
796-
pdb.Status.ConnString = cdb.Spec.DBTnsurl
797-
}
803+
if cdb.Spec.DBServer != "" {
804+
pdb.Status.ConnString = cdb.Spec.DBServer + ":" + strconv.Itoa(cdb.Spec.DBPort) + "/" + pdb.Spec.PDBName
805+
} else {
806+
pdb.Status.ConnString = cdb.Spec.DBTnsurl
807+
}
798808

799809
log.Info("Successfully plugged PDB", "PDB Name", pdb.Spec.PDBName)
800810
r.getPDBState(ctx, req, pdb)
@@ -809,9 +819,8 @@ func (r *PDBReconciler) unplugPDB(ctx context.Context, req ctrl.Request, pdb *db
809819
log := r.Log.WithValues("unplugPDB", req.NamespacedName)
810820

811821
var err error
812-
var tdePassword string
813-
var tdeSecret string
814-
822+
var tdePassword string
823+
var tdeSecret string
815824

816825
cdb, err := r.getCDBResource(ctx, req, pdb)
817826
if err != nil {
@@ -834,16 +843,16 @@ func (r *PDBReconciler) unplugPDB(ctx context.Context, req ctrl.Request, pdb *db
834843
return err
835844
}
836845

837-
tdeSecret = tdeSecret[:len(tdeSecret)-1]
838-
tdePassword = tdeSecret[:len(tdePassword)-1]
846+
tdeSecret = tdeSecret[:len(tdeSecret)-1]
847+
tdePassword = tdeSecret[:len(tdePassword)-1]
839848
values["tdePassword"] = tdePassword
840849
values["tdeKeystorePath"] = pdb.Spec.TDEKeystorePath
841850
values["tdeSecret"] = tdeSecret
842851
values["tdeExport"] = strconv.FormatBool(*(pdb.Spec.TDEExport))
843852
}
844853

845854
url := "https://" + pdb.Spec.CDBResName + "-ords:" + strconv.Itoa(cdb.Spec.ORDSPort) + "/ords/_/db-api/latest/database/pdbs/" + pdb.Spec.PDBName + "/"
846-
log.Info("CallAPI(url)", "url", url)
855+
log.Info("CallAPI(url)", "url", url)
847856

848857
pdb.Status.Phase = pdbPhaseUnplug
849858
pdb.Status.Msg = "Waiting for PDB to be unplugged"
@@ -888,6 +897,10 @@ func (r *PDBReconciler) modifyPDB(ctx context.Context, req ctrl.Request, pdb *db
888897

889898
err = r.getPDBState(ctx, req, pdb)
890899
if err != nil {
900+
if apierrors.IsNotFound(err) {
901+
log.Info("Warning PDB does not exist", "PDB Name", pdb.Spec.PDBName)
902+
return nil
903+
}
891904
return err
892905
}
893906

@@ -923,12 +936,11 @@ func (r *PDBReconciler) modifyPDB(ctx context.Context, req ctrl.Request, pdb *db
923936

924937
r.Recorder.Eventf(pdb, corev1.EventTypeNormal, "Modified", "PDB '%s' modified successfully", pdb.Spec.PDBName)
925938

926-
if cdb.Spec.DBServer != "" {
927-
pdb.Status.ConnString = cdb.Spec.DBServer + ":" + strconv.Itoa(cdb.Spec.DBPort) + "/" + pdb.Spec.PDBName
928-
} else {
929-
pdb.Status.ConnString = cdb.Spec.DBTnsurl
930-
}
931-
939+
if cdb.Spec.DBServer != "" {
940+
pdb.Status.ConnString = cdb.Spec.DBServer + ":" + strconv.Itoa(cdb.Spec.DBPort) + "/" + pdb.Spec.PDBName
941+
} else {
942+
pdb.Status.ConnString = cdb.Spec.DBTnsurl
943+
}
932944

933945
log.Info("Successfully modified PDB state", "PDB Name", pdb.Spec.PDBName)
934946
r.getPDBState(ctx, req, pdb)
@@ -961,6 +973,8 @@ func (r *PDBReconciler) getPDBState(ctx context.Context, req ctrl.Request, pdb *
961973

962974
if err != nil {
963975
pdb.Status.OpenMode = "UNKNOWN"
976+
pdb.Status.Msg = "CHECK PDB STATUS"
977+
pdb.Status.Status = false
964978
return err
965979
}
966980

@@ -1016,12 +1030,11 @@ func (r *PDBReconciler) mapPDB(ctx context.Context, req ctrl.Request, pdb *dbapi
10161030
pdb.Status.OpenMode = objmap["open_mode"].(string)
10171031
pdb.Status.TotalSize = fmt.Sprintf("%.2f", totSizeInGB) + "G"
10181032

1019-
if cdb.Spec.DBServer != "" {
1020-
pdb.Status.ConnString = cdb.Spec.DBServer + ":" + strconv.Itoa(cdb.Spec.DBPort) + "/" + pdb.Spec.PDBName
1021-
} else {
1022-
pdb.Status.ConnString = cdb.Spec.DBTnsurl
1023-
}
1024-
1033+
if cdb.Spec.DBServer != "" {
1034+
pdb.Status.ConnString = cdb.Spec.DBServer + ":" + strconv.Itoa(cdb.Spec.DBPort) + "/" + pdb.Spec.PDBName
1035+
} else {
1036+
pdb.Status.ConnString = cdb.Spec.DBTnsurl
1037+
}
10251038

10261039
log.Info("Successfully mapped PDB to Kubernetes resource", "PDB Name", pdb.Spec.PDBName)
10271040
return nil

0 commit comments

Comments
 (0)