feat: add client/server version check mechanism to gRPC calls (#260)

* Add version check mechanism to gRPC calls

* Use semver not semver/v3

* Give dev builds a special "infinite" version number (999.0.0-dev)

* Handle no metadata on grpc call correctly for version check

* Move versioncheck package to root pkg/ from pkg/api/ since it is shared by both pkg/api/ and pkg/client/

* Only show "no daemon version" warning once

* Append version headers to metadata, not overwrite...

* Unit tests on versioncheck logic

* Move SetHeader to the ServerStream in ServerStreamInterceptor

* Go modernizer nits: interface{} -> any

* Use more conventional gRPC header names for version/min-versions

* Add TODO notes on checkDaemonVersionInResponse and related code that can be removed eventually after transition to version checking client/daemons

* Use testify for testing assertions

* Add explanatory comments on MinCLIVersion and MinDaemonVersion

---------

Co-authored-by: Pasha Sviderski <me@psviderski.name>
This commit is contained in:
Justin Bradford
2026-04-08 19:52:42 +10:00
committed by GitHub
co-authored by Pasha Sviderski
parent 943fea0515
commit 897f30fd36
10 changed files with 419 additions and 0 deletions
+5
View File
@@ -34,6 +34,7 @@ import (
"github.com/psviderski/uncloud/internal/machine/network"
"github.com/psviderski/uncloud/internal/machine/store"
"github.com/psviderski/uncloud/pkg/api"
versionpkg "github.com/psviderski/uncloud/pkg/versioncheck"
"github.com/psviderski/unregistry"
"github.com/siderolabs/grpc-proxy/proxy"
"golang.org/x/sync/errgroup"
@@ -272,6 +273,8 @@ func NewMachine(config *Config) (*Machine, error) {
proxyDirector := apiproxy.NewDirector(config.MachineSockPath, constants.MachineAPIPort)
localProxyServer := grpc.NewServer(
grpc.ForceServerCodecV2(proxy.Codec()),
grpc.UnaryInterceptor(versionpkg.ServerUnaryInterceptor),
grpc.StreamInterceptor(versionpkg.ServerStreamInterceptor),
grpc.UnknownServiceHandler(
proxy.TransparentHandler(proxyDirector.Director),
),
@@ -425,6 +428,8 @@ func (m *Machine) Run(ctx context.Context) error {
m.proxyDirector.UpdateLocalAddress(m.state.Network.ManagementIP.String())
proxyServer := grpc.NewServer(
grpc.ForceServerCodecV2(proxy.Codec()),
grpc.UnaryInterceptor(versionpkg.ServerUnaryInterceptor),
grpc.StreamInterceptor(versionpkg.ServerStreamInterceptor),
grpc.UnknownServiceHandler(
proxy.TransparentHandler(m.proxyDirector.Director),
),
+3
View File
@@ -3,5 +3,8 @@ package version
var version string
func String() string {
if version == "" {
return "999.0.0-dev"
}
return version
}