Skip to content

Commit f1068a9

Browse files
committed
Merge branch 'AbhiK_tcps_support' into 'master'
Single Instance Database TCPS support See merge request rac-docker-dev/oracle-database-operator!218
2 parents 79cd34e + dbf8f5f commit f1068a9

File tree

10 files changed

+555
-89
lines changed

10 files changed

+555
-89
lines changed

apis/database/v1alpha1/oraclerestdataservice_webhook.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
package v1alpha1
4040

4141
import (
42-
4342
apierrors "k8s.io/apimachinery/pkg/api/errors"
4443
"k8s.io/apimachinery/pkg/runtime"
4544
"k8s.io/apimachinery/pkg/runtime/schema"

apis/database/v1alpha1/singleinstancedatabase_types.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,17 @@ type SingleInstanceDatabaseSpec struct {
5757
// +k8s:openapi-gen=true
5858
// +kubebuilder:validation:Pattern=`^[a-zA-Z0-9]+$`
5959
// +kubebuilder:validation:MaxLength:=12
60-
Sid string `json:"sid,omitempty"`
61-
Charset string `json:"charset,omitempty"`
62-
Pdbname string `json:"pdbName,omitempty"`
63-
LoadBalancer bool `json:"loadBalancer,omitempty"`
64-
ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"`
65-
FlashBack bool `json:"flashBack,omitempty"`
66-
ArchiveLog bool `json:"archiveLog,omitempty"`
67-
ForceLogging bool `json:"forceLog,omitempty"`
60+
Sid string `json:"sid,omitempty"`
61+
Charset string `json:"charset,omitempty"`
62+
Pdbname string `json:"pdbName,omitempty"`
63+
LoadBalancer bool `json:"loadBalancer,omitempty"`
64+
ServicePort int `json:"servicePort,omitempty"`
65+
ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"`
66+
FlashBack bool `json:"flashBack,omitempty"`
67+
ArchiveLog bool `json:"archiveLog,omitempty"`
68+
ForceLogging bool `json:"forceLog,omitempty"`
69+
EnableTCPS bool `json:"enableTCPS,omitempty"`
70+
TcpsCertRenewInterval string `json:"tcpsCertRenewInterval,omitempty"`
6871

6972
CloneFrom string `json:"cloneFrom,omitempty"`
7073
ReadinessCheckPeriod int `json:"readinessCheckPeriod,omitempty"`
@@ -146,6 +149,10 @@ type SingleInstanceDatabaseStatus struct {
146149
PdbConnectString string `json:"pdbConnectString,omitempty"`
147150
ApexInstalled bool `json:"apexInstalled,omitempty"`
148151
PrebuiltDB bool `json:"prebuiltDB,omitempty"`
152+
// +kubebuilder:default:=false
153+
IsTcpsEnabled bool `json:"isTcpsEnabled"`
154+
CertCreationTimestamp string `json:"certCreationTimestamp,omitempty"`
155+
CertRenewDuration string `json:"certRenewDuration,omitempty"`
149156

150157
// +patchMergeKey=type
151158
// +patchStrategy=merge

apis/database/v1alpha1/singleinstancedatabase_webhook.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ package v1alpha1
4040

4141
import (
4242
"strings"
43+
"time"
4344

4445
dbcommons "github.com/oracle/oracle-database-operator/commons/database"
4546

@@ -234,6 +235,32 @@ func (r *SingleInstanceDatabase) ValidateCreate() error {
234235
}
235236
}
236237

238+
// servicePort validation
239+
if !r.Spec.LoadBalancer {
240+
// NodePort service is expected. In this case servicePort should be in range 30000-32767
241+
if r.Spec.ServicePort != 0 && (r.Spec.ServicePort < 30000 || r.Spec.ServicePort > 32767) {
242+
allErrs = append(allErrs,
243+
field.Invalid(field.NewPath("spec").Child("servicePort"), r.Spec.ServicePort,
244+
"servicePort should be in 30000-32767 range."))
245+
}
246+
}
247+
248+
// Certificate Renew Duration Validation
249+
if r.Spec.TcpsCertRenewInterval != "" {
250+
duration, err := time.ParseDuration(r.Spec.TcpsCertRenewInterval)
251+
if err != nil {
252+
allErrs = append(allErrs,
253+
field.Invalid(field.NewPath("spec").Child("tcpsCertRenewInterval"), r.Spec.TcpsCertRenewInterval,
254+
"Please provide valid string to parse the tcpsCertRenewInterval."))
255+
}
256+
maxLimit, _ := time.ParseDuration("26280h")
257+
minLimit, _ := time.ParseDuration("1m")
258+
if duration > maxLimit || duration < minLimit {
259+
allErrs = append(allErrs,
260+
field.Invalid(field.NewPath("spec").Child("tcpsCertRenewInterval"), r.Spec.TcpsCertRenewInterval,
261+
"Please specify tcpsCertRenewInterval in the range: 1m to 26280h"))
262+
}
263+
}
237264
if len(allErrs) == 0 {
238265
return nil
239266
}

commons/database/constants.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838

3939
package commons
4040

41+
const CONTAINER_LISTENER_PORT int32 = 1521
42+
43+
const CONTAINER_TCPS_PORT int32 = 1522
44+
4145
const ORACLE_UID int64 = 54321
4246

4347
const ORACLE_GUID int64 = 54321
@@ -318,12 +322,12 @@ const InitORDSCMD string = "if [ -f $ORDS_HOME/config/ords/defaults.xml ]; then
318322
"\numask 022"
319323

320324
const GetSessionInfoSQL string = "select s.sid || ',' || s.serial# as Info FROM v\\$session s, v\\$process p " +
321-
"WHERE (s.username = 'ORDS_PUBLIC_USER' or "+
322-
"s.username = 'APEX_PUBLIC_USER' or "+
323-
"s.username = 'APEX_REST_PUBLIC_USER' or "+
324-
"s.username = 'APEX_LISTENER' or "+
325-
"s.username = 'C##_DBAPI_CDB_ADMIN' or "+
326-
"s.username = 'C##_DBAPI_PDB_ADMIN' ) AND p.addr(+) = s.paddr;"
325+
"WHERE (s.username = 'ORDS_PUBLIC_USER' or " +
326+
"s.username = 'APEX_PUBLIC_USER' or " +
327+
"s.username = 'APEX_REST_PUBLIC_USER' or " +
328+
"s.username = 'APEX_LISTENER' or " +
329+
"s.username = 'C##_DBAPI_CDB_ADMIN' or " +
330+
"s.username = 'C##_DBAPI_PDB_ADMIN' ) AND p.addr(+) = s.paddr;"
327331

328332
const KillSessionSQL string = "alter system kill session '%[1]s';"
329333

@@ -426,13 +430,12 @@ const ConfigureApexRest string = "if [ -f ${ORDS_HOME}/config/apex/apex_rest_con
426430
"echo -e \"%[1]s\n%[1]s\" | %[2]s ; else echo \"Apex Folder doesn't exist\" ; fi ;"
427431

428432
const AlterApexUsers string = "\nALTER SESSION SET CONTAINER=%[2]s;" +
429-
"\n ALTER USER APEX_PUBLIC_USER IDENTIFIED BY \\\"%[1]s\\\" ACCOUNT UNLOCK; "+
433+
"\n ALTER USER APEX_PUBLIC_USER IDENTIFIED BY \\\"%[1]s\\\" ACCOUNT UNLOCK; " +
430434
"\n ALTER USER APEX_REST_PUBLIC_USER IDENTIFIED BY \\\"%[1]s\\\" ACCOUNT UNLOCK;" +
431435
"\n ALTER USER APEX_LISTENER IDENTIFIED BY \\\"%[1]s\\\" ACCOUNT UNLOCK;" +
432436
"\nexec APEX_UTIL.set_workspace(p_workspace => 'INTERNAL');" +
433437
"\nexec APEX_UTIL.EDIT_USER(p_user_id => APEX_UTIL.GET_USER_ID('ADMIN'), p_user_name => 'ADMIN', p_web_password => '%[1]s', p_new_password => '%[1]s');\n"
434438

435-
436439
const CopyApexImages string = " ( while true; do sleep 60; echo \"Copying Apex Images...\" ; done ) & mkdir -p /opt/oracle/oradata/${ORACLE_SID^^}_ORDS/apex/images && " +
437440
" cp -R /opt/oracle/oradata/${ORACLE_SID^^}/apex/images/* /opt/oracle/oradata/${ORACLE_SID^^}_ORDS/apex/images; chown -R oracle:oinstall /opt/oracle/oradata/${ORACLE_SID^^}_ORDS/apex; kill -9 $!;"
438441

@@ -480,3 +483,15 @@ const SetApexUsers string = "\numask 177" +
480483

481484
// Get Sid, Pdbname, Edition for prebuilt db
482485
const GetSidPdbEditionCMD string = "echo $ORACLE_SID,$ORACLE_PDB,$ORACLE_EDITION,Edition;"
486+
487+
// Command to enable TCPS as a formatted string. The parameter would be the port at which TCPS is enabled.
488+
const EnableTcpsCMD string = "$ORACLE_BASE/$CONFIG_TCPS_FILE"
489+
490+
// Command for TCPS certs renewal to prevent their expiry. It is same as the EnableTcpsCMD
491+
const RenewCertsCMD string = EnableTcpsCMD
492+
493+
// Command to disable TCPS
494+
const DisableTcpsCMD string = "$ORACLE_BASE/$CONFIG_TCPS_FILE disable"
495+
496+
// TCPS clientWallet update command
497+
const ClientWalletUpdate string = "sed -i -e 's/HOST.*$/HOST=%s)/g' -e 's/PORT.*$/PORT=%d)/g' ${ORACLE_BASE}/oradata/clientWallet/${ORACLE_SID}/tnsnames.ora"

commons/database/utils.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import (
5050
"unicode"
5151

5252
corev1 "k8s.io/api/core/v1"
53+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5354

5455
apierrors "k8s.io/apimachinery/pkg/api/errors"
5556
"k8s.io/apimachinery/pkg/types"
@@ -673,3 +674,18 @@ func ApexPasswordValidator(pwd string) bool {
673674

674675
return hasMinLen && hasUpper && hasLower && hasNumber && hasSpecial
675676
}
677+
678+
// Function for patching the K8s service with the payload.
679+
// Patch strategy used: Strategic Merge Patch
680+
func PatchService(config *rest.Config, namespace string, ctx context.Context, req ctrl.Request, svcName string, payload string) error {
681+
log := ctrllog.FromContext(ctx).WithValues("patchService", req.NamespacedName)
682+
client, err := kubernetes.NewForConfig(config)
683+
if err != nil {
684+
log.Error(err, "config error")
685+
}
686+
687+
// Trying to patch the service resource using Strategic Merge strategy
688+
log.Info("Patching the service", "Service", svcName)
689+
_, err = client.CoreV1().Services(namespace).Patch(ctx, svcName, types.StrategicMergePatchType, []byte(payload), metav1.PatchOptions{})
690+
return err
691+
}

config/crd/bases/database.oracle.com_singleinstancedatabases.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ spec:
7777
type: object
7878
archiveLog:
7979
type: boolean
80+
certRenewDuration:
81+
type: string
8082
charset:
8183
type: string
8284
cloneFrom:
@@ -87,6 +89,8 @@ spec:
8789
- enterprise
8890
- express
8991
type: string
92+
enableTCPS:
93+
type: boolean
9094
flashBack:
9195
type: boolean
9296
forceLog:
@@ -154,6 +158,8 @@ spec:
154158
additionalProperties:
155159
type: string
156160
type: object
161+
servicePort:
162+
type: integer
157163
sid:
158164
description: SID must be alphanumeric (no special characters, only
159165
a-z, A-Z, 0-9), and no longer than 12 characters.
@@ -171,6 +177,10 @@ spec:
171177
type: boolean
172178
archiveLog:
173179
type: string
180+
certCreationTimestamp:
181+
type: string
182+
certRenewDuration:
183+
type: string
174184
charset:
175185
type: string
176186
cloneFrom:
@@ -279,6 +289,9 @@ spec:
279289
type: integer
280290
initSgaSize:
281291
type: integer
292+
isTcpsEnabled:
293+
default: false
294+
type: boolean
282295
nodes:
283296
items:
284297
type: string
@@ -326,6 +339,7 @@ spec:
326339
status:
327340
type: string
328341
required:
342+
- isTcpsEnabled
329343
- persistence
330344
type: object
331345
type: object

config/samples/sidb/singleinstancedatabase.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ spec:
4444
## Enable/Disable ForceLogging
4545
forceLog: false
4646

47+
## Enable TCPS
48+
enableTCPS: false
49+
50+
## TCPS Certificate Renewal Interval: The time after which TCPS certificate will be renewed if TCPS connections are enabled.
51+
## tcpsCertRenewInterval can be in hours(h), minutes(m) and seconds(s); e.g. 17520h, 8760h etc.
52+
## Maximum value is 26280h (3 years), Minimum value is 1m; Default value is 17520h (2 years)
53+
## If this field is commented out/removed from the yaml, it will disable the auto-renewal feature for TCPS certificate
54+
tcpsCertRenewInterval: 17520h
55+
4756
## NA if cloning from a SourceDB (cloneFrom is set)
4857
## Specify both sgaSize and pgaSize (in MB) or dont specify both
4958
## Specify Non-Zero value to use
@@ -79,6 +88,11 @@ spec:
7988
## Type of service . Applicable on cloud enviroments only
8089
## if loadBalService : false, service type = "NodePort" else "LoadBalancer"
8190
loadBalancer: false
91+
92+
## If loadBalancer is enabled, the servicePort is the load balancer port number
93+
## If loadBalancer is disabled, the servicePort is the NodePort(should be in range 30000-32767)
94+
#servicePort: 30001
95+
8296
## Service Annotations (Cloud provider specific), for configuring the service (e.g. private LoadBalancer service)
8397
#serviceAnnotations:
8498
# service.beta.kubernetes.io/oci-load-balancer-internal: "true"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#
2+
# Copyright (c) 2022, 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: v1
7+
kind: Secret
8+
metadata:
9+
name: db-admin-secret
10+
namespace: default
11+
type: Opaque
12+
stringData:
13+
# Specify your DB password here
14+
oracle_pwd:
15+
16+
---
17+
18+
apiVersion: database.oracle.com/v1alpha1
19+
kind: SingleInstanceDatabase
20+
metadata:
21+
# Creates base sidb-sample. Use singleinstancedatabase_clone.yaml for cloning
22+
# and singleinstancedatabase_patch.yaml for patching
23+
name: sidb-sample
24+
namespace: default
25+
spec:
26+
27+
## Use only alphanumeric characters for sid
28+
sid: ORCL1
29+
30+
## DB edition.
31+
edition: enterprise
32+
33+
## Secret containing SIDB password mapped to secretKey
34+
adminPassword:
35+
secretName: db-admin-secret
36+
37+
## DB character set
38+
charset: AL32UTF8
39+
40+
## PDB name
41+
pdbName: orclpdb1
42+
43+
## Enable/Disable ArchiveLog. Should be true to allow DB cloning
44+
archiveLog: true
45+
46+
## Enable TCPS
47+
enableTCPS: true
48+
49+
## TCPS Certificate Renewal Interval: The time after which TCPS certificate will be renewed if TCPS connections are enabled.
50+
## tcpsCertRenewInterval can be in hours(h), minutes(m) and seconds(s); e.g. 17520h, 8760h etc.
51+
## Maximum value is 26280h (3 years), Minimum value is 1m; Default value is 17520h (2 years)
52+
## If this field is commented out/removed from the yaml, it will disable the auto-renewal feature for TCPS certificate
53+
tcpsCertRenewInterval: 17520h
54+
55+
## Database image details
56+
image:
57+
pullFrom: container-registry.oracle.com/database/enterprise:latest
58+
pullSecrets: oracle-container-registry-secret
59+
60+
## size is the required minimum size of the persistent volume
61+
## storageClass is specified for automatic volume provisioning
62+
## accessMode can only accept one of ReadWriteOnce, ReadWriteMany
63+
persistence:
64+
size: 100Gi
65+
## oci-bv applies to OCI block volumes. Use "standard" storageClass for dynamic provisioning in Minikube. Update as appropriate for other cloud service providers
66+
storageClass: "oci-bv"
67+
accessMode: "ReadWriteOnce"
68+
69+
## Count of Database Pods.
70+
replicas: 1

0 commit comments

Comments
 (0)