• Kubernetes Submit Queue's avatar
    Merge pull request #64621 from RenaudWasTaken/pluginwatcher · 4da3bdc4
    Kubernetes Submit Queue authored
    Automatic merge from submit-queue (batch tested with PRs 68087, 68256, 64621, 68299, 68296). If you want to cherry-pick this change to another branch, please follow the instructions here: https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md.
    
    Change plugin watcher registration mechanism
    
    **Which issue(s) this PR fixes**: #64637
    
    **Notes For Reviewers**:
    The current API the plugin watcher exposes to kubelet is the following:
    ```golang
    type RegisterCallbackFn func(pluginName string, endpoint string,
                                 versions []string, socketPath string) (error, chan bool)	
    ```
    
    The callback channel is here to signal the plugin watcher consumer when the plugin watcher API has notified the plugin of it's successful registration.
    In other words the current lifecycle of a plugin is the following:
    ```
    (pluginwatcher) GetInfo -> (pluginwatcher) NotifyRegistrationStatus -> (deviceplugin) ListWatch
    ```
    Rather than
    ```
    (pluginwatcher) GetInfo (race) -> (pluginwatcher) NotifyRegistrationStatus
                            (race) -> (deviceplugin) ListWatch
    ```
    
    This PR changes the callback/channel mechanism to a more explicit, interfaced based contract (and more maintainable than a function to which we add more channels for more lifecycle events).
    
    This PR also introduces three new states: {Init, Register, DeRegister}
    ```golang
    // PluginHandler is an interface a client of the pluginwatcher API needs to implement in
    // order to consume plugins
    // The PluginHandler follows the simple following state machine:
    //
    //                         +--------------------------------------+
    //                         |            ReRegistration            |
    //                         | Socket created with same plugin name |
    //                         |                                      |
    //                         |                                      |
    //    Socket Created       v                                      +        Socket Deleted
    // +------------------> Validate +----------> Init +---------> Register +------------------> DeRegister
    //                         +                   +                                                +
    //                         |                   |                                                |
    //                         | Error             | Error                                          |
    //                         |                   |                                                |
    //                         v                   v                                                v
    //                        Out                 Out                                              Out
    //
    // The pluginwatcher module follows strictly and sequentially this state machine for each *plugin name*.
    // e.g: If you are Registering a plugin foo, you cannot get a DeRegister call for plugin foo
    //      until the Register("foo") call returns. Nor will you get a Validate("foo", "Different endpoint", ...)
    //      call until the Register("foo") call returns.
    //
    // ReRegistration: Socket created with same plugin name, usually for a plugin update
    // e.g: plugin with name foo registers at foo.com/foo-1.9.7 later a plugin with name foo
    //      registers at foo.com/foo-1.9.9
    //
    // DeRegistration: When ReRegistration happens only the deletion of the new socket will trigger a DeRegister call
    
    type PluginHandler interface {
            // Validate returns an error if the information provided by
            // the potential plugin is erroneous (unsupported version, ...)
            ValidatePlugin(pluginName string, endpoint string, versions []string) error
            // Init starts the plugin (e.g: contact the gRPC client, gets plugin
            // specific information, ...) but if another plugin with the same name
            // exists does not switch to the newer one.
            // Any error encountered here can still be Notified to the plugin.
            InitPlugin(pluginName string, endpoint string) error
            // Register is called once the pluginwatcher has notified the plugin
            // of its successful registration.
            // Errors at this point can no longer be bubbled up to the plugin
            RegisterPlugin(pluginName, endpoint string)
            // DeRegister is called once the pluginwatcher observes that the socket has
            // been deleted.
            DeRegisterPlugin(pluginName string)
    }
    ```
    
    ```release-note
    NONE
    ```
    /sig node
    /area hw-accelerators
    
    /cc @jiayingz @vikaschoudhary16 @vishh @vladimirvivien @sbezverk @figo (ccing the main reviewers of the original PR, feel free to cc more people)
    4da3bdc4
Name
Last commit
Last update
.github Loading commit data...
Godeps Loading commit data...
api Loading commit data...
build Loading commit data...
cluster Loading commit data...
cmd Loading commit data...
docs Loading commit data...
hack Loading commit data...
logo Loading commit data...
pkg Loading commit data...
plugin Loading commit data...
staging Loading commit data...
test Loading commit data...
third_party Loading commit data...
translations Loading commit data...
vendor Loading commit data...
.bazelrc Loading commit data...
.generated_files Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.kazelcfg.json Loading commit data...
BUILD.bazel Loading commit data...
CHANGELOG-1.10.md Loading commit data...
CHANGELOG-1.11.md Loading commit data...
CHANGELOG-1.12.md Loading commit data...
CHANGELOG-1.2.md Loading commit data...
CHANGELOG-1.3.md Loading commit data...
CHANGELOG-1.4.md Loading commit data...
CHANGELOG-1.5.md Loading commit data...
CHANGELOG-1.6.md Loading commit data...
CHANGELOG-1.7.md Loading commit data...
CHANGELOG-1.8.md Loading commit data...
CHANGELOG-1.9.md Loading commit data...
CHANGELOG.md Loading commit data...
CONTRIBUTING.md Loading commit data...
LICENSE Loading commit data...
Makefile Loading commit data...
Makefile.generated_files Loading commit data...
OWNERS Loading commit data...
OWNERS_ALIASES Loading commit data...
README.md Loading commit data...
SECURITY_CONTACTS Loading commit data...
SUPPORT.md Loading commit data...
WORKSPACE Loading commit data...
code-of-conduct.md Loading commit data...