-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix emqx cluster can not ready (#1038)
fix #1036 Signed-off-by: Rory Z <[email protected]>
- Loading branch information
Showing
6 changed files
with
67 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package v2beta1 | ||
|
||
import ( | ||
"context" | ||
|
||
emperror "emperror.dev/errors" | ||
appsv2beta1 "github.com/emqx/emqx-operator/apis/apps/v2beta1" | ||
innerReq "github.com/emqx/emqx-operator/internal/requester" | ||
"github.com/go-logr/logr" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
type addHeadlessSvc struct { | ||
*EMQXReconciler | ||
} | ||
|
||
func (a *addHeadlessSvc) reconcile(ctx context.Context, logger logr.Logger, instance *appsv2beta1.EMQX, _ innerReq.RequesterInterface) subResult { | ||
if err := a.CreateOrUpdateList(ctx, a.Scheme, logger, instance, []client.Object{generateHeadlessService(instance)}); err != nil { | ||
return subResult{err: emperror.Wrap(err, "failed to create or update services")} | ||
} | ||
return subResult{} | ||
} | ||
|
||
func generateHeadlessService(instance *appsv2beta1.EMQX) *corev1.Service { | ||
headlessSvc := &corev1.Service{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "v1", | ||
Kind: "Service", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: instance.Namespace, | ||
Name: instance.HeadlessServiceNamespacedName().Name, | ||
Labels: appsv2beta1.CloneAndMergeMap(appsv2beta1.DefaultLabels(instance), instance.Labels), | ||
}, | ||
Spec: corev1.ServiceSpec{ | ||
Type: corev1.ServiceTypeClusterIP, | ||
ClusterIP: corev1.ClusterIPNone, | ||
SessionAffinity: corev1.ServiceAffinityNone, | ||
PublishNotReadyAddresses: true, | ||
Selector: appsv2beta1.DefaultCoreLabels(instance), | ||
Ports: []corev1.ServicePort{ | ||
{ | ||
Name: "erlang-dist", | ||
Port: 4370, | ||
Protocol: corev1.ProtocolTCP, | ||
TargetPort: intstr.FromInt(4370), | ||
}, | ||
{ | ||
Name: "gen-rpc", | ||
Port: 5369, | ||
Protocol: corev1.ProtocolTCP, | ||
TargetPort: intstr.FromInt(5369), | ||
}, | ||
}, | ||
}, | ||
} | ||
return headlessSvc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters