Skip to content

Commit

Permalink
feat: add rebalance controller of v2alpha2
Browse files Browse the repository at this point in the history
  • Loading branch information
jacky-xbb committed Jul 20, 2023
1 parent 832d7e6 commit f6b4efa
Show file tree
Hide file tree
Showing 12 changed files with 1,241 additions and 8 deletions.
14 changes: 14 additions & 0 deletions apis/apps/v1beta4/emqxbroker_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ func (s *EmqxBrokerStatus) GetConditions() []Condition {
return s.Conditions
}

func (s *EmqxBrokerStatus) GetCondition(t ConditionType) (int, *Condition) {
for i, c := range s.GetConditions() {
if t == c.Type {
return i, &c
}

Check warning on line 142 in apis/apps/v1beta4/emqxbroker_types.go

View check run for this annotation

Codecov / codecov/patch

apis/apps/v1beta4/emqxbroker_types.go#L138-L142

Added lines #L138 - L142 were not covered by tests
}
return -1, nil

Check warning on line 144 in apis/apps/v1beta4/emqxbroker_types.go

View check run for this annotation

Codecov / codecov/patch

apis/apps/v1beta4/emqxbroker_types.go#L144

Added line #L144 was not covered by tests
}

func (s *EmqxBrokerStatus) IsConditionTrue(t ConditionType) bool {
_, c := s.GetCondition(t)
return c != nil && c.Status == corev1.ConditionTrue

Check warning on line 149 in apis/apps/v1beta4/emqxbroker_types.go

View check run for this annotation

Codecov / codecov/patch

apis/apps/v1beta4/emqxbroker_types.go#L147-L149

Added lines #L147 - L149 were not covered by tests
}

func (s *EmqxBrokerStatus) AddCondition(condType ConditionType, status corev1.ConditionStatus, reason, message string) {
s.Conditions = addCondition(s.Conditions, Condition{
Type: condType,
Expand Down
14 changes: 14 additions & 0 deletions apis/apps/v1beta4/emqxenterprise_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@ func (s *EmqxEnterpriseStatus) GetConditions() []Condition {
return s.Conditions
}

func (s *EmqxEnterpriseStatus) GetCondition(t ConditionType) (int, *Condition) {
for i, c := range s.GetConditions() {
if t == c.Type {
return i, &c
}

Check warning on line 180 in apis/apps/v1beta4/emqxenterprise_types.go

View check run for this annotation

Codecov / codecov/patch

apis/apps/v1beta4/emqxenterprise_types.go#L176-L180

Added lines #L176 - L180 were not covered by tests
}
return -1, nil

Check warning on line 182 in apis/apps/v1beta4/emqxenterprise_types.go

View check run for this annotation

Codecov / codecov/patch

apis/apps/v1beta4/emqxenterprise_types.go#L182

Added line #L182 was not covered by tests
}

func (s *EmqxEnterpriseStatus) IsConditionTrue(t ConditionType) bool {
_, c := s.GetCondition(t)
return c != nil && c.Status == corev1.ConditionTrue

Check warning on line 187 in apis/apps/v1beta4/emqxenterprise_types.go

View check run for this annotation

Codecov / codecov/patch

apis/apps/v1beta4/emqxenterprise_types.go#L185-L187

Added lines #L185 - L187 were not covered by tests
}

func (s *EmqxEnterpriseStatus) AddCondition(condType ConditionType, status corev1.ConditionStatus, reason, message string) {
s.Conditions = addCondition(s.Conditions, Condition{
Type: condType,
Expand Down
2 changes: 2 additions & 0 deletions apis/apps/v1beta4/status_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type EmqxStatus interface {
GetCurrentStatefulSetVersion() string
SetCurrentStatefulSetVersion(version string)
GetConditions() []Condition
GetCondition(t ConditionType) (int, *Condition)
IsConditionTrue(t ConditionType) bool
AddCondition(condType ConditionType, status corev1.ConditionStatus, reason, message string)
}

Expand Down
13 changes: 13 additions & 0 deletions controllers/apps/v1beta4/emqx_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ 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)
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

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L142 - L146 were not covered by tests
}

func newRequesterBySvc(client client.Client, instance appsv1beta4.Emqx) (innerReq.RequesterInterface, error) {
username, password, err := getBootstrapUser(context.Background(), client, instance)
if err != nil {
Expand Down
Loading

0 comments on commit f6b4efa

Please sign in to comment.