1 /* 2 Copyright 2019 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package cache 18 19 import "time" 20 21 // PluginHandler is an interface a client of the pluginwatcher API needs to implement in 22 // order to consume plugins 23 // The PluginHandler follows the simple following state machine: 24 // 25 // +--------------------------------------+ 26 // | ReRegistration | 27 // | Socket created with same plugin name | 28 // | | 29 // | | 30 // Socket Created v + Socket Deleted 31 // +------------------> Validate +---------------------------> Register +------------------> DeRegister 32 // + + + 33 // | | | 34 // | Error | Error | 35 // | | | 36 // v v v 37 // Out Out Out 38 // 39 // The pluginwatcher module follows strictly and sequentially this state machine for each *plugin name*. 40 // e.g: If you are Registering a plugin foo, you cannot get a DeRegister call for plugin foo 41 // until the Register("foo") call returns. Nor will you get a Validate("foo", "Different endpoint", ...) 42 // call until the Register("foo") call returns. 43 // 44 // ReRegistration: Socket created with same plugin name, usually for a plugin update 45 // e.g: plugin with name foo registers at foo.com/foo-1.9.7 later a plugin with name foo 46 // registers at foo.com/foo-1.9.9 47 // 48 // DeRegistration: When ReRegistration happens only the deletion of the new socket will trigger a DeRegister call 49 type PluginHandler interface { 50 // Validate returns an error if the information provided by 51 // the potential plugin is erroneous (unsupported version, ...) 52 ValidatePlugin(pluginName string, endpoint string, versions []string) error 53 // RegisterPlugin is called so that the plugin can be registered by any 54 // plugin consumer 55 // Error encountered here can still be Notified to the plugin. 56 RegisterPlugin(pluginName, endpoint string, versions []string, pluginClientTimeout *time.Duration) error 57 // DeRegisterPlugin is called once the pluginwatcher observes that the socket has 58 // been deleted. 59 DeRegisterPlugin(pluginName string) 60 } 61