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
ce62d35e
Commit
ce62d35e
authored
Jul 23, 2015
by
Vish Kannan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11735 from thockin/cleanup-volumes-legacy-mode
Remove volumes legacy mode
parents
b9e974b2
6eda8f47
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
3 additions
and
174 deletions
+3
-174
empty_dir.go
pkg/volume/empty_dir/empty_dir.go
+1
-29
empty_dir_test.go
pkg/volume/empty_dir/empty_dir_test.go
+0
-25
gce_pd.go
pkg/volume/gce_pd/gce_pd.go
+1
-31
gce_pd_test.go
pkg/volume/gce_pd/gce_pd_test.go
+0
-31
git_repo.go
pkg/volume/git_repo/git_repo.go
+1
-28
git_repo_test.go
pkg/volume/git_repo/git_repo_test.go
+0
-30
No files found.
pkg/volume/empty_dir/empty_dir.go
View file @
ce62d35e
...
@@ -31,21 +31,18 @@ import (
...
@@ -31,21 +31,18 @@ import (
// This is the primary entrypoint for volume plugins.
// This is the primary entrypoint for volume plugins.
func
ProbeVolumePlugins
()
[]
volume
.
VolumePlugin
{
func
ProbeVolumePlugins
()
[]
volume
.
VolumePlugin
{
return
[]
volume
.
VolumePlugin
{
return
[]
volume
.
VolumePlugin
{
&
emptyDirPlugin
{
nil
,
false
},
&
emptyDirPlugin
{
nil
},
&
emptyDirPlugin
{
nil
,
true
},
}
}
}
}
type
emptyDirPlugin
struct
{
type
emptyDirPlugin
struct
{
host
volume
.
VolumeHost
host
volume
.
VolumeHost
legacyMode
bool
// if set, plugin answers to the legacy name
}
}
var
_
volume
.
VolumePlugin
=
&
emptyDirPlugin
{}
var
_
volume
.
VolumePlugin
=
&
emptyDirPlugin
{}
const
(
const
(
emptyDirPluginName
=
"kubernetes.io/empty-dir"
emptyDirPluginName
=
"kubernetes.io/empty-dir"
emptyDirPluginLegacyName
=
"empty"
)
)
func
(
plugin
*
emptyDirPlugin
)
Init
(
host
volume
.
VolumeHost
)
{
func
(
plugin
*
emptyDirPlugin
)
Init
(
host
volume
.
VolumeHost
)
{
...
@@ -53,18 +50,10 @@ func (plugin *emptyDirPlugin) Init(host volume.VolumeHost) {
...
@@ -53,18 +50,10 @@ func (plugin *emptyDirPlugin) Init(host volume.VolumeHost) {
}
}
func
(
plugin
*
emptyDirPlugin
)
Name
()
string
{
func
(
plugin
*
emptyDirPlugin
)
Name
()
string
{
if
plugin
.
legacyMode
{
return
emptyDirPluginLegacyName
}
return
emptyDirPluginName
return
emptyDirPluginName
}
}
func
(
plugin
*
emptyDirPlugin
)
CanSupport
(
spec
*
volume
.
Spec
)
bool
{
func
(
plugin
*
emptyDirPlugin
)
CanSupport
(
spec
*
volume
.
Spec
)
bool
{
if
plugin
.
legacyMode
{
// Legacy mode instances can be cleaned up but not created anew.
return
false
}
if
spec
.
VolumeSource
.
EmptyDir
!=
nil
{
if
spec
.
VolumeSource
.
EmptyDir
!=
nil
{
return
true
return
true
}
}
...
@@ -76,10 +65,6 @@ func (plugin *emptyDirPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, opts v
...
@@ -76,10 +65,6 @@ func (plugin *emptyDirPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, opts v
}
}
func
(
plugin
*
emptyDirPlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
mounter
mount
.
Interface
,
mountDetector
mountDetector
,
opts
volume
.
VolumeOptions
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
emptyDirPlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
mounter
mount
.
Interface
,
mountDetector
mountDetector
,
opts
volume
.
VolumeOptions
)
(
volume
.
Builder
,
error
)
{
if
plugin
.
legacyMode
{
// Legacy mode instances can be cleaned up but not created anew.
return
nil
,
fmt
.
Errorf
(
"legacy mode: can not create new instances"
)
}
medium
:=
api
.
StorageMediumDefault
medium
:=
api
.
StorageMediumDefault
if
spec
.
VolumeSource
.
EmptyDir
!=
nil
{
// Support a non-specified source as EmptyDir.
if
spec
.
VolumeSource
.
EmptyDir
!=
nil
{
// Support a non-specified source as EmptyDir.
medium
=
spec
.
VolumeSource
.
EmptyDir
.
Medium
medium
=
spec
.
VolumeSource
.
EmptyDir
.
Medium
...
@@ -91,7 +76,6 @@ func (plugin *emptyDirPlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod
...
@@ -91,7 +76,6 @@ func (plugin *emptyDirPlugin) newBuilderInternal(spec *volume.Spec, pod *api.Pod
mounter
:
mounter
,
mounter
:
mounter
,
mountDetector
:
mountDetector
,
mountDetector
:
mountDetector
,
plugin
:
plugin
,
plugin
:
plugin
,
legacyMode
:
false
,
rootContext
:
opts
.
RootContext
,
rootContext
:
opts
.
RootContext
,
},
nil
},
nil
}
}
...
@@ -102,10 +86,6 @@ func (plugin *emptyDirPlugin) NewCleaner(volName string, podUID types.UID, mount
...
@@ -102,10 +86,6 @@ func (plugin *emptyDirPlugin) NewCleaner(volName string, podUID types.UID, mount
}
}
func
(
plugin
*
emptyDirPlugin
)
newCleanerInternal
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
,
mountDetector
mountDetector
)
(
volume
.
Cleaner
,
error
)
{
func
(
plugin
*
emptyDirPlugin
)
newCleanerInternal
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
,
mountDetector
mountDetector
)
(
volume
.
Cleaner
,
error
)
{
legacy
:=
false
if
plugin
.
legacyMode
{
legacy
=
true
}
ed
:=
&
emptyDir
{
ed
:=
&
emptyDir
{
podUID
:
podUID
,
podUID
:
podUID
,
volName
:
volName
,
volName
:
volName
,
...
@@ -113,7 +93,6 @@ func (plugin *emptyDirPlugin) newCleanerInternal(volName string, podUID types.UI
...
@@ -113,7 +93,6 @@ func (plugin *emptyDirPlugin) newCleanerInternal(volName string, podUID types.UI
mounter
:
mounter
,
mounter
:
mounter
,
mountDetector
:
mountDetector
,
mountDetector
:
mountDetector
,
plugin
:
plugin
,
plugin
:
plugin
,
legacyMode
:
legacy
,
}
}
return
ed
,
nil
return
ed
,
nil
}
}
...
@@ -144,7 +123,6 @@ type emptyDir struct {
...
@@ -144,7 +123,6 @@ type emptyDir struct {
mounter
mount
.
Interface
mounter
mount
.
Interface
mountDetector
mountDetector
mountDetector
mountDetector
plugin
*
emptyDirPlugin
plugin
*
emptyDirPlugin
legacyMode
bool
rootContext
string
rootContext
string
}
}
...
@@ -155,9 +133,6 @@ func (ed *emptyDir) SetUp() error {
...
@@ -155,9 +133,6 @@ func (ed *emptyDir) SetUp() error {
// SetUpAt creates new directory.
// SetUpAt creates new directory.
func
(
ed
*
emptyDir
)
SetUpAt
(
dir
string
)
error
{
func
(
ed
*
emptyDir
)
SetUpAt
(
dir
string
)
error
{
if
ed
.
legacyMode
{
return
fmt
.
Errorf
(
"legacy mode: can not create new instances"
)
}
switch
ed
.
medium
{
switch
ed
.
medium
{
case
api
.
StorageMediumDefault
:
case
api
.
StorageMediumDefault
:
return
ed
.
setupDefault
(
dir
)
return
ed
.
setupDefault
(
dir
)
...
@@ -212,9 +187,6 @@ func (ed *emptyDir) getTmpfsMountOptions() []string {
...
@@ -212,9 +187,6 @@ func (ed *emptyDir) getTmpfsMountOptions() []string {
func
(
ed
*
emptyDir
)
GetPath
()
string
{
func
(
ed
*
emptyDir
)
GetPath
()
string
{
name
:=
emptyDirPluginName
name
:=
emptyDirPluginName
if
ed
.
legacyMode
{
name
=
emptyDirPluginLegacyName
}
return
ed
.
plugin
.
host
.
GetPodVolumeDir
(
ed
.
podUID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
ed
.
volName
)
return
ed
.
plugin
.
host
.
GetPodVolumeDir
(
ed
.
podUID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
ed
.
volName
)
}
}
...
...
pkg/volume/empty_dir/empty_dir_test.go
View file @
ce62d35e
...
@@ -213,28 +213,3 @@ func TestPluginBackCompat(t *testing.T) {
...
@@ -213,28 +213,3 @@ func TestPluginBackCompat(t *testing.T) {
t
.
Errorf
(
"Got unexpected path: %s"
,
volPath
)
t
.
Errorf
(
"Got unexpected path: %s"
,
volPath
)
}
}
}
}
func
TestPluginLegacy
(
t
*
testing
.
T
)
{
plug
:=
makePluginUnderTest
(
t
,
"empty"
)
if
plug
.
Name
()
!=
"empty"
{
t
.
Errorf
(
"Wrong name: %s"
,
plug
.
Name
())
}
if
plug
.
CanSupport
(
&
volume
.
Spec
{
Name
:
"foo"
,
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{}}})
{
t
.
Errorf
(
"Expected false"
)
}
spec
:=
api
.
Volume
{
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{}}}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
if
_
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newBuilderInternal
(
volume
.
NewSpecFromVolume
(
&
spec
),
pod
,
&
mount
.
FakeMounter
{},
&
fakeMountDetector
{},
volume
.
VolumeOptions
{
""
});
err
==
nil
{
t
.
Errorf
(
"Expected failiure"
)
}
cleaner
,
err
:=
plug
.
(
*
emptyDirPlugin
)
.
newCleanerInternal
(
"vol1"
,
types
.
UID
(
"poduid"
),
&
mount
.
FakeMounter
{},
&
fakeMountDetector
{})
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Cleaner: %v"
,
err
)
}
if
cleaner
==
nil
{
t
.
Errorf
(
"Got a nil Cleaner"
)
}
}
pkg/volume/gce_pd/gce_pd.go
View file @
ce62d35e
...
@@ -17,7 +17,6 @@ limitations under the License.
...
@@ -17,7 +17,6 @@ limitations under the License.
package
gce_pd
package
gce_pd
import
(
import
(
"fmt"
"os"
"os"
"path"
"path"
"strconv"
"strconv"
...
@@ -33,19 +32,17 @@ import (
...
@@ -33,19 +32,17 @@ import (
// This is the primary entrypoint for volume plugins.
// This is the primary entrypoint for volume plugins.
func
ProbeVolumePlugins
()
[]
volume
.
VolumePlugin
{
func
ProbeVolumePlugins
()
[]
volume
.
VolumePlugin
{
return
[]
volume
.
VolumePlugin
{
&
gcePersistentDiskPlugin
{
nil
,
false
},
&
gcePersistentDiskPlugin
{
nil
,
true
}}
return
[]
volume
.
VolumePlugin
{
&
gcePersistentDiskPlugin
{
nil
}}
}
}
type
gcePersistentDiskPlugin
struct
{
type
gcePersistentDiskPlugin
struct
{
host
volume
.
VolumeHost
host
volume
.
VolumeHost
legacyMode
bool
// if set, plugin answers to the legacy name
}
}
var
_
volume
.
VolumePlugin
=
&
gcePersistentDiskPlugin
{}
var
_
volume
.
VolumePlugin
=
&
gcePersistentDiskPlugin
{}
const
(
const
(
gcePersistentDiskPluginName
=
"kubernetes.io/gce-pd"
gcePersistentDiskPluginName
=
"kubernetes.io/gce-pd"
gcePersistentDiskPluginLegacyName
=
"gce-pd"
)
)
func
(
plugin
*
gcePersistentDiskPlugin
)
Init
(
host
volume
.
VolumeHost
)
{
func
(
plugin
*
gcePersistentDiskPlugin
)
Init
(
host
volume
.
VolumeHost
)
{
...
@@ -53,18 +50,10 @@ func (plugin *gcePersistentDiskPlugin) Init(host volume.VolumeHost) {
...
@@ -53,18 +50,10 @@ func (plugin *gcePersistentDiskPlugin) Init(host volume.VolumeHost) {
}
}
func
(
plugin
*
gcePersistentDiskPlugin
)
Name
()
string
{
func
(
plugin
*
gcePersistentDiskPlugin
)
Name
()
string
{
if
plugin
.
legacyMode
{
return
gcePersistentDiskPluginLegacyName
}
return
gcePersistentDiskPluginName
return
gcePersistentDiskPluginName
}
}
func
(
plugin
*
gcePersistentDiskPlugin
)
CanSupport
(
spec
*
volume
.
Spec
)
bool
{
func
(
plugin
*
gcePersistentDiskPlugin
)
CanSupport
(
spec
*
volume
.
Spec
)
bool
{
if
plugin
.
legacyMode
{
// Legacy mode instances can be cleaned up but not created anew.
return
false
}
return
spec
.
VolumeSource
.
GCEPersistentDisk
!=
nil
||
spec
.
PersistentVolumeSource
.
GCEPersistentDisk
!=
nil
return
spec
.
VolumeSource
.
GCEPersistentDisk
!=
nil
||
spec
.
PersistentVolumeSource
.
GCEPersistentDisk
!=
nil
}
}
...
@@ -81,11 +70,6 @@ func (plugin *gcePersistentDiskPlugin) NewBuilder(spec *volume.Spec, pod *api.Po
...
@@ -81,11 +70,6 @@ func (plugin *gcePersistentDiskPlugin) NewBuilder(spec *volume.Spec, pod *api.Po
}
}
func
(
plugin
*
gcePersistentDiskPlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
podUID
types
.
UID
,
manager
pdManager
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
gcePersistentDiskPlugin
)
newBuilderInternal
(
spec
*
volume
.
Spec
,
podUID
types
.
UID
,
manager
pdManager
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
if
plugin
.
legacyMode
{
// Legacy mode instances can be cleaned up but not created anew.
return
nil
,
fmt
.
Errorf
(
"legacy mode: can not create new instances"
)
}
var
gce
*
api
.
GCEPersistentDiskVolumeSource
var
gce
*
api
.
GCEPersistentDiskVolumeSource
if
spec
.
VolumeSource
.
GCEPersistentDisk
!=
nil
{
if
spec
.
VolumeSource
.
GCEPersistentDisk
!=
nil
{
gce
=
spec
.
VolumeSource
.
GCEPersistentDisk
gce
=
spec
.
VolumeSource
.
GCEPersistentDisk
...
@@ -112,7 +96,6 @@ func (plugin *gcePersistentDiskPlugin) newBuilderInternal(spec *volume.Spec, pod
...
@@ -112,7 +96,6 @@ func (plugin *gcePersistentDiskPlugin) newBuilderInternal(spec *volume.Spec, pod
mounter
:
mounter
,
mounter
:
mounter
,
diskMounter
:
&
gceSafeFormatAndMount
{
mounter
,
exec
.
New
()},
diskMounter
:
&
gceSafeFormatAndMount
{
mounter
,
exec
.
New
()},
plugin
:
plugin
,
plugin
:
plugin
,
legacyMode
:
false
,
},
nil
},
nil
}
}
...
@@ -122,10 +105,6 @@ func (plugin *gcePersistentDiskPlugin) NewCleaner(volName string, podUID types.U
...
@@ -122,10 +105,6 @@ func (plugin *gcePersistentDiskPlugin) NewCleaner(volName string, podUID types.U
}
}
func
(
plugin
*
gcePersistentDiskPlugin
)
newCleanerInternal
(
volName
string
,
podUID
types
.
UID
,
manager
pdManager
,
mounter
mount
.
Interface
)
(
volume
.
Cleaner
,
error
)
{
func
(
plugin
*
gcePersistentDiskPlugin
)
newCleanerInternal
(
volName
string
,
podUID
types
.
UID
,
manager
pdManager
,
mounter
mount
.
Interface
)
(
volume
.
Cleaner
,
error
)
{
legacy
:=
false
if
plugin
.
legacyMode
{
legacy
=
true
}
return
&
gcePersistentDisk
{
return
&
gcePersistentDisk
{
podUID
:
podUID
,
podUID
:
podUID
,
volName
:
volName
,
volName
:
volName
,
...
@@ -133,7 +112,6 @@ func (plugin *gcePersistentDiskPlugin) newCleanerInternal(volName string, podUID
...
@@ -133,7 +112,6 @@ func (plugin *gcePersistentDiskPlugin) newCleanerInternal(volName string, podUID
mounter
:
mounter
,
mounter
:
mounter
,
diskMounter
:
&
gceSafeFormatAndMount
{
mounter
,
exec
.
New
()},
diskMounter
:
&
gceSafeFormatAndMount
{
mounter
,
exec
.
New
()},
plugin
:
plugin
,
plugin
:
plugin
,
legacyMode
:
legacy
,
},
nil
},
nil
}
}
...
@@ -165,7 +143,6 @@ type gcePersistentDisk struct {
...
@@ -165,7 +143,6 @@ type gcePersistentDisk struct {
// diskMounter provides the interface that is used to mount the actual block device.
// diskMounter provides the interface that is used to mount the actual block device.
diskMounter
mount
.
Interface
diskMounter
mount
.
Interface
plugin
*
gcePersistentDiskPlugin
plugin
*
gcePersistentDiskPlugin
legacyMode
bool
}
}
func
detachDiskLogError
(
pd
*
gcePersistentDisk
)
{
func
detachDiskLogError
(
pd
*
gcePersistentDisk
)
{
...
@@ -182,10 +159,6 @@ func (pd *gcePersistentDisk) SetUp() error {
...
@@ -182,10 +159,6 @@ func (pd *gcePersistentDisk) SetUp() error {
// SetUpAt attaches the disk and bind mounts to the volume path.
// SetUpAt attaches the disk and bind mounts to the volume path.
func
(
pd
*
gcePersistentDisk
)
SetUpAt
(
dir
string
)
error
{
func
(
pd
*
gcePersistentDisk
)
SetUpAt
(
dir
string
)
error
{
if
pd
.
legacyMode
{
return
fmt
.
Errorf
(
"legacy mode: can not create new instances"
)
}
// TODO: handle failed mounts here.
// TODO: handle failed mounts here.
mountpoint
,
err
:=
pd
.
mounter
.
IsMountPoint
(
dir
)
mountpoint
,
err
:=
pd
.
mounter
.
IsMountPoint
(
dir
)
glog
.
V
(
4
)
.
Infof
(
"PersistentDisk set up: %s %v %v"
,
dir
,
mountpoint
,
err
)
glog
.
V
(
4
)
.
Infof
(
"PersistentDisk set up: %s %v %v"
,
dir
,
mountpoint
,
err
)
...
@@ -250,9 +223,6 @@ func makeGlobalPDName(host volume.VolumeHost, devName string) string {
...
@@ -250,9 +223,6 @@ func makeGlobalPDName(host volume.VolumeHost, devName string) string {
func
(
pd
*
gcePersistentDisk
)
GetPath
()
string
{
func
(
pd
*
gcePersistentDisk
)
GetPath
()
string
{
name
:=
gcePersistentDiskPluginName
name
:=
gcePersistentDiskPluginName
if
pd
.
legacyMode
{
name
=
gcePersistentDiskPluginLegacyName
}
return
pd
.
plugin
.
host
.
GetPodVolumeDir
(
pd
.
podUID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
pd
.
volName
)
return
pd
.
plugin
.
host
.
GetPodVolumeDir
(
pd
.
podUID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
pd
.
volName
)
}
}
...
...
pkg/volume/gce_pd/gce_pd_test.go
View file @
ce62d35e
...
@@ -170,35 +170,4 @@ func TestPlugin(t *testing.T) {
...
@@ -170,35 +170,4 @@ func TestPlugin(t *testing.T) {
if
!
fakeManager
.
detachCalled
{
if
!
fakeManager
.
detachCalled
{
t
.
Errorf
(
"Detach watch not called"
)
t
.
Errorf
(
"Detach watch not called"
)
}
}
}
func
TestPluginLegacy
(
t
*
testing
.
T
)
{
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
volume
.
NewFakeVolumeHost
(
"/tmp/fake"
,
nil
,
nil
))
plug
,
err
:=
plugMgr
.
FindPluginByName
(
"gce-pd"
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
}
if
plug
.
Name
()
!=
"gce-pd"
{
t
.
Errorf
(
"Wrong name: %s"
,
plug
.
Name
())
}
if
plug
.
CanSupport
(
&
volume
.
Spec
{
Name
:
"foo"
,
VolumeSource
:
api
.
VolumeSource
{
GCEPersistentDisk
:
&
api
.
GCEPersistentDiskVolumeSource
{}}})
{
t
.
Errorf
(
"Expected false"
)
}
spec
:=
&
api
.
Volume
{
VolumeSource
:
api
.
VolumeSource
{
GCEPersistentDisk
:
&
api
.
GCEPersistentDiskVolumeSource
{}}}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
if
_
,
err
:=
plug
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
spec
),
pod
,
volume
.
VolumeOptions
{
""
},
nil
);
err
==
nil
{
t
.
Errorf
(
"Expected failiure"
)
}
cleaner
,
err
:=
plug
.
NewCleaner
(
"vol1"
,
types
.
UID
(
"poduid"
),
nil
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Cleaner: %v"
,
err
)
}
if
cleaner
==
nil
{
t
.
Errorf
(
"Got a nil Cleaner"
)
}
}
}
pkg/volume/git_repo/git_repo.go
View file @
ce62d35e
...
@@ -32,19 +32,17 @@ import (
...
@@ -32,19 +32,17 @@ import (
// This is the primary entrypoint for volume plugins.
// This is the primary entrypoint for volume plugins.
func
ProbeVolumePlugins
()
[]
volume
.
VolumePlugin
{
func
ProbeVolumePlugins
()
[]
volume
.
VolumePlugin
{
return
[]
volume
.
VolumePlugin
{
&
gitRepoPlugin
{
nil
,
false
},
&
gitRepoPlugin
{
nil
,
true
}}
return
[]
volume
.
VolumePlugin
{
&
gitRepoPlugin
{
nil
}}
}
}
type
gitRepoPlugin
struct
{
type
gitRepoPlugin
struct
{
host
volume
.
VolumeHost
host
volume
.
VolumeHost
legacyMode
bool
// if set, plugin answers to the legacy name
}
}
var
_
volume
.
VolumePlugin
=
&
gitRepoPlugin
{}
var
_
volume
.
VolumePlugin
=
&
gitRepoPlugin
{}
const
(
const
(
gitRepoPluginName
=
"kubernetes.io/git-repo"
gitRepoPluginName
=
"kubernetes.io/git-repo"
gitRepoPluginLegacyName
=
"git"
)
)
func
(
plugin
*
gitRepoPlugin
)
Init
(
host
volume
.
VolumeHost
)
{
func
(
plugin
*
gitRepoPlugin
)
Init
(
host
volume
.
VolumeHost
)
{
...
@@ -52,26 +50,14 @@ func (plugin *gitRepoPlugin) Init(host volume.VolumeHost) {
...
@@ -52,26 +50,14 @@ func (plugin *gitRepoPlugin) Init(host volume.VolumeHost) {
}
}
func
(
plugin
*
gitRepoPlugin
)
Name
()
string
{
func
(
plugin
*
gitRepoPlugin
)
Name
()
string
{
if
plugin
.
legacyMode
{
return
gitRepoPluginLegacyName
}
return
gitRepoPluginName
return
gitRepoPluginName
}
}
func
(
plugin
*
gitRepoPlugin
)
CanSupport
(
spec
*
volume
.
Spec
)
bool
{
func
(
plugin
*
gitRepoPlugin
)
CanSupport
(
spec
*
volume
.
Spec
)
bool
{
if
plugin
.
legacyMode
{
// Legacy mode instances can be cleaned up but not created anew.
return
false
}
return
spec
.
VolumeSource
.
GitRepo
!=
nil
return
spec
.
VolumeSource
.
GitRepo
!=
nil
}
}
func
(
plugin
*
gitRepoPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
gitRepoPlugin
)
NewBuilder
(
spec
*
volume
.
Spec
,
pod
*
api
.
Pod
,
opts
volume
.
VolumeOptions
,
mounter
mount
.
Interface
)
(
volume
.
Builder
,
error
)
{
if
plugin
.
legacyMode
{
// Legacy mode instances can be cleaned up but not created anew.
return
nil
,
fmt
.
Errorf
(
"legacy mode: can not create new instances"
)
}
return
&
gitRepo
{
return
&
gitRepo
{
pod
:
*
pod
,
pod
:
*
pod
,
volName
:
spec
.
Name
,
volName
:
spec
.
Name
,
...
@@ -79,22 +65,16 @@ func (plugin *gitRepoPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, opts vo
...
@@ -79,22 +65,16 @@ func (plugin *gitRepoPlugin) NewBuilder(spec *volume.Spec, pod *api.Pod, opts vo
revision
:
spec
.
VolumeSource
.
GitRepo
.
Revision
,
revision
:
spec
.
VolumeSource
.
GitRepo
.
Revision
,
exec
:
exec
.
New
(),
exec
:
exec
.
New
(),
plugin
:
plugin
,
plugin
:
plugin
,
legacyMode
:
false
,
opts
:
opts
,
opts
:
opts
,
mounter
:
mounter
,
mounter
:
mounter
,
},
nil
},
nil
}
}
func
(
plugin
*
gitRepoPlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
)
(
volume
.
Cleaner
,
error
)
{
func
(
plugin
*
gitRepoPlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
,
mounter
mount
.
Interface
)
(
volume
.
Cleaner
,
error
)
{
legacy
:=
false
if
plugin
.
legacyMode
{
legacy
=
true
}
return
&
gitRepo
{
return
&
gitRepo
{
pod
:
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
podUID
}},
pod
:
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
podUID
}},
volName
:
volName
,
volName
:
volName
,
plugin
:
plugin
,
plugin
:
plugin
,
legacyMode
:
legacy
,
mounter
:
mounter
,
mounter
:
mounter
,
},
nil
},
nil
}
}
...
@@ -108,7 +88,6 @@ type gitRepo struct {
...
@@ -108,7 +88,6 @@ type gitRepo struct {
revision
string
revision
string
exec
exec
.
Interface
exec
exec
.
Interface
plugin
*
gitRepoPlugin
plugin
*
gitRepoPlugin
legacyMode
bool
opts
volume
.
VolumeOptions
opts
volume
.
VolumeOptions
mounter
mount
.
Interface
mounter
mount
.
Interface
}
}
...
@@ -129,9 +108,6 @@ func (gr *gitRepo) SetUpAt(dir string) error {
...
@@ -129,9 +108,6 @@ func (gr *gitRepo) SetUpAt(dir string) error {
if
volumeutil
.
IsReady
(
gr
.
getMetaDir
())
{
if
volumeutil
.
IsReady
(
gr
.
getMetaDir
())
{
return
nil
return
nil
}
}
if
gr
.
legacyMode
{
return
fmt
.
Errorf
(
"legacy mode: can not create new instances"
)
}
// Wrap EmptyDir, let it do the setup.
// Wrap EmptyDir, let it do the setup.
wrapped
,
err
:=
gr
.
plugin
.
host
.
NewWrapperBuilder
(
wrappedVolumeSpec
,
&
gr
.
pod
,
gr
.
opts
,
gr
.
mounter
)
wrapped
,
err
:=
gr
.
plugin
.
host
.
NewWrapperBuilder
(
wrappedVolumeSpec
,
&
gr
.
pod
,
gr
.
opts
,
gr
.
mounter
)
...
@@ -183,9 +159,6 @@ func (gr *gitRepo) execCommand(command string, args []string, dir string) ([]byt
...
@@ -183,9 +159,6 @@ func (gr *gitRepo) execCommand(command string, args []string, dir string) ([]byt
func
(
gr
*
gitRepo
)
GetPath
()
string
{
func
(
gr
*
gitRepo
)
GetPath
()
string
{
name
:=
gitRepoPluginName
name
:=
gitRepoPluginName
if
gr
.
legacyMode
{
name
=
gitRepoPluginLegacyName
}
return
gr
.
plugin
.
host
.
GetPodVolumeDir
(
gr
.
pod
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
gr
.
volName
)
return
gr
.
plugin
.
host
.
GetPodVolumeDir
(
gr
.
pod
.
UID
,
util
.
EscapeQualifiedNameForDisk
(
name
),
gr
.
volName
)
}
}
...
...
pkg/volume/git_repo/git_repo_test.go
View file @
ce62d35e
...
@@ -159,33 +159,3 @@ func TestPlugin(t *testing.T) {
...
@@ -159,33 +159,3 @@ func TestPlugin(t *testing.T) {
t
.
Errorf
(
"SetUp() failed: %v"
,
err
)
t
.
Errorf
(
"SetUp() failed: %v"
,
err
)
}
}
}
}
func
TestPluginLegacy
(
t
*
testing
.
T
)
{
plugMgr
:=
volume
.
VolumePluginMgr
{}
plugMgr
.
InitPlugins
(
ProbeVolumePlugins
(),
newTestHost
(
t
))
plug
,
err
:=
plugMgr
.
FindPluginByName
(
"git"
)
if
err
!=
nil
{
t
.
Errorf
(
"Can't find the plugin by name"
)
}
if
plug
.
Name
()
!=
"git"
{
t
.
Errorf
(
"Wrong name: %s"
,
plug
.
Name
())
}
if
plug
.
CanSupport
(
&
volume
.
Spec
{
Name
:
"foo"
,
VolumeSource
:
api
.
VolumeSource
{
GitRepo
:
&
api
.
GitRepoVolumeSource
{}}})
{
t
.
Errorf
(
"Expected false"
)
}
spec
:=
&
api
.
Volume
{
VolumeSource
:
api
.
VolumeSource
{
GitRepo
:
&
api
.
GitRepoVolumeSource
{}}}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
types
.
UID
(
"poduid"
)}}
if
_
,
err
:=
plug
.
NewBuilder
(
volume
.
NewSpecFromVolume
(
spec
),
pod
,
volume
.
VolumeOptions
{
""
},
nil
);
err
==
nil
{
t
.
Errorf
(
"Expected failiure"
)
}
cleaner
,
err
:=
plug
.
NewCleaner
(
"vol1"
,
types
.
UID
(
"poduid"
),
nil
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to make a new Cleaner: %v"
,
err
)
}
if
cleaner
==
nil
{
t
.
Errorf
(
"Got a nil Cleaner"
)
}
}
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