diff --git a/hook/types.go b/hook/types.go index d81b34a1..d6293ac3 100644 --- a/hook/types.go +++ b/hook/types.go @@ -6,6 +6,13 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) +// ClientHook tells the sdk that this action watches on certain vcluster requests and wants +// to mutate these. The objects this action wants to watch can be defined through the +// Resource() function that returns a new object of the type to watch. By implementing +// the defined interfaces below it is possible to watch on: +// Create, Update (includes patch requests), Delete and Get requests. +// This makes it possible to change incoming or outgoing objects on the fly, without the +// need to completely replace a vanilla vcluster syncer. type ClientHook interface { syncer.Base diff --git a/plugin/plugin.go b/plugin/plugin.go index 99f5264a..952dd837 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -37,6 +37,8 @@ type Options struct { ListenAddress string } +type LeaderElectionHook func(ctx context.Context) error + type Manager interface { // Init creates a new plugin context and will block until the // vcluster container instance could be contacted. @@ -101,6 +103,7 @@ type manager struct { started bool syncers []syncer.Base + name string address string context *synccontext.RegisterContext @@ -125,6 +128,7 @@ func (m *manager) InitWithOptions(name string, opts Options) (*synccontext.Regis m.initialized = true log := log.New("plugin") + m.name = name m.address = "localhost:10099" if opts.ListenAddress != "" { m.address = opts.ListenAddress @@ -142,10 +146,7 @@ func (m *manager) InitWithOptions(name string, opts Options) (*synccontext.Regis ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() - pluginContext, err = remote.NewPluginInitializerClient(conn).Register(ctx, &remote.PluginInfo{ - Name: name, - Version: "v2", - }) + pluginContext, err = remote.NewVClusterClient(conn).GetContext(ctx, &remote.Empty{}) if err != nil { return false, nil } @@ -258,7 +259,7 @@ func (m *manager) Start() error { return nil } -func (m *manager) startHookServer(log log.Logger) error { +func (m *manager) registerPlugin(log log.Logger) error { serverAddress := os.Getenv(PLUGIN_SERVER_ADDRESS) if serverAddress == "" { log.Errorf("Environment variable %s not defined, are you using an old vcluster version?", PLUGIN_SERVER_ADDRESS) @@ -386,24 +387,47 @@ func (m *manager) startHookServer(log log.Logger) error { } // start the grpc server - log.Infof("Plugin server listening on %s", serverAddress) - lis, err := net.Listen("tcp", serverAddress) + if len(registeredHooks) > 0 { + log.Infof("Plugin server listening on %s", serverAddress) + lis, err := net.Listen("tcp", serverAddress) + if err != nil { + return fmt.Errorf("failed to listen: %v", err) + } + + var opts []grpc.ServerOption + grpcServer := grpc.NewServer(opts...) + remote.RegisterPluginServer(grpcServer, &pluginServer{ + hooks: hooks, + registeredHooks: registeredHooks, + }) + go func() { + err := grpcServer.Serve(lis) + if err != nil { + panic(err) + } + }() + } + + // register the plugin + ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) + defer cancel() + + conn, err := grpc.Dial(m.address, grpc.WithInsecure()) if err != nil { - return fmt.Errorf("failed to listen: %v", err) + return fmt.Errorf("error dialing vcluster: %v", err) } - var opts []grpc.ServerOption - grpcServer := grpc.NewServer(opts...) - remote.RegisterPluginServer(grpcServer, &pluginServer{ - hooks: hooks, - registeredHooks: registeredHooks, + defer conn.Close() + _, err = remote.NewVClusterClient(conn).RegisterPlugin(ctx, &remote.RegisterPluginRequest{ + Version: "v1", + Name: m.name, + Address: serverAddress, + ClientHooks: registeredHooks, }) - go func() { - err := grpcServer.Serve(lis) - if err != nil { - panic(err) - } - }() + if err != nil { + log.Errorf("error trying to connect to vcluster: %v", err) + return err + } return nil } @@ -414,7 +438,7 @@ func (m *manager) start() error { return fmt.Errorf("manager was already started") } - err := m.startHookServer(log) + err := m.registerPlugin(log) if err != nil { return errors.Wrap(err, "start hook server") } @@ -429,7 +453,7 @@ func (m *manager) start() error { ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() - isLeader, err := remote.NewPluginInitializerClient(conn).IsLeader(ctx, &remote.Empty{}) + isLeader, err := remote.NewVClusterClient(conn).IsLeader(ctx, &remote.Empty{}) if err != nil { log.Errorf("error trying to connect to vcluster: %v", err) conn.Close() diff --git a/plugin/plugin_server.go b/plugin/plugin_server.go index 0b81935e..fa2bc837 100644 --- a/plugin/plugin_server.go +++ b/plugin/plugin_server.go @@ -23,10 +23,6 @@ type ApiVersionKindType struct { var _ remote.PluginServer = &pluginServer{} -func (p *pluginServer) Register(ctx context.Context, req *remote.RegisterPluginRequest) (*remote.RegisterPluginResult, error) { - return &remote.RegisterPluginResult{ClientHooks: p.registeredHooks}, nil -} - func (p *pluginServer) Mutate(ctx context.Context, req *remote.MutateRequest) (*remote.MutateResult, error) { hooks, ok := p.hooks[ApiVersionKindType{ ApiVersion: req.ApiVersion, diff --git a/plugin/remote/plugin.pb.go b/plugin/remote/plugin.pb.go index 6181d2be..9d20bd7e 100644 --- a/plugin/remote/plugin.pb.go +++ b/plugin/remote/plugin.pb.go @@ -26,6 +26,11 @@ type RegisterPluginRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Address string `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"` + ClientHooks []*ClientHook `protobuf:"bytes,4,rep,name=clientHooks,proto3" json:"clientHooks,omitempty"` } func (x *RegisterPluginRequest) Reset() { @@ -60,12 +65,38 @@ func (*RegisterPluginRequest) Descriptor() ([]byte, []int) { return file_plugin_proto_rawDescGZIP(), []int{0} } +func (x *RegisterPluginRequest) GetVersion() string { + if x != nil { + return x.Version + } + return "" +} + +func (x *RegisterPluginRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *RegisterPluginRequest) GetAddress() string { + if x != nil { + return x.Address + } + return "" +} + +func (x *RegisterPluginRequest) GetClientHooks() []*ClientHook { + if x != nil { + return x.ClientHooks + } + return nil +} + type RegisterPluginResult struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - - ClientHooks []*ClientHook `protobuf:"bytes,1,rep,name=clientHooks,proto3" json:"clientHooks,omitempty"` } func (x *RegisterPluginResult) Reset() { @@ -100,25 +131,16 @@ func (*RegisterPluginResult) Descriptor() ([]byte, []int) { return file_plugin_proto_rawDescGZIP(), []int{1} } -func (x *RegisterPluginResult) GetClientHooks() []*ClientHook { - if x != nil { - return x.ClientHooks - } - return nil -} - -type ClientHook struct { +type PluginInfo struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ApiVersion string `protobuf:"bytes,1,opt,name=apiVersion,proto3" json:"apiVersion,omitempty"` - Kind string `protobuf:"bytes,2,opt,name=kind,proto3" json:"kind,omitempty"` - Types []string `protobuf:"bytes,3,rep,name=types,proto3" json:"types,omitempty"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` } -func (x *ClientHook) Reset() { - *x = ClientHook{} +func (x *PluginInfo) Reset() { + *x = PluginInfo{} if protoimpl.UnsafeEnabled { mi := &file_plugin_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -126,13 +148,13 @@ func (x *ClientHook) Reset() { } } -func (x *ClientHook) String() string { +func (x *PluginInfo) String() string { return protoimpl.X.MessageStringOf(x) } -func (*ClientHook) ProtoMessage() {} +func (*PluginInfo) ProtoMessage() {} -func (x *ClientHook) ProtoReflect() protoreflect.Message { +func (x *PluginInfo) ProtoReflect() protoreflect.Message { mi := &file_plugin_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -144,32 +166,18 @@ func (x *ClientHook) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use ClientHook.ProtoReflect.Descriptor instead. -func (*ClientHook) Descriptor() ([]byte, []int) { +// Deprecated: Use PluginInfo.ProtoReflect.Descriptor instead. +func (*PluginInfo) Descriptor() ([]byte, []int) { return file_plugin_proto_rawDescGZIP(), []int{2} } -func (x *ClientHook) GetApiVersion() string { - if x != nil { - return x.ApiVersion - } - return "" -} - -func (x *ClientHook) GetKind() string { +func (x *PluginInfo) GetName() string { if x != nil { - return x.Kind + return x.Name } return "" } -func (x *ClientHook) GetTypes() []string { - if x != nil { - return x.Types - } - return nil -} - type MutateRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -301,7 +309,8 @@ type LeaderInfo struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Leader bool `protobuf:"varint,1,opt,name=leader,proto3" json:"leader,omitempty"` + Leader bool `protobuf:"varint,1,opt,name=leader,proto3" json:"leader,omitempty"` + RunID string `protobuf:"bytes,2,opt,name=runID,proto3" json:"runID,omitempty"` } func (x *LeaderInfo) Reset() { @@ -343,17 +352,25 @@ func (x *LeaderInfo) GetLeader() bool { return false } -type PluginInfo struct { +func (x *LeaderInfo) GetRunID() string { + if x != nil { + return x.RunID + } + return "" +} + +type ClientHook struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` + ApiVersion string `protobuf:"bytes,1,opt,name=apiVersion,proto3" json:"apiVersion,omitempty"` + Kind string `protobuf:"bytes,2,opt,name=kind,proto3" json:"kind,omitempty"` + Types []string `protobuf:"bytes,3,rep,name=types,proto3" json:"types,omitempty"` } -func (x *PluginInfo) Reset() { - *x = PluginInfo{} +func (x *ClientHook) Reset() { + *x = ClientHook{} if protoimpl.UnsafeEnabled { mi := &file_plugin_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -361,13 +378,13 @@ func (x *PluginInfo) Reset() { } } -func (x *PluginInfo) String() string { +func (x *ClientHook) String() string { return protoimpl.X.MessageStringOf(x) } -func (*PluginInfo) ProtoMessage() {} +func (*ClientHook) ProtoMessage() {} -func (x *PluginInfo) ProtoReflect() protoreflect.Message { +func (x *ClientHook) ProtoReflect() protoreflect.Message { mi := &file_plugin_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -379,25 +396,32 @@ func (x *PluginInfo) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use PluginInfo.ProtoReflect.Descriptor instead. -func (*PluginInfo) Descriptor() ([]byte, []int) { +// Deprecated: Use ClientHook.ProtoReflect.Descriptor instead. +func (*ClientHook) Descriptor() ([]byte, []int) { return file_plugin_proto_rawDescGZIP(), []int{6} } -func (x *PluginInfo) GetName() string { +func (x *ClientHook) GetApiVersion() string { if x != nil { - return x.Name + return x.ApiVersion } return "" } -func (x *PluginInfo) GetVersion() string { +func (x *ClientHook) GetKind() string { if x != nil { - return x.Version + return x.Kind } return "" } +func (x *ClientHook) GetTypes() []string { + if x != nil { + return x.Types + } + return nil +} + type Context struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -527,73 +551,80 @@ var File_plugin_proto protoreflect.FileDescriptor var file_plugin_proto_rawDesc = []byte{ 0x0a, 0x0c, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, - 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x22, 0x17, 0x0a, 0x15, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, - 0x65, 0x72, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, - 0x4c, 0x0a, 0x14, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x50, 0x6c, 0x75, 0x67, 0x69, - 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x34, 0x0a, 0x0b, 0x63, 0x6c, 0x69, 0x65, 0x6e, - 0x74, 0x48, 0x6f, 0x6f, 0x6b, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x72, - 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x48, 0x6f, 0x6f, 0x6b, - 0x52, 0x0b, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x48, 0x6f, 0x6f, 0x6b, 0x73, 0x22, 0x56, 0x0a, - 0x0a, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x48, 0x6f, 0x6f, 0x6b, 0x12, 0x1e, 0x0a, 0x0a, 0x61, - 0x70, 0x69, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0a, 0x61, 0x70, 0x69, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6b, - 0x69, 0x6e, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x12, - 0x14, 0x0a, 0x05, 0x74, 0x79, 0x70, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, - 0x74, 0x79, 0x70, 0x65, 0x73, 0x22, 0x6f, 0x0a, 0x0d, 0x4d, 0x75, 0x74, 0x61, 0x74, 0x65, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x61, 0x70, 0x69, 0x56, 0x65, 0x72, - 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x61, 0x70, 0x69, 0x56, - 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x62, - 0x6a, 0x65, 0x63, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x62, 0x6a, 0x65, - 0x63, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x40, 0x0a, 0x0c, 0x4d, 0x75, 0x74, 0x61, 0x74, 0x65, - 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x18, - 0x0a, 0x07, 0x6d, 0x75, 0x74, 0x61, 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, - 0x07, 0x6d, 0x75, 0x74, 0x61, 0x74, 0x65, 0x64, 0x22, 0x24, 0x0a, 0x0a, 0x4c, 0x65, 0x61, 0x64, - 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x65, 0x61, 0x64, 0x65, 0x72, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x6c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x22, 0x3a, - 0x0a, 0x0a, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x12, 0x0a, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, - 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x87, 0x02, 0x0a, 0x07, 0x43, - 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x12, 0x32, 0x0a, 0x14, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, - 0x6c, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x14, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x6c, 0x75, - 0x73, 0x74, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x34, 0x0a, 0x15, 0x70, 0x68, - 0x79, 0x73, 0x69, 0x63, 0x61, 0x6c, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x43, 0x6f, 0x6e, - 0x66, 0x69, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x15, 0x70, 0x68, 0x79, 0x73, 0x69, - 0x63, 0x61, 0x6c, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x79, 0x6e, 0x63, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x79, 0x6e, 0x63, 0x65, 0x72, 0x43, 0x6f, - 0x6e, 0x66, 0x69, 0x67, 0x12, 0x28, 0x0a, 0x0f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x4e, 0x61, - 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x74, - 0x61, 0x72, 0x67, 0x65, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x2a, - 0x0a, 0x10, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, - 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, - 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x70, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x70, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x32, 0x77, 0x0a, - 0x11, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x49, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, - 0x65, 0x72, 0x12, 0x31, 0x0a, 0x08, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x12, 0x12, - 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x49, 0x6e, - 0x66, 0x6f, 0x1a, 0x0f, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x74, - 0x65, 0x78, 0x74, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x08, 0x49, 0x73, 0x4c, 0x65, 0x61, 0x64, 0x65, - 0x72, 0x12, 0x0d, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, - 0x1a, 0x12, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x4c, 0x65, 0x61, 0x64, 0x65, 0x72, - 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x00, 0x32, 0x8c, 0x01, 0x0a, 0x06, 0x50, 0x6c, 0x75, 0x67, 0x69, - 0x6e, 0x12, 0x49, 0x0a, 0x08, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x12, 0x1d, 0x2e, - 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x50, - 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x72, - 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x50, 0x6c, - 0x75, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, - 0x4d, 0x75, 0x74, 0x61, 0x74, 0x65, 0x12, 0x15, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, - 0x4d, 0x75, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, - 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x4d, 0x75, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, - 0x75, 0x6c, 0x74, 0x22, 0x00, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x6f, 0x66, 0x74, 0x2d, 0x73, 0x68, 0x2f, 0x76, 0x63, 0x6c, 0x75, - 0x73, 0x74, 0x65, 0x72, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2f, - 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x22, 0x95, 0x01, 0x0a, 0x15, 0x52, 0x65, 0x67, 0x69, 0x73, + 0x74, 0x65, 0x72, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, + 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, + 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x34, 0x0a, 0x0b, 0x63, 0x6c, 0x69, 0x65, + 0x6e, 0x74, 0x48, 0x6f, 0x6f, 0x6b, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, + 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x48, 0x6f, 0x6f, + 0x6b, 0x52, 0x0b, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x48, 0x6f, 0x6f, 0x6b, 0x73, 0x22, 0x16, + 0x0a, 0x14, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, + 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x20, 0x0a, 0x0a, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, + 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x6f, 0x0a, 0x0d, 0x4d, 0x75, 0x74, 0x61, + 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x61, 0x70, 0x69, + 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x61, + 0x70, 0x69, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6b, 0x69, 0x6e, + 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x12, 0x16, 0x0a, + 0x06, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, + 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x40, 0x0a, 0x0c, 0x4d, 0x75, 0x74, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x62, 0x6a, + 0x65, 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x62, 0x6a, 0x65, 0x63, + 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x75, 0x74, 0x61, 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x07, 0x6d, 0x75, 0x74, 0x61, 0x74, 0x65, 0x64, 0x22, 0x3a, 0x0a, 0x0a, 0x4c, + 0x65, 0x61, 0x64, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x16, 0x0a, 0x06, 0x6c, 0x65, 0x61, + 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x6c, 0x65, 0x61, 0x64, 0x65, + 0x72, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x75, 0x6e, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x72, 0x75, 0x6e, 0x49, 0x44, 0x22, 0x56, 0x0a, 0x0a, 0x43, 0x6c, 0x69, 0x65, 0x6e, + 0x74, 0x48, 0x6f, 0x6f, 0x6b, 0x12, 0x1e, 0x0a, 0x0a, 0x61, 0x70, 0x69, 0x56, 0x65, 0x72, 0x73, + 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x61, 0x70, 0x69, 0x56, 0x65, + 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x6b, 0x69, 0x6e, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x79, 0x70, + 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x05, 0x74, 0x79, 0x70, 0x65, 0x73, 0x22, + 0x87, 0x02, 0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x12, 0x32, 0x0a, 0x14, 0x76, + 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x43, 0x6f, 0x6e, + 0x66, 0x69, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x14, 0x76, 0x69, 0x72, 0x74, 0x75, + 0x61, 0x6c, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, + 0x34, 0x0a, 0x15, 0x70, 0x68, 0x79, 0x73, 0x69, 0x63, 0x61, 0x6c, 0x43, 0x6c, 0x75, 0x73, 0x74, + 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x15, + 0x70, 0x68, 0x79, 0x73, 0x69, 0x63, 0x61, 0x6c, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x79, 0x6e, 0x63, 0x65, 0x72, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x79, 0x6e, + 0x63, 0x65, 0x72, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x28, 0x0a, 0x0f, 0x74, 0x61, 0x72, + 0x67, 0x65, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, + 0x61, 0x63, 0x65, 0x12, 0x2a, 0x0a, 0x10, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x4e, 0x61, + 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x63, + 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, + 0x18, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, + 0x74, 0x79, 0x32, 0xef, 0x01, 0x0a, 0x08, 0x56, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x12, + 0x31, 0x0a, 0x08, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x12, 0x12, 0x2e, 0x72, 0x65, + 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x1a, + 0x0f, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, + 0x22, 0x00, 0x12, 0x4f, 0x0a, 0x0e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x50, 0x6c, + 0x75, 0x67, 0x69, 0x6e, 0x12, 0x1d, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x52, 0x65, + 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x52, 0x65, 0x67, + 0x69, 0x73, 0x74, 0x65, 0x72, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6c, + 0x74, 0x22, 0x00, 0x12, 0x2e, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, + 0x74, 0x12, 0x0d, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, + 0x1a, 0x0f, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, + 0x74, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x08, 0x49, 0x73, 0x4c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x12, + 0x0d, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x12, + 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x4c, 0x65, 0x61, 0x64, 0x65, 0x72, 0x49, 0x6e, + 0x66, 0x6f, 0x22, 0x00, 0x32, 0x41, 0x0a, 0x06, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x12, 0x37, + 0x0a, 0x06, 0x4d, 0x75, 0x74, 0x61, 0x74, 0x65, 0x12, 0x15, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, + 0x65, 0x2e, 0x4d, 0x75, 0x74, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x14, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x4d, 0x75, 0x74, 0x61, 0x74, 0x65, 0x52, + 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x00, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x6f, 0x66, 0x74, 0x2d, 0x73, 0x68, 0x2f, 0x76, 0x63, + 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, + 0x6e, 0x2f, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -612,26 +643,28 @@ var file_plugin_proto_msgTypes = make([]protoimpl.MessageInfo, 9) var file_plugin_proto_goTypes = []interface{}{ (*RegisterPluginRequest)(nil), // 0: remote.RegisterPluginRequest (*RegisterPluginResult)(nil), // 1: remote.RegisterPluginResult - (*ClientHook)(nil), // 2: remote.ClientHook + (*PluginInfo)(nil), // 2: remote.PluginInfo (*MutateRequest)(nil), // 3: remote.MutateRequest (*MutateResult)(nil), // 4: remote.MutateResult (*LeaderInfo)(nil), // 5: remote.LeaderInfo - (*PluginInfo)(nil), // 6: remote.PluginInfo + (*ClientHook)(nil), // 6: remote.ClientHook (*Context)(nil), // 7: remote.Context (*Empty)(nil), // 8: remote.Empty } var file_plugin_proto_depIdxs = []int32{ - 2, // 0: remote.RegisterPluginResult.clientHooks:type_name -> remote.ClientHook - 6, // 1: remote.PluginInitializer.Register:input_type -> remote.PluginInfo - 8, // 2: remote.PluginInitializer.IsLeader:input_type -> remote.Empty - 0, // 3: remote.Plugin.Register:input_type -> remote.RegisterPluginRequest - 3, // 4: remote.Plugin.Mutate:input_type -> remote.MutateRequest - 7, // 5: remote.PluginInitializer.Register:output_type -> remote.Context - 5, // 6: remote.PluginInitializer.IsLeader:output_type -> remote.LeaderInfo - 1, // 7: remote.Plugin.Register:output_type -> remote.RegisterPluginResult - 4, // 8: remote.Plugin.Mutate:output_type -> remote.MutateResult - 5, // [5:9] is the sub-list for method output_type - 1, // [1:5] is the sub-list for method input_type + 6, // 0: remote.RegisterPluginRequest.clientHooks:type_name -> remote.ClientHook + 2, // 1: remote.VCluster.Register:input_type -> remote.PluginInfo + 0, // 2: remote.VCluster.RegisterPlugin:input_type -> remote.RegisterPluginRequest + 8, // 3: remote.VCluster.GetContext:input_type -> remote.Empty + 8, // 4: remote.VCluster.IsLeader:input_type -> remote.Empty + 3, // 5: remote.Plugin.Mutate:input_type -> remote.MutateRequest + 7, // 6: remote.VCluster.Register:output_type -> remote.Context + 1, // 7: remote.VCluster.RegisterPlugin:output_type -> remote.RegisterPluginResult + 7, // 8: remote.VCluster.GetContext:output_type -> remote.Context + 5, // 9: remote.VCluster.IsLeader:output_type -> remote.LeaderInfo + 4, // 10: remote.Plugin.Mutate:output_type -> remote.MutateResult + 6, // [6:11] is the sub-list for method output_type + 1, // [1:6] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name 1, // [1:1] is the sub-list for extension extendee 0, // [0:1] is the sub-list for field type_name @@ -668,7 +701,7 @@ func file_plugin_proto_init() { } } file_plugin_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ClientHook); i { + switch v := v.(*PluginInfo); i { case 0: return &v.state case 1: @@ -716,7 +749,7 @@ func file_plugin_proto_init() { } } file_plugin_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PluginInfo); i { + switch v := v.(*ClientHook); i { case 0: return &v.state case 1: diff --git a/plugin/remote/plugin.proto b/plugin/remote/plugin.proto index 803aeb7f..b2431d0e 100644 --- a/plugin/remote/plugin.proto +++ b/plugin/remote/plugin.proto @@ -5,28 +5,32 @@ package remote; option go_package = "github.com/loft-sh/vcluster/pkg/plugin/remote"; -service PluginInitializer { +service VCluster { + // Deprecated: Use GetContext & RegisterPlugin instead rpc Register (PluginInfo) returns (Context) {} + + rpc RegisterPlugin (RegisterPluginRequest) returns (RegisterPluginResult) {} + rpc GetContext (Empty) returns (Context) {} rpc IsLeader (Empty) returns (LeaderInfo) {} } service Plugin { - rpc Register (RegisterPluginRequest) returns (RegisterPluginResult) {} rpc Mutate (MutateRequest) returns (MutateResult) {} } message RegisterPluginRequest { - + string version = 1; + string name = 2; + string address = 3; + repeated ClientHook clientHooks = 4; } message RegisterPluginResult { - repeated ClientHook clientHooks = 1; + } -message ClientHook { - string apiVersion = 1; - string kind = 2; - repeated string types = 3; +message PluginInfo { + string name = 1; } message MutateRequest { @@ -43,11 +47,13 @@ message MutateResult { message LeaderInfo { bool leader = 1; + string runID = 2; } -message PluginInfo { - string name = 1; - string version = 2; +message ClientHook { + string apiVersion = 1; + string kind = 2; + repeated string types = 3; } message Context { diff --git a/plugin/remote/plugin_grpc.pb.go b/plugin/remote/plugin_grpc.pb.go index dc11b26d..b54478c3 100644 --- a/plugin/remote/plugin_grpc.pb.go +++ b/plugin/remote/plugin_grpc.pb.go @@ -18,122 +18,196 @@ import ( // Requires gRPC-Go v1.32.0 or later. const _ = grpc.SupportPackageIsVersion7 -// PluginInitializerClient is the client API for PluginInitializer service. +// VClusterClient is the client API for VCluster 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 PluginInitializerClient interface { +type VClusterClient interface { + // Deprecated: Use GetContext & RegisterPlugin instead Register(ctx context.Context, in *PluginInfo, opts ...grpc.CallOption) (*Context, error) + RegisterPlugin(ctx context.Context, in *RegisterPluginRequest, opts ...grpc.CallOption) (*RegisterPluginResult, error) + GetContext(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Context, error) IsLeader(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*LeaderInfo, error) } -type pluginInitializerClient struct { +type vClusterClient struct { cc grpc.ClientConnInterface } -func NewPluginInitializerClient(cc grpc.ClientConnInterface) PluginInitializerClient { - return &pluginInitializerClient{cc} +func NewVClusterClient(cc grpc.ClientConnInterface) VClusterClient { + return &vClusterClient{cc} } -func (c *pluginInitializerClient) Register(ctx context.Context, in *PluginInfo, opts ...grpc.CallOption) (*Context, error) { +func (c *vClusterClient) Register(ctx context.Context, in *PluginInfo, opts ...grpc.CallOption) (*Context, error) { out := new(Context) - err := c.cc.Invoke(ctx, "/remote.PluginInitializer/Register", in, out, opts...) + err := c.cc.Invoke(ctx, "/remote.VCluster/Register", in, out, opts...) if err != nil { return nil, err } return out, nil } -func (c *pluginInitializerClient) IsLeader(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*LeaderInfo, error) { +func (c *vClusterClient) RegisterPlugin(ctx context.Context, in *RegisterPluginRequest, opts ...grpc.CallOption) (*RegisterPluginResult, error) { + out := new(RegisterPluginResult) + err := c.cc.Invoke(ctx, "/remote.VCluster/RegisterPlugin", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *vClusterClient) GetContext(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Context, error) { + out := new(Context) + err := c.cc.Invoke(ctx, "/remote.VCluster/GetContext", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *vClusterClient) IsLeader(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*LeaderInfo, error) { out := new(LeaderInfo) - err := c.cc.Invoke(ctx, "/remote.PluginInitializer/IsLeader", in, out, opts...) + err := c.cc.Invoke(ctx, "/remote.VCluster/IsLeader", in, out, opts...) if err != nil { return nil, err } return out, nil } -// PluginInitializerServer is the server API for PluginInitializer service. -// All implementations must embed UnimplementedPluginInitializerServer +// VClusterServer is the server API for VCluster service. +// All implementations must embed UnimplementedVClusterServer // for forward compatibility -type PluginInitializerServer interface { +type VClusterServer interface { + // Deprecated: Use GetContext & RegisterPlugin instead Register(context.Context, *PluginInfo) (*Context, error) + RegisterPlugin(context.Context, *RegisterPluginRequest) (*RegisterPluginResult, error) + GetContext(context.Context, *Empty) (*Context, error) IsLeader(context.Context, *Empty) (*LeaderInfo, error) - mustEmbedUnimplementedPluginInitializerServer() + mustEmbedUnimplementedVClusterServer() } -// UnimplementedPluginInitializerServer must be embedded to have forward compatible implementations. -type UnimplementedPluginInitializerServer struct { +// UnimplementedVClusterServer must be embedded to have forward compatible implementations. +type UnimplementedVClusterServer struct { } -func (UnimplementedPluginInitializerServer) Register(context.Context, *PluginInfo) (*Context, error) { +func (UnimplementedVClusterServer) Register(context.Context, *PluginInfo) (*Context, error) { return nil, status.Errorf(codes.Unimplemented, "method Register not implemented") } -func (UnimplementedPluginInitializerServer) IsLeader(context.Context, *Empty) (*LeaderInfo, error) { +func (UnimplementedVClusterServer) RegisterPlugin(context.Context, *RegisterPluginRequest) (*RegisterPluginResult, error) { + return nil, status.Errorf(codes.Unimplemented, "method RegisterPlugin not implemented") +} +func (UnimplementedVClusterServer) GetContext(context.Context, *Empty) (*Context, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetContext not implemented") +} +func (UnimplementedVClusterServer) IsLeader(context.Context, *Empty) (*LeaderInfo, error) { return nil, status.Errorf(codes.Unimplemented, "method IsLeader not implemented") } -func (UnimplementedPluginInitializerServer) mustEmbedUnimplementedPluginInitializerServer() {} +func (UnimplementedVClusterServer) mustEmbedUnimplementedVClusterServer() {} -// UnsafePluginInitializerServer may be embedded to opt out of forward compatibility for this service. -// Use of this interface is not recommended, as added methods to PluginInitializerServer will +// UnsafeVClusterServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to VClusterServer will // result in compilation errors. -type UnsafePluginInitializerServer interface { - mustEmbedUnimplementedPluginInitializerServer() +type UnsafeVClusterServer interface { + mustEmbedUnimplementedVClusterServer() } -func RegisterPluginInitializerServer(s grpc.ServiceRegistrar, srv PluginInitializerServer) { - s.RegisterService(&PluginInitializer_ServiceDesc, srv) +func RegisterVClusterServer(s grpc.ServiceRegistrar, srv VClusterServer) { + s.RegisterService(&VCluster_ServiceDesc, srv) } -func _PluginInitializer_Register_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _VCluster_Register_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(PluginInfo) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(PluginInitializerServer).Register(ctx, in) + return srv.(VClusterServer).Register(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/remote.VCluster/Register", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VClusterServer).Register(ctx, req.(*PluginInfo)) + } + return interceptor(ctx, in, info, handler) +} + +func _VCluster_RegisterPlugin_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RegisterPluginRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VClusterServer).RegisterPlugin(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/remote.VCluster/RegisterPlugin", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VClusterServer).RegisterPlugin(ctx, req.(*RegisterPluginRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _VCluster_GetContext_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VClusterServer).GetContext(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/remote.PluginInitializer/Register", + FullMethod: "/remote.VCluster/GetContext", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(PluginInitializerServer).Register(ctx, req.(*PluginInfo)) + return srv.(VClusterServer).GetContext(ctx, req.(*Empty)) } return interceptor(ctx, in, info, handler) } -func _PluginInitializer_IsLeader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _VCluster_IsLeader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(Empty) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(PluginInitializerServer).IsLeader(ctx, in) + return srv.(VClusterServer).IsLeader(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/remote.PluginInitializer/IsLeader", + FullMethod: "/remote.VCluster/IsLeader", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(PluginInitializerServer).IsLeader(ctx, req.(*Empty)) + return srv.(VClusterServer).IsLeader(ctx, req.(*Empty)) } return interceptor(ctx, in, info, handler) } -// PluginInitializer_ServiceDesc is the grpc.ServiceDesc for PluginInitializer service. +// VCluster_ServiceDesc is the grpc.ServiceDesc for VCluster service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) -var PluginInitializer_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "remote.PluginInitializer", - HandlerType: (*PluginInitializerServer)(nil), +var VCluster_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "remote.VCluster", + HandlerType: (*VClusterServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "Register", - Handler: _PluginInitializer_Register_Handler, + Handler: _VCluster_Register_Handler, + }, + { + MethodName: "RegisterPlugin", + Handler: _VCluster_RegisterPlugin_Handler, + }, + { + MethodName: "GetContext", + Handler: _VCluster_GetContext_Handler, }, { MethodName: "IsLeader", - Handler: _PluginInitializer_IsLeader_Handler, + Handler: _VCluster_IsLeader_Handler, }, }, Streams: []grpc.StreamDesc{}, @@ -144,7 +218,6 @@ var PluginInitializer_ServiceDesc = grpc.ServiceDesc{ // // 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 PluginClient interface { - Register(ctx context.Context, in *RegisterPluginRequest, opts ...grpc.CallOption) (*RegisterPluginResult, error) Mutate(ctx context.Context, in *MutateRequest, opts ...grpc.CallOption) (*MutateResult, error) } @@ -156,15 +229,6 @@ func NewPluginClient(cc grpc.ClientConnInterface) PluginClient { return &pluginClient{cc} } -func (c *pluginClient) Register(ctx context.Context, in *RegisterPluginRequest, opts ...grpc.CallOption) (*RegisterPluginResult, error) { - out := new(RegisterPluginResult) - err := c.cc.Invoke(ctx, "/remote.Plugin/Register", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *pluginClient) Mutate(ctx context.Context, in *MutateRequest, opts ...grpc.CallOption) (*MutateResult, error) { out := new(MutateResult) err := c.cc.Invoke(ctx, "/remote.Plugin/Mutate", in, out, opts...) @@ -178,7 +242,6 @@ func (c *pluginClient) Mutate(ctx context.Context, in *MutateRequest, opts ...gr // All implementations must embed UnimplementedPluginServer // for forward compatibility type PluginServer interface { - Register(context.Context, *RegisterPluginRequest) (*RegisterPluginResult, error) Mutate(context.Context, *MutateRequest) (*MutateResult, error) mustEmbedUnimplementedPluginServer() } @@ -187,9 +250,6 @@ type PluginServer interface { type UnimplementedPluginServer struct { } -func (UnimplementedPluginServer) Register(context.Context, *RegisterPluginRequest) (*RegisterPluginResult, error) { - return nil, status.Errorf(codes.Unimplemented, "method Register not implemented") -} func (UnimplementedPluginServer) Mutate(context.Context, *MutateRequest) (*MutateResult, error) { return nil, status.Errorf(codes.Unimplemented, "method Mutate not implemented") } @@ -206,24 +266,6 @@ func RegisterPluginServer(s grpc.ServiceRegistrar, srv PluginServer) { s.RegisterService(&Plugin_ServiceDesc, srv) } -func _Plugin_Register_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(RegisterPluginRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(PluginServer).Register(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/remote.Plugin/Register", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(PluginServer).Register(ctx, req.(*RegisterPluginRequest)) - } - return interceptor(ctx, in, info, handler) -} - func _Plugin_Mutate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(MutateRequest) if err := dec(in); err != nil { @@ -249,10 +291,6 @@ var Plugin_ServiceDesc = grpc.ServiceDesc{ ServiceName: "remote.Plugin", HandlerType: (*PluginServer)(nil), Methods: []grpc.MethodDesc{ - { - MethodName: "Register", - Handler: _Plugin_Register_Handler, - }, { MethodName: "Mutate", Handler: _Plugin_Mutate_Handler, diff --git a/syncer/context/context.go b/syncer/context/context.go index 40f49355..e0f80961 100644 --- a/syncer/context/context.go +++ b/syncer/context/context.go @@ -80,6 +80,7 @@ type RegisterContext struct { SyncerConfig clientcmd.ClientConfig } +// VirtualClusterOptions holds the vcluster flags that were used to start the vcluster // VirtualClusterOptions holds the cmd flags type VirtualClusterOptions struct { Controllers []string `json:"controllers,omitempty"` @@ -88,54 +89,59 @@ type VirtualClusterOptions struct { ServerCaKey string `json:"serverCaKey,omitempty"` TLSSANs []string `json:"tlsSans,omitempty"` RequestHeaderCaCert string `json:"requestHeaderCaCert,omitempty"` - ClientCaCert string `json:"clientCaCert"` - KubeConfig string `json:"kubeConfig"` + ClientCaCert string `json:"clientCaCert,omitempty"` + KubeConfig string `json:"kubeConfig,omitempty"` - KubeConfigSecret string `json:"kubeConfigSecret"` - KubeConfigSecretNamespace string `json:"kubeConfigSecretNamespace"` - KubeConfigServer string `json:"kubeConfigServer"` + KubeConfigSecret string `json:"kubeConfigSecret,omitempty"` + KubeConfigSecretNamespace string `json:"kubeConfigSecretNamespace,omitempty"` + KubeConfigServer string `json:"kubeConfigServer,omitempty"` Tolerations []string `json:"tolerations,omitempty"` - BindAddress string `json:"bindAddress"` - Port int `json:"port"` + BindAddress string `json:"bindAddress,omitempty"` + Port int `json:"port,omitempty"` - Name string `json:"name"` + Name string `json:"name,omitempty"` - TargetNamespace string `json:"targetNamespace"` - ServiceName string `json:"serviceName"` + TargetNamespace string `json:"targetNamespace,omitempty"` + ServiceName string `json:"serviceName,omitempty"` - SetOwner bool `json:"setOwner"` + SetOwner bool `json:"setOwner,omitempty"` - SyncAllNodes bool `json:"syncAllNodes"` - SyncNodeChanges bool `json:"syncNodeChanges"` - DisableFakeKubelets bool `json:"disableFakeKubelets"` + SyncAllNodes bool `json:"syncAllNodes,omitempty"` + EnableScheduler bool `json:"enableScheduler,omitempty"` + DisableFakeKubelets bool `json:"disableFakeKubelets,omitempty"` - TranslateImages []string `json:"translateImages"` + TranslateImages []string `json:"translateImages,omitempty"` - NodeSelector string `json:"nodeSelector"` - ServiceAccount string `json:"serviceAccount"` - EnforceNodeSelector bool `json:"enforceNodeSelector"` + NodeSelector string `json:"nodeSelector,omitempty"` + EnforceNodeSelector bool `json:"enforceNodeSelector,omitempty"` + ServiceAccount string `json:"serviceAccount,omitempty"` - OverrideHosts bool `json:"overrideHosts"` - OverrideHostsContainerImage string `json:"overrideHostsContainerImage"` + OverrideHosts bool `json:"overrideHosts,omitempty"` + OverrideHostsContainerImage string `json:"overrideHostsContainerImage,omitempty"` - ClusterDomain string `json:"clusterDomain"` + ClusterDomain string `json:"clusterDomain,omitempty"` - LeaderElect bool `json:"leaderElect"` - LeaseDuration int64 `json:"leaseDuration"` - RenewDeadline int64 `json:"renewDeadline"` - RetryPeriod int64 `json:"retryPeriod"` + LeaderElect bool `json:"leaderElect,omitempty"` + LeaseDuration int64 `json:"leaseDuration,omitempty"` + RenewDeadline int64 `json:"renewDeadline,omitempty"` + RetryPeriod int64 `json:"retryPeriod,omitempty"` - DisablePlugins bool `json:"disablePlugins"` - PluginListenAddress string `json:"pluginListenAddress"` + DisablePlugins bool `json:"disablePlugins,omitempty"` + PluginListenAddress string `json:"pluginListenAddress,omitempty"` + Plugins []string `json:"plugins,omitempty"` - DefaultImageRegistry string `json:"defaultImageRegistry"` + DefaultImageRegistry string `json:"defaultImageRegistry,omitempty"` - EnforcePodSecurityStandard string `json:"enforcePodSecurityStandard"` + EnforcePodSecurityStandard string `json:"enforcePodSecurityStandard,omitempty"` - SyncLabels []string `json:"syncLabels"` + MapHostServices []string `json:"mapHostServices,omitempty"` + MapVirtualServices []string `json:"mapVirtualServices,omitempty"` + + SyncLabels []string `json:"syncLabels,omitempty"` // DEPRECATED FLAGS + DeprecatedSyncNodeChanges bool `json:"syncNodeChanges"` DeprecatedDisableSyncResources string DeprecatedOwningStatefulSet string DeprecatedUseFakeNodes bool diff --git a/syncer/translator/cluster_translator.go b/syncer/translator/cluster_translator.go index e450532c..46d367ce 100644 --- a/syncer/translator/cluster_translator.go +++ b/syncer/translator/cluster_translator.go @@ -82,24 +82,30 @@ func (n *clusterTranslator) TranslateMetadata(vObj client.Object) client.Object return nil } - pObj.SetLabels(n.TranslateLabels(vObj)) + pObj.SetLabels(n.TranslateLabels(vObj, nil)) pObj.SetAnnotations(n.TranslateAnnotations(vObj, nil)) return pObj } func (n *clusterTranslator) TranslateMetadataUpdate(vObj client.Object, pObj client.Object) (changed bool, annotations map[string]string, labels map[string]string) { updatedAnnotations := n.TranslateAnnotations(vObj, pObj) - updatedLabels := n.TranslateLabels(vObj) + updatedLabels := n.TranslateLabels(vObj, pObj) return !equality.Semantic.DeepEqual(updatedAnnotations, pObj.GetAnnotations()) || !equality.Semantic.DeepEqual(updatedLabels, pObj.GetLabels()), updatedAnnotations, updatedLabels } -func (n *clusterTranslator) TranslateLabels(vObj client.Object) map[string]string { +func (n *clusterTranslator) TranslateLabels(vObj client.Object, pObj client.Object) map[string]string { newLabels := map[string]string{} if vObj != nil { for k, v := range vObj.GetLabels() { newLabels[convertNamespacedLabelKey(n.physicalNamespace, k)] = v } } + if pObj != nil { + pObjLabels := pObj.GetLabels() + if pObjLabels != nil && pObjLabels[translate.ControllerLabel] != "" { + newLabels[translate.ControllerLabel] = pObjLabels[translate.ControllerLabel] + } + } newLabels[translate.MarkerLabel] = translate.SafeConcatName(n.physicalNamespace, "x", translate.Suffix) return newLabels } diff --git a/syncer/translator/namespaced_translator.go b/syncer/translator/namespaced_translator.go index 04f1f7a5..516caa07 100644 --- a/syncer/translator/namespaced_translator.go +++ b/syncer/translator/namespaced_translator.go @@ -144,7 +144,7 @@ func TranslateMetadata(phyiscalNamespace string, vObj client.Object, excludedAnn return nil } - pObj.SetLabels(translateLabels(vObj)) + pObj.SetLabels(translateLabels(vObj, nil)) pObj.SetAnnotations(translateAnnotations(vObj, nil, excludedAnnotations)) return pObj } @@ -155,7 +155,7 @@ func (n *namespacedTranslator) TranslateMetadataUpdate(vObj client.Object, pObj func TranslateMetadataUpdate(vObj client.Object, pObj client.Object, excludedAnnotations ...string) (bool, map[string]string, map[string]string) { updatedAnnotations := translateAnnotations(vObj, pObj, excludedAnnotations) - updatedLabels := translateLabels(vObj) + updatedLabels := translateLabels(vObj, pObj) return !equality.Semantic.DeepEqual(updatedAnnotations, pObj.GetAnnotations()) || !equality.Semantic.DeepEqual(updatedLabels, pObj.GetLabels()), updatedAnnotations, updatedLabels } @@ -213,7 +213,7 @@ func translateAnnotations(vObj client.Object, pObj client.Object, excluded []str return retMap } -func translateLabels(vObj client.Object) map[string]string { +func translateLabels(vObj client.Object, pObj client.Object) map[string]string { newLabels := map[string]string{} for k, v := range vObj.GetLabels() { if k == translate.NamespaceLabel { @@ -223,6 +223,12 @@ func translateLabels(vObj client.Object) map[string]string { newLabels[ConvertLabelKey(k)] = v } + if pObj != nil { + pObjLabels := pObj.GetLabels() + if pObjLabels != nil && pObjLabels[translate.ControllerLabel] != "" { + newLabels[translate.ControllerLabel] = pObjLabels[translate.ControllerLabel] + } + } newLabels[translate.MarkerLabel] = translate.Suffix if vObj.GetNamespace() != "" { diff --git a/syncer/types.go b/syncer/types.go index b3ffd1ac..ed273dfa 100644 --- a/syncer/types.go +++ b/syncer/types.go @@ -9,12 +9,12 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -// Base is a basic entity, which identifies the syncer through its name. Additional +// Base is a basic entity, which identifies the action through its name. Additional // functionality can be added to this basic identity through implementing other interfaces -// below. The functionality is additive, which means that syncers that implement multiple -// interfaces are valid. The syncer or fake syncer interface are not needed to get implemented -// and syncers that implement for example only the Initializer or IndicesRegisterer interfaces -// are totally valid. +// below. The functionality is additive, which means that actions that implement multiple +// interfaces are valid. The syncer, fake syncer or hook interface are not needed to get implemented +// and actions that implement for example only the Initializer or IndicesRegisterer interfaces +// are valid. type Base interface { Name() string } diff --git a/translate/translate.go b/translate/translate.go index fd375870..33673f3f 100644 --- a/translate/translate.go +++ b/translate/translate.go @@ -13,9 +13,10 @@ import ( ) var ( - NamespaceLabel = "vcluster.loft.sh/namespace" - MarkerLabel = "vcluster.loft.sh/managed-by" - Suffix = "suffix" + NamespaceLabel = "vcluster.loft.sh/namespace" + MarkerLabel = "vcluster.loft.sh/managed-by" + ControllerLabel = "vcluster.loft.sh/controlled-by" + Suffix = "suffix" ) var Owner client.Object