Change status host if proxysql type LoadBalancer
@@ -15,6 +15,7 @@ import (
api "github.com/percona/percona-xtradb-cluster-operator/pkg/apis/pxc/v1"
"github.com/percona/percona-xtradb-cluster-operator/pkg/pxc/app"
"github.com/percona/percona-xtradb-cluster-operator/pkg/pxc/app/statefulset"
+ "github.com/pkg/errors"
)
const maxStatusesQuantity = 20
@@ -103,7 +104,23 @@ func (r *ReconcilePerconaXtraDBCluster) updateStatus(cr *api.PerconaXtraDBCluste
}
cr.Status.ProxySQL = proxyStatus
- cr.Status.Host = cr.Name + "-" + "proxysql"
+
+ cr.Status.Host = cr.Name + "-" + "proxysql." + cr.Namespace
+ if cr.Spec.ProxySQL != nil && cr.Spec.ProxySQL.ServiceType != nil && *cr.Spec.ProxySQL.ServiceType == corev1.ServiceTypeLoadBalancer {
+ svc := &corev1.Service{}
+ err := r.client.Get(context.TODO(),
+ types.NamespacedName{
+ Namespace: cr.Namespace,
+ Name: cr.Name + "-" + "proxysql",
+ }, svc)
+ if err != nil {
+ return errors.Wrap(err, "get proxysql service")
+ }
+ for _, i := range svc.Status.LoadBalancer.Ingress {
+ cr.Status.Host = i.IP
+ }
+ }
+
if cr.Status.ProxySQL.Message != "" {
cr.Status.Messages = append(cr.Status.Messages, "ProxySQL: "+cr.Status.ProxySQL.Message)
}
