-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update cluster health based on the dialin connection (#108)
* 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
1 parent
42f1abc
commit 47e3f14
Showing
4 changed files
with
77 additions
and
4 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
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,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) | ||
} |