Skip to content

Commit f9d3cf5

Browse files
Abhishek Kumaryunus-qureshi
authored andcommitted
Added service annotations for SIDB & ORDS controllers
1 parent f132753 commit f9d3cf5

9 files changed

+78
-29
lines changed

apis/database/v1alpha1/oraclerestdataservice_types.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type OracleRestDataServiceSpec struct {
5252

5353
DatabaseRef string `json:"databaseRef"`
5454
LoadBalancer bool `json:"loadBalancer,omitempty"`
55+
ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"`
5556
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
5657
Image OracleRestDataServiceImage `json:"image,omitempty"`
5758
OrdsPassword OracleRestDataServicePassword `json:"ordsPassword"`
@@ -74,8 +75,8 @@ type OracleRestDataServicePersistence struct {
7475
StorageClass string `json:"storageClass,omitempty"`
7576

7677
// +kubebuilder:validation:Enum=ReadWriteOnce;ReadWriteMany
77-
AccessMode string `json:"accessMode,omitempty"`
78-
VolumeName string `json:"volumeName,omitempty"`
78+
AccessMode string `json:"accessMode,omitempty"`
79+
VolumeName string `json:"volumeName,omitempty"`
7980
}
8081

8182
// OracleRestDataServiceImage defines the Image source and pullSecrets for POD
@@ -90,15 +91,15 @@ type OracleRestDataServicePassword struct {
9091
SecretName string `json:"secretName"`
9192
// +kubebuilder:default:="oracle_pwd"
9293
SecretKey string `json:"secretKey,omitempty"`
93-
KeepSecret *bool `json:"keepSecret,omitempty"`
94+
KeepSecret *bool `json:"keepSecret,omitempty"`
9495
}
9596

9697
// OracleRestDataServicePDBSchemas defines the PDB Schemas to be ORDS Enabled
9798
type OracleRestDataServiceRestEnableSchemas struct {
98-
PdbName string `json:"pdbName,omitempty"`
99-
SchemaName string `json:"schemaName"`
100-
UrlMapping string `json:"urlMapping,omitempty"`
101-
Enable bool `json:"enable"`
99+
PdbName string `json:"pdbName,omitempty"`
100+
SchemaName string `json:"schemaName"`
101+
UrlMapping string `json:"urlMapping,omitempty"`
102+
Enable bool `json:"enable"`
102103
}
103104

104105
// OracleRestDataServiceStatus defines the observed state of OracleRestDataService

apis/database/v1alpha1/singleinstancedatabase_types.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ 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-
FlashBack bool `json:"flashBack,omitempty"`
65-
ArchiveLog bool `json:"archiveLog,omitempty"`
66-
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+
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"`
6768

6869
CloneFrom string `json:"cloneFrom,omitempty"`
6970
ReadinessCheckPeriod int `json:"readinessCheckPeriod,omitempty"`
@@ -81,10 +82,10 @@ type SingleInstanceDatabaseSpec struct {
8182

8283
// SingleInstanceDatabasePersistence defines the storage size and class for PVC
8384
type SingleInstanceDatabasePersistence struct {
84-
Size string `json:"size,omitempty"`
85-
StorageClass string `json:"storageClass,omitempty"`
85+
Size string `json:"size,omitempty"`
86+
StorageClass string `json:"storageClass,omitempty"`
8687
// +kubebuilder:validation:Enum=ReadWriteOnce;ReadWriteMany
87-
AccessMode string `json:"accessMode,omitempty"`
88+
AccessMode string `json:"accessMode,omitempty"`
8889
VolumeName string `json:"volumeName,omitempty"`
8990
VolumeClaimAnnotation string `json:"volumeClaimAnnotation,omitempty"`
9091
}

apis/database/v1alpha1/zz_generated.deepcopy.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,13 @@ func (in *OracleRestDataServiceRestEnableSchemas) DeepCopy() *OracleRestDataServ
15011501
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
15021502
func (in *OracleRestDataServiceSpec) DeepCopyInto(out *OracleRestDataServiceSpec) {
15031503
*out = *in
1504+
if in.ServiceAnnotations != nil {
1505+
in, out := &in.ServiceAnnotations, &out.ServiceAnnotations
1506+
*out = make(map[string]string, len(*in))
1507+
for key, val := range *in {
1508+
(*out)[key] = val
1509+
}
1510+
}
15041511
if in.NodeSelector != nil {
15051512
in, out := &in.NodeSelector, &out.NodeSelector
15061513
*out = make(map[string]string, len(*in))
@@ -2113,6 +2120,13 @@ func (in *SingleInstanceDatabasePersistence) DeepCopy() *SingleInstanceDatabaseP
21132120
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
21142121
func (in *SingleInstanceDatabaseSpec) DeepCopyInto(out *SingleInstanceDatabaseSpec) {
21152122
*out = *in
2123+
if in.ServiceAnnotations != nil {
2124+
in, out := &in.ServiceAnnotations, &out.ServiceAnnotations
2125+
*out = make(map[string]string, len(*in))
2126+
for key, val := range *in {
2127+
(*out)[key] = val
2128+
}
2129+
}
21162130
if in.NodeSelector != nil {
21172131
in, out := &in.NodeSelector, &out.NodeSelector
21182132
*out = make(map[string]string, len(*in))

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ spec:
159159
type: array
160160
serviceAccountName:
161161
type: string
162+
serviceAnnotations:
163+
additionalProperties:
164+
type: string
165+
type: object
162166
required:
163167
- adminPassword
164168
- databaseRef

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ spec:
150150
type: integer
151151
serviceAccountName:
152152
type: string
153+
serviceAnnotations:
154+
additionalProperties:
155+
type: string
156+
type: object
153157
sid:
154158
description: SID must be alphanumeric (no special characters, only
155159
a-z, A-Z, 0-9), and no longer than 12 characters.

config/samples/sidb/oraclerestdataservice.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ spec:
6262
## Type of service Applicable on cloud enviroments only.
6363
## if loadBalService: false, service type = "NodePort" else "LoadBalancer"
6464
loadBalancer: false
65+
## Service Annotations (Cloud provider specific), for configuring the service (e.g. private LoadBalancer service)
66+
#serviceAnnotations:
67+
# service.beta.kubernetes.io/oci-load-balancer-internal: "true"
68+
6569

6670
## Deploy only on nodes having required labels. Format label_name: label_value
6771
## The same lables are applied to the created PVC

config/samples/sidb/singleinstancedatabase.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ spec:
7979
## Type of service . Applicable on cloud enviroments only
8080
## if loadBalService : false, service type = "NodePort" else "LoadBalancer"
8181
loadBalancer: false
82+
## Service Annotations (Cloud provider specific), for configuring the service (e.g. private LoadBalancer service)
83+
#serviceAnnotations:
84+
# service.beta.kubernetes.io/oci-load-balancer-internal: "true"
8285

8386
## Deploy only on nodes having required labels. Format label_name: label_value
8487
## For instance if the pods need to be restricted to a particular AD

controllers/database/oraclerestdataservice_controller.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (r *OracleRestDataServiceReconciler) validate(m *dbapi.OracleRestDataServic
251251
eventMsgs = append(eventMsgs, "cannot configure ORDS for database "+m.Spec.DatabaseRef+" that has no attached persistent volume")
252252
}
253253
if !m.Status.OrdsInstalled && n.Status.OrdsReference != "" {
254-
eventMsgs = append(eventMsgs, "database "+m.Spec.DatabaseRef+ " is already configured with ORDS "+n.Status.OrdsReference)
254+
eventMsgs = append(eventMsgs, "database "+m.Spec.DatabaseRef+" is already configured with ORDS "+n.Status.OrdsReference)
255255
}
256256
if m.Status.DatabaseRef != "" && m.Status.DatabaseRef != m.Spec.DatabaseRef {
257257
eventMsgs = append(eventMsgs, "databaseRef cannot be updated")
@@ -458,6 +458,15 @@ func (r *OracleRestDataServiceReconciler) instantiateSVCSpec(m *dbapi.OracleRest
458458
Labels: map[string]string{
459459
"app": m.Name,
460460
},
461+
Annotations: func() map[string]string {
462+
annotations := make(map[string]string)
463+
if len(m.Spec.ServiceAnnotations) != 0 {
464+
for key, value := range m.Spec.ServiceAnnotations {
465+
annotations[key] = value
466+
}
467+
}
468+
return annotations
469+
}(),
461470
},
462471
Spec: corev1.ServiceSpec{
463472
Ports: []corev1.ServicePort{
@@ -768,7 +777,7 @@ func (r *OracleRestDataServiceReconciler) instantiatePVCSpec(m *dbapi.OracleRest
768777
},
769778
},
770779
StorageClassName: &m.Spec.Persistence.StorageClass,
771-
VolumeName: m.Spec.Persistence.VolumeName,
780+
VolumeName: m.Spec.Persistence.VolumeName,
772781
Selector: func() *metav1.LabelSelector {
773782
if m.Spec.Persistence.StorageClass != "oci" {
774783
return nil
@@ -1237,8 +1246,8 @@ func (r *OracleRestDataServiceReconciler) configureApex(m *dbapi.OracleRestDataS
12371246
// Alter Apex Users
12381247
log.Info("Alter APEX Users")
12391248
_, err := dbcommons.ExecCommand(r, r.Config, sidbReadyPod.Name, sidbReadyPod.Namespace, "",
1240-
ctx, req, true, "bash", "-c", fmt.Sprintf("echo -e \"%s\" | %s",
1241-
fmt.Sprintf(dbcommons.AlterApexUsers, apexPassword, n.Spec.Pdbname), dbcommons.SQLPlusCLI))
1249+
ctx, req, true, "bash", "-c", fmt.Sprintf("echo -e \"%s\" | %s",
1250+
fmt.Sprintf(dbcommons.AlterApexUsers, apexPassword, n.Spec.Pdbname), dbcommons.SQLPlusCLI))
12421251
if err != nil {
12431252
log.Error(err, err.Error())
12441253
return requeueY
@@ -1339,7 +1348,7 @@ func (r *OracleRestDataServiceReconciler) installApex(m *dbapi.OracleRestDataSer
13391348
m.Status.Status = dbcommons.StatusReady
13401349
eventReason = "Apex Installation"
13411350
outArr := strings.Split(out, apexInstalled)
1342-
eventMsg = "installation of Apex "+ strings.TrimSpace(outArr[len(outArr)-1]) +" completed"
1351+
eventMsg = "installation of Apex " + strings.TrimSpace(outArr[len(outArr)-1]) + " completed"
13431352
r.Recorder.Eventf(m, corev1.EventTypeNormal, eventReason, eventMsg)
13441353
n.Status.ApexInstalled = true
13451354
r.Status().Update(ctx, n)
@@ -1432,7 +1441,7 @@ func (r *OracleRestDataServiceReconciler) restEnableSchemas(m *dbapi.OracleRestD
14321441
// If the PDB mentioned in yaml doesnt contain in the database , continue
14331442
if !strings.Contains(strings.ToUpper(availablePDBS), strings.ToUpper(pdbName)) {
14341443
eventReason := "PDB Check"
1435-
eventMsg := "PDB "+ pdbName +" not found for specified schema " + m.Spec.RestEnableSchemas[i].SchemaName
1444+
eventMsg := "PDB " + pdbName + " not found for specified schema " + m.Spec.RestEnableSchemas[i].SchemaName
14361445
log.Info(eventMsg)
14371446
r.Recorder.Eventf(m, corev1.EventTypeWarning, eventReason, eventMsg)
14381447
continue
@@ -1450,10 +1459,10 @@ func (r *OracleRestDataServiceReconciler) restEnableSchemas(m *dbapi.OracleRestD
14501459

14511460
// if ORDS already enabled for given PDB
14521461
if strings.Contains(out, "STATUS:ENABLED") {
1453-
if m.Spec.RestEnableSchemas[i].Enable {
1462+
if m.Spec.RestEnableSchemas[i].Enable {
14541463
log.Info("Schema already enabled", "schema", m.Spec.RestEnableSchemas[i].SchemaName)
14551464
continue
1456-
}
1465+
}
14571466
} else if strings.Contains(out, "STATUS:DISABLED") {
14581467
if !m.Spec.RestEnableSchemas[i].Enable {
14591468
log.Info("Schema already disabled", "schema", m.Spec.RestEnableSchemas[i].SchemaName)
@@ -1479,7 +1488,7 @@ func (r *OracleRestDataServiceReconciler) restEnableSchemas(m *dbapi.OracleRestD
14791488
createSchemaSQL := fmt.Sprintf(dbcommons.CreateORDSSchemaSQL, m.Spec.RestEnableSchemas[i].SchemaName, password, pdbName)
14801489
log.Info("Creating schema", "schema", m.Spec.RestEnableSchemas[i].SchemaName)
14811490
_, err = dbcommons.ExecCommand(r, r.Config, sidbReadyPod.Name, sidbReadyPod.Namespace, "", ctx, req, true, "bash", "-c",
1482-
fmt.Sprintf("echo -e \"%s\" | %s", createSchemaSQL, dbcommons.SQLPlusCLI))
1491+
fmt.Sprintf("echo -e \"%s\" | %s", createSchemaSQL, dbcommons.SQLPlusCLI))
14831492
if err != nil {
14841493
log.Error(err, err.Error())
14851494
return requeueY
@@ -1514,7 +1523,7 @@ func (r *OracleRestDataServiceReconciler) restEnableSchemas(m *dbapi.OracleRestD
15141523
}
15151524

15161525
if restartORDS {
1517-
r.Log.Info("Restarting ORDS Pod "+ordsReadyPod.Name+" to clear disabled schemas cache")
1526+
r.Log.Info("Restarting ORDS Pod " + ordsReadyPod.Name + " to clear disabled schemas cache")
15181527
var gracePeriodSeconds int64 = 0
15191528
policy := metav1.DeletePropagationForeground
15201529
err = r.Delete(ctx, &ordsReadyPod, &client.DeleteOptions{

controllers/database/singleinstancedatabase_controller.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,15 @@ func (r *SingleInstanceDatabaseReconciler) instantiateSVCSpec(m *dbapi.SingleIns
865865
Labels: map[string]string{
866866
"app": m.Name,
867867
},
868+
Annotations: func() map[string]string {
869+
annotations := make(map[string]string)
870+
if len(m.Spec.ServiceAnnotations) != 0 {
871+
for key, value := range m.Spec.ServiceAnnotations {
872+
annotations[key] = value
873+
}
874+
}
875+
return annotations
876+
}(),
868877
},
869878
Spec: corev1.ServiceSpec{
870879
Ports: []corev1.ServicePort{
@@ -933,7 +942,7 @@ func (r *SingleInstanceDatabaseReconciler) instantiatePVCSpec(m *dbapi.SingleIns
933942
},
934943
},
935944
StorageClassName: &m.Spec.Persistence.StorageClass,
936-
VolumeName: m.Spec.Persistence.VolumeName,
945+
VolumeName: m.Spec.Persistence.VolumeName,
937946
Selector: func() *metav1.LabelSelector {
938947
if m.Spec.Persistence.StorageClass != "oci" {
939948
return nil
@@ -1712,7 +1721,7 @@ func (r *SingleInstanceDatabaseReconciler) runDatapatch(m *dbapi.SingleInstanceD
17121721
m.Status.DatafilesPatched = "true"
17131722
status, versionFrom, versionTo, _ := dbcommons.GetSqlpatchStatus(r, r.Config, readyPod, ctx, req)
17141723
if versionTo != "" {
1715-
eventMsg = "data files patched from release update " + versionFrom + " to " + versionTo + ", "+ status + ": " +releaseUpdate
1724+
eventMsg = "data files patched from release update " + versionFrom + " to " + versionTo + ", " + status + ": " + releaseUpdate
17161725
} else {
17171726
eventMsg = "datapatch execution completed"
17181727
}

0 commit comments

Comments
 (0)