DRA driver: optionally support kubelet 1.31

Supporting the alpha gRPC interface isn't enough anymore to be compatible
with kubelet 1.31: the "supported versions" must contain version numbers,
otherwise the older kubelet refuses to register the driver.

With this change, a DRA driver can decide to support both kubelet 1.31 and
kubelet 1.32 by registering *only* the alpha gRPC interface (NodeV1alpha4(true)
and NodeV1beta1(false) as options for Start).

The default is to provide both interfaces and using the registration mechanism
for 1.32, which makes DRA drivers compatible only with Kubernetes >= 1.32.
This commit is contained in:
Patrick Ohly 2024-11-03 14:55:54 +01:00
parent 2c23fe1b82
commit 1193ff1271

View File

@ -271,6 +271,12 @@ type draPlugin struct {
//
// If the plugin will be used to publish resources, [KubeClient] and [NodeName]
// options are mandatory.
//
// By default, the DRA driver gets registered so that the plugin is compatible
// with Kubernetes >= 1.32. To be compatible with Kubernetes >= 1.31, a driver
// has to ask specifically to register only the alpha gRPC API, i.e. use:
//
// Start(..., NodeV1beta1(false))
func Start(ctx context.Context, nodeServer interface{}, opts ...Option) (result DRAPlugin, finalErr error) {
logger := klog.FromContext(ctx)
o := options{
@ -351,6 +357,15 @@ func Start(ctx context.Context, nodeServer interface{}, opts ...Option) (result
return nil, errors.New("no supported DRA gRPC API is implemented and enabled")
}
// Backwards compatibility hack: if only the alpha gRPC service is enabled,
// then we can support registration against a 1.31 kubelet by reporting "1.0.0"
// as version. That also works with 1.32 because 1.32 supports that legacy
// behavior and 1.31 works because it doesn't fail while parsing "v1alpha3.Node"
// as version.
if len(supportedServices) == 1 && supportedServices[0] == drapbv1alpha4.NodeService {
supportedServices = []string{"1.0.0"}
}
// Now make it available to kubelet.
registrar, err := startRegistrar(klog.NewContext(ctx, klog.LoggerWithName(logger, "registrar")), o.grpcVerbosity, o.unaryInterceptors, o.streamInterceptors, o.driverName, supportedServices, o.draAddress, o.pluginRegistrationEndpoint)
if err != nil {