Skip to content

Commit ecdec61

Browse files
committed
Merge branch 'mmalvezz' into 'master'
bug 34699326 + usecase01 See merge request rac-docker-dev/oracle-database-operator!231
2 parents 1f99d32 + b4365d0 commit ecdec61

File tree

16 files changed

+1662
-49
lines changed

16 files changed

+1662
-49
lines changed

apis/database/v1alpha1/cdb_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type CDBSpec struct {
8686
DBPort int `json:"dbPort,omitempty"`
8787
// Node Selector for running the Pod
8888
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
89+
DBTnsurl string `json:"dbTnsurl,omitempty"`
8990
}
9091

9192
// CDBSecret defines the secretName
@@ -150,6 +151,7 @@ type CDBStatus struct {
150151
// +kubebuilder:printcolumn:JSONPath=".spec.cdbName",name="CDB Name",type="string",description="Name of the CDB"
151152
// +kubebuilder:printcolumn:JSONPath=".spec.dbServer",name="DB Server",type="string",description=" Name of the DB Server"
152153
// +kubebuilder:printcolumn:JSONPath=".spec.dbPort",name="DB Port",type="integer",description="DB server port"
154+
// +kubebuilder:printcolumn:JSONPath=".spec.dbTnsurl",name="TNS STRING",type="string",description=" string of the tnsalias"
153155
// +kubebuilder:printcolumn:JSONPath=".spec.replicas",name="Replicas",type="integer",description="Replicas"
154156
// +kubebuilder:printcolumn:JSONPath=".status.phase",name="Status",type="string",description="Status of the CDB Resource"
155157
// +kubebuilder:printcolumn:JSONPath=".status.msg",name="Message",type="string",description="Error message, if any"

apis/database/v1alpha1/cdb_webhook.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (r *CDB) ValidateCreate() error {
8888

8989
var allErrs field.ErrorList
9090

91-
if r.Spec.ServiceName == "" {
91+
if r.Spec.ServiceName == "" && r.Spec.DBServer != "" {
9292
allErrs = append(allErrs,
9393
field.Required(field.NewPath("spec").Child("serviceName"), "Please specify CDB Service name"))
9494
}
@@ -108,15 +108,21 @@ func (r *CDB) ValidateCreate() error {
108108
field.Required(field.NewPath("spec").Child("scanName"), "Please specify SCAN Name for CDB"))
109109
}*/
110110

111-
if r.Spec.DBServer == "" {
111+
if ((r.Spec.DBServer == "" && r.Spec.DBTnsurl == "") || (r.Spec.DBServer != "" && r.Spec.DBTnsurl != "")) {
112112
allErrs = append(allErrs,
113-
field.Required(field.NewPath("spec").Child("dbServer"), "Please specify Database Server Name or IP Address"))
113+
field.Required(field.NewPath("spec").Child("dbServer"), "Please specify Database Server Name/IP Address or tnsalias string"))
114114
}
115-
if r.Spec.DBPort == 0 {
115+
116+
if r.Spec.DBTnsurl != "" && ( r.Spec.DBServer != "" || r.Spec.DBPort != 0 || r.Spec.ServiceName != "" ) {
117+
allErrs = append(allErrs,
118+
field.Required(field.NewPath("spec").Child("dbServer"), "DBtnsurl is orthogonal to (DBServer,DBport,Services)"))
119+
}
120+
121+
if r.Spec.DBPort == 0 && r.Spec.DBServer != "" {
116122
allErrs = append(allErrs,
117123
field.Required(field.NewPath("spec").Child("dbPort"), "Please specify DB Server Port"))
118124
}
119-
if r.Spec.DBPort < 0 {
125+
if r.Spec.DBPort < 0 && r.Spec.DBServer != "" {
120126
allErrs = append(allErrs,
121127
field.Required(field.NewPath("spec").Child("dbPort"), "Please specify a valid DB Server Port"))
122128
}

controllers/DBserver

Lines changed: 0 additions & 33 deletions
This file was deleted.

controllers/database/cdb_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +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+
},
452456
{
453457
Name: "TLSCRT",
454458
Value: cdb.Spec.CDBTlsCrt.Secret.Key,

controllers/database/pdb_controller.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,12 @@ func (r *PDBReconciler) createPDB(ctx context.Context, req ctrl.Request, pdb *db
641641

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

644+
if cdb.Spec.DBServer != "" {
644645
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+
645650
log.Info("Created PDB Resource", "PDB Name", pdb.Spec.PDBName)
646651
r.getPDBState(ctx, req, pdb)
647652
return nil
@@ -695,7 +700,13 @@ func (r *PDBReconciler) clonePDB(ctx context.Context, req ctrl.Request, pdb *dba
695700

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

698-
pdb.Status.ConnString = cdb.Spec.DBServer + ":" + strconv.Itoa(cdb.Spec.DBPort) + "/" + pdb.Spec.PDBName
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+
709+
699710
log.Info("Cloned PDB successfully", "Source PDB Name", pdb.Spec.SrcPDBName, "Clone PDB Name", pdb.Spec.PDBName)
700711
r.getPDBState(ctx, req, pdb)
701712
return nil
@@ -763,7 +774,12 @@ func (r *PDBReconciler) plugPDB(ctx context.Context, req ctrl.Request, pdb *dbap
763774

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

766-
pdb.Status.ConnString = cdb.Spec.DBServer + ":" + strconv.Itoa(cdb.Spec.DBPort) + "/" + pdb.Spec.PDBName
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+
}
782+
767783
log.Info("Successfully plugged PDB", "PDB Name", pdb.Spec.PDBName)
768784
r.getPDBState(ctx, req, pdb)
769785
return nil
@@ -883,7 +899,13 @@ func (r *PDBReconciler) modifyPDB(ctx context.Context, req ctrl.Request, pdb *db
883899
}
884900

885901
r.Recorder.Eventf(pdb, corev1.EventTypeNormal, "Modified", "PDB '%s' modified successfully", pdb.Spec.PDBName)
886-
pdb.Status.ConnString = cdb.Spec.DBServer + ":" + strconv.Itoa(cdb.Spec.DBPort) + "/" + pdb.Spec.PDBName
902+
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+
887909

888910
log.Info("Successfully modified PDB state", "PDB Name", pdb.Spec.PDBName)
889911
r.getPDBState(ctx, req, pdb)
@@ -970,7 +992,13 @@ func (r *PDBReconciler) mapPDB(ctx context.Context, req ctrl.Request, pdb *dbapi
970992

971993
pdb.Status.OpenMode = objmap["open_mode"].(string)
972994
pdb.Status.TotalSize = fmt.Sprintf("%.2f", totSizeInGB) + "G"
973-
pdb.Status.ConnString = cdb.Spec.DBServer + ":" + strconv.Itoa(cdb.Spec.DBPort) + "/" + pdb.Spec.PDBName
995+
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+
9741002

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

0 commit comments

Comments
 (0)