Skip to content

Commit 8e59edb

Browse files
author
abhisbyk
committed
Configurable renewCertDuration and Nodeport svc abrupt deletion fix
Signed-off-by: abhisbyk <[email protected]>
1 parent 3a49ff3 commit 8e59edb

File tree

5 files changed

+60
-27
lines changed

5 files changed

+60
-27
lines changed

apis/database/v1alpha1/singleinstancedatabase_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type SingleInstanceDatabaseSpec struct {
6767
ArchiveLog bool `json:"archiveLog,omitempty"`
6868
ForceLogging bool `json:"forceLog,omitempty"`
6969
EnableTCPS bool `json:"enableTCPS,omitempty"`
70+
CertRenewDuration string `json:"certRenewDuration,omitempty"`
7071

7172
CloneFrom string `json:"cloneFrom,omitempty"`
7273
ReadinessCheckPeriod int `json:"readinessCheckPeriod,omitempty"`
@@ -151,8 +152,7 @@ type SingleInstanceDatabaseStatus struct {
151152
// +kubebuilder:default:=false
152153
IsTcpsEnabled bool `json:"isTcpsEnabled"`
153154
CertCreationTimestamp string `json:"certCreationTimestamp,omitempty"`
154-
DbHostname string `json:"dbHostname,omitempty"`
155-
DbPort int `json:"dbPort,omitempty"`
155+
CertRenewDuration string `json:"certRenewDuration,omitempty"`
156156

157157
// +patchMergeKey=type
158158
// +patchStrategy=merge

apis/database/v1alpha1/singleinstancedatabase_webhook.go

Lines changed: 21 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

@@ -244,6 +245,26 @@ func (r *SingleInstanceDatabase) ValidateCreate() error {
244245
}
245246
}
246247

248+
// Certificate Renew Duration Validation
249+
if r.Spec.CertRenewDuration != "" {
250+
duration, err := time.ParseDuration(r.Spec.CertRenewDuration)
251+
if err != nil {
252+
allErrs = append(allErrs,
253+
field.Invalid(field.NewPath("spec").Child("certRenewDuration"), r.Spec.CertRenewDuration,
254+
"Please provide valid string to parse the certRenewDuration."))
255+
}
256+
maxLimit, _ := time.ParseDuration("26000h")
257+
minLimit, _ := time.ParseDuration("1m")
258+
if duration > maxLimit || duration < minLimit {
259+
allErrs = append(allErrs,
260+
field.Invalid(field.NewPath("spec").Child("certRenewDuration"), r.Spec.CertRenewDuration,
261+
"Please specify certRenewDuration in the range: 1m to 26000h"))
262+
}
263+
} else {
264+
// Setting the default value
265+
r.Spec.CertRenewDuration = "26000h"
266+
}
267+
247268
if len(allErrs) == 0 {
248269
return nil
249270
}

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

Lines changed: 4 additions & 4 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:
@@ -177,6 +179,8 @@ spec:
177179
type: string
178180
certCreationTimestamp:
179181
type: string
182+
certRenewDuration:
183+
type: string
180184
charset:
181185
type: string
182186
cloneFrom:
@@ -263,10 +267,6 @@ spec:
263267
datafilesPatched:
264268
default: "false"
265269
type: string
266-
dbHostname:
267-
type: string
268-
dbPort:
269-
type: integer
270270
edition:
271271
type: string
272272
flashBack:

config/samples/sidb/singleinstancedatabase.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ spec:
4747
## Enable TCPS
4848
enableTCPS: false
4949

50+
## Certificate Renewal Duration: The time after which certificates will be renewed if TCPS connections are enabled; can be in hours(h), minutes(m) and seconds(s)
51+
## Maximum value is 26000h
52+
#certRenewDuration: 26000h
53+
5054
## NA if cloning from a SourceDB (cloneFrom is set)
5155
## Specify both sgaSize and pgaSize (in MB) or dont specify both
5256
## Specify Non-Zero value to use

controllers/database/singleinstancedatabase_controller.go

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -197,22 +197,22 @@ func (r *SingleInstanceDatabaseReconciler) Reconcile(ctx context.Context, req ct
197197
}
198198
}
199199

200-
// Configure TCPS
201-
result, err = r.configTcps(singleInstanceDatabase, readyPod, ctx, req)
200+
// Update DB config
201+
result, err = r.updateDBConfig(singleInstanceDatabase, readyPod, ctx, req)
202202
if result.Requeue {
203203
r.Log.Info("Reconcile queued")
204204
return result, nil
205205
}
206206

207-
// Update DB config
208-
result, err = r.updateDBConfig(singleInstanceDatabase, readyPod, ctx, req)
207+
// Update Init Parameters
208+
result, err = r.updateInitParameters(singleInstanceDatabase, readyPod, ctx, req)
209209
if result.Requeue {
210210
r.Log.Info("Reconcile queued")
211211
return result, nil
212212
}
213213

214-
// Update Init Parameters
215-
result, err = r.updateInitParameters(singleInstanceDatabase, readyPod, ctx, req)
214+
// Configure TCPS
215+
result, err = r.configTcps(singleInstanceDatabase, readyPod, ctx, req)
216216
if result.Requeue {
217217
r.Log.Info("Reconcile queued")
218218
return result, nil
@@ -1114,7 +1114,7 @@ func (r *SingleInstanceDatabaseReconciler) createOrReplaceSVC(ctx context.Contex
11141114
extSvcPort = extSvc.Spec.Ports[1].NodePort
11151115
}
11161116

1117-
if extSvc.Spec.Type != extSvcType || extSvcPort != svcPort || extSvc.Spec.Ports[1].TargetPort.IntVal != extSvcTargetPort {
1117+
if extSvc.Spec.Type != extSvcType || (m.Spec.ServicePort != 0 && extSvcPort != svcPort) || extSvc.Spec.Ports[1].TargetPort.IntVal != extSvcTargetPort {
11181118
// Deleting th service
11191119
log.Info("Deleting service", "name", extSvcName)
11201120
err := r.Delete(ctx, extSvc)
@@ -1794,16 +1794,15 @@ func (r *SingleInstanceDatabaseReconciler) updateClientWallet(m *dbapi.SingleIns
17941794
port = extSvc.Spec.Ports[1].NodePort
17951795
}
17961796
}
1797-
if host != "" && host != m.Status.DbHostname && port != int32(m.Status.DbPort) {
1798-
_, err := dbcommons.ExecCommand(r, r.Config, readyPod.Name, readyPod.Namespace, "",
1799-
ctx, req, false, "bash", "-c", fmt.Sprintf(dbcommons.ClientWalletUpdate, host, port))
1800-
if err != nil {
1801-
r.Log.Error(err, err.Error())
1802-
return err
1803-
}
1804-
m.Status.DbHostname = host
1805-
m.Status.DbPort = int(port)
1797+
1798+
r.Log.Info("Updating the client wallet...")
1799+
_, err := dbcommons.ExecCommand(r, r.Config, readyPod.Name, readyPod.Namespace, "",
1800+
ctx, req, false, "bash", "-c", fmt.Sprintf(dbcommons.ClientWalletUpdate, host, port))
1801+
if err != nil {
1802+
r.Log.Error(err, err.Error())
1803+
return err
18061804
}
1805+
18071806
} else {
18081807
r.Log.Info("Unable to get the service while updating the clientWallet", "Service.Namespace", extSvc.Namespace, "Service.Name", extSvcName)
18091808
return getExtSvcErr
@@ -1842,8 +1841,9 @@ func (r *SingleInstanceDatabaseReconciler) configTcps(m *dbapi.SingleInstanceDat
18421841
eventMsg = "TCPS Enabled."
18431842
r.Recorder.Eventf(m, corev1.EventTypeNormal, eventReason, eventMsg)
18441843

1845-
// 26040h = 1085 days
1846-
futureRequeue = ctrl.Result{Requeue: true, RequeueAfter: func() time.Duration { requeueDuration, _ := time.ParseDuration("26040h"); return requeueDuration }()}
1844+
requeueDuration, _ := time.ParseDuration(m.Spec.CertRenewDuration)
1845+
requeueDuration += func() time.Duration { requeueDuration, _ := time.ParseDuration("1s"); return requeueDuration }()
1846+
futureRequeue = ctrl.Result{Requeue: true, RequeueAfter: requeueDuration}
18471847

18481848
// update clientWallet
18491849
err = r.updateClientWallet(m, readyPod, ctx, req)
@@ -1879,7 +1879,7 @@ func (r *SingleInstanceDatabaseReconciler) configTcps(m *dbapi.SingleInstanceDat
18791879
// Certificates are renewed when 10 days remain for certs expiry
18801880
certCreationTimestamp, _ := time.Parse(time.RFC3339, m.Status.CertCreationTimestamp)
18811881
duration := time.Since(certCreationTimestamp)
1882-
allowdDuration, _ := time.ParseDuration("26000h")
1882+
allowdDuration, _ := time.ParseDuration(m.Spec.CertRenewDuration)
18831883
if duration > allowdDuration {
18841884
m.Status.Status = dbcommons.StatusUpdating
18851885
r.Status().Update(ctx, m)
@@ -1898,8 +1898,16 @@ func (r *SingleInstanceDatabaseReconciler) configTcps(m *dbapi.SingleInstanceDat
18981898
eventMsg := "TCPS Certificates Renewed at time %s,"
18991899
r.Recorder.Eventf(m, corev1.EventTypeNormal, eventReason, eventMsg, time.Now().Format(time.RFC3339))
19001900

1901-
// 26040h = 1085 days
1902-
futureRequeue = ctrl.Result{Requeue: true, RequeueAfter: func() time.Duration { requeueDuration, _ := time.ParseDuration("26040h"); return requeueDuration }()}
1901+
requeueDuration, _ := time.ParseDuration(m.Spec.CertRenewDuration)
1902+
requeueDuration += func() time.Duration { requeueDuration, _ := time.ParseDuration("1s"); return requeueDuration }()
1903+
futureRequeue = ctrl.Result{Requeue: true, RequeueAfter: requeueDuration}
1904+
}
1905+
if m.Status.CertRenewDuration != m.Spec.CertRenewDuration {
1906+
requeueDuration, _ := time.ParseDuration(m.Spec.CertRenewDuration)
1907+
requeueDuration += func() time.Duration { requeueDuration, _ := time.ParseDuration("1s"); return requeueDuration }()
1908+
futureRequeue = ctrl.Result{Requeue: true, RequeueAfter: requeueDuration}
1909+
1910+
m.Status.CertRenewDuration = m.Spec.CertRenewDuration
19031911
}
19041912
// update clientWallet
19051913
err := r.updateClientWallet(m, readyPod, ctx, req)

0 commit comments

Comments
 (0)