From 92d04220b99de95cf596f383c983ae176fe50f15 Mon Sep 17 00:00:00 2001 From: Tom Martensen Date: Fri, 3 Jan 2025 12:35:20 +0100 Subject: [PATCH] fix missing protoc binary --- Makefile | 10 +- generated/api/v1/service_grpc.pb.go | 298 +++++++++++++++++++--------- service/cluster/helpers.go | 11 +- 3 files changed, 221 insertions(+), 98 deletions(-) diff --git a/Makefile b/Makefile index 9de4a8dab..5c8742d21 100644 --- a/Makefile +++ b/Makefile @@ -36,12 +36,14 @@ image-name: # Tool versions. protoc-version = 29.2 protoc-gen-go-version = 1.36.1 +protoc-gen-go-grpc-version = 1.5.1 protoc-gen-grpc-gateway-version = 2.25.1 protoc-gen-openapiv2-version = 2.25.1 # Tool binary paths protoc = $(GOPATH)/bin/protoc protoc-gen-go = $(GOPATH)/bin/protoc-gen-go +protoc-gen-go-grpc = $(GOPATH)/bin/protoc-gen-go-grpc protoc-gen-grpc-gateway = $(GOPATH)/bin/protoc-gen-grpc-gateway protoc-gen-openapiv2 = $(GOPATH)/bin/protoc-gen-openapiv2 @@ -68,6 +70,12 @@ $(protoc-gen-go): @echo "Installing protoc-gen-go $(protoc-gen-go-version) to $(protoc-gen-go)" @cd /tmp; go install google.golang.org/protobuf/cmd/protoc-gen-go@v$(protoc-gen-go-version) +# This target installs the protoc-gen-go-grpc binary. +$(protoc-gen-go-grpc): + @echo "+ $@" + @echo "Installing protoc-gen-go-grpc $(protoc-gen-go-grpc-version) to $(protoc-gen-go-grpc)" + @cd /tmp; go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v$(protoc-gen-go-grpc-version) + # This target installs the protoc-gen-grpc-gateway binary. $(protoc-gen-grpc-gateway): @echo "+ $@" @@ -82,7 +90,7 @@ $(protoc-gen-openapiv2): # This target installs all of the protoc related binaries. .PHONY: protoc-tools -protoc-tools: $(protoc) $(protoc-gen-go) $(protoc-gen-grpc-gateway) $(protoc-gen-openapiv2) +protoc-tools: $(protoc) $(protoc-gen-go) $(protoc-gen-go-grpc) $(protoc-gen-grpc-gateway) $(protoc-gen-openapiv2) PROTO_INPUT_DIR = proto/api/v1 PROTO_THIRD_PARTY = proto/third_party diff --git a/generated/api/v1/service_grpc.pb.go b/generated/api/v1/service_grpc.pb.go index ef355a545..cc8f87952 100644 --- a/generated/api/v1/service_grpc.pb.go +++ b/generated/api/v1/service_grpc.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.2.0 +// - protoc-gen-go-grpc v1.5.1 // - protoc v5.29.2 // source: service.proto @@ -17,8 +17,12 @@ import ( // 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.32.0 or later. -const _ = grpc.SupportPackageIsVersion7 +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + VersionService_GetVersion_FullMethodName = "/v1.VersionService/GetVersion" +) // VersionServiceClient is the client API for VersionService service. // @@ -36,8 +40,9 @@ func NewVersionServiceClient(cc grpc.ClientConnInterface) VersionServiceClient { } func (c *versionServiceClient) GetVersion(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*Version, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(Version) - err := c.cc.Invoke(ctx, "/v1.VersionService/GetVersion", in, out, opts...) + err := c.cc.Invoke(ctx, VersionService_GetVersion_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -46,20 +51,24 @@ func (c *versionServiceClient) GetVersion(ctx context.Context, in *emptypb.Empty // VersionServiceServer is the server API for VersionService service. // All implementations must embed UnimplementedVersionServiceServer -// for forward compatibility +// for forward compatibility. type VersionServiceServer interface { GetVersion(context.Context, *emptypb.Empty) (*Version, error) mustEmbedUnimplementedVersionServiceServer() } -// UnimplementedVersionServiceServer must be embedded to have forward compatible implementations. -type UnimplementedVersionServiceServer struct { -} +// UnimplementedVersionServiceServer 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 UnimplementedVersionServiceServer struct{} func (UnimplementedVersionServiceServer) GetVersion(context.Context, *emptypb.Empty) (*Version, error) { return nil, status.Errorf(codes.Unimplemented, "method GetVersion not implemented") } func (UnimplementedVersionServiceServer) mustEmbedUnimplementedVersionServiceServer() {} +func (UnimplementedVersionServiceServer) testEmbeddedByValue() {} // UnsafeVersionServiceServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to VersionServiceServer will @@ -69,6 +78,13 @@ type UnsafeVersionServiceServer interface { } func RegisterVersionServiceServer(s grpc.ServiceRegistrar, srv VersionServiceServer) { + // If the following call pancis, it indicates UnimplementedVersionServiceServer 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(&VersionService_ServiceDesc, srv) } @@ -82,7 +98,7 @@ func _VersionService_GetVersion_Handler(srv interface{}, ctx context.Context, de } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.VersionService/GetVersion", + FullMethod: VersionService_GetVersion_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(VersionServiceServer).GetVersion(ctx, req.(*emptypb.Empty)) @@ -106,6 +122,12 @@ var VersionService_ServiceDesc = grpc.ServiceDesc{ Metadata: "service.proto", } +const ( + UserService_Whoami_FullMethodName = "/v1.UserService/Whoami" + UserService_CreateToken_FullMethodName = "/v1.UserService/CreateToken" + UserService_Token_FullMethodName = "/v1.UserService/Token" +) + // UserServiceClient is the client API for UserService 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. @@ -127,8 +149,9 @@ func NewUserServiceClient(cc grpc.ClientConnInterface) UserServiceClient { } func (c *userServiceClient) Whoami(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*WhoamiResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(WhoamiResponse) - err := c.cc.Invoke(ctx, "/v1.UserService/Whoami", in, out, opts...) + err := c.cc.Invoke(ctx, UserService_Whoami_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -136,8 +159,9 @@ func (c *userServiceClient) Whoami(ctx context.Context, in *emptypb.Empty, opts } func (c *userServiceClient) CreateToken(ctx context.Context, in *ServiceAccount, opts ...grpc.CallOption) (*TokenResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(TokenResponse) - err := c.cc.Invoke(ctx, "/v1.UserService/CreateToken", in, out, opts...) + err := c.cc.Invoke(ctx, UserService_CreateToken_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -145,8 +169,9 @@ func (c *userServiceClient) CreateToken(ctx context.Context, in *ServiceAccount, } func (c *userServiceClient) Token(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*TokenResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(TokenResponse) - err := c.cc.Invoke(ctx, "/v1.UserService/Token", in, out, opts...) + err := c.cc.Invoke(ctx, UserService_Token_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -155,7 +180,7 @@ func (c *userServiceClient) Token(ctx context.Context, in *emptypb.Empty, opts . // UserServiceServer is the server API for UserService service. // All implementations must embed UnimplementedUserServiceServer -// for forward compatibility +// for forward compatibility. type UserServiceServer interface { // Whoami provides information about the currently authenticated principal. Whoami(context.Context, *emptypb.Empty) (*WhoamiResponse, error) @@ -166,9 +191,12 @@ type UserServiceServer interface { mustEmbedUnimplementedUserServiceServer() } -// UnimplementedUserServiceServer must be embedded to have forward compatible implementations. -type UnimplementedUserServiceServer struct { -} +// UnimplementedUserServiceServer 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 UnimplementedUserServiceServer struct{} func (UnimplementedUserServiceServer) Whoami(context.Context, *emptypb.Empty) (*WhoamiResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Whoami not implemented") @@ -180,6 +208,7 @@ func (UnimplementedUserServiceServer) Token(context.Context, *emptypb.Empty) (*T return nil, status.Errorf(codes.Unimplemented, "method Token not implemented") } func (UnimplementedUserServiceServer) mustEmbedUnimplementedUserServiceServer() {} +func (UnimplementedUserServiceServer) testEmbeddedByValue() {} // UnsafeUserServiceServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to UserServiceServer will @@ -189,6 +218,13 @@ type UnsafeUserServiceServer interface { } func RegisterUserServiceServer(s grpc.ServiceRegistrar, srv UserServiceServer) { + // If the following call pancis, it indicates UnimplementedUserServiceServer 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(&UserService_ServiceDesc, srv) } @@ -202,7 +238,7 @@ func _UserService_Whoami_Handler(srv interface{}, ctx context.Context, dec func( } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.UserService/Whoami", + FullMethod: UserService_Whoami_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(UserServiceServer).Whoami(ctx, req.(*emptypb.Empty)) @@ -220,7 +256,7 @@ func _UserService_CreateToken_Handler(srv interface{}, ctx context.Context, dec } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.UserService/CreateToken", + FullMethod: UserService_CreateToken_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(UserServiceServer).CreateToken(ctx, req.(*ServiceAccount)) @@ -238,7 +274,7 @@ func _UserService_Token_Handler(srv interface{}, ctx context.Context, dec func(i } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.UserService/Token", + FullMethod: UserService_Token_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(UserServiceServer).Token(ctx, req.(*emptypb.Empty)) @@ -270,9 +306,16 @@ var UserService_ServiceDesc = grpc.ServiceDesc{ Metadata: "service.proto", } +const ( + FlavorService_List_FullMethodName = "/v1.FlavorService/List" + FlavorService_Info_FullMethodName = "/v1.FlavorService/Info" +) + // FlavorServiceClient is the client API for FlavorService 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. +// +// FlavorService provides flavor based functionality. type FlavorServiceClient interface { // List provides information about the available flavors. List(ctx context.Context, in *FlavorListRequest, opts ...grpc.CallOption) (*FlavorListResponse, error) @@ -289,8 +332,9 @@ func NewFlavorServiceClient(cc grpc.ClientConnInterface) FlavorServiceClient { } func (c *flavorServiceClient) List(ctx context.Context, in *FlavorListRequest, opts ...grpc.CallOption) (*FlavorListResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(FlavorListResponse) - err := c.cc.Invoke(ctx, "/v1.FlavorService/List", in, out, opts...) + err := c.cc.Invoke(ctx, FlavorService_List_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -298,8 +342,9 @@ func (c *flavorServiceClient) List(ctx context.Context, in *FlavorListRequest, o } func (c *flavorServiceClient) Info(ctx context.Context, in *ResourceByID, opts ...grpc.CallOption) (*Flavor, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(Flavor) - err := c.cc.Invoke(ctx, "/v1.FlavorService/Info", in, out, opts...) + err := c.cc.Invoke(ctx, FlavorService_Info_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -308,7 +353,9 @@ func (c *flavorServiceClient) Info(ctx context.Context, in *ResourceByID, opts . // FlavorServiceServer is the server API for FlavorService service. // All implementations must embed UnimplementedFlavorServiceServer -// for forward compatibility +// for forward compatibility. +// +// FlavorService provides flavor based functionality. type FlavorServiceServer interface { // List provides information about the available flavors. List(context.Context, *FlavorListRequest) (*FlavorListResponse, error) @@ -317,9 +364,12 @@ type FlavorServiceServer interface { mustEmbedUnimplementedFlavorServiceServer() } -// UnimplementedFlavorServiceServer must be embedded to have forward compatible implementations. -type UnimplementedFlavorServiceServer struct { -} +// UnimplementedFlavorServiceServer 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 UnimplementedFlavorServiceServer struct{} func (UnimplementedFlavorServiceServer) List(context.Context, *FlavorListRequest) (*FlavorListResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method List not implemented") @@ -328,6 +378,7 @@ func (UnimplementedFlavorServiceServer) Info(context.Context, *ResourceByID) (*F return nil, status.Errorf(codes.Unimplemented, "method Info not implemented") } func (UnimplementedFlavorServiceServer) mustEmbedUnimplementedFlavorServiceServer() {} +func (UnimplementedFlavorServiceServer) testEmbeddedByValue() {} // UnsafeFlavorServiceServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to FlavorServiceServer will @@ -337,6 +388,13 @@ type UnsafeFlavorServiceServer interface { } func RegisterFlavorServiceServer(s grpc.ServiceRegistrar, srv FlavorServiceServer) { + // If the following call pancis, it indicates UnimplementedFlavorServiceServer 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(&FlavorService_ServiceDesc, srv) } @@ -350,7 +408,7 @@ func _FlavorService_List_Handler(srv interface{}, ctx context.Context, dec func( } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.FlavorService/List", + FullMethod: FlavorService_List_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(FlavorServiceServer).List(ctx, req.(*FlavorListRequest)) @@ -368,7 +426,7 @@ func _FlavorService_Info_Handler(srv interface{}, ctx context.Context, dec func( } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.FlavorService/Info", + FullMethod: FlavorService_Info_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(FlavorServiceServer).Info(ctx, req.(*ResourceByID)) @@ -396,9 +454,21 @@ var FlavorService_ServiceDesc = grpc.ServiceDesc{ Metadata: "service.proto", } +const ( + ClusterService_Info_FullMethodName = "/v1.ClusterService/Info" + ClusterService_List_FullMethodName = "/v1.ClusterService/List" + ClusterService_Lifespan_FullMethodName = "/v1.ClusterService/Lifespan" + ClusterService_Create_FullMethodName = "/v1.ClusterService/Create" + ClusterService_Artifacts_FullMethodName = "/v1.ClusterService/Artifacts" + ClusterService_Delete_FullMethodName = "/v1.ClusterService/Delete" + ClusterService_Logs_FullMethodName = "/v1.ClusterService/Logs" +) + // ClusterServiceClient is the client API for ClusterService 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. +// +// FlavorService provides flavor based functionality. type ClusterServiceClient interface { // Info provides information about a specific cluster. Info(ctx context.Context, in *ResourceByID, opts ...grpc.CallOption) (*Cluster, error) @@ -425,8 +495,9 @@ func NewClusterServiceClient(cc grpc.ClientConnInterface) ClusterServiceClient { } func (c *clusterServiceClient) Info(ctx context.Context, in *ResourceByID, opts ...grpc.CallOption) (*Cluster, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(Cluster) - err := c.cc.Invoke(ctx, "/v1.ClusterService/Info", in, out, opts...) + err := c.cc.Invoke(ctx, ClusterService_Info_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -434,8 +505,9 @@ func (c *clusterServiceClient) Info(ctx context.Context, in *ResourceByID, opts } func (c *clusterServiceClient) List(ctx context.Context, in *ClusterListRequest, opts ...grpc.CallOption) (*ClusterListResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(ClusterListResponse) - err := c.cc.Invoke(ctx, "/v1.ClusterService/List", in, out, opts...) + err := c.cc.Invoke(ctx, ClusterService_List_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -443,8 +515,9 @@ func (c *clusterServiceClient) List(ctx context.Context, in *ClusterListRequest, } func (c *clusterServiceClient) Lifespan(ctx context.Context, in *LifespanRequest, opts ...grpc.CallOption) (*durationpb.Duration, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(durationpb.Duration) - err := c.cc.Invoke(ctx, "/v1.ClusterService/Lifespan", in, out, opts...) + err := c.cc.Invoke(ctx, ClusterService_Lifespan_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -452,8 +525,9 @@ func (c *clusterServiceClient) Lifespan(ctx context.Context, in *LifespanRequest } func (c *clusterServiceClient) Create(ctx context.Context, in *CreateClusterRequest, opts ...grpc.CallOption) (*ResourceByID, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(ResourceByID) - err := c.cc.Invoke(ctx, "/v1.ClusterService/Create", in, out, opts...) + err := c.cc.Invoke(ctx, ClusterService_Create_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -461,8 +535,9 @@ func (c *clusterServiceClient) Create(ctx context.Context, in *CreateClusterRequ } func (c *clusterServiceClient) Artifacts(ctx context.Context, in *ResourceByID, opts ...grpc.CallOption) (*ClusterArtifacts, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(ClusterArtifacts) - err := c.cc.Invoke(ctx, "/v1.ClusterService/Artifacts", in, out, opts...) + err := c.cc.Invoke(ctx, ClusterService_Artifacts_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -470,8 +545,9 @@ func (c *clusterServiceClient) Artifacts(ctx context.Context, in *ResourceByID, } func (c *clusterServiceClient) Delete(ctx context.Context, in *ResourceByID, opts ...grpc.CallOption) (*emptypb.Empty, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(emptypb.Empty) - err := c.cc.Invoke(ctx, "/v1.ClusterService/Delete", in, out, opts...) + err := c.cc.Invoke(ctx, ClusterService_Delete_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -479,8 +555,9 @@ func (c *clusterServiceClient) Delete(ctx context.Context, in *ResourceByID, opt } func (c *clusterServiceClient) Logs(ctx context.Context, in *ResourceByID, opts ...grpc.CallOption) (*LogsResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(LogsResponse) - err := c.cc.Invoke(ctx, "/v1.ClusterService/Logs", in, out, opts...) + err := c.cc.Invoke(ctx, ClusterService_Logs_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -489,7 +566,9 @@ func (c *clusterServiceClient) Logs(ctx context.Context, in *ResourceByID, opts // ClusterServiceServer is the server API for ClusterService service. // All implementations must embed UnimplementedClusterServiceServer -// for forward compatibility +// for forward compatibility. +// +// FlavorService provides flavor based functionality. type ClusterServiceServer interface { // Info provides information about a specific cluster. Info(context.Context, *ResourceByID) (*Cluster, error) @@ -508,9 +587,12 @@ type ClusterServiceServer interface { mustEmbedUnimplementedClusterServiceServer() } -// UnimplementedClusterServiceServer must be embedded to have forward compatible implementations. -type UnimplementedClusterServiceServer struct { -} +// UnimplementedClusterServiceServer 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 UnimplementedClusterServiceServer struct{} func (UnimplementedClusterServiceServer) Info(context.Context, *ResourceByID) (*Cluster, error) { return nil, status.Errorf(codes.Unimplemented, "method Info not implemented") @@ -534,6 +616,7 @@ func (UnimplementedClusterServiceServer) Logs(context.Context, *ResourceByID) (* return nil, status.Errorf(codes.Unimplemented, "method Logs not implemented") } func (UnimplementedClusterServiceServer) mustEmbedUnimplementedClusterServiceServer() {} +func (UnimplementedClusterServiceServer) testEmbeddedByValue() {} // UnsafeClusterServiceServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to ClusterServiceServer will @@ -543,6 +626,13 @@ type UnsafeClusterServiceServer interface { } func RegisterClusterServiceServer(s grpc.ServiceRegistrar, srv ClusterServiceServer) { + // If the following call pancis, it indicates UnimplementedClusterServiceServer 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(&ClusterService_ServiceDesc, srv) } @@ -556,7 +646,7 @@ func _ClusterService_Info_Handler(srv interface{}, ctx context.Context, dec func } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.ClusterService/Info", + FullMethod: ClusterService_Info_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ClusterServiceServer).Info(ctx, req.(*ResourceByID)) @@ -574,7 +664,7 @@ func _ClusterService_List_Handler(srv interface{}, ctx context.Context, dec func } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.ClusterService/List", + FullMethod: ClusterService_List_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ClusterServiceServer).List(ctx, req.(*ClusterListRequest)) @@ -592,7 +682,7 @@ func _ClusterService_Lifespan_Handler(srv interface{}, ctx context.Context, dec } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.ClusterService/Lifespan", + FullMethod: ClusterService_Lifespan_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ClusterServiceServer).Lifespan(ctx, req.(*LifespanRequest)) @@ -610,7 +700,7 @@ func _ClusterService_Create_Handler(srv interface{}, ctx context.Context, dec fu } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.ClusterService/Create", + FullMethod: ClusterService_Create_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ClusterServiceServer).Create(ctx, req.(*CreateClusterRequest)) @@ -628,7 +718,7 @@ func _ClusterService_Artifacts_Handler(srv interface{}, ctx context.Context, dec } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.ClusterService/Artifacts", + FullMethod: ClusterService_Artifacts_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ClusterServiceServer).Artifacts(ctx, req.(*ResourceByID)) @@ -646,7 +736,7 @@ func _ClusterService_Delete_Handler(srv interface{}, ctx context.Context, dec fu } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.ClusterService/Delete", + FullMethod: ClusterService_Delete_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ClusterServiceServer).Delete(ctx, req.(*ResourceByID)) @@ -664,7 +754,7 @@ func _ClusterService_Logs_Handler(srv interface{}, ctx context.Context, dec func } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.ClusterService/Logs", + FullMethod: ClusterService_Logs_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(ClusterServiceServer).Logs(ctx, req.(*ResourceByID)) @@ -712,12 +802,18 @@ var ClusterService_ServiceDesc = grpc.ServiceDesc{ Metadata: "service.proto", } +const ( + CliService_Upgrade_FullMethodName = "/v1.CliService/Upgrade" +) + // CliServiceClient is the client API for CliService 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. +// +// CliService provides an upgrade path for the command line interface. type CliServiceClient interface { // Upgrade - gets an updated binary if it exists. - Upgrade(ctx context.Context, in *CliUpgradeRequest, opts ...grpc.CallOption) (CliService_UpgradeClient, error) + Upgrade(ctx context.Context, in *CliUpgradeRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[CliUpgradeResponse], error) } type cliServiceClient struct { @@ -728,12 +824,13 @@ func NewCliServiceClient(cc grpc.ClientConnInterface) CliServiceClient { return &cliServiceClient{cc} } -func (c *cliServiceClient) Upgrade(ctx context.Context, in *CliUpgradeRequest, opts ...grpc.CallOption) (CliService_UpgradeClient, error) { - stream, err := c.cc.NewStream(ctx, &CliService_ServiceDesc.Streams[0], "/v1.CliService/Upgrade", opts...) +func (c *cliServiceClient) Upgrade(ctx context.Context, in *CliUpgradeRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[CliUpgradeResponse], error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + stream, err := c.cc.NewStream(ctx, &CliService_ServiceDesc.Streams[0], CliService_Upgrade_FullMethodName, cOpts...) if err != nil { return nil, err } - x := &cliServiceUpgradeClient{stream} + x := &grpc.GenericClientStream[CliUpgradeRequest, CliUpgradeResponse]{ClientStream: stream} if err := x.ClientStream.SendMsg(in); err != nil { return nil, err } @@ -743,40 +840,32 @@ func (c *cliServiceClient) Upgrade(ctx context.Context, in *CliUpgradeRequest, o return x, nil } -type CliService_UpgradeClient interface { - Recv() (*CliUpgradeResponse, error) - grpc.ClientStream -} - -type cliServiceUpgradeClient struct { - grpc.ClientStream -} - -func (x *cliServiceUpgradeClient) Recv() (*CliUpgradeResponse, error) { - m := new(CliUpgradeResponse) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil -} +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type CliService_UpgradeClient = grpc.ServerStreamingClient[CliUpgradeResponse] // CliServiceServer is the server API for CliService service. // All implementations must embed UnimplementedCliServiceServer -// for forward compatibility +// for forward compatibility. +// +// CliService provides an upgrade path for the command line interface. type CliServiceServer interface { // Upgrade - gets an updated binary if it exists. - Upgrade(*CliUpgradeRequest, CliService_UpgradeServer) error + Upgrade(*CliUpgradeRequest, grpc.ServerStreamingServer[CliUpgradeResponse]) error mustEmbedUnimplementedCliServiceServer() } -// UnimplementedCliServiceServer must be embedded to have forward compatible implementations. -type UnimplementedCliServiceServer struct { -} +// UnimplementedCliServiceServer 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 UnimplementedCliServiceServer struct{} -func (UnimplementedCliServiceServer) Upgrade(*CliUpgradeRequest, CliService_UpgradeServer) error { +func (UnimplementedCliServiceServer) Upgrade(*CliUpgradeRequest, grpc.ServerStreamingServer[CliUpgradeResponse]) error { return status.Errorf(codes.Unimplemented, "method Upgrade not implemented") } func (UnimplementedCliServiceServer) mustEmbedUnimplementedCliServiceServer() {} +func (UnimplementedCliServiceServer) testEmbeddedByValue() {} // UnsafeCliServiceServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to CliServiceServer will @@ -786,6 +875,13 @@ type UnsafeCliServiceServer interface { } func RegisterCliServiceServer(s grpc.ServiceRegistrar, srv CliServiceServer) { + // If the following call pancis, it indicates UnimplementedCliServiceServer 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(&CliService_ServiceDesc, srv) } @@ -794,21 +890,11 @@ func _CliService_Upgrade_Handler(srv interface{}, stream grpc.ServerStream) erro if err := stream.RecvMsg(m); err != nil { return err } - return srv.(CliServiceServer).Upgrade(m, &cliServiceUpgradeServer{stream}) + return srv.(CliServiceServer).Upgrade(m, &grpc.GenericServerStream[CliUpgradeRequest, CliUpgradeResponse]{ServerStream: stream}) } -type CliService_UpgradeServer interface { - Send(*CliUpgradeResponse) error - grpc.ServerStream -} - -type cliServiceUpgradeServer struct { - grpc.ServerStream -} - -func (x *cliServiceUpgradeServer) Send(m *CliUpgradeResponse) error { - return x.ServerStream.SendMsg(m) -} +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type CliService_UpgradeServer = grpc.ServerStreamingServer[CliUpgradeResponse] // CliService_ServiceDesc is the grpc.ServiceDesc for CliService service. // It's only intended for direct use with grpc.RegisterService, @@ -827,9 +913,17 @@ var CliService_ServiceDesc = grpc.ServiceDesc{ Metadata: "service.proto", } +const ( + InfraStatusService_GetStatus_FullMethodName = "/v1.InfraStatusService/GetStatus" + InfraStatusService_ResetStatus_FullMethodName = "/v1.InfraStatusService/ResetStatus" + InfraStatusService_SetStatus_FullMethodName = "/v1.InfraStatusService/SetStatus" +) + // InfraStatusServiceClient is the client API for InfraStatusService 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. +// +// InfraStatusService provides information on the status of the server. type InfraStatusServiceClient interface { // GetStatus gets the maintenance GetStatus(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*InfraStatus, error) @@ -848,8 +942,9 @@ func NewInfraStatusServiceClient(cc grpc.ClientConnInterface) InfraStatusService } func (c *infraStatusServiceClient) GetStatus(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*InfraStatus, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(InfraStatus) - err := c.cc.Invoke(ctx, "/v1.InfraStatusService/GetStatus", in, out, opts...) + err := c.cc.Invoke(ctx, InfraStatusService_GetStatus_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -857,8 +952,9 @@ func (c *infraStatusServiceClient) GetStatus(ctx context.Context, in *emptypb.Em } func (c *infraStatusServiceClient) ResetStatus(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*InfraStatus, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(InfraStatus) - err := c.cc.Invoke(ctx, "/v1.InfraStatusService/ResetStatus", in, out, opts...) + err := c.cc.Invoke(ctx, InfraStatusService_ResetStatus_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -866,8 +962,9 @@ func (c *infraStatusServiceClient) ResetStatus(ctx context.Context, in *emptypb. } func (c *infraStatusServiceClient) SetStatus(ctx context.Context, in *InfraStatus, opts ...grpc.CallOption) (*InfraStatus, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(InfraStatus) - err := c.cc.Invoke(ctx, "/v1.InfraStatusService/SetStatus", in, out, opts...) + err := c.cc.Invoke(ctx, InfraStatusService_SetStatus_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -876,7 +973,9 @@ func (c *infraStatusServiceClient) SetStatus(ctx context.Context, in *InfraStatu // InfraStatusServiceServer is the server API for InfraStatusService service. // All implementations must embed UnimplementedInfraStatusServiceServer -// for forward compatibility +// for forward compatibility. +// +// InfraStatusService provides information on the status of the server. type InfraStatusServiceServer interface { // GetStatus gets the maintenance GetStatus(context.Context, *emptypb.Empty) (*InfraStatus, error) @@ -887,9 +986,12 @@ type InfraStatusServiceServer interface { mustEmbedUnimplementedInfraStatusServiceServer() } -// UnimplementedInfraStatusServiceServer must be embedded to have forward compatible implementations. -type UnimplementedInfraStatusServiceServer struct { -} +// UnimplementedInfraStatusServiceServer 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 UnimplementedInfraStatusServiceServer struct{} func (UnimplementedInfraStatusServiceServer) GetStatus(context.Context, *emptypb.Empty) (*InfraStatus, error) { return nil, status.Errorf(codes.Unimplemented, "method GetStatus not implemented") @@ -901,6 +1003,7 @@ func (UnimplementedInfraStatusServiceServer) SetStatus(context.Context, *InfraSt return nil, status.Errorf(codes.Unimplemented, "method SetStatus not implemented") } func (UnimplementedInfraStatusServiceServer) mustEmbedUnimplementedInfraStatusServiceServer() {} +func (UnimplementedInfraStatusServiceServer) testEmbeddedByValue() {} // UnsafeInfraStatusServiceServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to InfraStatusServiceServer will @@ -910,6 +1013,13 @@ type UnsafeInfraStatusServiceServer interface { } func RegisterInfraStatusServiceServer(s grpc.ServiceRegistrar, srv InfraStatusServiceServer) { + // If the following call pancis, it indicates UnimplementedInfraStatusServiceServer 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(&InfraStatusService_ServiceDesc, srv) } @@ -923,7 +1033,7 @@ func _InfraStatusService_GetStatus_Handler(srv interface{}, ctx context.Context, } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.InfraStatusService/GetStatus", + FullMethod: InfraStatusService_GetStatus_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(InfraStatusServiceServer).GetStatus(ctx, req.(*emptypb.Empty)) @@ -941,7 +1051,7 @@ func _InfraStatusService_ResetStatus_Handler(srv interface{}, ctx context.Contex } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.InfraStatusService/ResetStatus", + FullMethod: InfraStatusService_ResetStatus_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(InfraStatusServiceServer).ResetStatus(ctx, req.(*emptypb.Empty)) @@ -959,7 +1069,7 @@ func _InfraStatusService_SetStatus_Handler(srv interface{}, ctx context.Context, } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/v1.InfraStatusService/SetStatus", + FullMethod: InfraStatusService_SetStatus_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(InfraStatusServiceServer).SetStatus(ctx, req.(*InfraStatus)) diff --git a/service/cluster/helpers.go b/service/cluster/helpers.go index 84154a267..6e5d402ee 100644 --- a/service/cluster/helpers.go +++ b/service/cluster/helpers.go @@ -11,6 +11,7 @@ import ( v1 "github.com/stackrox/infra/generated/api/v1" "github.com/stackrox/infra/pkg/logging" "github.com/stackrox/infra/slack" + "google.golang.org/protobuf/types/known/timestamppb" ) func getClusterIDFromWorkflow(workflow *v1alpha1.Workflow) string { @@ -33,10 +34,10 @@ func clusterFromWorkflow(workflow v1alpha1.Workflow) *v1.Cluster { Description: GetDescription(&workflow), } - cluster.CreatedOn, _ = ptypes.TimestampProto(workflow.Status.StartedAt.Time.UTC()) + cluster.CreatedOn = timestamppb.New(workflow.Status.StartedAt.Time.UTC()) if !workflow.Status.FinishedAt.Time.IsZero() { - cluster.DestroyedOn, _ = ptypes.TimestampProto(workflow.Status.FinishedAt.Time.UTC()) + cluster.DestroyedOn = timestamppb.New(workflow.Status.FinishedAt.Time.UTC()) } return cluster @@ -50,8 +51,12 @@ func isWorkflowExpired(workflow v1alpha1.Workflow) bool { } func isNearingExpiry(workflow v1alpha1.Workflow) bool { - lifespan, _ := ptypes.Duration(GetLifespan(&workflow)) + dur := GetLifespan(&workflow) + if !dur.IsValid() { + return false + } + lifespan := dur.AsDuration() workflowExpiryTime := workflow.Status.StartedAt.Time.Add(lifespan) return time.Now().Add(nearExpiry).After(workflowExpiryTime) }