Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
8fa92e48
Commit
8fa92e48
authored
Sep 03, 2017
by
Yecheng Fu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RBD Plugin: Omit volume.MetricsProvider field and add some testcases.
parent
4af900b4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
2 deletions
+88
-2
BUILD
pkg/volume/rbd/BUILD
+1
-0
rbd.go
pkg/volume/rbd/rbd.go
+2
-2
rbd_test.go
pkg/volume/rbd/rbd_test.go
+85
-0
No files found.
pkg/volume/rbd/BUILD
View file @
8fa92e48
...
@@ -40,6 +40,7 @@ go_test(
...
@@ -40,6 +40,7 @@ go_test(
"//pkg/util/mount:go_default_library",
"//pkg/util/mount:go_default_library",
"//pkg/volume:go_default_library",
"//pkg/volume:go_default_library",
"//pkg/volume/testing:go_default_library",
"//pkg/volume/testing:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
...
...
pkg/volume/rbd/rbd.go
View file @
8fa92e48
...
@@ -409,8 +409,8 @@ type rbd struct {
...
@@ -409,8 +409,8 @@ type rbd struct {
mounter
*
mount
.
SafeFormatAndMount
mounter
*
mount
.
SafeFormatAndMount
exec
mount
.
Exec
exec
mount
.
Exec
// Utility interface that provides API calls to the provider to attach/detach disks.
// Utility interface that provides API calls to the provider to attach/detach disks.
manager
diskManager
manager
diskManager
volume
.
MetricsProvider
volume
.
MetricsProvider
`json:"-"`
}
}
func
(
rbd
*
rbd
)
GetPath
()
string
{
func
(
rbd
*
rbd
)
GetPath
()
string
{
...
...
pkg/volume/rbd/rbd_test.go
View file @
8fa92e48
...
@@ -18,9 +18,13 @@ package rbd
...
@@ -18,9 +18,13 @@ package rbd
import
(
import
(
"fmt"
"fmt"
"io/ioutil"
"os"
"os"
"path/filepath"
"reflect"
"testing"
"testing"
"github.com/stretchr/testify/assert"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
...
@@ -244,3 +248,84 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
...
@@ -244,3 +248,84 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
t
.
Errorf
(
"Expected true for mounter.IsReadOnly"
)
t
.
Errorf
(
"Expected true for mounter.IsReadOnly"
)
}
}
}
}
func
TestPersistAndLoadRBD
(
t
*
testing
.
T
)
{
tmpDir
,
err
:=
utiltesting
.
MkTmpdir
(
"rbd_test"
)
if
err
!=
nil
{
t
.
Fatalf
(
"error creating temp dir: %v"
,
err
)
}
defer
os
.
RemoveAll
(
tmpDir
)
testcases
:=
[]
struct
{
rbdMounter
rbdMounter
expectedJSONStr
string
expectedLoadedRBDMounter
rbdMounter
}{
{
rbdMounter
{},
`{"Mon":null,"Id":"","Keyring":"","Secret":""}`
,
rbdMounter
{},
},
{
rbdMounter
{
rbd
:
&
rbd
{
podUID
:
"poduid"
,
Pool
:
"kube"
,
Image
:
"some-test-image"
,
ReadOnly
:
false
,
MetricsProvider
:
volume
.
NewMetricsStatFS
(
"/tmp"
),
},
Mon
:
[]
string
{
"127.0.0.1"
},
Id
:
"kube"
,
Keyring
:
""
,
Secret
:
"QVFEcTdKdFp4SmhtTFJBQUNwNDI3UnhGRzBvQ1Y0SUJwLy9pRUE9PQ=="
,
},
`
{
"Pool": "kube",
"Image": "some-test-image",
"ReadOnly": false,
"Mon": ["127.0.0.1"],
"Id": "kube",
"Keyring": "",
"Secret": "QVFEcTdKdFp4SmhtTFJBQUNwNDI3UnhGRzBvQ1Y0SUJwLy9pRUE9PQ=="
}
`
,
rbdMounter
{
rbd
:
&
rbd
{
Pool
:
"kube"
,
Image
:
"some-test-image"
,
ReadOnly
:
false
,
},
Mon
:
[]
string
{
"127.0.0.1"
},
Id
:
"kube"
,
Keyring
:
""
,
Secret
:
"QVFEcTdKdFp4SmhtTFJBQUNwNDI3UnhGRzBvQ1Y0SUJwLy9pRUE9PQ=="
,
},
},
}
util
:=
&
RBDUtil
{}
for
_
,
c
:=
range
testcases
{
err
=
util
.
persistRBD
(
c
.
rbdMounter
,
tmpDir
)
if
err
!=
nil
{
t
.
Errorf
(
"failed to persist rbd: %v, err: %v"
,
c
.
rbdMounter
,
err
)
}
jsonFile
:=
filepath
.
Join
(
tmpDir
,
"rbd.json"
)
jsonData
,
err
:=
ioutil
.
ReadFile
(
jsonFile
)
if
err
!=
nil
{
t
.
Errorf
(
"failed to read json file %s: %v"
,
jsonFile
,
err
)
}
if
!
assert
.
JSONEq
(
t
,
c
.
expectedJSONStr
,
string
(
jsonData
))
{
t
.
Errorf
(
"json file does not match expected one: %s, should be %s"
,
string
(
jsonData
),
c
.
expectedJSONStr
)
}
tmpRBDMounter
:=
rbdMounter
{}
err
=
util
.
loadRBD
(
&
tmpRBDMounter
,
tmpDir
)
if
err
!=
nil
{
t
.
Errorf
(
"faild to load rbd: %v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
tmpRBDMounter
,
c
.
expectedLoadedRBDMounter
)
{
t
.
Errorf
(
"loaded rbd does not equal to expected one: %v, should be %v"
,
tmpRBDMounter
,
c
.
rbdMounter
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment