2018-05-01 02:15:06 -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 (
|
2018-08-11 18:10:36 -04:00
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
2018-05-01 02:15:06 -04:00
|
|
|
"io/ioutil"
|
2018-08-11 18:10:36 -04:00
|
|
|
"os"
|
2018-05-01 02:15:06 -04:00
|
|
|
"sync"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
2018-11-09 13:49:10 -05:00
|
|
|
"k8s.io/klog"
|
2018-11-02 19:19:27 -04:00
|
|
|
registerapi "k8s.io/kubernetes/pkg/kubelet/apis/pluginregistration/v1"
|
2018-05-01 02:15:06 -04:00
|
|
|
)
|
|
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
var (
|
2018-11-20 23:06:10 -05:00
|
|
|
socketDir string
|
|
|
|
|
deprecatedSocketDir string
|
2018-08-11 18:10:36 -04:00
|
|
|
|
|
|
|
|
supportedVersions = []string{"v1beta1", "v1beta2"}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
var logLevel string
|
|
|
|
|
|
2018-11-09 13:49:10 -05:00
|
|
|
klog.InitFlags(flag.CommandLine)
|
2018-08-11 18:10:36 -04:00
|
|
|
flag.Set("alsologtostderr", fmt.Sprintf("%t", true))
|
|
|
|
|
flag.StringVar(&logLevel, "logLevel", "6", "test")
|
|
|
|
|
flag.Lookup("v").Value.Set(logLevel)
|
|
|
|
|
|
|
|
|
|
d, err := ioutil.TempDir("", "plugin_test")
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(fmt.Sprintf("Could not create a temp directory: %s", d))
|
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
|
|
|
|
2018-11-20 23:06:10 -05:00
|
|
|
d2, err := ioutil.TempDir("", "deprecated_plugin_test")
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(fmt.Sprintf("Could not create a temp directory: %s", d))
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
socketDir = d
|
2018-11-20 23:06:10 -05:00
|
|
|
deprecatedSocketDir = d2
|
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
|
|
|
func cleanup(t *testing.T) {
|
|
|
|
|
require.NoError(t, os.RemoveAll(socketDir))
|
2018-11-20 23:06:10 -05:00
|
|
|
require.NoError(t, os.RemoveAll(deprecatedSocketDir))
|
2018-08-11 18:10:36 -04:00
|
|
|
os.MkdirAll(socketDir, 0755)
|
2018-11-20 23:06:10 -05:00
|
|
|
os.MkdirAll(deprecatedSocketDir, 0755)
|
2018-08-11 18:10:36 -04:00
|
|
|
}
|
2018-05-01 02:15:06 -04:00
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
func TestPluginRegistration(t *testing.T) {
|
|
|
|
|
defer cleanup(t)
|
2018-05-01 02:15:06 -04:00
|
|
|
|
2018-11-20 23:06:10 -05:00
|
|
|
hdlr := NewExampleHandler(supportedVersions, false /* permitDeprecatedDir */)
|
|
|
|
|
w := newWatcherWithHandler(t, hdlr, false /* testDeprecatedDir */)
|
2018-08-11 18:10:36 -04:00
|
|
|
defer func() { require.NoError(t, w.Stop()) }()
|
2018-05-01 02:15:06 -04:00
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
|
socketPath := fmt.Sprintf("%s/plugin-%d.sock", socketDir, i)
|
|
|
|
|
pluginName := fmt.Sprintf("example-plugin-%d", i)
|
2018-05-01 02:15:06 -04:00
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
hdlr.AddPluginName(pluginName)
|
2018-05-01 02:15:06 -04:00
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
p := NewTestExamplePlugin(pluginName, registerapi.DevicePlugin, socketPath, supportedVersions...)
|
|
|
|
|
require.NoError(t, p.Serve("v1beta1", "v1beta2"))
|
2018-05-01 02:15:06 -04:00
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
require.True(t, waitForEvent(t, exampleEventValidate, hdlr.EventChan(p.pluginName)))
|
|
|
|
|
require.True(t, waitForEvent(t, exampleEventRegister, hdlr.EventChan(p.pluginName)))
|
2018-05-01 02:15:06 -04:00
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
require.True(t, waitForPluginRegistrationStatus(t, p.registrationStatus))
|
2018-05-01 02:15:06 -04:00
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
require.NoError(t, p.Stop())
|
|
|
|
|
require.True(t, waitForEvent(t, exampleEventDeRegister, hdlr.EventChan(p.pluginName)))
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-01 02:15:06 -04:00
|
|
|
|
2018-11-20 23:06:10 -05:00
|
|
|
func TestPluginRegistrationDeprecated(t *testing.T) {
|
|
|
|
|
defer cleanup(t)
|
|
|
|
|
|
|
|
|
|
hdlr := NewExampleHandler(supportedVersions, true /* permitDeprecatedDir */)
|
|
|
|
|
w := newWatcherWithHandler(t, hdlr, true /* testDeprecatedDir */)
|
|
|
|
|
defer func() { require.NoError(t, w.Stop()) }()
|
|
|
|
|
|
|
|
|
|
// Test plugins in deprecated dir
|
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
|
endpoint := fmt.Sprintf("%s/dep-plugin-%d.sock", deprecatedSocketDir, i)
|
|
|
|
|
pluginName := fmt.Sprintf("dep-example-plugin-%d", i)
|
|
|
|
|
|
|
|
|
|
hdlr.AddPluginName(pluginName)
|
|
|
|
|
|
|
|
|
|
p := NewTestExamplePlugin(pluginName, registerapi.DevicePlugin, endpoint, supportedVersions...)
|
|
|
|
|
require.NoError(t, p.Serve("v1beta1", "v1beta2"))
|
|
|
|
|
|
|
|
|
|
require.True(t, waitForEvent(t, exampleEventValidate, hdlr.EventChan(p.pluginName)))
|
|
|
|
|
require.True(t, waitForEvent(t, exampleEventRegister, hdlr.EventChan(p.pluginName)))
|
|
|
|
|
|
|
|
|
|
require.True(t, waitForPluginRegistrationStatus(t, p.registrationStatus))
|
|
|
|
|
|
|
|
|
|
require.NoError(t, p.Stop())
|
|
|
|
|
require.True(t, waitForEvent(t, exampleEventDeRegister, hdlr.EventChan(p.pluginName)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
func TestPluginReRegistration(t *testing.T) {
|
|
|
|
|
defer cleanup(t)
|
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
|
|
|
pluginName := fmt.Sprintf("example-plugin")
|
2018-11-20 23:06:10 -05:00
|
|
|
hdlr := NewExampleHandler(supportedVersions, false /* 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
|
|
|
|
2018-11-20 23:06:10 -05:00
|
|
|
w := newWatcherWithHandler(t, hdlr, false /* testDeprecatedDir */)
|
2018-08-11 18:10:36 -04:00
|
|
|
defer func() { require.NoError(t, w.Stop()) }()
|
2018-05-01 02:15:06 -04:00
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
plugins := make([]*examplePlugin, 10)
|
2018-05-01 02:15:06 -04:00
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
|
socketPath := fmt.Sprintf("%s/plugin-%d.sock", socketDir, i)
|
|
|
|
|
hdlr.AddPluginName(pluginName)
|
|
|
|
|
|
|
|
|
|
p := NewTestExamplePlugin(pluginName, registerapi.DevicePlugin, socketPath, supportedVersions...)
|
|
|
|
|
require.NoError(t, p.Serve("v1beta1", "v1beta2"))
|
|
|
|
|
|
|
|
|
|
require.True(t, waitForEvent(t, exampleEventValidate, hdlr.EventChan(p.pluginName)))
|
|
|
|
|
require.True(t, waitForEvent(t, exampleEventRegister, hdlr.EventChan(p.pluginName)))
|
|
|
|
|
|
|
|
|
|
require.True(t, waitForPluginRegistrationStatus(t, p.registrationStatus))
|
|
|
|
|
|
|
|
|
|
plugins[i] = p
|
2018-05-01 02:15:06 -04:00
|
|
|
}
|
|
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
plugins[len(plugins)-1].Stop()
|
|
|
|
|
require.True(t, waitForEvent(t, exampleEventDeRegister, hdlr.EventChan(pluginName)))
|
|
|
|
|
|
|
|
|
|
close(hdlr.EventChan(pluginName))
|
|
|
|
|
for i := 0; i < len(plugins)-1; i++ {
|
|
|
|
|
plugins[i].Stop()
|
|
|
|
|
}
|
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
|
|
|
func TestPluginRegistrationAtKubeletStart(t *testing.T) {
|
|
|
|
|
defer cleanup(t)
|
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-11-20 23:06:10 -05:00
|
|
|
hdlr := NewExampleHandler(supportedVersions, false /* permitDeprecatedDir */)
|
2018-08-11 18:10:36 -04:00
|
|
|
plugins := make([]*examplePlugin, 10)
|
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
|
|
|
for i := 0; i < len(plugins); i++ {
|
|
|
|
|
socketPath := fmt.Sprintf("%s/plugin-%d.sock", socketDir, i)
|
|
|
|
|
pluginName := fmt.Sprintf("example-plugin-%d", i)
|
|
|
|
|
hdlr.AddPluginName(pluginName)
|
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 := NewTestExamplePlugin(pluginName, registerapi.DevicePlugin, socketPath, supportedVersions...)
|
|
|
|
|
require.NoError(t, p.Serve("v1beta1", "v1beta2"))
|
|
|
|
|
defer func(p *examplePlugin) { require.NoError(t, p.Stop()) }(p)
|
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
|
|
|
plugins[i] = p
|
|
|
|
|
}
|
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-11-20 23:06:10 -05:00
|
|
|
w := newWatcherWithHandler(t, hdlr, false /* testDeprecatedDir */)
|
2018-08-11 18:10:36 -04:00
|
|
|
defer func() { require.NoError(t, w.Stop()) }()
|
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
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
for i := 0; i < len(plugins); i++ {
|
|
|
|
|
wg.Add(1)
|
|
|
|
|
go func(p *examplePlugin) {
|
|
|
|
|
defer wg.Done()
|
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
|
|
|
require.True(t, waitForEvent(t, exampleEventValidate, hdlr.EventChan(p.pluginName)))
|
|
|
|
|
require.True(t, waitForEvent(t, exampleEventRegister, hdlr.EventChan(p.pluginName)))
|
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
|
|
|
require.True(t, waitForPluginRegistrationStatus(t, p.registrationStatus))
|
|
|
|
|
}(plugins[i])
|
|
|
|
|
}
|
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
|
|
|
c := make(chan struct{})
|
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
|
|
|
go func() {
|
2018-08-11 18:10:36 -04:00
|
|
|
defer close(c)
|
|
|
|
|
wg.Wait()
|
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
|
|
|
select {
|
|
|
|
|
case <-c:
|
|
|
|
|
return
|
|
|
|
|
case <-time.After(2 * time.Second):
|
|
|
|
|
t.Fatalf("Timeout while waiting for the plugin registration status")
|
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
|
|
|
}
|
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
|
|
|
func TestPluginRegistrationFailureWithUnsupportedVersion(t *testing.T) {
|
|
|
|
|
defer cleanup(t)
|
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
|
|
|
pluginName := fmt.Sprintf("example-plugin")
|
|
|
|
|
socketPath := socketDir + "/plugin.sock"
|
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-11-20 23:06:10 -05:00
|
|
|
hdlr := NewExampleHandler(supportedVersions, false /* permitDeprecatedDir */)
|
2018-08-11 18:10:36 -04:00
|
|
|
hdlr.AddPluginName(pluginName)
|
|
|
|
|
|
2018-11-20 23:06:10 -05:00
|
|
|
w := newWatcherWithHandler(t, hdlr, false /* testDeprecatedDir */)
|
2018-08-11 18:10:36 -04:00
|
|
|
defer func() { require.NoError(t, w.Stop()) }()
|
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
|
|
|
// Advertise v1beta3 but don't serve anything else than the plugin service
|
|
|
|
|
p := NewTestExamplePlugin(pluginName, registerapi.DevicePlugin, socketPath, "v1beta3")
|
|
|
|
|
require.NoError(t, p.Serve())
|
|
|
|
|
defer func() { require.NoError(t, p.Stop()) }()
|
|
|
|
|
|
|
|
|
|
require.True(t, waitForEvent(t, exampleEventValidate, hdlr.EventChan(p.pluginName)))
|
|
|
|
|
require.False(t, waitForPluginRegistrationStatus(t, p.registrationStatus))
|
2018-05-01 02:15:06 -04:00
|
|
|
}
|
|
|
|
|
|
2018-08-11 18:10:36 -04:00
|
|
|
func TestPlugiRegistrationFailureWithUnsupportedVersionAtKubeletStart(t *testing.T) {
|
|
|
|
|
defer cleanup(t)
|
|
|
|
|
|
|
|
|
|
pluginName := fmt.Sprintf("example-plugin")
|
|
|
|
|
socketPath := socketDir + "/plugin.sock"
|
|
|
|
|
|
|
|
|
|
// Advertise v1beta3 but don't serve anything else than the plugin service
|
|
|
|
|
p := NewTestExamplePlugin(pluginName, registerapi.DevicePlugin, socketPath, "v1beta3")
|
|
|
|
|
require.NoError(t, p.Serve())
|
|
|
|
|
defer func() { require.NoError(t, p.Stop()) }()
|
|
|
|
|
|
2018-11-20 23:06:10 -05:00
|
|
|
hdlr := NewExampleHandler(supportedVersions, false /* permitDeprecatedDir */)
|
2018-08-11 18:10:36 -04:00
|
|
|
hdlr.AddPluginName(pluginName)
|
|
|
|
|
|
2018-11-20 23:06:10 -05:00
|
|
|
w := newWatcherWithHandler(t, hdlr, false /* testDeprecatedDir */)
|
2018-08-11 18:10:36 -04:00
|
|
|
defer func() { require.NoError(t, w.Stop()) }()
|
|
|
|
|
|
|
|
|
|
require.True(t, waitForEvent(t, exampleEventValidate, hdlr.EventChan(p.pluginName)))
|
|
|
|
|
require.False(t, waitForPluginRegistrationStatus(t, p.registrationStatus))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func waitForPluginRegistrationStatus(t *testing.T, statusChan chan registerapi.RegistrationStatus) bool {
|
2018-05-01 02:15:06 -04:00
|
|
|
select {
|
2018-08-11 18:10:36 -04:00
|
|
|
case status := <-statusChan:
|
2018-05-01 02:15:06 -04:00
|
|
|
return status.PluginRegistered
|
|
|
|
|
case <-time.After(10 * time.Second):
|
|
|
|
|
t.Fatalf("Timed out while waiting for registration status")
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
2018-08-11 18:10:36 -04:00
|
|
|
|
|
|
|
|
func waitForEvent(t *testing.T, expected examplePluginEvent, eventChan chan examplePluginEvent) bool {
|
|
|
|
|
select {
|
|
|
|
|
case event := <-eventChan:
|
|
|
|
|
return event == expected
|
|
|
|
|
case <-time.After(2 * time.Second):
|
|
|
|
|
t.Fatalf("Timed out while waiting for registration status %v", expected)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 23:06:10 -05:00
|
|
|
func newWatcherWithHandler(t *testing.T, hdlr PluginHandler, testDeprecatedDir bool) *Watcher {
|
|
|
|
|
depSocketDir := ""
|
|
|
|
|
if testDeprecatedDir {
|
|
|
|
|
depSocketDir = deprecatedSocketDir
|
|
|
|
|
}
|
|
|
|
|
w := NewWatcher(socketDir, depSocketDir)
|
2018-08-11 18:10:36 -04:00
|
|
|
|
|
|
|
|
w.AddHandler(registerapi.DevicePlugin, hdlr)
|
|
|
|
|
require.NoError(t, w.Start())
|
|
|
|
|
|
|
|
|
|
return w
|
|
|
|
|
}
|
2018-11-20 23:06:10 -05:00
|
|
|
|
|
|
|
|
func TestFoundInDeprecatedDir(t *testing.T) {
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
sockDir string
|
|
|
|
|
deprecatedSockDir string
|
|
|
|
|
socketPath string
|
|
|
|
|
expectFoundInDeprecatedDir bool
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
socketPath: "/var/lib/kubelet/plugins_registry/mydriver.foo/csi.sock",
|
|
|
|
|
expectFoundInDeprecatedDir: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
socketPath: "/var/lib/kubelet/plugins/mydriver.foo/csi.sock",
|
|
|
|
|
expectFoundInDeprecatedDir: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
socketPath: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
expectFoundInDeprecatedDir: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
socketPath: "/var/lib/kubelet/plugins",
|
|
|
|
|
expectFoundInDeprecatedDir: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
socketPath: "/var/lib/kubelet/plugins/kubernetes.io",
|
|
|
|
|
expectFoundInDeprecatedDir: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
socketPath: "/var/lib/kubelet/plugins/my.driver.com",
|
|
|
|
|
expectFoundInDeprecatedDir: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
socketPath: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
expectFoundInDeprecatedDir: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
socketPath: "/var/lib/kubelet/plugins_registry/kubernetes.io",
|
|
|
|
|
expectFoundInDeprecatedDir: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
socketPath: "/var/lib/kubelet/plugins_registry/my.driver.com",
|
|
|
|
|
expectFoundInDeprecatedDir: false,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
// Arrange & Act
|
|
|
|
|
watcher := NewWatcher(tc.sockDir, tc.deprecatedSockDir)
|
|
|
|
|
|
|
|
|
|
actualFoundInDeprecatedDir := watcher.foundInDeprecatedDir(tc.socketPath)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
if tc.expectFoundInDeprecatedDir != actualFoundInDeprecatedDir {
|
|
|
|
|
t.Fatalf("expecting actualFoundInDeprecatedDir=%v, but got %v for testcase: %#v", tc.expectFoundInDeprecatedDir, actualFoundInDeprecatedDir, tc)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestContainsBlacklistedDir(t *testing.T) {
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
sockDir string
|
|
|
|
|
deprecatedSockDir string
|
|
|
|
|
path string
|
|
|
|
|
expected bool
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins_registry/mydriver.foo/csi.sock",
|
|
|
|
|
expected: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins/mydriver.foo/csi.sock",
|
|
|
|
|
expected: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
expected: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins",
|
|
|
|
|
expected: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins/kubernetes.io",
|
|
|
|
|
expected: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins/kubernetes.io/csi.sock",
|
|
|
|
|
expected: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins/kubernetes.io/my.plugin/csi.sock",
|
|
|
|
|
expected: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins/kubernetes.io/",
|
|
|
|
|
expected: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins/my.driver.com",
|
|
|
|
|
expected: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
expected: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins_registry/kubernetes.io",
|
|
|
|
|
expected: false, // New (non-deprecated dir) has no blacklist
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins_registry/my.driver.com",
|
|
|
|
|
expected: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins/my-kubernetes.io-plugin",
|
|
|
|
|
expected: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins/my-kubernetes.io-plugin/csi.sock",
|
|
|
|
|
expected: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins/kubernetes.io-plugin",
|
|
|
|
|
expected: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins/kubernetes.io-plugin/csi.sock",
|
|
|
|
|
expected: false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sockDir: "/var/lib/kubelet/plugins_registry",
|
|
|
|
|
deprecatedSockDir: "/var/lib/kubelet/plugins",
|
|
|
|
|
path: "/var/lib/kubelet/plugins/kubernetes.io-plugin/",
|
|
|
|
|
expected: false,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
// Arrange & Act
|
|
|
|
|
watcher := NewWatcher(tc.sockDir, tc.deprecatedSockDir)
|
|
|
|
|
|
|
|
|
|
actual := watcher.containsBlacklistedDir(tc.path)
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
if tc.expected != actual {
|
|
|
|
|
t.Fatalf("expecting %v but got %v for testcase: %#v", tc.expected, actual, tc)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|