Plugins: Add support for ResourceConversion (#91977)
This commit is contained in:
@@ -34,6 +34,7 @@ var pluginSet = map[int]goplugin.PluginSet{
|
||||
"data": &grpcplugin.DataGRPCPlugin{},
|
||||
"stream": &grpcplugin.StreamGRPCPlugin{},
|
||||
"admission": &grpcplugin.AdmissionGRPCPlugin{},
|
||||
"conversion": &grpcplugin.ConversionGRPCPlugin{},
|
||||
"renderer": &pluginextensionv2.RendererGRPCPlugin{},
|
||||
"secretsmanager": &secretsmanagerplugin.SecretsManagerGRPCPlugin{},
|
||||
},
|
||||
|
||||
@@ -26,6 +26,7 @@ type ProtoClient interface {
|
||||
pluginv2.DiagnosticsClient
|
||||
pluginv2.StreamClient
|
||||
pluginv2.AdmissionControlClient
|
||||
pluginv2.ResourceConversionClient
|
||||
|
||||
PID(context.Context) (string, error)
|
||||
PluginID() string
|
||||
@@ -202,10 +203,10 @@ func (r *protoClient) MutateAdmission(ctx context.Context, in *pluginv2.Admissio
|
||||
return c.AdmissionClient.MutateAdmission(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (r *protoClient) ConvertObject(ctx context.Context, in *pluginv2.ConversionRequest, opts ...grpc.CallOption) (*pluginv2.ConversionResponse, error) {
|
||||
func (r *protoClient) ConvertObjects(ctx context.Context, in *pluginv2.ConversionRequest, opts ...grpc.CallOption) (*pluginv2.ConversionResponse, error) {
|
||||
c, exists := r.client(ctx)
|
||||
if !exists {
|
||||
return nil, errClientNotStarted
|
||||
}
|
||||
return c.AdmissionClient.ConvertObject(ctx, in, opts...)
|
||||
return c.ConversionClient.ConvertObjects(ctx, in, opts...)
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ type ClientV2 struct {
|
||||
grpcplugin.DataClient
|
||||
grpcplugin.StreamClient
|
||||
grpcplugin.AdmissionClient
|
||||
grpcplugin.ConversionClient
|
||||
pluginextensionv2.RendererPlugin
|
||||
secretsmanagerplugin.SecretsManagerPlugin
|
||||
}
|
||||
@@ -50,6 +51,11 @@ func newClientV2(descriptor PluginDescriptor, logger log.Logger, rpcClient plugi
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rawConversion, err := rpcClient.Dispense("conversion")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rawStream, err := rpcClient.Dispense("stream")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -90,6 +96,12 @@ func newClientV2(descriptor PluginDescriptor, logger log.Logger, rpcClient plugi
|
||||
}
|
||||
}
|
||||
|
||||
if rawConversion != nil {
|
||||
if conversionClient, ok := rawConversion.(grpcplugin.ConversionClient); ok {
|
||||
c.ConversionClient = conversionClient
|
||||
}
|
||||
}
|
||||
|
||||
if rawStream != nil {
|
||||
if streamClient, ok := rawStream.(grpcplugin.StreamClient); ok {
|
||||
c.StreamClient = streamClient
|
||||
@@ -308,13 +320,13 @@ func (c *ClientV2) MutateAdmission(ctx context.Context, req *backend.AdmissionRe
|
||||
return backend.FromProto().MutationResponse(protoResp), nil
|
||||
}
|
||||
|
||||
func (c *ClientV2) ConvertObject(ctx context.Context, req *backend.ConversionRequest) (*backend.ConversionResponse, error) {
|
||||
if c.AdmissionClient == nil {
|
||||
func (c *ClientV2) ConvertObjects(ctx context.Context, req *backend.ConversionRequest) (*backend.ConversionResponse, error) {
|
||||
if c.ConversionClient == nil {
|
||||
return nil, plugins.ErrMethodNotImplemented
|
||||
}
|
||||
|
||||
protoReq := backend.ToProto().ConversionRequest(req)
|
||||
protoResp, err := c.AdmissionClient.ConvertObject(ctx, protoReq)
|
||||
protoResp, err := c.ConversionClient.ConvertObjects(ctx, protoReq)
|
||||
|
||||
if err != nil {
|
||||
if status.Code(err) == codes.Unimplemented {
|
||||
|
||||
@@ -20,6 +20,7 @@ type pluginClient interface {
|
||||
backend.QueryDataHandler
|
||||
backend.CallResourceHandler
|
||||
backend.AdmissionHandler
|
||||
backend.ConversionHandler
|
||||
backend.StreamHandler
|
||||
}
|
||||
|
||||
@@ -217,10 +218,10 @@ func (p *grpcPlugin) MutateAdmission(ctx context.Context, request *backend.Admis
|
||||
return pluginClient.MutateAdmission(ctx, request)
|
||||
}
|
||||
|
||||
func (p *grpcPlugin) ConvertObject(ctx context.Context, request *backend.ConversionRequest) (*backend.ConversionResponse, error) {
|
||||
func (p *grpcPlugin) ConvertObjects(ctx context.Context, request *backend.ConversionRequest) (*backend.ConversionResponse, error) {
|
||||
pluginClient, ok := p.getPluginClient()
|
||||
if !ok {
|
||||
return nil, plugins.ErrPluginUnavailable
|
||||
}
|
||||
return pluginClient.ConvertObject(ctx, request)
|
||||
return pluginClient.ConvertObjects(ctx, request)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user