Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(add_svc): fix service port error #1033

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
timeout-minutes: 5
run: kubectl wait --for=condition=Ready pods -l "control-plane=controller-manager" -n emqx-operator-system
- name: Deployment emqx
timeout-minutes: 5
timeout-minutes: 10
uses: ./.github/actions/deploy-emqx
with:
kind: ${{ matrix.emqx[0] }}
Expand Down
2 changes: 1 addition & 1 deletion config/samples/emqx/v2alpha1/emqx-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: EMQX
metadata:
name: emqx
spec:
image: "emqx:5.1"
image: "emqx:5"
imagePullPolicy: IfNotPresent
# imagePullSecrets:
# - name: fake-secrets
Expand Down
2 changes: 1 addition & 1 deletion config/samples/emqx/v2alpha1/emqx-slim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: EMQX
metadata:
name: emqx
spec:
image: emqx:5.1
image: emqx:5
33 changes: 28 additions & 5 deletions controllers/apps/v2beta1/add_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v2beta1

import (
"context"
"net/http"

emperror "emperror.dev/errors"
appsv2beta1 "github.com/emqx/emqx-operator/apis/apps/v2beta1"
Expand All @@ -17,13 +18,20 @@ type addSvc struct {
*EMQXReconciler
}

func (a *addSvc) reconcile(ctx context.Context, logger logr.Logger, instance *appsv2beta1.EMQX, _ innerReq.RequesterInterface) subResult {
configMap := &corev1.ConfigMap{}
if err := a.Client.Get(ctx, instance.ConfigsNamespacedName(), configMap); err != nil {
return subResult{err: emperror.Wrap(err, "failed to get configmap")}
func (a *addSvc) reconcile(ctx context.Context, logger logr.Logger, instance *appsv2beta1.EMQX, r innerReq.RequesterInterface) subResult {
if r == nil {
return subResult{}
}

if !instance.Status.IsConditionTrue(appsv2beta1.CoreNodesReady) {
return subResult{}
}

configStr, err := a.getEMQXConfigsByAPI(r)
if err != nil {
return subResult{err: emperror.Wrap(err, "failed to get emqx configs by api")}
}

configStr := configMap.Data["emqx.conf"]
resources := []client.Object{generateHeadlessService(instance)}
if dashboard := generateDashboardService(instance, configStr); dashboard != nil {
resources = append(resources, dashboard)
Expand All @@ -38,6 +46,21 @@ func (a *addSvc) reconcile(ctx context.Context, logger logr.Logger, instance *ap
return subResult{}
}

func (a *addSvc) getEMQXConfigsByAPI(r innerReq.RequesterInterface) (string, error) {
url := r.GetURL("api/v5/configs")

resp, body, err := r.Request("GET", url, nil, http.Header{
"Accept": []string{"text/plain"},
})
if err != nil {
return "", emperror.Wrapf(err, "failed to get API %s", url.String())
}
if resp.StatusCode != 200 {
return "", emperror.Errorf("failed to get API %s, status : %s, body: %s", url.String(), resp.Status, body)
}
return string(body), nil
}

func generateHeadlessService(instance *appsv2beta1.EMQX) *corev1.Service {
headlessSvc := &corev1.Service{
TypeMeta: metav1.TypeMeta{
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/v2beta1/emqx_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ func (r *EMQXReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
&addBootstrap{r},
&updateStatus{r},
&syncConfig{r},
&addSvc{r},
&addCore{r},
&addRepl{r},
&addPdb{r},
&addSvc{r},
&updatePodConditions{r},
&updateStatus{r},
&syncPods{r},
Expand Down