Skip to content

Commit 554dd88

Browse files
committed
Merge branch 'idesai_23c_free_support_sidb_operator' into 'master'
Idesai 23c free support sidb operator See merge request rac-docker-dev/oracle-database-operator!245
2 parents f0115a5 + 23d99b9 commit 554dd88

File tree

6 files changed

+132
-34
lines changed

6 files changed

+132
-34
lines changed

apis/database/v1alpha1/singleinstancedatabase_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type SingleInstanceDatabaseSpec struct {
5050
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
5151
// Important: Run "make" to regenerate code after modifying this file
5252

53-
// +kubebuilder:validation:Enum=standard;enterprise;express
53+
// +kubebuilder:validation:Enum=standard;enterprise;express;free
5454
Edition string `json:"edition,omitempty"`
5555

5656
// SID must be alphanumeric (no special characters, only a-z, A-Z, 0-9), and no longer than 12 characters.

apis/database/v1alpha1/singleinstancedatabase_webhook.go

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ func (r *SingleInstanceDatabase) Default() {
8686
if r.Spec.Sid == "" {
8787
if r.Spec.Edition == "express" {
8888
r.Spec.Sid = "XE"
89+
} else if r.Spec.Edition == "free" {
90+
r.Spec.Sid = "FREE"
8991
} else {
9092
r.Spec.Sid = "ORCLCDB"
9193
}
@@ -94,12 +96,14 @@ func (r *SingleInstanceDatabase) Default() {
9496
if r.Spec.Pdbname == "" {
9597
if r.Spec.Edition == "express" {
9698
r.Spec.Pdbname = "XEPDB1"
99+
} else if r.Spec.Edition == "free" {
100+
r.Spec.Pdbname = "FREEPDB1"
97101
} else {
98102
r.Spec.Pdbname = "ORCLPDB1"
99103
}
100104
}
101105

102-
if r.Spec.Edition == "express" {
106+
if r.Spec.Edition == "express" || r.Spec.Edition == "free" {
103107
if r.Status.Replicas == 1 {
104108
// default the replicas for XE
105109
r.Spec.Replicas = 1
@@ -147,8 +151,8 @@ func (r *SingleInstanceDatabase) ValidateCreate() error {
147151
// Replica validation
148152
if r.Spec.Replicas > 1 {
149153
valMsg := ""
150-
if r.Spec.Edition == "express" {
151-
valMsg = "should be 1 for express edition"
154+
if r.Spec.Edition == "express" || r.Spec.Edition == "free" {
155+
valMsg = "should be 1 for " + r.Spec.Edition + " edition"
152156
}
153157
if r.Spec.Persistence.Size == "" {
154158
valMsg = "should be 1 if no persistence is specified"
@@ -158,54 +162,69 @@ func (r *SingleInstanceDatabase) ValidateCreate() error {
158162
field.Invalid(field.NewPath("spec").Child("replicas"), r.Spec.Replicas, valMsg))
159163
}
160164
}
161-
162-
if r.Spec.Edition == "express" {
165+
166+
if r.Spec.Edition == "express" || r.Spec.Edition == "free" {
163167
if r.Spec.CloneFrom != "" {
164168
allErrs = append(allErrs,
165169
field.Invalid(field.NewPath("spec").Child("cloneFrom"), r.Spec.CloneFrom,
166-
"Cloning not supported for Express edition"))
170+
"Cloning not supported for " + r.Spec.Edition + " edition"))
167171
}
168172
if r.Spec.CreateAsStandby {
169173
allErrs = append(allErrs,
170174
field.Invalid(field.NewPath("spec").Child("createAsStandby"), r.Spec.CreateAsStandby,
171-
"Physical Standby Database creation is not supported for Express edition"))
175+
"Physical Standby Database creation is not supported for " + r.Spec.Edition + " edition"))
172176
}
173-
if strings.ToUpper(r.Spec.Sid) != "XE" {
177+
if r.Spec.Edition == "express" && strings.ToUpper(r.Spec.Sid) != "XE" {
174178
allErrs = append(allErrs,
175179
field.Invalid(field.NewPath("spec").Child("sid"), r.Spec.Sid,
176180
"Express edition SID must only be XE"))
177181
}
178-
if strings.ToUpper(r.Spec.Pdbname) != "XEPDB1" {
182+
if r.Spec.Edition == "free" && strings.ToUpper(r.Spec.Sid) != "FREE" {
183+
allErrs = append(allErrs,
184+
field.Invalid(field.NewPath("spec").Child("sid"), r.Spec.Sid,
185+
"Free edition SID must only be FREE"))
186+
}
187+
if r.Spec.Edition == "express" && strings.ToUpper(r.Spec.Pdbname) != "XEPDB1" {
179188
allErrs = append(allErrs,
180189
field.Invalid(field.NewPath("spec").Child("pdbName"), r.Spec.Pdbname,
181190
"Express edition PDB must be XEPDB1"))
182191
}
192+
if r.Spec.Edition == "free" && strings.ToUpper(r.Spec.Pdbname) != "FREEPDB1" {
193+
allErrs = append(allErrs,
194+
field.Invalid(field.NewPath("spec").Child("pdbName"), r.Spec.Pdbname,
195+
"Free edition PDB must be FREEPDB1"))
196+
}
183197
if r.Spec.InitParams.CpuCount != 0 {
184198
allErrs = append(allErrs,
185199
field.Invalid(field.NewPath("spec").Child("initParams").Child("cpuCount"), r.Spec.InitParams.CpuCount,
186-
"Express edition does not support changing init parameter cpuCount."))
200+
r.Spec.Edition + " edition does not support changing init parameter cpuCount."))
187201
}
188202
if r.Spec.InitParams.Processes != 0 {
189203
allErrs = append(allErrs,
190204
field.Invalid(field.NewPath("spec").Child("initParams").Child("processes"), r.Spec.InitParams.Processes,
191-
"Express edition does not support changing init parameter process."))
205+
r.Spec.Edition + " edition does not support changing init parameter process."))
192206
}
193207
if r.Spec.InitParams.SgaTarget != 0 {
194208
allErrs = append(allErrs,
195209
field.Invalid(field.NewPath("spec").Child("initParams").Child("sgaTarget"), r.Spec.InitParams.SgaTarget,
196-
"Express edition does not support changing init parameter sgaTarget."))
210+
r.Spec.Edition + " edition does not support changing init parameter sgaTarget."))
197211
}
198212
if r.Spec.InitParams.PgaAggregateTarget != 0 {
199213
allErrs = append(allErrs,
200214
field.Invalid(field.NewPath("spec").Child("initParams").Child("pgaAggregateTarget"), r.Spec.InitParams.PgaAggregateTarget,
201-
"Express edition does not support changing init parameter pgaAggregateTarget."))
215+
r.Spec.Edition + " edition does not support changing init parameter pgaAggregateTarget."))
202216
}
203217
} else {
204218
if r.Spec.Sid == "XE" {
205219
allErrs = append(allErrs,
206220
field.Invalid(field.NewPath("spec").Child("sid"), r.Spec.Sid,
207221
"XE is reserved as the SID for Express edition of the database"))
208222
}
223+
if r.Spec.Sid == "FREE" {
224+
allErrs = append(allErrs,
225+
field.Invalid(field.NewPath("spec").Child("sid"), r.Spec.Sid,
226+
"FREE is reserved as the SID for FREE edition of the database"))
227+
}
209228
}
210229

211230
if r.Spec.CloneFrom != "" {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# Copyright (c) 2023, Oracle and/or its affiliates.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
4+
#
5+
6+
apiVersion: database.oracle.com/v1alpha1
7+
kind: SingleInstanceDatabase
8+
metadata:
9+
name: freedb-sample
10+
namespace: default
11+
spec:
12+
13+
## Use only alphanumeric characters for sid
14+
sid: FREE
15+
16+
## DB edition
17+
edition: free
18+
19+
## Secret containing SIDB password mapped to secretKey
20+
adminPassword:
21+
secretName: freedb-admin-secret
22+
23+
## Database image details
24+
image:
25+
pullFrom: container-registry.oracle.com/database/free:latest
26+
prebuiltDB: true
27+
28+
## size is the required minimum size of the persistent volume
29+
## storageClass is specified for automatic volume provisioning
30+
## accessMode can only accept one of ReadWriteOnce, ReadWriteMany
31+
persistence:
32+
size: 50Gi
33+
## oci-bv applies to OCI block volumes. Use "standard" storageClass for dynamic provisioning in Minikube. Update as appropriate for other cloud service providers
34+
storageClass: "oci-bv"
35+
accessMode: "ReadWriteOnce"
36+
37+
## Count of Database Pods. Should be 1 for express edition.
38+
replicas: 1

config/samples/sidb/singleinstancedatabase_prebuiltdb.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ metadata:
1111
spec:
1212

1313
## DB edition
14-
edition: express
14+
edition: free
1515

1616
## Secret containing SIDB password mapped to secretKey
1717
adminPassword:
1818
secretName: prebuiltdb-admin-secret
1919

2020
## Database Image
2121
image:
22-
pullFrom: container-registry.oracle.com/database/express:latest
22+
pullFrom: container-registry.oracle.com/database/free:latest
2323
prebuiltDB: true
2424

2525
## Persistence is optional for prebuilt DB image

config/samples/sidb/singleinstancedatabase_secrets.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,16 @@ type: Opaque
3939
stringData:
4040
## Specify your DB password here
4141
oracle_pwd:
42+
43+
---
44+
45+
## Prebuilt-Database Admin password secret
46+
apiVersion: v1
47+
kind: Secret
48+
metadata:
49+
name: freedb-admin-secret
50+
namespace: default
51+
type: Opaque
52+
stringData:
53+
## Specify your DB password here
54+
oracle_pwd:

controllers/database/singleinstancedatabase_controller.go

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ var futureRequeue ctrl.Result = requeueN
8585

8686
const singleInstanceDatabaseFinalizer = "database.oracle.com/singleinstancedatabasefinalizer"
8787

88+
var oemExpressUrl string
89+
8890
//+kubebuilder:rbac:groups=database.oracle.com,resources=singleinstancedatabases,verbs=get;list;watch;create;update;patch;delete
8991
//+kubebuilder:rbac:groups=database.oracle.com,resources=singleinstancedatabases/status,verbs=get;update;patch
9092
//+kubebuilder:rbac:groups=database.oracle.com,resources=singleinstancedatabases/finalizers,verbs=update
@@ -369,9 +371,9 @@ func (r *SingleInstanceDatabaseReconciler) validate(m *dbapi.SingleInstanceDatab
369371
}
370372
}
371373

372-
// If Express Edition, ensure Replicas=1
373-
if m.Spec.Edition == "express" && m.Spec.Replicas > 1 {
374-
eventMsgs = append(eventMsgs, "express edition supports only one replica")
374+
// If Express/Free Edition, ensure Replicas=1
375+
if (m.Spec.Edition == "express" || m.Spec.Edition == "free") && m.Spec.Replicas > 1 {
376+
eventMsgs = append(eventMsgs, m.Spec.Edition + " edition supports only one replica")
375377
}
376378
// If no persistence, ensure Replicas=1
377379
if m.Spec.Persistence.Size == "" && m.Spec.Replicas > 1 {
@@ -394,11 +396,11 @@ func (r *SingleInstanceDatabaseReconciler) validate(m *dbapi.SingleInstanceDatab
394396
m.Status.CloneFrom != dbcommons.NoCloneRef && m.Status.CloneFrom != m.Spec.CloneFrom) {
395397
eventMsgs = append(eventMsgs, "cloneFrom cannot be updated")
396398
}
397-
if m.Spec.Edition == "express" && m.Spec.CloneFrom != "" {
398-
eventMsgs = append(eventMsgs, "cloning not supported for express edition")
399+
if (m.Spec.Edition == "express" || m.Spec.Edition == "free") && m.Spec.CloneFrom != "" {
400+
eventMsgs = append(eventMsgs, "cloning not supported for " + m.Spec.Edition + " edition")
399401
}
400-
if m.Spec.Edition == "express" && m.Spec.PrimaryDatabaseRef != "" && m.Spec.CreateAsStandby {
401-
eventMsgs = append(eventMsgs, "Standby database creation is not supported for express edition")
402+
if (m.Spec.Edition == "express" || m.Spec.Edition == "free") && m.Spec.PrimaryDatabaseRef != "" && m.Spec.CreateAsStandby {
403+
eventMsgs = append(eventMsgs, "Standby database creation is not supported for " + m.Spec.Edition + " edition")
402404
}
403405
if m.Status.OrdsReference != "" && m.Status.Persistence.Size != "" && m.Status.Persistence != m.Spec.Persistence {
404406
eventMsgs = append(eventMsgs, "uninstall ORDS to change Peristence")
@@ -665,8 +667,8 @@ func (r *SingleInstanceDatabaseReconciler) instantiatePodSpec(m *dbapi.SingleIns
665667
})
666668
}
667669
}
668-
/* Wallet only for non-express edition, non-prebuiltDB */
669-
if m.Spec.Edition != "express" && !m.Spec.Image.PrebuiltDB {
670+
/* Wallet only for edition barring express and free editions, non-prebuiltDB */
671+
if (m.Spec.Edition != "express" && m.Spec.Edition != "free") && !m.Spec.Image.PrebuiltDB {
670672
initContainers = append(initContainers, corev1.Container{
671673
Name: "init-wallet",
672674
Image: m.Spec.Image.PullFrom,
@@ -766,7 +768,7 @@ func (r *SingleInstanceDatabaseReconciler) instantiatePodSpec(m *dbapi.SingleIns
766768
}(),
767769
Env: func() []corev1.EnvVar {
768770
// adding XE support, useful for dev/test/CI-CD
769-
if m.Spec.Edition == "express" {
771+
if m.Spec.Edition == "express" || m.Spec.Edition == "free" {
770772
return []corev1.EnvVar{
771773
{
772774
Name: "SVC_HOST",
@@ -1481,7 +1483,7 @@ func (r *SingleInstanceDatabaseReconciler) createOrReplaceSVC(ctx context.Contex
14811483
}
14821484
m.Status.ConnectString = lbAddress + ":" + fmt.Sprint(extSvc.Spec.Ports[1].Port) + "/" + strings.ToUpper(sid)
14831485
m.Status.PdbConnectString = lbAddress + ":" + fmt.Sprint(extSvc.Spec.Ports[1].Port) + "/" + strings.ToUpper(pdbName)
1484-
m.Status.OemExpressUrl = "https://" + lbAddress + ":" + fmt.Sprint(extSvc.Spec.Ports[0].Port) + "/em"
1486+
oemExpressUrl = "https://" + lbAddress + ":" + fmt.Sprint(extSvc.Spec.Ports[0].Port) + "/em"
14851487
if m.Spec.EnableTCPS {
14861488
m.Status.TcpsConnectString = lbAddress + ":" + fmt.Sprint(extSvc.Spec.Ports[len(extSvc.Spec.Ports)-1].Port) + "/" + strings.ToUpper(sid)
14871489
m.Status.TcpsPdbConnectString = lbAddress + ":" + fmt.Sprint(extSvc.Spec.Ports[len(extSvc.Spec.Ports)-1].Port) + "/" + strings.ToUpper(pdbName)
@@ -1493,7 +1495,7 @@ func (r *SingleInstanceDatabaseReconciler) createOrReplaceSVC(ctx context.Contex
14931495
if nodeip != "" {
14941496
m.Status.ConnectString = nodeip + ":" + fmt.Sprint(extSvc.Spec.Ports[1].NodePort) + "/" + strings.ToUpper(sid)
14951497
m.Status.PdbConnectString = nodeip + ":" + fmt.Sprint(extSvc.Spec.Ports[1].NodePort) + "/" + strings.ToUpper(pdbName)
1496-
m.Status.OemExpressUrl = "https://" + nodeip + ":" + fmt.Sprint(extSvc.Spec.Ports[0].NodePort) + "/em"
1498+
oemExpressUrl = "https://" + nodeip + ":" + fmt.Sprint(extSvc.Spec.Ports[0].NodePort) + "/em"
14971499
if m.Spec.EnableTCPS {
14981500
m.Status.TcpsConnectString = nodeip + ":" + fmt.Sprint(extSvc.Spec.Ports[len(extSvc.Spec.Ports)-1].NodePort) + "/" + strings.ToUpper(sid)
14991501
m.Status.TcpsPdbConnectString = nodeip + ":" + fmt.Sprint(extSvc.Spec.Ports[len(extSvc.Spec.Ports)-1].NodePort) + "/" + strings.ToUpper(pdbName)
@@ -1701,8 +1703,8 @@ func (r *SingleInstanceDatabaseReconciler) createOrReplacePods(m *dbapi.SingleIn
17011703
// #############################################################################
17021704
func (r *SingleInstanceDatabaseReconciler) createWallet(m *dbapi.SingleInstanceDatabase, ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
17031705

1704-
// Wallet not supported for XE Database
1705-
if m.Spec.Edition == "express" {
1706+
// Wallet not supported for Express/Free Database
1707+
if m.Spec.Edition == "express" || m.Spec.Edition == "free" {
17061708
return requeueN, nil
17071709
}
17081710

@@ -2016,6 +2018,16 @@ func (r *SingleInstanceDatabaseReconciler) validateDBReadiness(m *dbapi.SingleIn
20162018
m.Status.ReleaseUpdate = version
20172019
}
20182020
}
2021+
oemSupport, err := isOEMSupported(r,m.Status.ReleaseUpdate)
2022+
if err != nil {
2023+
r.Log.Error(err, err.Error())
2024+
return requeueY, readyPod, err
2025+
}
2026+
if oemSupport {
2027+
m.Status.OemExpressUrl = oemExpressUrl
2028+
} else {
2029+
m.Status.OemExpressUrl = dbcommons.ValueUnavailable
2030+
}
20192031

20202032
if strings.ToUpper(m.Status.Role) == "PRIMARY" && m.Status.DatafilesPatched != "true" {
20212033
eventReason := "Datapatch Pending"
@@ -2034,8 +2046,8 @@ func (r *SingleInstanceDatabaseReconciler) validateDBReadiness(m *dbapi.SingleIn
20342046
// #############################################################################
20352047
func (r *SingleInstanceDatabaseReconciler) deleteWallet(m *dbapi.SingleInstanceDatabase, ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
20362048

2037-
// Wallet not supported for XE Database
2038-
if m.Spec.Edition == "express" {
2049+
// Wallet not supported for Express/Free Database
2050+
if m.Spec.Edition == "express" || m.Spec.Edition == "free" {
20392051
return requeueN, nil
20402052
}
20412053

@@ -2250,9 +2262,9 @@ func (r *SingleInstanceDatabaseReconciler) runDatapatch(m *dbapi.SingleInstanceD
22502262
readyPod corev1.Pod, ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
22512263

22522264
// Datapatch not supported for XE Database
2253-
if m.Spec.Edition == "express" {
2265+
if m.Spec.Edition == "express" || m.Spec.Edition == "free" {
22542266
eventReason := "Datapatch Check"
2255-
eventMsg := "datapatch not supported for express edition"
2267+
eventMsg := "datapatch not supported for " + m.Spec.Edition + " edition"
22562268
r.Recorder.Eventf(m, corev1.EventTypeNormal, eventReason, eventMsg)
22572269
r.Log.Info(eventMsg)
22582270
return requeueN, nil
@@ -3074,3 +3086,19 @@ func SetupStandbyDatabase(r *SingleInstanceDatabaseReconciler, stdby *dbapi.Sing
30743086

30753087
return nil
30763088
}
3089+
3090+
3091+
func isOEMSupported (r *SingleInstanceDatabaseReconciler,version string) (bool,error) {
3092+
majorVersion, err := strconv.Atoi(strings.Split(version,".")[0])
3093+
r.Log.Info("majorVersion of database is " + strconv.Itoa(majorVersion))
3094+
if err != nil {
3095+
return false,err
3096+
}
3097+
if majorVersion > 21{
3098+
r.Log.Info("major Version " + strconv.Itoa(majorVersion) + " is greater that 21 so OEM Express is not supported")
3099+
return false,nil
3100+
} else {
3101+
r.Log.Info("major Version " + strconv.Itoa(majorVersion) + " is lesser than equal to 21 so OEM Express is supported")
3102+
return true,nil
3103+
}
3104+
}

0 commit comments

Comments
 (0)