Skip to content

Commit

Permalink
issue-698, Save default user ref for zookeeper
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksiienkoMykyta committed Feb 15, 2024
1 parent 10a2b46 commit a20fe3b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,14 @@
"filename": "apis/clusters/v1beta1/zookeeper_types.go",
"hashed_secret": "5ffe533b830f08a0326348a9160afafc8ada44db",
"is_verified": false,
"line_number": 234
"line_number": 235
},
{
"type": "Secret Keyword",
"filename": "apis/clusters/v1beta1/zookeeper_types.go",
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
"is_verified": false,
"line_number": 239
"line_number": 240
}
],
"apis/clusters/v1beta1/zz_generated.deepcopy.go": [
Expand Down Expand Up @@ -1130,5 +1130,5 @@
}
]
},
"generated_at": "2024-02-12T11:41:39Z"
"generated_at": "2024-02-15T12:14:33Z"
}
3 changes: 2 additions & 1 deletion apis/clusters/v1beta1/zookeeper_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ type ZookeeperStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

ClusterStatus `json:",inline"`
ClusterStatus `json:",inline"`
DefaultUserSecretRef *Reference `json:"defaultRef,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
5 changes: 5 additions & 0 deletions apis/clusters/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions config/crd/bases/clusters.instaclustr.com_zookeepers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ spec:
status:
description: ZookeeperStatus defines the observed state of Zookeeper
properties:
DefaultRef:
description: ObjectReference is namespaced reference to an object
properties:
name:
type: string
namespace:
type: string
required:
- name
- namespace
type: object
cdcid:
type: string
currentClusterOperationStatus:
Expand Down
19 changes: 19 additions & 0 deletions controllers/clusters/zookeeper_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func (r *ZookeeperReconciler) createDefaultSecret(ctx context.Context, zk *v1bet
return err
}

patch := zk.NewPatch()
secret := zk.NewDefaultUserSecret(username, password)
err = r.Create(ctx, secret)
if err != nil {
Expand All @@ -224,6 +225,24 @@ func (r *ZookeeperReconciler) createDefaultSecret(ctx context.Context, zk *v1bet
return err
}

zk.Status.DefaultUserSecretRef = &v1beta1.Reference{
Name: secret.Name,
Namespace: secret.Namespace,
}

err = r.Status().Patch(ctx, zk, patch)
if err != nil {
l.Error(err, "Cannot patch Zookeeper resource",
"cluster name", zk.Spec.Name,
"status", zk.Status)

r.EventRecorder.Eventf(
zk, models.Warning, models.PatchFailed,
"Cluster resource patch is failed. Reason: %v", err)

return err
}

return nil
}

Expand Down

0 comments on commit a20fe3b

Please sign in to comment.