k8s.io/kubernetes@v1.29.3/pkg/kubelet/pluginmanager/cache/types.go (about)

     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  // PluginHandler is an interface a client of the pluginwatcher API needs to implement in
    20  // order to consume plugins
    21  // The PluginHandler follows the simple following state machine:
    22  //
    23  //	                       +--------------------------------------+
    24  //	                       |            ReRegistration            |
    25  //	                       | Socket created with same plugin name |
    26  //	                       |                                      |
    27  //	                       |                                      |
    28  //	  Socket Created       v                                      +        Socket Deleted
    29  //	+------------------> Validate +---------------------------> Register +------------------> DeRegister
    30  //	                       +                                      +                              +
    31  //	                       |                                      |                              |
    32  //	                       | Error                                | Error                        |
    33  //	                       |                                      |                              |
    34  //	                       v                                      v                              v
    35  //	                      Out                                    Out                            Out
    36  //
    37  // The pluginwatcher module follows strictly and sequentially this state machine for each *plugin name*.
    38  // e.g: If you are Registering a plugin foo, you cannot get a DeRegister call for plugin foo
    39  // until the Register("foo") call returns. Nor will you get a Validate("foo", "Different endpoint", ...)
    40  // call until the Register("foo") call returns.
    41  //
    42  // ReRegistration: Socket created with same plugin name, usually for a plugin update
    43  // e.g: plugin with name foo registers at foo.com/foo-1.9.7 later a plugin with name foo
    44  // registers at foo.com/foo-1.9.9
    45  //
    46  // DeRegistration: When ReRegistration happens only the deletion of the new socket will trigger a DeRegister call
    47  type PluginHandler interface {
    48  	// Validate returns an error if the information provided by
    49  	// the potential plugin is erroneous (unsupported version, ...)
    50  	ValidatePlugin(pluginName string, endpoint string, versions []string) error
    51  	// RegisterPlugin is called so that the plugin can be register by any
    52  	// plugin consumer
    53  	// Error encountered here can still be Notified to the plugin.
    54  	RegisterPlugin(pluginName, endpoint string, versions []string) error
    55  	// DeRegister is called once the pluginwatcher observes that the socket has
    56  	// been deleted.
    57  	DeRegisterPlugin(pluginName string)
    58  }