1
0
mirror of https://github.com/containers/podman.git synced 2026-02-05 06:45:31 +01:00

Add a no-op GRPC responder service to the podman system service

Add a bare minimum GRPC service to the podman system service socket.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai
2025-10-27 18:51:18 -04:00
parent e0800b5a24
commit be82989be3
16 changed files with 611 additions and 52 deletions

12
pkg/api/grpcpb/build.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
set -e
cd $(dirname ${BASH_SOURCE[0]})
TOP=../../..
PATH=${TOP}/test/tools/build:${PATH}
set -x
for proto in *.proto ; do
protoc \
--go_opt=paths=source_relative --go_out . \
--go-grpc_opt=paths=source_relative --go-grpc_out . \
${proto}
done

174
pkg/api/grpcpb/noop.pb.go Normal file
View File

@@ -0,0 +1,174 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.10
// protoc v3.19.6
// source: noop.proto
package grpcpb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type NoopRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Ignored string `protobuf:"bytes,1,opt,name=ignored,proto3" json:"ignored,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *NoopRequest) Reset() {
*x = NoopRequest{}
mi := &file_noop_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *NoopRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*NoopRequest) ProtoMessage() {}
func (x *NoopRequest) ProtoReflect() protoreflect.Message {
mi := &file_noop_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use NoopRequest.ProtoReflect.Descriptor instead.
func (*NoopRequest) Descriptor() ([]byte, []int) {
return file_noop_proto_rawDescGZIP(), []int{0}
}
func (x *NoopRequest) GetIgnored() string {
if x != nil {
return x.Ignored
}
return ""
}
type NoopResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Ignored string `protobuf:"bytes,1,opt,name=ignored,proto3" json:"ignored,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *NoopResponse) Reset() {
*x = NoopResponse{}
mi := &file_noop_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *NoopResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*NoopResponse) ProtoMessage() {}
func (x *NoopResponse) ProtoReflect() protoreflect.Message {
mi := &file_noop_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use NoopResponse.ProtoReflect.Descriptor instead.
func (*NoopResponse) Descriptor() ([]byte, []int) {
return file_noop_proto_rawDescGZIP(), []int{1}
}
func (x *NoopResponse) GetIgnored() string {
if x != nil {
return x.Ignored
}
return ""
}
var File_noop_proto protoreflect.FileDescriptor
const file_noop_proto_rawDesc = "" +
"\n" +
"\n" +
"noop.proto\x12\fio.podman.v1\"'\n" +
"\vNoopRequest\x12\x18\n" +
"\aignored\x18\x01 \x01(\tR\aignored\"(\n" +
"\fNoopResponse\x12\x18\n" +
"\aignored\x18\x01 \x01(\tR\aignored2E\n" +
"\x04Noop\x12=\n" +
"\x04Noop\x12\x19.io.podman.v1.NoopRequest\x1a\x1a.io.podman.v1.NoopResponseB0Z.github.com/containers/podman/v6/pkg/api/grpcpbb\x06proto3"
var (
file_noop_proto_rawDescOnce sync.Once
file_noop_proto_rawDescData []byte
)
func file_noop_proto_rawDescGZIP() []byte {
file_noop_proto_rawDescOnce.Do(func() {
file_noop_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_noop_proto_rawDesc), len(file_noop_proto_rawDesc)))
})
return file_noop_proto_rawDescData
}
var file_noop_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_noop_proto_goTypes = []any{
(*NoopRequest)(nil), // 0: io.podman.v1.NoopRequest
(*NoopResponse)(nil), // 1: io.podman.v1.NoopResponse
}
var file_noop_proto_depIdxs = []int32{
0, // 0: io.podman.v1.Noop.Noop:input_type -> io.podman.v1.NoopRequest
1, // 1: io.podman.v1.Noop.Noop:output_type -> io.podman.v1.NoopResponse
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_noop_proto_init() }
func file_noop_proto_init() {
if File_noop_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_noop_proto_rawDesc), len(file_noop_proto_rawDesc)),
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_noop_proto_goTypes,
DependencyIndexes: file_noop_proto_depIdxs,
MessageInfos: file_noop_proto_msgTypes,
}.Build()
File_noop_proto = out.File
file_noop_proto_goTypes = nil
file_noop_proto_depIdxs = nil
}

17
pkg/api/grpcpb/noop.proto Normal file
View File

@@ -0,0 +1,17 @@
syntax = "proto3";
package io.podman.v1;
option go_package = "github.com/containers/podman/v6/pkg/api/grpcpb";
service Noop {
rpc Noop(NoopRequest) returns (NoopResponse);
}
message NoopRequest {
string ignored = 1;
}
message NoopResponse {
string ignored = 1;
}

View File

@@ -0,0 +1,121 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.5.1
// - protoc v3.19.6
// source: noop.proto
package grpcpb
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.64.0 or later.
const _ = grpc.SupportPackageIsVersion9
const (
Noop_Noop_FullMethodName = "/io.podman.v1.Noop/Noop"
)
// NoopClient is the client API for Noop service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type NoopClient interface {
Noop(ctx context.Context, in *NoopRequest, opts ...grpc.CallOption) (*NoopResponse, error)
}
type noopClient struct {
cc grpc.ClientConnInterface
}
func NewNoopClient(cc grpc.ClientConnInterface) NoopClient {
return &noopClient{cc}
}
func (c *noopClient) Noop(ctx context.Context, in *NoopRequest, opts ...grpc.CallOption) (*NoopResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(NoopResponse)
err := c.cc.Invoke(ctx, Noop_Noop_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// NoopServer is the server API for Noop service.
// All implementations must embed UnimplementedNoopServer
// for forward compatibility.
type NoopServer interface {
Noop(context.Context, *NoopRequest) (*NoopResponse, error)
mustEmbedUnimplementedNoopServer()
}
// UnimplementedNoopServer must be embedded to have
// forward compatible implementations.
//
// NOTE: this should be embedded by value instead of pointer to avoid a nil
// pointer dereference when methods are called.
type UnimplementedNoopServer struct{}
func (UnimplementedNoopServer) Noop(context.Context, *NoopRequest) (*NoopResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Noop not implemented")
}
func (UnimplementedNoopServer) mustEmbedUnimplementedNoopServer() {}
func (UnimplementedNoopServer) testEmbeddedByValue() {}
// UnsafeNoopServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to NoopServer will
// result in compilation errors.
type UnsafeNoopServer interface {
mustEmbedUnimplementedNoopServer()
}
func RegisterNoopServer(s grpc.ServiceRegistrar, srv NoopServer) {
// If the following call pancis, it indicates UnimplementedNoopServer was
// embedded by pointer and is nil. This will cause panics if an
// unimplemented method is ever invoked, so we test this at initialization
// time to prevent it from happening at runtime later due to I/O.
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
t.testEmbeddedByValue()
}
s.RegisterService(&Noop_ServiceDesc, srv)
}
func _Noop_Noop_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(NoopRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(NoopServer).Noop(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Noop_Noop_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(NoopServer).Noop(ctx, req.(*NoopRequest))
}
return interceptor(ctx, in, info, handler)
}
// Noop_ServiceDesc is the grpc.ServiceDesc for Noop service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var Noop_ServiceDesc = grpc.ServiceDesc{
ServiceName: "io.podman.v1.Noop",
HandlerType: (*NoopServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Noop",
Handler: _Noop_Noop_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "noop.proto",
}

View File

@@ -0,0 +1,26 @@
//go:build !remote
package grpc
import (
"context"
"github.com/containers/podman/v6/libpod"
"github.com/containers/podman/v6/pkg/api/grpcpb"
)
type noopServer struct {
grpcpb.UnimplementedNoopServer
runtime *libpod.Runtime
}
func (noopServer) Noop(_ context.Context, req *grpcpb.NoopRequest) (*grpcpb.NoopResponse, error) {
resp := &grpcpb.NoopResponse{
Ignored: req.GetIgnored(),
}
return resp, nil
}
func NewNoopServer(runtime *libpod.Runtime) grpcpb.NoopServer {
return &noopServer{runtime: runtime}
}

View File

@@ -19,7 +19,9 @@ import (
"github.com/containers/podman/v6/libpod"
"github.com/containers/podman/v6/libpod/shutdown"
"github.com/containers/podman/v6/pkg/api/grpcpb"
"github.com/containers/podman/v6/pkg/api/handlers"
grpchandlers "github.com/containers/podman/v6/pkg/api/handlers/grpc"
"github.com/containers/podman/v6/pkg/api/server/idle"
"github.com/containers/podman/v6/pkg/api/types"
"github.com/containers/podman/v6/pkg/domain/entities"
@@ -28,12 +30,13 @@ import (
"github.com/gorilla/mux"
"github.com/gorilla/schema"
"github.com/sirupsen/logrus"
_ "google.golang.org/grpc"
_ "google.golang.org/grpc/reflection"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
type APIServer struct {
http.Server // The HTTP work happens here
http.Server // The HTTP work happens here
grpc *grpc.Server // GRPC stuff happens here
net.Listener // mux for routing HTTP API calls to libpod routines
*libpod.Runtime // Where the real work happens
*schema.Decoder // Decoder for Query parameters to structs
@@ -73,6 +76,10 @@ func newServer(runtime *libpod.Runtime, listener net.Listener, opts entities.Ser
router := mux.NewRouter().UseEncodedPath()
tracker := idle.NewTracker(opts.Timeout)
serverProtocols := &http.Protocols{}
serverProtocols.SetHTTP1(true)
serverProtocols.SetHTTP2(true)
server := APIServer{
Server: http.Server{
ConnContext: func(ctx context.Context, c net.Conn) context.Context {
@@ -82,7 +89,9 @@ func newServer(runtime *libpod.Runtime, listener net.Listener, opts entities.Ser
ErrorLog: log.New(logrus.StandardLogger().Out, "", 0),
Handler: router,
IdleTimeout: opts.Timeout * 2,
Protocols: serverProtocols,
},
grpc: grpc.NewServer(),
CorsHeaders: opts.CorsHeaders,
Listener: listener,
PProfAddr: opts.PProfAddr,
@@ -92,6 +101,9 @@ func newServer(runtime *libpod.Runtime, listener net.Listener, opts entities.Ser
tlsClientCAFile: opts.TLSClientCAFile,
}
router.NewRoute().HeadersRegexp("Content-Type", "application/grpc(\\+.*)?").Handler(server.grpc)
reflection.Register(server.grpc)
server.BaseContext = func(_ net.Listener) context.Context {
ctx := context.WithValue(context.Background(), types.DecoderKey, handlers.NewAPIDecoder())
ctx = context.WithValue(ctx, types.CompatDecoderKey, handlers.NewCompatAPIDecoder())
@@ -163,6 +175,8 @@ func newServer(runtime *libpod.Runtime, listener net.Listener, opts entities.Ser
}
}
grpcpb.RegisterNoopServer(server.grpc, grpchandlers.NewNoopServer(runtime)) // TODO: make this table-driven instead of a one-off?
if logrus.IsLevelEnabled(logrus.TraceLevel) {
// If in trace mode log request and response bodies
router.Use(loggingHandler())
@@ -213,6 +227,7 @@ func (s *APIServer) Serve() error {
s.setupPprof()
if err := shutdown.Register("service", func(_ os.Signal) error {
s.grpc.GracefulStop()
err := s.Shutdown(true)
if err == nil {
// For `systemctl stop podman.service` support, exit code should be 0
@@ -247,6 +262,7 @@ func (s *APIServer) Serve() error {
}
err = s.Server.ServeTLS(s.Listener, s.tlsCertFile, s.tlsKeyFile)
} else {
s.Server.Protocols.SetUnencryptedHTTP2(true)
err = s.Server.Serve(s.Listener)
}
if err != nil && err != http.ErrServerClosed {