@@ -119,6 +119,10 @@ var (
119
119
120
120
const PDBFinalizer = "database.oracle.com/PDBfinalizer"
121
121
122
+ var tdePassword string
123
+ var tdeSecret string
124
+ var floodcontrol bool = false
125
+
122
126
//+kubebuilder:rbac:groups=database.oracle.com,resources=pdbs,verbs=get;list;watch;create;update;patch;delete
123
127
//+kubebuilder:rbac:groups=database.oracle.com,resources=pdbs/status,verbs=get;update;patch
124
128
//+kubebuilder:rbac:groups=database.oracle.com,resources=pdbs/finalizers,verbs=get;create;update;patch;delete
@@ -133,7 +137,7 @@ const PDBFinalizer = "database.oracle.com/PDBfinalizer"
133
137
// For more details, check Reconcile and its Result here:
134
138
// - https://pkg.go.dev/sigs.k8s.io/[email protected] /pkg/reconcile
135
139
func (r * PDBReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
136
- log := r .Log .WithValues ("onpremdboperator " , req .NamespacedName )
140
+ log := r .Log .WithValues ("multitenantoperator " , req .NamespacedName )
137
141
log .Info ("Reconcile requested" )
138
142
139
143
reconcilePeriod := r .Interval * time .Second
@@ -225,6 +229,8 @@ func (r *PDBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
225
229
err = r .getPDBState (ctx , req , pdb )
226
230
case pdbPhaseMap :
227
231
err = r .mapPDB (ctx , req , pdb )
232
+ case pdbPhaseFail :
233
+ err = r .mapPDB (ctx , req , pdb )
228
234
default :
229
235
log .Info ("DEFAULT:" , "Name" , pdb .Name , "Phase" , phase , "Status" , strconv .FormatBool (pdb .Status .Status ))
230
236
return requeueN , nil
@@ -239,7 +245,7 @@ func (r *PDBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
239
245
}
240
246
241
247
log .Info ("Reconcile completed" )
242
- return requeueN , nil
248
+ return requeueY , nil
243
249
}
244
250
245
251
/*************************************************
@@ -444,11 +450,11 @@ func (r *PDBReconciler) callAPI(ctx context.Context, req ctrl.Request, pdb *dbap
444
450
}
445
451
446
452
caCert := secret .Data [pdb .Spec .PDBTlsCat .Secret .Key ]
447
- /*
448
- r.Recorder.Eventf(pdb, corev1.EventTypeWarning, "ORDSINFO", string(rsaKeyPEM))
449
- r.Recorder.Eventf(pdb, corev1.EventTypeWarning, "ORDSINFO", string(rsaCertPEM))
450
- r.Recorder.Eventf(pdb, corev1.EventTypeWarning, "ORDSINFO", string(caCert))
451
- */
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
+ */
452
458
453
459
certificate , err := tls .X509KeyPair ([]byte (rsaCertPEM ), []byte (rsaKeyPEM ))
454
460
if err != nil {
@@ -531,18 +537,28 @@ func (r *PDBReconciler) callAPI(ctx context.Context, req ctrl.Request, pdb *dbap
531
537
if resp .StatusCode == 404 {
532
538
pdb .Status .ConnString = ""
533
539
pdb .Status .Msg = pdb .Spec .PDBName + " not found"
540
+
534
541
} else {
535
- 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 ))
536
549
}
537
- log .Info ("ORDS Error - HTTP Status Code :" + strconv .Itoa (resp .StatusCode ), "Err" , string (bb ))
538
550
539
551
var apiErr ORDSError
540
552
json .Unmarshal ([]byte (bb ), & apiErr )
541
- 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
+ }
542
556
//fmt.Printf("%+v", apiErr)
543
557
//fmt.Println(string(bb))
558
+ floodcontrol = true
544
559
return "" , errors .New ("ORDS Error" )
545
560
}
561
+ floodcontrol = false
546
562
547
563
defer resp .Body .Close ()
548
564
@@ -585,6 +601,8 @@ func (r *PDBReconciler) createPDB(ctx context.Context, req ctrl.Request, pdb *db
585
601
log := r .Log .WithValues ("createPDB" , req .NamespacedName )
586
602
587
603
var err error
604
+ var tdePassword string
605
+ var tdeSecret string
588
606
589
607
cdb , err := r .getCDBResource (ctx , req , pdb )
590
608
if err != nil {
@@ -613,14 +631,17 @@ func (r *PDBReconciler) createPDB(ctx context.Context, req ctrl.Request, pdb *db
613
631
"getScript" : strconv .FormatBool (* (pdb .Spec .GetScript ))}
614
632
615
633
if * (pdb .Spec .TDEImport ) {
616
- 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 )
617
635
if err != nil {
618
636
return err
619
637
}
620
- 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 )
621
639
if err != nil {
622
640
return err
623
641
}
642
+
643
+ tdeSecret = tdeSecret [:len (tdeSecret )- 1 ]
644
+ tdePassword = tdeSecret [:len (tdePassword )- 1 ]
624
645
values ["tdePassword" ] = tdePassword
625
646
values ["tdeKeystorePath" ] = pdb .Spec .TDEKeystorePath
626
647
values ["tdeSecret" ] = tdeSecret
@@ -636,17 +657,18 @@ func (r *PDBReconciler) createPDB(ctx context.Context, req ctrl.Request, pdb *db
636
657
}
637
658
_ , err = r .callAPI (ctx , req , pdb , url , values , "POST" )
638
659
if err != nil {
660
+ log .Error (err , "callAPI error" , err .Error ())
639
661
return err
640
662
}
641
663
642
664
r .Recorder .Eventf (pdb , corev1 .EventTypeNormal , "Created" , "PDB '%s' created successfully" , pdb .Spec .PDBName )
643
665
644
- if cdb .Spec .DBServer != "" {
645
- pdb .Status .ConnString = cdb .Spec .DBServer + ":" + strconv .Itoa (cdb .Spec .DBPort ) + "/" + pdb .Spec .PDBName
646
- } else {
647
- pdb .Status .ConnString = cdb .Spec .DBTnsurl
648
- }
649
-
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
+
650
672
log .Info ("Created PDB Resource" , "PDB Name" , pdb .Spec .PDBName )
651
673
r .getPDBState (ctx , req , pdb )
652
674
return nil
@@ -700,12 +722,11 @@ func (r *PDBReconciler) clonePDB(ctx context.Context, req ctrl.Request, pdb *dba
700
722
701
723
r .Recorder .Eventf (pdb , corev1 .EventTypeNormal , "Created" , "PDB '%s' cloned successfully" , pdb .Spec .PDBName )
702
724
703
- if cdb .Spec .DBServer != "" {
704
- pdb .Status .ConnString = cdb .Spec .DBServer + ":" + strconv .Itoa (cdb .Spec .DBPort ) + "/" + pdb .Spec .PDBName
705
- } else {
706
- pdb .Status .ConnString = cdb .Spec .DBTnsurl
707
- }
708
-
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
+ }
709
730
710
731
log .Info ("Cloned PDB successfully" , "Source PDB Name" , pdb .Spec .SrcPDBName , "Clone PDB Name" , pdb .Spec .PDBName )
711
732
r .getPDBState (ctx , req , pdb )
@@ -720,6 +741,8 @@ func (r *PDBReconciler) plugPDB(ctx context.Context, req ctrl.Request, pdb *dbap
720
741
log := r .Log .WithValues ("plugPDB" , req .NamespacedName )
721
742
722
743
var err error
744
+ var tdePassword string
745
+ var tdeSecret string
723
746
724
747
cdb , err := r .getCDBResource (ctx , req , pdb )
725
748
if err != nil {
@@ -742,14 +765,17 @@ func (r *PDBReconciler) plugPDB(ctx context.Context, req ctrl.Request, pdb *dbap
742
765
"getScript" : strconv .FormatBool (* (pdb .Spec .GetScript ))}
743
766
744
767
if * (pdb .Spec .TDEImport ) {
745
- tdePassword , err : = r .getSecret (ctx , req , pdb , pdb .Spec .TDEPassword .Secret .SecretName , pdb .Spec .TDEPassword .Secret .Key )
768
+ tdePassword , err = r .getSecret (ctx , req , pdb , pdb .Spec .TDEPassword .Secret .SecretName , pdb .Spec .TDEPassword .Secret .Key )
746
769
if err != nil {
747
770
return err
748
771
}
749
- tdeSecret , err : = r .getSecret (ctx , req , pdb , pdb .Spec .TDESecret .Secret .SecretName , pdb .Spec .TDESecret .Secret .Key )
772
+ tdeSecret , err = r .getSecret (ctx , req , pdb , pdb .Spec .TDESecret .Secret .SecretName , pdb .Spec .TDESecret .Secret .Key )
750
773
if err != nil {
751
774
return err
752
775
}
776
+
777
+ tdeSecret = tdeSecret [:len (tdeSecret )- 1 ]
778
+ tdePassword = tdeSecret [:len (tdePassword )- 1 ]
753
779
values ["tdePassword" ] = tdePassword
754
780
values ["tdeKeystorePath" ] = pdb .Spec .TDEKeystorePath
755
781
values ["tdeSecret" ] = tdeSecret
@@ -774,11 +800,11 @@ func (r *PDBReconciler) plugPDB(ctx context.Context, req ctrl.Request, pdb *dbap
774
800
775
801
r .Recorder .Eventf (pdb , corev1 .EventTypeNormal , "Created" , "PDB '%s' plugged successfully" , pdb .Spec .PDBName )
776
802
777
- if cdb .Spec .DBServer != "" {
778
- pdb .Status .ConnString = cdb .Spec .DBServer + ":" + strconv .Itoa (cdb .Spec .DBPort ) + "/" + pdb .Spec .PDBName
779
- } else {
780
- pdb .Status .ConnString = cdb .Spec .DBTnsurl
781
- }
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
+ }
782
808
783
809
log .Info ("Successfully plugged PDB" , "PDB Name" , pdb .Spec .PDBName )
784
810
r .getPDBState (ctx , req , pdb )
@@ -793,6 +819,8 @@ func (r *PDBReconciler) unplugPDB(ctx context.Context, req ctrl.Request, pdb *db
793
819
log := r .Log .WithValues ("unplugPDB" , req .NamespacedName )
794
820
795
821
var err error
822
+ var tdePassword string
823
+ var tdeSecret string
796
824
797
825
cdb , err := r .getCDBResource (ctx , req , pdb )
798
826
if err != nil {
@@ -806,21 +834,25 @@ func (r *PDBReconciler) unplugPDB(ctx context.Context, req ctrl.Request, pdb *db
806
834
807
835
if * (pdb .Spec .TDEExport ) {
808
836
// Get the TDE Password
809
- tdePassword , err : = r .getSecret (ctx , req , pdb , pdb .Spec .TDEPassword .Secret .SecretName , pdb .Spec .TDEPassword .Secret .Key )
837
+ tdePassword , err = r .getSecret (ctx , req , pdb , pdb .Spec .TDEPassword .Secret .SecretName , pdb .Spec .TDEPassword .Secret .Key )
810
838
if err != nil {
811
839
return err
812
840
}
813
- tdeSecret , err : = r .getSecret (ctx , req , pdb , pdb .Spec .TDESecret .Secret .SecretName , pdb .Spec .TDESecret .Secret .Key )
841
+ tdeSecret , err = r .getSecret (ctx , req , pdb , pdb .Spec .TDESecret .Secret .SecretName , pdb .Spec .TDESecret .Secret .Key )
814
842
if err != nil {
815
843
return err
816
844
}
845
+
846
+ tdeSecret = tdeSecret [:len (tdeSecret )- 1 ]
847
+ tdePassword = tdeSecret [:len (tdePassword )- 1 ]
817
848
values ["tdePassword" ] = tdePassword
818
849
values ["tdeKeystorePath" ] = pdb .Spec .TDEKeystorePath
819
850
values ["tdeSecret" ] = tdeSecret
820
851
values ["tdeExport" ] = strconv .FormatBool (* (pdb .Spec .TDEExport ))
821
852
}
822
853
823
854
url := "https://" + pdb .Spec .CDBResName + "-ords:" + strconv .Itoa (cdb .Spec .ORDSPort ) + "/ords/_/db-api/latest/database/pdbs/" + pdb .Spec .PDBName + "/"
855
+ log .Info ("CallAPI(url)" , "url" , url )
824
856
825
857
pdb .Status .Phase = pdbPhaseUnplug
826
858
pdb .Status .Msg = "Waiting for PDB to be unplugged"
@@ -865,6 +897,10 @@ func (r *PDBReconciler) modifyPDB(ctx context.Context, req ctrl.Request, pdb *db
865
897
866
898
err = r .getPDBState (ctx , req , pdb )
867
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
+ }
868
904
return err
869
905
}
870
906
@@ -900,12 +936,11 @@ func (r *PDBReconciler) modifyPDB(ctx context.Context, req ctrl.Request, pdb *db
900
936
901
937
r .Recorder .Eventf (pdb , corev1 .EventTypeNormal , "Modified" , "PDB '%s' modified successfully" , pdb .Spec .PDBName )
902
938
903
- if cdb .Spec .DBServer != "" {
904
- pdb .Status .ConnString = cdb .Spec .DBServer + ":" + strconv .Itoa (cdb .Spec .DBPort ) + "/" + pdb .Spec .PDBName
905
- } else {
906
- pdb .Status .ConnString = cdb .Spec .DBTnsurl
907
- }
908
-
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
+ }
909
944
910
945
log .Info ("Successfully modified PDB state" , "PDB Name" , pdb .Spec .PDBName )
911
946
r .getPDBState (ctx , req , pdb )
@@ -938,6 +973,8 @@ func (r *PDBReconciler) getPDBState(ctx context.Context, req ctrl.Request, pdb *
938
973
939
974
if err != nil {
940
975
pdb .Status .OpenMode = "UNKNOWN"
976
+ pdb .Status .Msg = "CHECK PDB STATUS"
977
+ pdb .Status .Status = false
941
978
return err
942
979
}
943
980
@@ -993,12 +1030,11 @@ func (r *PDBReconciler) mapPDB(ctx context.Context, req ctrl.Request, pdb *dbapi
993
1030
pdb .Status .OpenMode = objmap ["open_mode" ].(string )
994
1031
pdb .Status .TotalSize = fmt .Sprintf ("%.2f" , totSizeInGB ) + "G"
995
1032
996
- if cdb .Spec .DBServer != "" {
997
- pdb .Status .ConnString = cdb .Spec .DBServer + ":" + strconv .Itoa (cdb .Spec .DBPort ) + "/" + pdb .Spec .PDBName
998
- } else {
999
- pdb .Status .ConnString = cdb .Spec .DBTnsurl
1000
- }
1001
-
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
+ }
1002
1038
1003
1039
log .Info ("Successfully mapped PDB to Kubernetes resource" , "PDB Name" , pdb .Spec .PDBName )
1004
1040
return nil
@@ -1098,7 +1134,7 @@ func (r *PDBReconciler) deletePDBInstance(req ctrl.Request, ctx context.Context,
1098
1134
}
1099
1135
1100
1136
values := map [string ]string {
1101
- "method " : "DELETE " ,
1137
+ "action " : "KEEP " ,
1102
1138
"getScript" : strconv .FormatBool (* (pdb .Spec .GetScript ))}
1103
1139
1104
1140
if pdb .Spec .DropAction != "" {
0 commit comments