Agent check gRPC version against server (#1653)

close #1114

As long as the `VersionResponse` type is not changed the check will
fail/pass gracefully

example output:
```
{"level":"error","error":"GRPC version mismatch","time":"2023-03-19T19:49:09+01:00","message":"Server version next-6923e7ab does report grpc version 2 but we only understand 1"}
GRPC version mismatch
```
This commit is contained in:
6543
2023-03-19 22:42:21 +01:00
committed by GitHub
parent f582ad3159
commit 92614dfb1e
14 changed files with 632 additions and 353 deletions

View File

@@ -1,3 +1,4 @@
// Copyright 2023 Woodpecker Authors
// Copyright 2018 Drone.IO Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,6 +18,7 @@ package main
import (
"context"
"crypto/tls"
"errors"
"net/http"
"os"
"runtime"
@@ -154,6 +156,21 @@ func loop(c *cli.Context) error {
sigterm.Set()
})
// check if grpc server version is compatible with agent
grpcServerVersion, err := client.Version(ctx)
if err != nil {
log.Error().Err(err).Msg("could not get grpc server version")
return err
}
if grpcServerVersion.GrpcVersion != agentRpc.ClientGrpcVersion {
err := errors.New("GRPC version mismatch")
log.Error().Err(err).Msgf("Server version %s does report grpc version %d but we only understand %d",
grpcServerVersion.ServerVersion,
grpcServerVersion.GrpcVersion,
agentRpc.ClientGrpcVersion)
return err
}
backendCtx := context.WithValue(ctx, types.CliContext, c)
backend.Init(backendCtx)