doudao1837 2019-08-30 20:14
浏览 1022
已采纳

从protobuf中的其他包导入类型定义

I am trying to create a grpc service with a very basic single action which is GetDeployment, takes a namespace and a name as an input, and returns a Kubernetes deployment. The thing is that I do not want to define my own message for the Deployment as it already exists on the official Kubernetes repository.

I am pretty new to grpc and probably do not understand well enough how it works but can I import this message to my own file in a way I could then write the following .proto file ?

syntax = "proto3";
package api;

import "google/api/annotations.proto";
import "k8s.io/kubernetes/pkg/api/v1/generated.proto";

message GetDeploymentOptions {
  string namespace = 1;
  string name = 2;
}

service AppsV1 {
  rpc GetDeployment(GetDeploymentOptions) returns (k8s.io.kubernetes.pkg.api.v1.Deployment) {}
}

Thank you in advance

  • 写回答

1条回答 默认 最新

  • douhe4336 2019-08-30 21:31
    关注

    GRPC codegen is just a protoc plugin. It generates code for service and rpc but it follows the normal protobuf rules for imports.

    In your example, if your file is in src/api.proto and the k8s api repo is a git submodule checked out into thirdparty/k8s.io/api folder you would generate the files you'd need by running:

    root>protoc.exe -I thirdparty k8s.io/api/core/v1/generated.proto --go_out=go
    root>protoc.exe -I thirdparty src/api.proto --go_out=plugins=grpc:go
    

    The first command is generating the .pb.go file which contains the k8s messages, while the second command is generating the .pb.go file which contains your messages and your service.

    Looking at the transient imports of that file, you may also need to checkout api-machinery into k8s.io/apimachinery and run protoc on that file as well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器