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 774cbf7
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd scripts && ./make_creds_secret.sh
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
kubectl apply -f ~/creds_secret.yaml
$(KUSTOMIZE) build config/default | kubectl apply -f -

.PHONY: helm-deploy
helm-deploy:
Expand Down
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
2 changes: 1 addition & 1 deletion config/samples/clusters_v1beta1_zookeeper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Zookeeper
metadata:
name: zookeeper-sample
spec:
name: "username-zookeeper"
name: "mykyta-zookeeper-test"
# description: "some description"
dataCentres:
- clientToServerEncryption: false
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 @@ -199,6 +199,7 @@ func (r *ZookeeperReconciler) handleCreateCluster(
}

func (r *ZookeeperReconciler) createDefaultSecret(ctx context.Context, zk *v1beta1.Zookeeper, l logr.Logger) error {
patch := zk.NewPatch()
username, password, err := r.API.GetDefaultCredentialsV1(zk.Status.ID)
if err != nil {
l.Error(err, "Cannot get default user creds for Zookeeper cluster from the Instaclustr API",
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 774cbf7

Please sign in to comment.