Skip to content

Commit 488cdf6

Browse files
committed
Merge branch 'AbhiK_dg1' into 'master'
Unification of standby controller in singleinstancedatabase controller See merge request rac-docker-dev/oracle-database-operator!236
2 parents acd471e + dd86d12 commit 488cdf6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3021
-272
lines changed

PROJECT

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,17 @@ resources:
123123
kind: DbcsSystem
124124
path: github.com/oracle/oracle-database-operator/apis/database/v1alpha1
125125
version: v1alpha1
126+
- api:
127+
crdVersion: v1beta1
128+
namespaced: true
129+
controller: true
130+
domain: oracle.com
131+
group: database
132+
kind: DataguardBroker
133+
path: github.com/oracle/oracle-database-operator/apis/database/v1alpha1
134+
version: v1alpha1
135+
webhooks:
136+
defaulting: true
137+
validation: true
138+
webhookVersion: v1beta1
126139
version: "3"
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
** Copyright (c) 2023 Oracle and/or its affiliates.
3+
**
4+
** The Universal Permissive License (UPL), Version 1.0
5+
**
6+
** Subject to the condition set forth below, permission is hereby granted to any
7+
** person obtaining a copy of this software, associated documentation and/or data
8+
** (collectively the "Software"), free of charge and under any and all copyright
9+
** rights in the Software, and any and all patent rights owned or freely
10+
** licensable by each licensor hereunder covering either (i) the unmodified
11+
** Software as contributed to or provided by such licensor, or (ii) the Larger
12+
** Works (as defined below), to deal in both
13+
**
14+
** (a) the Software, and
15+
** (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16+
** one is included with the Software (each a "Larger Work" to which the Software
17+
** is contributed by such licensors),
18+
**
19+
** without restriction, including without limitation the rights to copy, create
20+
** derivative works of, display, perform, and distribute the Software and make,
21+
** use, sell, offer for sale, import, export, have made, and have sold the
22+
** Software and the Larger Work(s), and to sublicense the foregoing rights on
23+
** either these or other terms.
24+
**
25+
** This license is subject to the following condition:
26+
** The above copyright notice and either this complete permission notice or at
27+
** a minimum a reference to the UPL must be included in all copies or
28+
** substantial portions of the Software.
29+
**
30+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
** SOFTWARE.
37+
*/
38+
39+
package v1alpha1
40+
41+
import (
42+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
43+
)
44+
45+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
46+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
47+
48+
// DataguardBrokerSpec defines the desired state of DataguardBroker
49+
type DataguardBrokerSpec struct {
50+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
51+
// Important: Run "make" to regenerate code after modifying this file
52+
53+
PrimaryDatabaseRef string `json:"primaryDatabaseRef"`
54+
StandbyDatabaseRefs []string `json:"standbyDatabaseRefs"`
55+
SetAsPrimaryDatabase string `json:"setAsPrimaryDatabase,omitempty"`
56+
LoadBalancer bool `json:"loadBalancer,omitempty"`
57+
58+
// +kubebuilder:validation:Enum=MaxPerformance;MaxAvailability
59+
ProtectionMode string `json:"protectionMode"`
60+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
61+
FastStartFailOver DataguardBrokerFastStartFailOver `json:"fastStartFailOver,omitempty"`
62+
AdminPassword DataguardBrokerPassword `json:"adminPassword"`
63+
}
64+
65+
// DataguardBrokerPassword defines the secret containing Password mapped to secretKey
66+
type DataguardBrokerPassword struct {
67+
SecretName string `json:"secretName,omitempty"`
68+
SecretKey string `json:"secretKey"`
69+
KeepSecret bool `json:"keepSecret"`
70+
}
71+
72+
type DataguardBrokerFastStartFailOver struct {
73+
Enable bool `json:"enable,omitempty"`
74+
Strategy []DataguardBrokerStrategy `json:"strategy,omitempty"`
75+
}
76+
77+
// FSFO strategy
78+
type DataguardBrokerStrategy struct {
79+
SourceDatabaseRef string `json:"sourceDatabaseRef,omitempty"`
80+
TargetDatabaseRefs string `json:"targetDatabaseRefs,omitempty"`
81+
}
82+
83+
// DataguardBrokerStatus defines the observed state of DataguardBroker
84+
type DataguardBrokerStatus struct {
85+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
86+
// Important: Run "make" to regenerate code after modifying this file
87+
88+
PrimaryDatabaseRef string `json:"primaryDatabaseRef,omitempty"`
89+
ProtectionMode string `json:"protectionMode,omitempty"`
90+
PrimaryDatabase string `json:"primaryDatabase,omitempty"`
91+
StandbyDatabases string `json:"standbyDatabases,omitempty"`
92+
ExternalConnectString string `json:"externalConnectString,omitempty"`
93+
ClusterConnectString string `json:"clusterConnectString,omitempty"`
94+
Status string `json:"status,omitempty"`
95+
}
96+
97+
//+kubebuilder:object:root=true
98+
//+kubebuilder:subresource:status
99+
// +kubebuilder:printcolumn:JSONPath=".status.primaryDatabase",name="Primary",type="string"
100+
// +kubebuilder:printcolumn:JSONPath=".status.standbyDatabases",name="Standbys",type="string"
101+
// +kubebuilder:printcolumn:JSONPath=".spec.protectionMode",name="Protection Mode",type="string"
102+
// +kubebuilder:printcolumn:JSONPath=".status.clusterConnectString",name="Cluster Connect Str",type="string",priority=1
103+
// +kubebuilder:printcolumn:JSONPath=".status.externalConnectString",name="Connect Str",type="string"
104+
// +kubebuilder:printcolumn:JSONPath=".spec.primaryDatabaseRef",name="Primary Database",type="string"
105+
// +kubebuilder:printcolumn:JSONPath=".status.status",name="Status",type="string"
106+
107+
// DataguardBroker is the Schema for the dataguardbrokers API
108+
type DataguardBroker struct {
109+
metav1.TypeMeta `json:",inline"`
110+
metav1.ObjectMeta `json:"metadata,omitempty"`
111+
112+
Spec DataguardBrokerSpec `json:"spec,omitempty"`
113+
Status DataguardBrokerStatus `json:"status,omitempty"`
114+
}
115+
116+
//+kubebuilder:object:root=true
117+
118+
// DataguardBrokerList contains a list of DataguardBroker
119+
type DataguardBrokerList struct {
120+
metav1.TypeMeta `json:",inline"`
121+
metav1.ListMeta `json:"metadata,omitempty"`
122+
Items []DataguardBroker `json:"items"`
123+
}
124+
125+
func init() {
126+
SchemeBuilder.Register(&DataguardBroker{}, &DataguardBrokerList{})
127+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
** Copyright (c) 2023 Oracle and/or its affiliates.
3+
**
4+
** The Universal Permissive License (UPL), Version 1.0
5+
**
6+
** Subject to the condition set forth below, permission is hereby granted to any
7+
** person obtaining a copy of this software, associated documentation and/or data
8+
** (collectively the "Software"), free of charge and under any and all copyright
9+
** rights in the Software, and any and all patent rights owned or freely
10+
** licensable by each licensor hereunder covering either (i) the unmodified
11+
** Software as contributed to or provided by such licensor, or (ii) the Larger
12+
** Works (as defined below), to deal in both
13+
**
14+
** (a) the Software, and
15+
** (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
16+
** one is included with the Software (each a "Larger Work" to which the Software
17+
** is contributed by such licensors),
18+
**
19+
** without restriction, including without limitation the rights to copy, create
20+
** derivative works of, display, perform, and distribute the Software and make,
21+
** use, sell, offer for sale, import, export, have made, and have sold the
22+
** Software and the Larger Work(s), and to sublicense the foregoing rights on
23+
** either these or other terms.
24+
**
25+
** This license is subject to the following condition:
26+
** The above copyright notice and either this complete permission notice or at
27+
** a minimum a reference to the UPL must be included in all copies or
28+
** substantial portions of the Software.
29+
**
30+
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31+
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33+
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35+
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36+
** SOFTWARE.
37+
*/
38+
39+
package v1alpha1
40+
41+
import (
42+
"strings"
43+
44+
apierrors "k8s.io/apimachinery/pkg/api/errors"
45+
"k8s.io/apimachinery/pkg/runtime"
46+
"k8s.io/apimachinery/pkg/runtime/schema"
47+
"k8s.io/apimachinery/pkg/util/validation/field"
48+
ctrl "sigs.k8s.io/controller-runtime"
49+
logf "sigs.k8s.io/controller-runtime/pkg/log"
50+
"sigs.k8s.io/controller-runtime/pkg/webhook"
51+
)
52+
53+
// log is for logging in this package.
54+
var dataguardbrokerlog = logf.Log.WithName("dataguardbroker-resource")
55+
56+
func (r *DataguardBroker) SetupWebhookWithManager(mgr ctrl.Manager) error {
57+
return ctrl.NewWebhookManagedBy(mgr).
58+
For(r).
59+
Complete()
60+
}
61+
62+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
63+
64+
//+kubebuilder:webhook:path=/mutate-database-oracle-com-v1alpha1-dataguardbroker,mutating=true,failurePolicy=fail,sideEffects=None,groups=database.oracle.com,resources=dataguardbrokers,verbs=create;update,versions=v1alpha1,name=mdataguardbroker.kb.io,admissionReviewVersions={v1,v1beta1}
65+
66+
var _ webhook.Defaulter = &DataguardBroker{}
67+
68+
// Default implements webhook.Defaulter so a webhook will be registered for the type
69+
func (r *DataguardBroker) Default() {
70+
dataguardbrokerlog.Info("default", "name", r.Name)
71+
72+
// TODO(user): fill in your defaulting logic.
73+
}
74+
75+
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
76+
//+kubebuilder:webhook:verbs=create;update,path=/validate-database-oracle-com-v1alpha1-dataguardbroker,mutating=false,failurePolicy=fail,sideEffects=None,groups=database.oracle.com,resources=dataguardbrokers,versions=v1alpha1,name=vdataguardbroker.kb.io,admissionReviewVersions={v1,v1beta1}
77+
78+
var _ webhook.Validator = &DataguardBroker{}
79+
80+
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
81+
func (r *DataguardBroker) ValidateCreate() error {
82+
dataguardbrokerlog.Info("validate create", "name", r.Name)
83+
84+
// TODO(user): fill in your validation logic upon object creation.
85+
return nil
86+
}
87+
88+
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
89+
func (r *DataguardBroker) ValidateUpdate(old runtime.Object) error {
90+
dataguardbrokerlog.Info("validate update", "name", r.Name)
91+
92+
dataguardbrokerlog.Info("validate update", "name", r.Name)
93+
var allErrs field.ErrorList
94+
95+
// check creation validations first
96+
err := r.ValidateCreate()
97+
if err != nil {
98+
return err
99+
}
100+
101+
// Validate Deletion
102+
if r.GetDeletionTimestamp() != nil {
103+
err := r.ValidateDelete()
104+
if err != nil {
105+
return err
106+
}
107+
}
108+
109+
// Now check for updation errors
110+
oldObj, ok := old.(*DataguardBroker)
111+
if !ok {
112+
return nil
113+
}
114+
115+
if oldObj.Status.ProtectionMode != "" && !strings.EqualFold(r.Spec.ProtectionMode, oldObj.Status.ProtectionMode) {
116+
allErrs = append(allErrs,
117+
field.Forbidden(field.NewPath("spec").Child("protectionMode"), "cannot be changed"))
118+
}
119+
if oldObj.Status.PrimaryDatabaseRef != "" && !strings.EqualFold(oldObj.Status.PrimaryDatabaseRef, r.Spec.PrimaryDatabaseRef) {
120+
allErrs = append(allErrs,
121+
field.Forbidden(field.NewPath("spec").Child("primaryDatabaseRef"), "cannot be changed"))
122+
}
123+
124+
if len(allErrs) == 0 {
125+
return nil
126+
}
127+
return apierrors.NewInvalid(
128+
schema.GroupKind{Group: "database.oracle.com", Kind: "DataguardBroker"},
129+
r.Name, allErrs)
130+
131+
}
132+
133+
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
134+
func (r *DataguardBroker) ValidateDelete() error {
135+
dataguardbrokerlog.Info("validate delete", "name", r.Name)
136+
137+
// TODO(user): fill in your validation logic upon object deletion.
138+
return nil
139+
}

apis/database/v1alpha1/oraclerestdataservice_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** Copyright (c) 2022 Oracle and/or its affiliates.
2+
** Copyright (c) 2023 Oracle and/or its affiliates.
33
**
44
** The Universal Permissive License (UPL), Version 1.0
55
**

apis/database/v1alpha1/oraclerestdataservice_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** Copyright (c) 2022 Oracle and/or its affiliates.
2+
** Copyright (c) 2023 Oracle and/or its affiliates.
33
**
44
** The Universal Permissive License (UPL), Version 1.0
55
**

apis/database/v1alpha1/singleinstancedatabase_types.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** Copyright (c) 2022 Oracle and/or its affiliates.
2+
** Copyright (c) 2023 Oracle and/or its affiliates.
33
**
44
** The Universal Permissive License (UPL), Version 1.0
55
**
@@ -69,8 +69,11 @@ type SingleInstanceDatabaseSpec struct {
6969
ForceLogging bool `json:"forceLog,omitempty"`
7070
EnableTCPS bool `json:"enableTCPS,omitempty"`
7171
TcpsCertRenewInterval string `json:"tcpsCertRenewInterval,omitempty"`
72+
DgBrokerConfigured bool `json:"dgBrokerConfigured,omitempty"`
7273

7374
CloneFrom string `json:"cloneFrom,omitempty"`
75+
PrimaryDatabaseRef string `json:"primaryDatabaseRef,omitempty"`
76+
CreateAsStandby bool `json:"createAsStandby,omitempty"`
7477
ReadinessCheckPeriod int `json:"readinessCheckPeriod,omitempty"`
7578
ServiceAccountName string `json:"serviceAccountName,omitempty"`
7679

@@ -157,6 +160,8 @@ type SingleInstanceDatabaseStatus struct {
157160
CertCreationTimestamp string `json:"certCreationTimestamp,omitempty"`
158161
CertRenewInterval string `json:"certRenewInterval,omitempty"`
159162
ClientWalletLoc string `json:"clientWalletLoc,omitempty"`
163+
PrimaryDatabase string `json:"primaryDatabase,omitempty"`
164+
DgBrokerConfigured bool `json:"dgBrokerConfigured,omitempty"`
160165

161166
// +patchMergeKey=type
162167
// +patchStrategy=merge
@@ -172,12 +177,13 @@ type SingleInstanceDatabaseStatus struct {
172177
//+kubebuilder:subresource:status
173178
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas
174179
// +kubebuilder:printcolumn:JSONPath=".status.edition",name="Edition",type="string"
180+
// +kubebuilder:printcolumn:JSONPath=".status.sid",name="Sid",type="string,priority=1"
175181
// +kubebuilder:printcolumn:JSONPath=".status.status",name="Status",type="string"
176-
// +kubebuilder:printcolumn:JSONPath=".status.role",name="Role",type="string",priority=1
182+
// +kubebuilder:printcolumn:JSONPath=".status.role",name="Role",type="string"
177183
// +kubebuilder:printcolumn:JSONPath=".status.releaseUpdate",name="Version",type="string"
178184
// +kubebuilder:printcolumn:JSONPath=".status.connectString",name="Connect Str",type="string"
179-
// +kubebuilder:printcolumn:JSONPath=".status.tcpsConnectString",name="TCPS Connect Str",type="string"
180185
// +kubebuilder:printcolumn:JSONPath=".status.pdbConnectString",name="Pdb Connect Str",type="string",priority=1
186+
// +kubebuilder:printcolumn:JSONPath=".status.tcpsConnectString",name="TCPS Connect Str",type="string"
181187
// +kubebuilder:printcolumn:JSONPath=".status.tcpsPdbConnectString",name="TCPS Pdb Connect Str",type="string", priority=1
182188
// +kubebuilder:printcolumn:JSONPath=".status.oemExpressUrl",name="Oem Express Url",type="string"
183189

apis/database/v1alpha1/singleinstancedatabase_webhook.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** Copyright (c) 2022 Oracle and/or its affiliates.
2+
** Copyright (c) 2023 Oracle and/or its affiliates.
33
**
44
** The Universal Permissive License (UPL), Version 1.0
55
**
@@ -159,6 +159,11 @@ func (r *SingleInstanceDatabase) ValidateCreate() error {
159159
field.Invalid(field.NewPath("spec").Child("cloneFrom"), r.Spec.CloneFrom,
160160
"Cloning not supported for Express edition"))
161161
}
162+
if r.Spec.CreateAsStandby {
163+
allErrs = append(allErrs,
164+
field.Invalid(field.NewPath("spec").Child("createAsStandby"), r.Spec.CreateAsStandby,
165+
"Physical Standby Database creation is not supported for Express edition"))
166+
}
162167
if strings.ToUpper(r.Spec.Sid) != "XE" {
163168
allErrs = append(allErrs,
164169
field.Invalid(field.NewPath("spec").Child("sid"), r.Spec.Sid,

0 commit comments

Comments
 (0)