Added Error field in Payload and Subscriber restart on connection failure (#1958)

This PR has the following commits:
- Added Error check for graphql cluster-connect errors
- Restart Subscriber on Connection Failure

Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com>
This commit is contained in:
Soumya Ghosh Dastidar 2020-09-04 17:12:05 +05:30 committed by GitHub
parent 2b379a9849
commit d74c1d3898
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View File

@ -100,6 +100,7 @@ func (r *subscriptionResolver) ClusterConnect(ctx context.Context, clusterInfo m
clusterAction := make(chan *model.ClusterAction, 1) clusterAction := make(chan *model.ClusterAction, 1)
verifiedCluster, err := cluster.VerifyCluster(clusterInfo) verifiedCluster, err := cluster.VerifyCluster(clusterInfo)
if err != nil { if err != nil {
log.Print("VALIDATION FAILED : ", clusterInfo.ClusterID)
return clusterAction, err return clusterAction, err
} }
@ -110,7 +111,6 @@ func (r *subscriptionResolver) ClusterConnect(ctx context.Context, clusterInfo m
} }
store.ConnectedCluster[clusterInfo.ClusterID] = clusterAction store.ConnectedCluster[clusterInfo.ClusterID] = clusterAction
store.Mutex.Unlock() store.Mutex.Unlock()
go func() { go func() {
<-ctx.Done() <-ctx.Done()
verifiedCluster.IsActive = false verifiedCluster.IsActive = false

View File

@ -55,8 +55,7 @@ func ClusterConnect(clusterData map[string]string) {
for { for {
_, message, err := c.ReadMessage() _, message, err := c.ReadMessage()
if err != nil { if err != nil {
log.Println("read:", err) log.Fatal("SUBSCRIPTION ERROR : ", err)
return
} }
var r types.RawData var r types.RawData
err = json.Unmarshal(message, &r) err = json.Unmarshal(message, &r)
@ -69,6 +68,10 @@ func ClusterConnect(clusterData map[string]string) {
if r.Type != "data" { if r.Type != "data" {
continue continue
} }
if r.Payload.Errors != nil {
log.Fatal("ERROR: ", string(message))
}
if strings.ToLower(r.Payload.Data.ClusterConnect.Action.RequestType) == "logs" { if strings.ToLower(r.Payload.Data.ClusterConnect.Action.RequestType) == "logs" {
podRequest := types.PodLogRequest{ podRequest := types.PodLogRequest{
RequestID: r.Payload.Data.ClusterConnect.ProjectID, RequestID: r.Payload.Data.ClusterConnect.ProjectID,
@ -80,7 +83,7 @@ func ClusterConnect(clusterData map[string]string) {
// send pod logs // send pod logs
logrus.Print("LOG REQUEST ", podRequest) logrus.Print("LOG REQUEST ", podRequest)
SendPodLogs(clusterData, podRequest) SendPodLogs(clusterData, podRequest)
} else { } else if strings.Index("create update delete get", strings.ToLower(r.Payload.Data.ClusterConnect.Action.RequestType)) >= 0 {
logrus.Print("WORKFLOW REQUEST ", r.Payload.Data.ClusterConnect.Action) logrus.Print("WORKFLOW REQUEST ", r.Payload.Data.ClusterConnect.Action)
_, err = operations.ClusterOperations(r.Payload.Data.ClusterConnect.Action.K8SManifest, r.Payload.Data.ClusterConnect.Action.RequestType) _, err = operations.ClusterOperations(r.Payload.Data.ClusterConnect.Action.K8SManifest, r.Payload.Data.ClusterConnect.Action.RequestType)
if err != nil { if err != nil {

View File

@ -14,7 +14,8 @@ type RawData struct {
} }
type Payload struct { type Payload struct {
Data Data `json:"data"` Errors interface{} `json:"errors"`
Data Data `json:"data"`
} }
type Data struct { type Data struct {