Skip to content

Commit

Permalink
feat: update cluster health based on the dialin connection (#108)
Browse files Browse the repository at this point in the history
* invoke updating cluster health based on the dialin connection

Signed-off-by: niravparikh05 <[email protected]>

* added return from healthz during errors

Signed-off-by: niravparikh05 <[email protected]>

---------

Signed-off-by: niravparikh05 <[email protected]>
  • Loading branch information
niravparikh05 authored Feb 28, 2024
1 parent 42f1abc commit 47e3f14
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/inconshreveable/go-vhost v0.0.0-20160627193104-06d84117953b
github.com/jinzhu/inflection v1.0.0
github.com/julienschmidt/httprouter v1.3.0
github.com/paralus/paralus v0.2.5-0.20230921060456-1b7a9a1fa32e
github.com/paralus/paralus v0.2.7-0.20240212135918-669e222441b2
github.com/rs/xid v1.3.0
github.com/segmentio/encoding v0.3.4
github.com/spf13/pflag v1.0.5
Expand All @@ -22,6 +22,7 @@ require (
golang.org/x/net v0.17.0
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
google.golang.org/grpc v1.56.3
google.golang.org/protobuf v1.30.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
k8s.io/api v0.23.4
k8s.io/apimachinery v0.23.4
Expand Down Expand Up @@ -110,7 +111,6 @@ require (
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/ory/kratos-client-go v0.11.0 h1:8FF2GiLjvDEPiN4fVLiHgnKZspQdd7kXDlBbeJJq+aw=
github.com/ory/kratos-client-go v0.11.0/go.mod h1:8gqPMa6bB+NHbDurRY6D2dOTLrjYEdg/Dx+JvwXsZ0Q=
github.com/paralus/paralus v0.2.5-0.20230921060456-1b7a9a1fa32e h1:4tXra34G/yMoBhznlumOAVtZX5KnD5jWPlJfOoXnb8g=
github.com/paralus/paralus v0.2.5-0.20230921060456-1b7a9a1fa32e/go.mod h1:blseZik4e+Ddm6jhOlBiZVXAE5aaRNeI+qQ9r2a0s/Q=
github.com/paralus/paralus v0.2.7-0.20240212135918-669e222441b2 h1:/pqUIwhrAMp6cr+oNx9hXOthoFEOlbShK8NhM1h/e+Q=
github.com/paralus/paralus v0.2.7-0.20240212135918-669e222441b2/go.mod h1:utnT63Nd7EiYw3oc7NryvL6V3zhfVYSNWXZG4Hpwy8U=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
Expand Down
6 changes: 6 additions & 0 deletions pkg/tunnel/dialin_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync"
"time"

commonv3 "github.com/paralus/paralus/proto/types/commonpb/v3"
"github.com/paralus/relay/pkg/relaylogger"
"github.com/paralus/relay/pkg/utils"
"golang.org/x/net/http2"
Expand Down Expand Up @@ -85,6 +86,7 @@ func (p *dialinPool) MarkDead(c *http2.ClientConn) {
if !p.deleteDialinConnectorKey(sni, addr) {
_dplog.Error(nil, "error in dialin MarkDead connector key delete did not find key ", addr)
}
go syncClusterHeath(sni, commonv3.ParalusConditionStatus_Unhealthy, "connection to target cluster lost..")
}
return
}
Expand Down Expand Up @@ -148,6 +150,8 @@ func (p *dialinPool) AddConn(conn net.Conn, identifier string, sni string, remot
sort.Strings(p.dialinConnectors[sni].connKeys)
}

go syncClusterHeath(key, commonv3.ParalusConditionStatus_Healthy, "successful dialin connection established with agent")

_dplog.Info(
"Added dialin connection",
"addr", addr,
Expand Down Expand Up @@ -273,6 +277,8 @@ func (p *dialinPool) DeleteConn(identifier string, sni string, remoteAddr string
)
}

go syncClusterHeath(key, commonv3.ParalusConditionStatus_Unhealthy, "connection to target cluster lost..")

if p.deleteDialinConnectorKey(sni, addr) {
return
}
Expand Down
67 changes: 67 additions & 0 deletions pkg/tunnel/healthz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package tunnel

import (
"context"
"net/url"

"github.com/paralus/paralus/pkg/grpc"
rpcv3 "github.com/paralus/paralus/proto/rpc/scheduler"
commonv3 "github.com/paralus/paralus/proto/types/commonpb/v3"
infrav3 "github.com/paralus/paralus/proto/types/infrapb/v3"
"github.com/paralus/relay/pkg/utils"
"google.golang.org/grpc/credentials"
"google.golang.org/protobuf/types/known/timestamppb"
)

func syncClusterHeath(sni string, status commonv3.ParalusConditionStatus, reason string) {
id, err := getClusterID(sni)
if err != nil {
_log.Error("unable to get clusterID", "error", err)
return
}

u, err := url.Parse(utils.PeerServiceURI)
if err != nil {
_log.Error("unable to parse peer service url", "error", err)
return
}
//Load certificates
tlsConfig, err := ClientTLSConfigFromBytes(utils.PeerCertificate, utils.PeerPrivateKey, utils.PeerCACertificate, u.Host)
if err != nil {
_log.Error("unable to build tls config for peer service", "error", err)
return
}
transportCreds := credentials.NewTLS(tlsConfig)
peerSeviceHost := u.Host

ctx := context.Background()
conn, err := grpc.NewSecureClientConn(ctx, peerSeviceHost, transportCreds)
if err != nil {
_log.Error("unable to connect to core", "error", err)
return
}
defer conn.Close()

client := rpcv3.NewClusterServiceClient(conn)
_, err = client.UpdateClusterStatus(ctx, &rpcv3.UpdateClusterStatusRequest{
Metadata: &commonv3.Metadata{
Id: id,
Project: id,
},
ClusterStatus: &infrav3.ClusterStatus{
Conditions: []*infrav3.ClusterCondition{
{
Type: infrav3.ClusterConditionType_ClusterHealth,
Status: status,
LastUpdated: timestamppb.Now(),
Reason: reason,
},
},
},
})
if err != nil {
_log.Error("failed to update cluster status", "error", err)
return
}
_log.Debug("successfully update cluster ", sni, " status ", status)
}

0 comments on commit 47e3f14

Please sign in to comment.