Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
/*
|
|
|
|
|
Copyright 2018 The Kubernetes Authors.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package pluginwatcher
|
|
|
|
|
|
|
|
|
|
import (
|
2019-12-17 03:01:53 -05:00
|
|
|
"context"
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
2019-03-09 08:25:08 -05:00
|
|
|
"net"
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
"reflect"
|
|
|
|
|
"sync"
|
|
|
|
|
"time"
|
|
|
|
|
|
2019-03-09 08:25:08 -05:00
|
|
|
"google.golang.org/grpc"
|
2020-04-17 15:25:06 -04:00
|
|
|
"k8s.io/klog/v2"
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
|
2019-10-06 15:24:24 -04:00
|
|
|
registerapi "k8s.io/kubelet/pkg/apis/pluginregistration/v1"
|
2019-03-09 08:25:08 -05:00
|
|
|
v1beta1 "k8s.io/kubernetes/pkg/kubelet/pluginmanager/pluginwatcher/example_plugin_apis/v1beta1"
|
|
|
|
|
v1beta2 "k8s.io/kubernetes/pkg/kubelet/pluginmanager/pluginwatcher/example_plugin_apis/v1beta2"
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type exampleHandler struct {
|
2018-08-11 18:10:36 -04:00
|
|
|
SupportedVersions []string
|
|
|
|
|
ExpectedNames map[string]int
|
|
|
|
|
|
|
|
|
|
eventChans map[string]chan examplePluginEvent // map[pluginName]eventChan
|
|
|
|
|
|
2019-08-08 16:25:30 -04:00
|
|
|
m sync.Mutex
|
2018-11-20 23:06:10 -05:00
|
|
|
|
|
|
|
|
permitDeprecatedDir bool
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
}
|
|
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
type examplePluginEvent int
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
exampleEventValidate examplePluginEvent = 0
|
|
|
|
|
exampleEventRegister examplePluginEvent = 1
|
|
|
|
|
exampleEventDeRegister examplePluginEvent = 2
|
|
|
|
|
)
|
|
|
|
|
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
// NewExampleHandler provide a example handler
|
2018-11-20 23:06:10 -05:00
|
|
|
func NewExampleHandler(supportedVersions []string, permitDeprecatedDir bool) *exampleHandler {
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
return &exampleHandler{
|
2018-08-11 18:10:36 -04:00
|
|
|
SupportedVersions: supportedVersions,
|
|
|
|
|
ExpectedNames: make(map[string]int),
|
|
|
|
|
|
2018-11-20 23:06:10 -05:00
|
|
|
eventChans: make(map[string]chan examplePluginEvent),
|
|
|
|
|
permitDeprecatedDir: permitDeprecatedDir,
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-11 14:42:58 -05:00
|
|
|
func (p *exampleHandler) ValidatePlugin(pluginName string, endpoint string, versions []string) error {
|
2018-08-11 18:10:36 -04:00
|
|
|
p.SendEvent(pluginName, exampleEventValidate)
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
n, ok := p.DecreasePluginCount(pluginName)
|
|
|
|
|
if !ok && n > 0 {
|
|
|
|
|
return fmt.Errorf("pluginName('%s') wasn't expected (count is %d)", pluginName, n)
|
|
|
|
|
}
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
if !reflect.DeepEqual(versions, p.SupportedVersions) {
|
|
|
|
|
return fmt.Errorf("versions('%v') != supported versions('%v')", versions, p.SupportedVersions)
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this handler expects non-empty endpoint as an example
|
|
|
|
|
if len(endpoint) == 0 {
|
2018-08-11 18:10:36 -04:00
|
|
|
return errors.New("expecting non empty endpoint")
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
}
|
|
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 23:06:10 -05:00
|
|
|
func (p *exampleHandler) RegisterPlugin(pluginName, endpoint string, versions []string) error {
|
2018-08-11 18:10:36 -04:00
|
|
|
p.SendEvent(pluginName, exampleEventRegister)
|
|
|
|
|
|
|
|
|
|
// Verifies the grpcServer is ready to serve services.
|
|
|
|
|
_, conn, err := dial(endpoint, time.Second)
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
if err != nil {
|
2019-08-09 14:46:45 -04:00
|
|
|
return fmt.Errorf("failed dialing endpoint (%s): %v", endpoint, err)
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
}
|
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
|
|
// The plugin handler should be able to use any listed service API version.
|
|
|
|
|
v1beta1Client := v1beta1.NewExampleClient(conn)
|
|
|
|
|
v1beta2Client := v1beta2.NewExampleClient(conn)
|
|
|
|
|
|
|
|
|
|
// Tests v1beta1 GetExampleInfo
|
2018-08-11 18:10:36 -04:00
|
|
|
_, err = v1beta1Client.GetExampleInfo(context.Background(), &v1beta1.ExampleRequest{})
|
|
|
|
|
if err != nil {
|
2019-08-09 14:46:45 -04:00
|
|
|
return fmt.Errorf("failed GetExampleInfo for v1beta2Client(%s): %v", endpoint, err)
|
2018-08-11 18:10:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Tests v1beta1 GetExampleInfo
|
|
|
|
|
_, err = v1beta2Client.GetExampleInfo(context.Background(), &v1beta2.ExampleRequest{})
|
|
|
|
|
if err != nil {
|
2019-08-09 14:46:45 -04:00
|
|
|
return fmt.Errorf("failed GetExampleInfo for v1beta2Client(%s): %v", endpoint, err)
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
}
|
|
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *exampleHandler) DeRegisterPlugin(pluginName string) {
|
|
|
|
|
p.SendEvent(pluginName, exampleEventDeRegister)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *exampleHandler) EventChan(pluginName string) chan examplePluginEvent {
|
|
|
|
|
return p.eventChans[pluginName]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *exampleHandler) SendEvent(pluginName string, event examplePluginEvent) {
|
2021-03-06 01:06:39 -05:00
|
|
|
klog.V(2).InfoS("Sending event for plugin", "pluginName", pluginName, "event", event, "channel", p.eventChans[pluginName])
|
2018-08-11 18:10:36 -04:00
|
|
|
p.eventChans[pluginName] <- event
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *exampleHandler) AddPluginName(pluginName string) {
|
|
|
|
|
p.m.Lock()
|
|
|
|
|
defer p.m.Unlock()
|
|
|
|
|
|
|
|
|
|
v, ok := p.ExpectedNames[pluginName]
|
|
|
|
|
if !ok {
|
|
|
|
|
p.eventChans[pluginName] = make(chan examplePluginEvent)
|
|
|
|
|
v = 1
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
}
|
|
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
p.ExpectedNames[pluginName] = v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *exampleHandler) DecreasePluginCount(pluginName string) (old int, ok bool) {
|
|
|
|
|
p.m.Lock()
|
|
|
|
|
defer p.m.Unlock()
|
|
|
|
|
|
|
|
|
|
v, ok := p.ExpectedNames[pluginName]
|
|
|
|
|
if !ok {
|
|
|
|
|
v = -1
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
}
|
2018-08-11 18:10:36 -04:00
|
|
|
|
|
|
|
|
return v, ok
|
Add hierarchy support for plugin directory
it traverses and watch plugin directory and its sub directory recursively,
plugin socket file only need be unique within one directory,
- plugin socket directory
- |
- ---->sub directory 1
- | |
- | -----> socket1, socket2 ...
- ----->sub directory 2
- |
- ------> socket1, socket2 ...
the design itself allow sub directory be anything,
but in practical, each plugin type could just use one sub directory.
four bonus changes added as below
1. extract example handler out from test, it is easier to read the code
with the seperation.
2. there are two variables here: "Watcher" and "watcher".
"Watcher" is the plugin watcher, and "watcher" is the fsnotify watcher.
so rename the "watcher" to "fsWatcher" to make code easier to
understand.
3. change RegisterCallbackFn() return value order, it is
conventional to return error last, after this change,
the pkg/volume/csi is compliance with golint, so remove it
from hack/.golint_failures
4. refactor errors handling at invokeRegistrationCallbackAtHandler()
to make error message more clear.
2018-05-30 20:07:58 -04:00
|
|
|
}
|
2019-03-09 08:25:08 -05:00
|
|
|
|
|
|
|
|
// Dial establishes the gRPC communication with the picked up plugin socket. https://godoc.org/google.golang.org/grpc#Dial
|
|
|
|
|
func dial(unixSocketPath string, timeout time.Duration) (registerapi.RegistrationClient, *grpc.ClientConn, error) {
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
c, err := grpc.DialContext(ctx, unixSocketPath, grpc.WithInsecure(), grpc.WithBlock(),
|
2019-10-25 04:30:41 -04:00
|
|
|
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
|
|
|
|
return (&net.Dialer{}).DialContext(ctx, "unix", addr)
|
2019-03-09 08:25:08 -05:00
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, nil, fmt.Errorf("failed to dial socket %s, err: %v", unixSocketPath, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return registerapi.NewRegistrationClient(c), c, nil
|
|
|
|
|
}
|