Skip to content

Commit

Permalink
feat: create client service for zookeeper cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsxu committed Feb 14, 2022
1 parent bb871d5 commit 9165c3b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions controllers/zookeepercluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func (r *ZookeeperClusterReconciler) Reconcile(ctx context.Context, req ctrl.Req
return ctrl.Result{}, err
}

svcClient := r.createService(zk)
if err := r.Create(ctx, svcClient); err != nil {
r.Logger.Error(err, "creating client service")
return ctrl.Result{}, err
}

return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -148,6 +154,27 @@ func (r *ZookeeperClusterReconciler) createStatefulSet(zk *zookeeperv1alpha1.Zoo
}
}

func (r *ZookeeperClusterReconciler) createService(zk *zookeeperv1alpha1.ZookeeperCluster) *corev1.Service {
return &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: zk.Name,
Namespace: zk.Namespace,
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeNodePort,
Selector: map[string]string{
"app": zk.Name,
},
Ports: []corev1.ServicePort{
{
Name: "client",
Port: 2181,
},
},
},
}
}

// SetupWithManager sets up the controller with the Manager.
func (r *ZookeeperClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
Expand Down

0 comments on commit 9165c3b

Please sign in to comment.