Skip to content

Commit 72ad2b2

Browse files
Abhishek Kumaryunus-qureshi
authored andcommitted
Added some DG changes
1 parent d8e03a1 commit 72ad2b2

File tree

9 files changed

+217
-268
lines changed

9 files changed

+217
-268
lines changed

apis/database/v1alpha1/dataguardbroker_types.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,6 @@ type DataguardBrokerSpec struct {
5959
ProtectionMode string `json:"protectionMode"`
6060
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
6161
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-
// +kubebuilder:default:="oracle_pwd"
69-
SecretKey string `json:"secretKey,omitempty"`
70-
KeepSecret *bool `json:"keepSecret,omitempty"`
7162
}
7263

7364
type DataguardBrokerFastStartFailOver struct {
@@ -102,7 +93,7 @@ type DataguardBrokerStatus struct {
10293
// +kubebuilder:printcolumn:JSONPath=".spec.protectionMode",name="Protection Mode",type="string"
10394
// +kubebuilder:printcolumn:JSONPath=".status.clusterConnectString",name="Cluster Connect Str",type="string",priority=1
10495
// +kubebuilder:printcolumn:JSONPath=".status.externalConnectString",name="Connect Str",type="string"
105-
// +kubebuilder:printcolumn:JSONPath=".spec.primaryDatabaseRef",name="Primary Database",type="string"
96+
// +kubebuilder:printcolumn:JSONPath=".spec.primaryDatabaseRef",name="Primary Database",type="string", priority=1
10697
// +kubebuilder:printcolumn:JSONPath=".status.status",name="Status",type="string"
10798

10899
// DataguardBroker is the Schema for the dataguardbrokers API

apis/database/v1alpha1/dataguardbroker_webhook.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ var _ webhook.Defaulter = &DataguardBroker{}
6969
func (r *DataguardBroker) Default() {
7070
dataguardbrokerlog.Info("default", "name", r.Name)
7171

72-
if r.Spec.AdminPassword.KeepSecret == nil {
73-
keepSecret := true
74-
r.Spec.AdminPassword.KeepSecret = &keepSecret
75-
}
7672
}
7773

7874
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.

apis/database/v1alpha1/zz_generated.deepcopy.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -954,26 +954,6 @@ func (in *DataguardBrokerList) DeepCopyObject() runtime.Object {
954954
return nil
955955
}
956956

957-
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
958-
func (in *DataguardBrokerPassword) DeepCopyInto(out *DataguardBrokerPassword) {
959-
*out = *in
960-
if in.KeepSecret != nil {
961-
in, out := &in.KeepSecret, &out.KeepSecret
962-
*out = new(bool)
963-
**out = **in
964-
}
965-
}
966-
967-
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DataguardBrokerPassword.
968-
func (in *DataguardBrokerPassword) DeepCopy() *DataguardBrokerPassword {
969-
if in == nil {
970-
return nil
971-
}
972-
out := new(DataguardBrokerPassword)
973-
in.DeepCopyInto(out)
974-
return out
975-
}
976-
977957
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
978958
func (in *DataguardBrokerSpec) DeepCopyInto(out *DataguardBrokerSpec) {
979959
*out = *in
@@ -990,7 +970,6 @@ func (in *DataguardBrokerSpec) DeepCopyInto(out *DataguardBrokerSpec) {
990970
}
991971
}
992972
in.FastStartFailOver.DeepCopyInto(&out.FastStartFailOver)
993-
in.AdminPassword.DeepCopyInto(&out.AdminPassword)
994973
}
995974

996975
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DataguardBrokerSpec.

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ spec:
3535
type: string
3636
- jsonPath: .spec.primaryDatabaseRef
3737
name: Primary Database
38+
priority: 1
3839
type: string
3940
- jsonPath: .status.status
4041
name: Status
@@ -59,18 +60,6 @@ spec:
5960
spec:
6061
description: DataguardBrokerSpec defines the desired state of DataguardBroker
6162
properties:
62-
adminPassword:
63-
description: DataguardBrokerPassword defines the secret containing
64-
Password mapped to secretKey
65-
properties:
66-
keepSecret:
67-
type: boolean
68-
secretKey:
69-
default: oracle_pwd
70-
type: string
71-
secretName:
72-
type: string
73-
type: object
7463
fastStartFailOver:
7564
properties:
7665
enable:
@@ -106,7 +95,6 @@ spec:
10695
type: string
10796
type: array
10897
required:
109-
- adminPassword
11098
- primaryDatabaseRef
11199
- protectionMode
112100
- standbyDatabaseRefs

config/samples/database_v1alpha1_dataguardbroker.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

config/samples/sidb/dataguardbroker.yaml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,6 @@ spec:
1818
# - standbyDatabase-sample1
1919
# - standbyDatabase-sample2
2020

21-
## Secret containing databaseRef password mapped to secretKey.
22-
## This secret will be deleted after Dataguard setup unless keepSecret set to true.
23-
adminPassword:
24-
secretName:
25-
secretKey:
26-
keepSecret: false
27-
28-
## Deploy only on nodes having required labels . Format label_name : label_value .
29-
## Leave empty if there is no such requirement .
30-
## Uncomment to use
31-
# nodeSelector:
32-
# failure-domain.beta.kubernetes.io/zone: bVCG:PHX-AD-1
33-
# pool: sidb
34-
3521
## Type of service . Applicable on cloud enviroments only
3622
## if loadBalService : false , service type = "NodePort" . else "LoadBalancer"
3723
loadBalancer: false

controllers/database/dataguardbroker_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,20 +199,20 @@ func (r *DataguardBrokerReconciler) validateSidbReadiness(m *dbapi.DataguardBrok
199199

200200
// Validate databaseRef Admin Password
201201
adminPasswordSecret := &corev1.Secret{}
202-
err = r.Get(ctx, types.NamespacedName{Name: m.Spec.AdminPassword.SecretName, Namespace: m.Namespace}, adminPasswordSecret)
202+
err = r.Get(ctx, types.NamespacedName{Name: n.Spec.AdminPassword.SecretName, Namespace: n.Namespace}, adminPasswordSecret)
203203
if err != nil {
204204
if apierrors.IsNotFound(err) {
205205
//m.Status.Status = dbcommons.StatusError
206206
eventReason := "Waiting"
207-
eventMsg := "waiting for secret : " + m.Spec.AdminPassword.SecretName + " to get created"
207+
eventMsg := "waiting for secret : " + n.Spec.AdminPassword.SecretName + " to get created"
208208
r.Recorder.Eventf(m, corev1.EventTypeNormal, eventReason, eventMsg)
209-
r.Log.Info("Secret " + m.Spec.AdminPassword.SecretName + " Not Found")
209+
r.Log.Info("Secret " + n.Spec.AdminPassword.SecretName + " Not Found")
210210
return requeueY, sidbReadyPod, adminPassword
211211
}
212212
log.Error(err, err.Error())
213213
return requeueY, sidbReadyPod, adminPassword
214214
}
215-
adminPassword = string(adminPasswordSecret.Data[m.Spec.AdminPassword.SecretKey])
215+
adminPassword = string(adminPasswordSecret.Data[n.Spec.AdminPassword.SecretKey])
216216

217217
out, err := dbcommons.ExecCommand(r, r.Config, sidbReadyPod.Name, sidbReadyPod.Namespace, "", ctx, req, true, "bash", "-c",
218218
fmt.Sprintf("echo -e \"%s\" | %s", fmt.Sprintf(dbcommons.ValidateAdminPassword, adminPassword), dbcommons.GetSqlClient(n.Spec.Edition)))
@@ -225,7 +225,7 @@ func (r *DataguardBrokerReconciler) validateSidbReadiness(m *dbapi.DataguardBrok
225225
} else if strings.Contains(out, "ORA-01017") {
226226
//m.Status.Status = dbcommons.StatusError
227227
eventReason := "Logon denied"
228-
eventMsg := "invalid databaseRef admin password. secret: " + m.Spec.AdminPassword.SecretName
228+
eventMsg := "invalid databaseRef admin password. secret: " + n.Spec.AdminPassword.SecretName
229229
r.Recorder.Eventf(m, corev1.EventTypeWarning, eventReason, eventMsg)
230230
return requeueY, sidbReadyPod, adminPassword
231231
} else {

controllers/database/singleinstancedatabase_controller.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,34 @@ func (r *SingleInstanceDatabaseReconciler) instantiatePodSpec(m *dbapi.SingleIns
994994
},
995995
}
996996

997+
// Adding pod anti-affinity for standby cases
998+
if m.Spec.PrimaryDatabaseRef != "" && m.Spec.CreateAsStandby {
999+
weightedPodAffinityTerm := corev1.WeightedPodAffinityTerm{
1000+
Weight: 100,
1001+
PodAffinityTerm: corev1.PodAffinityTerm{
1002+
LabelSelector: &metav1.LabelSelector{
1003+
MatchExpressions: []metav1.LabelSelectorRequirement{{
1004+
Key: "app",
1005+
Operator: metav1.LabelSelectorOpIn,
1006+
Values: []string{rp.Name},
1007+
}},
1008+
},
1009+
TopologyKey: "kubernetes.io/hostname",
1010+
},
1011+
}
1012+
if m.Spec.Persistence.AccessMode == "ReadWriteOnce" {
1013+
pod.Spec.Affinity.PodAntiAffinity = &corev1.PodAntiAffinity{
1014+
PreferredDuringSchedulingIgnoredDuringExecution: []corev1.WeightedPodAffinityTerm{
1015+
weightedPodAffinityTerm,
1016+
},
1017+
}
1018+
} else {
1019+
pod.Spec.Affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution =
1020+
append(pod.Spec.Affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution, weightedPodAffinityTerm)
1021+
}
1022+
1023+
}
1024+
9971025
// Set SingleInstanceDatabase instance as the owner and controller
9981026
ctrl.SetControllerReference(m, pod, r.Scheme)
9991027
return pod

0 commit comments

Comments
 (0)