Skip to content

Commit

Permalink
Merge pull request #1 from Rory-Z/feat/rebalance-controller
Browse files Browse the repository at this point in the history
style(v2alpha2): format rebalance controller
  • Loading branch information
jacky-xbb authored Jul 21, 2023
2 parents f6b4efa + e7d0858 commit ca65e3a
Show file tree
Hide file tree
Showing 6 changed files with 303 additions and 363 deletions.
26 changes: 19 additions & 7 deletions controllers/apps/v1beta4/emqx_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,29 @@ func (r *EmqxReconciler) processResult(subResult subResult, instance appsv1beta4
return subResult.result, subResult.err
}

func NewRequesterByPod(client client.Client, instance appsv1beta4.Emqx, pod *corev1.Pod) (innerReq.RequesterInterface, error) {
username, password, err := getBootstrapUser(context.Background(), client, instance)
func NewRequesterByPod(k8sClient client.Client, instance appsv1beta4.Emqx) (innerReq.RequesterInterface, error) {
username, password, err := getBootstrapUser(context.Background(), k8sClient, instance)
if err != nil {
return nil, err
}

Check warning on line 140 in controllers/apps/v1beta4/emqx_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/apps/v1beta4/emqx_controller.go#L136-L140

Added lines #L136 - L140 were not covered by tests

return &innerReq.Requester{
Host: fmt.Sprintf("%s:8081", pod.Status.PodIP),
Username: username,
Password: password,
}, nil
podList := &corev1.PodList{}
_ = k8sClient.List(context.Background(), podList,
client.InNamespace(instance.GetNamespace()),
client.MatchingLabels(instance.GetSpec().GetTemplate().Labels),
)
for _, pod := range podList.Items {
for _, c := range pod.Status.Conditions {
if c.Type == corev1.PodReady && c.Status == corev1.ConditionTrue {
return &innerReq.Requester{
Host: fmt.Sprintf("%s:8081", pod.Status.PodIP),
Username: username,
Password: password,
}, nil
}

Check warning on line 155 in controllers/apps/v1beta4/emqx_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/apps/v1beta4/emqx_controller.go#L142-L155

Added lines #L142 - L155 were not covered by tests
}
}
return nil, emperror.New("failed to get ready pod")

Check warning on line 158 in controllers/apps/v1beta4/emqx_controller.go

View check run for this annotation

Codecov / codecov/patch

controllers/apps/v1beta4/emqx_controller.go#L158

Added line #L158 was not covered by tests
}

func newRequesterBySvc(client client.Client, instance appsv1beta4.Emqx) (innerReq.RequesterInterface, error) {
Expand Down
Loading

0 comments on commit ca65e3a

Please sign in to comment.