Skip to content

Commit 999d92a

Browse files
Abhishek Kumaryunus-qureshi
authored andcommitted
Added some fixes
1 parent 0bb532f commit 999d92a

11 files changed

+67
-50
lines changed

apis/database/v1alpha1/dataguardbroker_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ type DataguardBrokerSpec struct {
6565
// DataguardBrokerPassword defines the secret containing Password mapped to secretKey
6666
type DataguardBrokerPassword struct {
6767
SecretName string `json:"secretName,omitempty"`
68-
SecretKey string `json:"secretKey"`
69-
KeepSecret bool `json:"keepSecret"`
68+
// +kubebuilder:default:="oracle_pwd"
69+
SecretKey string `json:"secretKey,omitempty"`
70+
KeepSecret *bool `json:"keepSecret,omitempty"`
7071
}
7172

7273
type DataguardBrokerFastStartFailOver struct {

apis/database/v1alpha1/dataguardbroker_webhook.go

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

72-
// TODO(user): fill in your defaulting logic.
72+
if r.Spec.AdminPassword.KeepSecret == nil {
73+
keepSecret := true
74+
r.Spec.AdminPassword.KeepSecret = &keepSecret
75+
}
7376
}
7477

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

apis/database/v1alpha1/singleinstancedatabase_webhook.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ func (r *SingleInstanceDatabase) Default() {
105105
r.Spec.Replicas = 1
106106
}
107107
}
108+
109+
if r.Spec.PrimaryDatabaseRef != "" && r.Spec.CreateAsStandby {
110+
if r.Spec.Replicas == 0 {
111+
r.Spec.Replicas = 1
112+
}
113+
}
108114
}
109115

110116
// 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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,11 @@ func (in *DataguardBrokerList) DeepCopyObject() runtime.Object {
957957
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
958958
func (in *DataguardBrokerPassword) DeepCopyInto(out *DataguardBrokerPassword) {
959959
*out = *in
960+
if in.KeepSecret != nil {
961+
in, out := &in.KeepSecret, &out.KeepSecret
962+
*out = new(bool)
963+
**out = **in
964+
}
960965
}
961966

962967
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DataguardBrokerPassword.
@@ -985,7 +990,7 @@ func (in *DataguardBrokerSpec) DeepCopyInto(out *DataguardBrokerSpec) {
985990
}
986991
}
987992
in.FastStartFailOver.DeepCopyInto(&out.FastStartFailOver)
988-
out.AdminPassword = in.AdminPassword
993+
in.AdminPassword.DeepCopyInto(&out.AdminPassword)
989994
}
990995

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

commons/database/utils.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -540,35 +540,32 @@ func GetNodeIp(r client.Reader, ctx context.Context, req ctrl.Request) string {
540540

541541
log := ctrllog.FromContext(ctx).WithValues("GetNodeIp", req.NamespacedName)
542542

543-
readyPod, _, available, _, err := FindPods(r, "", "", req.Name, req.Namespace, ctx, req)
543+
//new workflow
544+
nl := &corev1.NodeList{}
545+
err := r.List(ctx, nl)
546+
nodeip := ""
544547
if err != nil {
545548
log.Error(err, err.Error())
546-
return ""
547-
}
548-
if readyPod.Name != "" {
549-
available = append(available, readyPod)
549+
return nodeip
550550
}
551-
nodeip := ""
552-
for _, pod := range available {
553-
if nodeip == "" {
554-
nodeip = pod.Status.HostIP
555-
}
556-
if pod.Status.HostIP < nodeip {
557-
nodeip = pod.Status.HostIP
551+
552+
for _, address := range nl.Items[0].Status.Addresses {
553+
if address.Type == "ExternalIP" {
554+
nodeip = address.Address
555+
break
558556
}
559557
}
560-
561-
node := &corev1.Node{}
562-
err = r.Get(ctx, types.NamespacedName{Name: nodeip, Namespace: req.Namespace}, node)
563-
564-
if err == nil {
565-
for _, address := range node.Status.Addresses {
566-
if address.Type == "ExternalIP" {
558+
if nodeip == "" {
559+
for _, address := range nl.Items[0].Status.Addresses {
560+
if address.Type == "InternalIP" {
567561
nodeip = address.Address
562+
break
568563
}
569564
}
570565
}
571566

567+
log.Info("Node IP obtained ! ", "nodeip: ", nodeip)
568+
572569
return nodeip
573570
}
574571

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,10 @@ spec:
6666
keepSecret:
6767
type: boolean
6868
secretKey:
69+
default: oracle_pwd
6970
type: string
7071
secretName:
7172
type: string
72-
required:
73-
- keepSecret
74-
- secretKey
7573
type: object
7674
fastStartFailOver:
7775
properties:

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,14 @@ spec:
342342
description: "Condition contains details for one aspect of the current
343343
state of this API Resource. --- This struct is intended for direct
344344
use as an array at the field path .status.conditions. For example,
345-
type FooStatus struct{ // Represents the observations of a
346-
foo's current state. // Known .status.conditions.type are:
347-
\"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type
348-
\ // +patchStrategy=merge // +listType=map // +listMapKey=type
349-
\ Conditions []metav1.Condition `json:\"conditions,omitempty\"
350-
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
351-
\n // other fields }"
345+
\n \ttype FooStatus struct{ \t // Represents the observations
346+
of a foo's current state. \t // Known .status.conditions.type
347+
are: \"Available\", \"Progressing\", and \"Degraded\" \t //
348+
+patchMergeKey=type \t // +patchStrategy=merge \t // +listType=map
349+
\t // +listMapKey=type \t Conditions []metav1.Condition
350+
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
351+
protobuf:\"bytes,1,rep,name=conditions\"` \n \t // other fields
352+
\t}"
352353
properties:
353354
lastTransitionTime:
354355
description: lastTransitionTime is the last time the condition

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ spec:
2020
- jsonPath: .status.edition
2121
name: Edition
2222
type: string
23+
- jsonPath: .status.sid
24+
name: Sid
25+
priority: 1
26+
type: string
2327
- jsonPath: .status.status
2428
name: Status
2529
type: string
@@ -32,13 +36,13 @@ spec:
3236
- jsonPath: .status.connectString
3337
name: Connect Str
3438
type: string
35-
- jsonPath: .status.tcpsConnectString
36-
name: TCPS Connect Str
37-
type: string
3839
- jsonPath: .status.pdbConnectString
3940
name: Pdb Connect Str
4041
priority: 1
4142
type: string
43+
- jsonPath: .status.tcpsConnectString
44+
name: TCPS Connect Str
45+
type: string
4246
- jsonPath: .status.tcpsPdbConnectString
4347
name: TCPS Pdb Connect Str
4448
priority: 1

controllers/database/dataguardbroker_controller.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ func (r *DataguardBrokerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
103103

104104
// Manage SingleInstanceDatabase Deletion
105105
result, err := r.manageDataguardBrokerDeletion(req, ctx, dataguardBroker)
106-
if result.Requeue {
106+
if result.Requeue || err != nil {
107107
r.Log.Info("Reconcile queued")
108-
return result, nil
108+
return result, err
109109
}
110110

111111
// Fetch Primary Database Reference
@@ -151,11 +151,6 @@ func (r *DataguardBrokerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
151151
return result, nil
152152
}
153153

154-
// If LoadBalancer = true , ensure Connect String is updated
155-
if dataguardBroker.Status.ExternalConnectString == dbcommons.ValueUnavailable {
156-
return requeueY, nil
157-
}
158-
159154
// Set a particular database as primary
160155
result = r.SetAsPrimaryDatabase(singleInstanceDatabase.Spec.Sid, dataguardBroker.Spec.SetAsPrimaryDatabase, dataguardBroker,
161156
singleInstanceDatabase, adminPassword, ctx, req)
@@ -164,6 +159,11 @@ func (r *DataguardBrokerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
164159
return result, nil
165160
}
166161

162+
// If LoadBalancer = true , ensure Connect String is updated
163+
if dataguardBroker.Status.ExternalConnectString == dbcommons.ValueUnavailable {
164+
return requeueY, nil
165+
}
166+
167167
dataguardBroker.Status.Status = dbcommons.StatusReady
168168

169169
r.Log.Info("Reconcile completed")
@@ -325,7 +325,7 @@ func (r *DataguardBrokerReconciler) createSVC(ctx context.Context, req ctrl.Requ
325325
}
326326

327327
// update service status
328-
328+
log.Info("Updating the service status...")
329329
m.Status.ClusterConnectString = svc.Name + "." + svc.Namespace + ":" + fmt.Sprint(svc.Spec.Ports[0].Port) + "/DATAGUARD"
330330
if m.Spec.LoadBalancer {
331331
if len(svc.Status.LoadBalancer.Ingress) > 0 {
@@ -341,6 +341,7 @@ func (r *DataguardBrokerReconciler) createSVC(ctx context.Context, req ctrl.Requ
341341
m.Status.ExternalConnectString = nodeip + ":" + fmt.Sprint(svc.Spec.Ports[0].NodePort) + "/DATAGUARD"
342342
}
343343
}
344+
r.Status().Update(ctx, m)
344345

345346
return requeueN
346347
}

controllers/database/singleinstancedatabase_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ func (r *SingleInstanceDatabaseReconciler) validate(m *dbapi.SingleInstanceDatab
380380
if m.Status.Sid != "" && !strings.EqualFold(m.Spec.Sid, m.Status.Sid) {
381381
eventMsgs = append(eventMsgs, "sid cannot be updated")
382382
}
383-
if m.Spec.CloneFrom == "" && m.Status.Edition != "" && !strings.EqualFold(m.Status.Edition, m.Spec.Edition) {
383+
if m.Spec.CloneFrom == "" && m.Spec.Edition != "" && m.Status.Edition != "" && !strings.EqualFold(m.Status.Edition, m.Spec.Edition) {
384384
eventMsgs = append(eventMsgs, "edition cannot be updated")
385385
}
386386
if m.Status.Charset != "" && !strings.EqualFold(m.Status.Charset, m.Spec.Charset) {
@@ -2012,7 +2012,7 @@ func (r *SingleInstanceDatabaseReconciler) deleteWallet(m *dbapi.SingleInstanceD
20122012

20132013
// Deleting the secret and then deleting the wallet
20142014
// If the secret is not found it means that the secret and wallet both are deleted, hence no need to requeue
2015-
if !*m.Spec.AdminPassword.KeepSecret {
2015+
if m.Spec.AdminPassword.KeepSecret != nil && !*m.Spec.AdminPassword.KeepSecret {
20162016
r.Log.Info("Querying the database secret ...")
20172017
secret := &corev1.Secret{}
20182018
err := r.Get(ctx, types.NamespacedName{Name: m.Spec.AdminPassword.SecretName, Namespace: m.Namespace}, secret)

0 commit comments

Comments
 (0)