@@ -121,7 +121,7 @@ const PDBFinalizer = "database.oracle.com/PDBfinalizer"
121
121
122
122
var tdePassword string
123
123
var tdeSecret string
124
-
124
+ var floodcontrol bool = false
125
125
126
126
//+kubebuilder:rbac:groups=database.oracle.com,resources=pdbs,verbs=get;list;watch;create;update;patch;delete
127
127
//+kubebuilder:rbac:groups=database.oracle.com,resources=pdbs/status,verbs=get;update;patch
@@ -137,7 +137,7 @@ var tdeSecret string
137
137
// For more details, check Reconcile and its Result here:
138
138
// - https://pkg.go.dev/sigs.k8s.io/[email protected] /pkg/reconcile
139
139
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 )
141
141
log .Info ("Reconcile requested" )
142
142
143
143
reconcilePeriod := r .Interval * time .Second
@@ -229,6 +229,8 @@ func (r *PDBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
229
229
err = r .getPDBState (ctx , req , pdb )
230
230
case pdbPhaseMap :
231
231
err = r .mapPDB (ctx , req , pdb )
232
+ case pdbPhaseFail :
233
+ err = r .mapPDB (ctx , req , pdb )
232
234
default :
233
235
log .Info ("DEFAULT:" , "Name" , pdb .Name , "Phase" , phase , "Status" , strconv .FormatBool (pdb .Status .Status ))
234
236
return requeueN , nil
@@ -243,7 +245,7 @@ func (r *PDBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
243
245
}
244
246
245
247
log .Info ("Reconcile completed" )
246
- return requeueN , nil
248
+ return requeueY , nil
247
249
}
248
250
249
251
/*************************************************
@@ -448,11 +450,11 @@ func (r *PDBReconciler) callAPI(ctx context.Context, req ctrl.Request, pdb *dbap
448
450
}
449
451
450
452
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
+ */
456
458
457
459
certificate , err := tls .X509KeyPair ([]byte (rsaCertPEM ), []byte (rsaKeyPEM ))
458
460
if err != nil {
@@ -535,18 +537,28 @@ func (r *PDBReconciler) callAPI(ctx context.Context, req ctrl.Request, pdb *dbap
535
537
if resp .StatusCode == 404 {
536
538
pdb .Status .ConnString = ""
537
539
pdb .Status .Msg = pdb .Spec .PDBName + " not found"
540
+
538
541
} 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 ))
540
549
}
541
- log .Info ("ORDS Error - HTTP Status Code :" + strconv .Itoa (resp .StatusCode ), "Err" , string (bb ))
542
550
543
551
var apiErr ORDSError
544
552
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
+ }
546
556
//fmt.Printf("%+v", apiErr)
547
557
//fmt.Println(string(bb))
558
+ floodcontrol = true
548
559
return "" , errors .New ("ORDS Error" )
549
560
}
561
+ floodcontrol = false
550
562
551
563
defer resp .Body .Close ()
552
564
@@ -589,9 +601,8 @@ func (r *PDBReconciler) createPDB(ctx context.Context, req ctrl.Request, pdb *db
589
601
log := r .Log .WithValues ("createPDB" , req .NamespacedName )
590
602
591
603
var err error
592
- var tdePassword string
593
- var tdeSecret string
594
-
604
+ var tdePassword string
605
+ var tdeSecret string
595
606
596
607
cdb , err := r .getCDBResource (ctx , req , pdb )
597
608
if err != nil {
@@ -620,17 +631,17 @@ func (r *PDBReconciler) createPDB(ctx context.Context, req ctrl.Request, pdb *db
620
631
"getScript" : strconv .FormatBool (* (pdb .Spec .GetScript ))}
621
632
622
633
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 )
624
635
if err != nil {
625
636
return err
626
637
}
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 )
628
639
if err != nil {
629
640
return err
630
641
}
631
642
632
- tdeSecret = tdeSecret [:len (tdeSecret )- 1 ]
633
- tdePassword = tdeSecret [:len (tdePassword )- 1 ]
643
+ tdeSecret = tdeSecret [:len (tdeSecret )- 1 ]
644
+ tdePassword = tdeSecret [:len (tdePassword )- 1 ]
634
645
values ["tdePassword" ] = tdePassword
635
646
values ["tdeKeystorePath" ] = pdb .Spec .TDEKeystorePath
636
647
values ["tdeSecret" ] = tdeSecret
@@ -652,12 +663,12 @@ func (r *PDBReconciler) createPDB(ctx context.Context, req ctrl.Request, pdb *db
652
663
653
664
r .Recorder .Eventf (pdb , corev1 .EventTypeNormal , "Created" , "PDB '%s' created successfully" , pdb .Spec .PDBName )
654
665
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
+
661
672
log .Info ("Created PDB Resource" , "PDB Name" , pdb .Spec .PDBName )
662
673
r .getPDBState (ctx , req , pdb )
663
674
return nil
@@ -711,12 +722,11 @@ func (r *PDBReconciler) clonePDB(ctx context.Context, req ctrl.Request, pdb *dba
711
722
712
723
r .Recorder .Eventf (pdb , corev1 .EventTypeNormal , "Created" , "PDB '%s' cloned successfully" , pdb .Spec .PDBName )
713
724
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
+ }
720
730
721
731
log .Info ("Cloned PDB successfully" , "Source PDB Name" , pdb .Spec .SrcPDBName , "Clone PDB Name" , pdb .Spec .PDBName )
722
732
r .getPDBState (ctx , req , pdb )
@@ -731,8 +741,8 @@ func (r *PDBReconciler) plugPDB(ctx context.Context, req ctrl.Request, pdb *dbap
731
741
log := r .Log .WithValues ("plugPDB" , req .NamespacedName )
732
742
733
743
var err error
734
- var tdePassword string
735
- var tdeSecret string
744
+ var tdePassword string
745
+ var tdeSecret string
736
746
737
747
cdb , err := r .getCDBResource (ctx , req , pdb )
738
748
if err != nil {
@@ -763,9 +773,9 @@ func (r *PDBReconciler) plugPDB(ctx context.Context, req ctrl.Request, pdb *dbap
763
773
if err != nil {
764
774
return err
765
775
}
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 ]
769
779
values ["tdePassword" ] = tdePassword
770
780
values ["tdeKeystorePath" ] = pdb .Spec .TDEKeystorePath
771
781
values ["tdeSecret" ] = tdeSecret
@@ -790,11 +800,11 @@ func (r *PDBReconciler) plugPDB(ctx context.Context, req ctrl.Request, pdb *dbap
790
800
791
801
r .Recorder .Eventf (pdb , corev1 .EventTypeNormal , "Created" , "PDB '%s' plugged successfully" , pdb .Spec .PDBName )
792
802
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
+ }
798
808
799
809
log .Info ("Successfully plugged PDB" , "PDB Name" , pdb .Spec .PDBName )
800
810
r .getPDBState (ctx , req , pdb )
@@ -809,9 +819,8 @@ func (r *PDBReconciler) unplugPDB(ctx context.Context, req ctrl.Request, pdb *db
809
819
log := r .Log .WithValues ("unplugPDB" , req .NamespacedName )
810
820
811
821
var err error
812
- var tdePassword string
813
- var tdeSecret string
814
-
822
+ var tdePassword string
823
+ var tdeSecret string
815
824
816
825
cdb , err := r .getCDBResource (ctx , req , pdb )
817
826
if err != nil {
@@ -834,16 +843,16 @@ func (r *PDBReconciler) unplugPDB(ctx context.Context, req ctrl.Request, pdb *db
834
843
return err
835
844
}
836
845
837
- tdeSecret = tdeSecret [:len (tdeSecret )- 1 ]
838
- tdePassword = tdeSecret [:len (tdePassword )- 1 ]
846
+ tdeSecret = tdeSecret [:len (tdeSecret )- 1 ]
847
+ tdePassword = tdeSecret [:len (tdePassword )- 1 ]
839
848
values ["tdePassword" ] = tdePassword
840
849
values ["tdeKeystorePath" ] = pdb .Spec .TDEKeystorePath
841
850
values ["tdeSecret" ] = tdeSecret
842
851
values ["tdeExport" ] = strconv .FormatBool (* (pdb .Spec .TDEExport ))
843
852
}
844
853
845
854
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 )
847
856
848
857
pdb .Status .Phase = pdbPhaseUnplug
849
858
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
888
897
889
898
err = r .getPDBState (ctx , req , pdb )
890
899
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
+ }
891
904
return err
892
905
}
893
906
@@ -923,12 +936,11 @@ func (r *PDBReconciler) modifyPDB(ctx context.Context, req ctrl.Request, pdb *db
923
936
924
937
r .Recorder .Eventf (pdb , corev1 .EventTypeNormal , "Modified" , "PDB '%s' modified successfully" , pdb .Spec .PDBName )
925
938
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
+ }
932
944
933
945
log .Info ("Successfully modified PDB state" , "PDB Name" , pdb .Spec .PDBName )
934
946
r .getPDBState (ctx , req , pdb )
@@ -961,6 +973,8 @@ func (r *PDBReconciler) getPDBState(ctx context.Context, req ctrl.Request, pdb *
961
973
962
974
if err != nil {
963
975
pdb .Status .OpenMode = "UNKNOWN"
976
+ pdb .Status .Msg = "CHECK PDB STATUS"
977
+ pdb .Status .Status = false
964
978
return err
965
979
}
966
980
@@ -1016,12 +1030,11 @@ func (r *PDBReconciler) mapPDB(ctx context.Context, req ctrl.Request, pdb *dbapi
1016
1030
pdb .Status .OpenMode = objmap ["open_mode" ].(string )
1017
1031
pdb .Status .TotalSize = fmt .Sprintf ("%.2f" , totSizeInGB ) + "G"
1018
1032
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
+ }
1025
1038
1026
1039
log .Info ("Successfully mapped PDB to Kubernetes resource" , "PDB Name" , pdb .Spec .PDBName )
1027
1040
return nil
0 commit comments