Skip to content

Commit 4e13046

Browse files
author
abhisbyk
committed
Added cert renewal logic, enable/disable TCPs, creation of clusterIP service for ORDS/APEX installation
Signed-off-by: abhisbyk <[email protected]>
1 parent 5085f82 commit 4e13046

File tree

6 files changed

+269
-110
lines changed

6 files changed

+269
-110
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ type SingleInstanceDatabaseStatus struct {
149149
ApexInstalled bool `json:"apexInstalled,omitempty"`
150150
PrebuiltDB bool `json:"prebuiltDB,omitempty"`
151151
// +kubebuilder:default:=false
152-
IsTcpsEnabled bool `json:"isTcpsEnabled"`
152+
IsTcpsEnabled bool `json:"isTcpsEnabled"`
153+
TcpsPort int `json:"tcpsPort,omitempty"`
154+
CertCreationTimestamp string `json:"certCreationTimestamp,omitempty"`
153155

154156
// +patchMergeKey=type
155157
// +patchStrategy=merge

commons/database/constants.go

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

3939
package commons
4040

41+
const DEFAULT_LISTENER_PORT int32 = 1521
42+
4143
const ORACLE_UID int64 = 54321
4244

4345
const ORACLE_GUID int64 = 54321
@@ -318,12 +320,12 @@ const InitORDSCMD string = "if [ -f $ORDS_HOME/config/ords/defaults.xml ]; then
318320
"\numask 022"
319321

320322
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;"
323+
"WHERE (s.username = 'ORDS_PUBLIC_USER' or " +
324+
"s.username = 'APEX_PUBLIC_USER' or " +
325+
"s.username = 'APEX_REST_PUBLIC_USER' or " +
326+
"s.username = 'APEX_LISTENER' or " +
327+
"s.username = 'C##_DBAPI_CDB_ADMIN' or " +
328+
"s.username = 'C##_DBAPI_PDB_ADMIN' ) AND p.addr(+) = s.paddr;"
327329

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

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

428430
const AlterApexUsers string = "\nALTER SESSION SET CONTAINER=%[2]s;" +
429-
"\n ALTER USER APEX_PUBLIC_USER IDENTIFIED BY \\\"%[1]s\\\" ACCOUNT UNLOCK; "+
431+
"\n ALTER USER APEX_PUBLIC_USER IDENTIFIED BY \\\"%[1]s\\\" ACCOUNT UNLOCK; " +
430432
"\n ALTER USER APEX_REST_PUBLIC_USER IDENTIFIED BY \\\"%[1]s\\\" ACCOUNT UNLOCK;" +
431433
"\n ALTER USER APEX_LISTENER IDENTIFIED BY \\\"%[1]s\\\" ACCOUNT UNLOCK;" +
432434
"\nexec APEX_UTIL.set_workspace(p_workspace => 'INTERNAL');" +
433435
"\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"
434436

435-
436437
const CopyApexImages string = " ( while true; do sleep 60; echo \"Copying Apex Images...\" ; done ) & mkdir -p /opt/oracle/oradata/${ORACLE_SID^^}_ORDS/apex/images && " +
437438
" 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 $!;"
438439

@@ -480,3 +481,12 @@ const SetApexUsers string = "\numask 177" +
480481

481482
// Get Sid, Pdbname, Edition for prebuilt db
482483
const GetSidPdbEditionCMD string = "echo $ORACLE_SID,$ORACLE_PDB,$ORACLE_EDITION,Edition;"
484+
485+
// Command to enable TCPS as a formatted string. The parameter would be the port at which TCPS is enabled.
486+
const EnableTcpsCMD string = "$ORACLE_BASE/$CONFIG_TCPS_FILE %d"
487+
488+
// Command for TCPS certs renewal to prevent their expiry. It is same as the EnableTcpsCMD
489+
const RenewCertsCMD string = EnableTcpsCMD
490+
491+
// Command to disable TCPS
492+
const DisableTcpsCMD string = "$ORACLE_BASE/$CONFIG_TCPS_FILE disable"

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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ spec:
175175
type: boolean
176176
archiveLog:
177177
type: string
178+
certCreationTimestamp:
179+
type: string
178180
charset:
179181
type: string
180182
cloneFrom:
@@ -283,6 +285,9 @@ spec:
283285
type: integer
284286
initSgaSize:
285287
type: integer
288+
isTcpsEnabled:
289+
default: false
290+
type: boolean
286291
nodes:
287292
items:
288293
type: string
@@ -329,7 +334,10 @@ spec:
329334
type: object
330335
status:
331336
type: string
337+
tcpsPort:
338+
type: integer
332339
required:
340+
- isTcpsEnabled
333341
- persistence
334342
type: object
335343
type: object

0 commit comments

Comments
 (0)