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
064b7dec
Commit
064b7dec
authored
Mar 24, 2015
by
Tim Hockin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5807 from pmorie/secret_volume_ref
Change secret volume plugin reference to name
parents
c1730989
e40ba109
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
96 additions
and
33 deletions
+96
-33
types.go
pkg/api/types.go
+2
-2
conversion.go
pkg/api/v1beta1/conversion.go
+8
-0
conversion_test.go
pkg/api/v1beta1/conversion_test.go
+28
-0
types.go
pkg/api/v1beta1/types.go
+2
-1
conversion.go
pkg/api/v1beta2/conversion.go
+8
-0
conversion_test.go
pkg/api/v1beta2/conversion_test.go
+28
-0
types.go
pkg/api/v1beta2/types.go
+2
-1
types.go
pkg/api/v1beta3/types.go
+4
-2
validation.go
pkg/api/validation/validation.go
+2
-8
validation_test.go
pkg/api/validation/validation_test.go
+1
-1
secret.go
pkg/volume/secret/secret.go
+8
-8
secret_test.go
pkg/volume/secret/secret_test.go
+2
-5
secrets.go
test/e2e/secrets.go
+1
-5
No files found.
pkg/api/types.go
View file @
064b7dec
...
@@ -265,8 +265,8 @@ type GitRepoVolumeSource struct {
...
@@ -265,8 +265,8 @@ type GitRepoVolumeSource struct {
// The contents of the target Secret's Data field will be presented in a volume
// The contents of the target Secret's Data field will be presented in a volume
// as files using the keys in the Data field as the file names.
// as files using the keys in the Data field as the file names.
type
SecretVolumeSource
struct
{
type
SecretVolumeSource
struct
{
//
Reference to a Secret
//
Name of the secret in the pod's namespace to use
Target
ObjectReference
`json:"target
"`
SecretName
string
`json:"secretName
"`
}
}
// NFSVolumeSource represents an NFS Mount that lasts the lifetime of a pod
// NFSVolumeSource represents an NFS Mount that lasts the lifetime of a pod
...
...
pkg/api/v1beta1/conversion.go
View file @
064b7dec
...
@@ -1377,6 +1377,14 @@ func init() {
...
@@ -1377,6 +1377,14 @@ func init() {
out
.
PodID
=
in
.
Name
out
.
PodID
=
in
.
Name
return
nil
return
nil
},
},
func
(
in
*
newer
.
SecretVolumeSource
,
out
*
SecretVolumeSource
,
s
conversion
.
Scope
)
error
{
out
.
Target
.
ID
=
in
.
SecretName
return
nil
},
func
(
in
*
SecretVolumeSource
,
out
*
newer
.
SecretVolumeSource
,
s
conversion
.
Scope
)
error
{
out
.
SecretName
=
in
.
Target
.
ID
return
nil
},
)
)
if
err
!=
nil
{
if
err
!=
nil
{
// If one of the conversion functions is malformed, detect it immediately.
// If one of the conversion functions is malformed, detect it immediately.
...
...
pkg/api/v1beta1/conversion_test.go
View file @
064b7dec
...
@@ -462,3 +462,31 @@ func TestEndpointsConversion(t *testing.T) {
...
@@ -462,3 +462,31 @@ func TestEndpointsConversion(t *testing.T) {
}
}
}
}
}
}
func
TestSecretVolumeSourceConversion
(
t
*
testing
.
T
)
{
given
:=
current
.
SecretVolumeSource
{
Target
:
current
.
ObjectReference
{
ID
:
"foo"
,
},
}
expected
:=
newer
.
SecretVolumeSource
{
SecretName
:
"foo"
,
}
got
:=
newer
.
SecretVolumeSource
{}
if
err
:=
Convert
(
&
given
,
&
got
);
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
if
got
.
SecretName
!=
expected
.
SecretName
{
t
.
Errorf
(
"Expected %v; got %v"
,
expected
,
got
)
}
got2
:=
current
.
SecretVolumeSource
{}
if
err
:=
Convert
(
&
got
,
&
got2
);
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
if
got2
.
Target
.
ID
!=
given
.
Target
.
ID
{
t
.
Errorf
(
"Expected %v; got %v"
,
given
,
got2
)
}
}
pkg/api/v1beta1/types.go
View file @
064b7dec
...
@@ -171,7 +171,8 @@ type GitRepoVolumeSource struct {
...
@@ -171,7 +171,8 @@ type GitRepoVolumeSource struct {
// SecretVolumeSource adapts a Secret into a VolumeSource
// SecretVolumeSource adapts a Secret into a VolumeSource
type
SecretVolumeSource
struct
{
type
SecretVolumeSource
struct
{
// Reference to a Secret
// Reference to a Secret to use. Only the ID field of this reference is used; a
// secret can only be used by pods in its namespace.
Target
ObjectReference
`json:"target" description:"target is a reference to a secret"`
Target
ObjectReference
`json:"target" description:"target is a reference to a secret"`
}
}
...
...
pkg/api/v1beta2/conversion.go
View file @
064b7dec
...
@@ -1305,6 +1305,14 @@ func init() {
...
@@ -1305,6 +1305,14 @@ func init() {
out
.
PodID
=
in
.
Name
out
.
PodID
=
in
.
Name
return
nil
return
nil
},
},
func
(
in
*
newer
.
SecretVolumeSource
,
out
*
SecretVolumeSource
,
s
conversion
.
Scope
)
error
{
out
.
Target
.
ID
=
in
.
SecretName
return
nil
},
func
(
in
*
SecretVolumeSource
,
out
*
newer
.
SecretVolumeSource
,
s
conversion
.
Scope
)
error
{
out
.
SecretName
=
in
.
Target
.
ID
return
nil
},
)
)
if
err
!=
nil
{
if
err
!=
nil
{
// If one of the conversion functions is malformed, detect it immediately.
// If one of the conversion functions is malformed, detect it immediately.
...
...
pkg/api/v1beta2/conversion_test.go
View file @
064b7dec
...
@@ -281,3 +281,31 @@ func TestEndpointsConversion(t *testing.T) {
...
@@ -281,3 +281,31 @@ func TestEndpointsConversion(t *testing.T) {
}
}
}
}
}
}
func
TestSecretVolumeSourceConversion
(
t
*
testing
.
T
)
{
given
:=
current
.
SecretVolumeSource
{
Target
:
current
.
ObjectReference
{
ID
:
"foo"
,
},
}
expected
:=
newer
.
SecretVolumeSource
{
SecretName
:
"foo"
,
}
got
:=
newer
.
SecretVolumeSource
{}
if
err
:=
newer
.
Scheme
.
Convert
(
&
given
,
&
got
);
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
if
got
.
SecretName
!=
expected
.
SecretName
{
t
.
Errorf
(
"Expected %v; got %v"
,
expected
,
got
)
}
got2
:=
current
.
SecretVolumeSource
{}
if
err
:=
newer
.
Scheme
.
Convert
(
&
got
,
&
got2
);
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
if
got2
.
Target
.
ID
!=
given
.
Target
.
ID
{
t
.
Errorf
(
"Expected %v; got %v"
,
given
,
got2
)
}
}
pkg/api/v1beta2/types.go
View file @
064b7dec
...
@@ -110,7 +110,8 @@ const (
...
@@ -110,7 +110,8 @@ const (
//
//
// https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/design/secrets.md
// https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/design/secrets.md
type
SecretVolumeSource
struct
{
type
SecretVolumeSource
struct
{
// Reference to a Secret
// Reference to a Secret to use. Only the ID field of this reference is used; a
// secret can only be used by pods in its namespace.
Target
ObjectReference
`json:"target" description:"target is a reference to a secret"`
Target
ObjectReference
`json:"target" description:"target is a reference to a secret"`
}
}
...
...
pkg/api/v1beta3/types.go
View file @
064b7dec
...
@@ -274,9 +274,11 @@ type GitRepoVolumeSource struct {
...
@@ -274,9 +274,11 @@ type GitRepoVolumeSource struct {
}
}
// SecretVolumeSource adapts a Secret into a VolumeSource
// SecretVolumeSource adapts a Secret into a VolumeSource
//
// https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/design/secrets.md
type
SecretVolumeSource
struct
{
type
SecretVolumeSource
struct
{
//
Reference to a Secret
//
Name of the secret in the pod's namespace to use
Target
ObjectReference
`json:"target" description:"target is a reference to a secret
"`
SecretName
string
`json:"secretName" description:"secretName is the name of a secret in the pod's namespace
"`
}
}
// NFSVolumeSource represents an NFS mount that lasts the lifetime of a pod
// NFSVolumeSource represents an NFS mount that lasts the lifetime of a pod
...
...
pkg/api/validation/validation.go
View file @
064b7dec
...
@@ -331,14 +331,8 @@ func validateGCEPersistentDiskVolumeSource(PD *api.GCEPersistentDiskVolumeSource
...
@@ -331,14 +331,8 @@ func validateGCEPersistentDiskVolumeSource(PD *api.GCEPersistentDiskVolumeSource
func
validateSecretVolumeSource
(
secretSource
*
api
.
SecretVolumeSource
)
errs
.
ValidationErrorList
{
func
validateSecretVolumeSource
(
secretSource
*
api
.
SecretVolumeSource
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
allErrs
:=
errs
.
ValidationErrorList
{}
if
secretSource
.
Target
.
Name
==
""
{
if
secretSource
.
SecretName
==
""
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldRequired
(
"target.name"
))
allErrs
=
append
(
allErrs
,
errs
.
NewFieldRequired
(
"secretName"
))
}
if
secretSource
.
Target
.
Namespace
==
""
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldRequired
(
"target.namespace"
))
}
if
secretSource
.
Target
.
Kind
!=
"Secret"
{
allErrs
=
append
(
allErrs
,
errs
.
NewFieldInvalid
(
"target.kind"
,
secretSource
.
Target
.
Kind
,
"Secret"
))
}
}
return
allErrs
return
allErrs
}
}
...
...
pkg/api/validation/validation_test.go
View file @
064b7dec
...
@@ -211,7 +211,7 @@ func TestValidateVolumes(t *testing.T) {
...
@@ -211,7 +211,7 @@ func TestValidateVolumes(t *testing.T) {
{
Name
:
"empty"
,
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{}}},
{
Name
:
"empty"
,
VolumeSource
:
api
.
VolumeSource
{
EmptyDir
:
&
api
.
EmptyDirVolumeSource
{}}},
{
Name
:
"gcepd"
,
VolumeSource
:
api
.
VolumeSource
{
GCEPersistentDisk
:
&
api
.
GCEPersistentDiskVolumeSource
{
"my-PD"
,
"ext4"
,
1
,
false
}}},
{
Name
:
"gcepd"
,
VolumeSource
:
api
.
VolumeSource
{
GCEPersistentDisk
:
&
api
.
GCEPersistentDiskVolumeSource
{
"my-PD"
,
"ext4"
,
1
,
false
}}},
{
Name
:
"gitrepo"
,
VolumeSource
:
api
.
VolumeSource
{
GitRepo
:
&
api
.
GitRepoVolumeSource
{
"my-repo"
,
"hashstring"
}}},
{
Name
:
"gitrepo"
,
VolumeSource
:
api
.
VolumeSource
{
GitRepo
:
&
api
.
GitRepoVolumeSource
{
"my-repo"
,
"hashstring"
}}},
{
Name
:
"secret"
,
VolumeSource
:
api
.
VolumeSource
{
Secret
:
&
api
.
SecretVolumeSource
{
api
.
ObjectReference
{
Namespace
:
api
.
NamespaceDefault
,
Name
:
"my-secret"
,
Kind
:
"Secret"
}
}}},
{
Name
:
"secret"
,
VolumeSource
:
api
.
VolumeSource
{
Secret
:
&
api
.
SecretVolumeSource
{
"my-secret"
}}},
}
}
names
,
errs
:=
validateVolumes
(
successCase
)
names
,
errs
:=
validateVolumes
(
successCase
)
if
len
(
errs
)
!=
0
{
if
len
(
errs
)
!=
0
{
...
...
pkg/volume/secret/secret.go
View file @
064b7dec
...
@@ -63,7 +63,7 @@ func (plugin *secretPlugin) NewBuilder(spec *api.Volume, podRef *api.ObjectRefer
...
@@ -63,7 +63,7 @@ func (plugin *secretPlugin) NewBuilder(spec *api.Volume, podRef *api.ObjectRefer
}
}
func
(
plugin
*
secretPlugin
)
newBuilderInternal
(
spec
*
api
.
Volume
,
podRef
*
api
.
ObjectReference
)
(
volume
.
Builder
,
error
)
{
func
(
plugin
*
secretPlugin
)
newBuilderInternal
(
spec
*
api
.
Volume
,
podRef
*
api
.
ObjectReference
)
(
volume
.
Builder
,
error
)
{
return
&
secretVolume
{
spec
.
Name
,
*
podRef
,
plugin
,
spec
.
Secret
.
Target
},
nil
return
&
secretVolume
{
spec
.
Name
,
*
podRef
,
plugin
,
spec
.
Secret
.
SecretName
},
nil
}
}
func
(
plugin
*
secretPlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
)
(
volume
.
Cleaner
,
error
)
{
func
(
plugin
*
secretPlugin
)
NewCleaner
(
volName
string
,
podUID
types
.
UID
)
(
volume
.
Cleaner
,
error
)
{
...
@@ -71,16 +71,16 @@ func (plugin *secretPlugin) NewCleaner(volName string, podUID types.UID) (volume
...
@@ -71,16 +71,16 @@ func (plugin *secretPlugin) NewCleaner(volName string, podUID types.UID) (volume
}
}
func
(
plugin
*
secretPlugin
)
newCleanerInternal
(
volName
string
,
podUID
types
.
UID
)
(
volume
.
Cleaner
,
error
)
{
func
(
plugin
*
secretPlugin
)
newCleanerInternal
(
volName
string
,
podUID
types
.
UID
)
(
volume
.
Cleaner
,
error
)
{
return
&
secretVolume
{
volName
,
api
.
ObjectReference
{
UID
:
podUID
},
plugin
,
api
.
ObjectReference
{}
},
nil
return
&
secretVolume
{
volName
,
api
.
ObjectReference
{
UID
:
podUID
},
plugin
,
""
},
nil
}
}
// secretVolume handles retrieving secrets from the API server
// secretVolume handles retrieving secrets from the API server
// and placing them into the volume on the host.
// and placing them into the volume on the host.
type
secretVolume
struct
{
type
secretVolume
struct
{
volName
string
volName
string
podRef
api
.
ObjectReference
podRef
api
.
ObjectReference
plugin
*
secretPlugin
plugin
*
secretPlugin
secret
Ref
api
.
ObjectReference
secret
Name
string
}
}
func
(
sv
*
secretVolume
)
SetUp
()
error
{
func
(
sv
*
secretVolume
)
SetUp
()
error
{
...
@@ -110,9 +110,9 @@ func (sv *secretVolume) SetUpAt(dir string) error {
...
@@ -110,9 +110,9 @@ func (sv *secretVolume) SetUpAt(dir string) error {
return
fmt
.
Errorf
(
"Cannot setup secret volume %v because kube client is not configured"
,
sv
)
return
fmt
.
Errorf
(
"Cannot setup secret volume %v because kube client is not configured"
,
sv
)
}
}
secret
,
err
:=
kubeClient
.
Secrets
(
sv
.
podRef
.
Namespace
)
.
Get
(
sv
.
secret
Ref
.
Name
)
secret
,
err
:=
kubeClient
.
Secrets
(
sv
.
podRef
.
Namespace
)
.
Get
(
sv
.
secretName
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Couldn't get secret %v/%v"
,
sv
.
secretRef
.
Namespace
,
sv
.
secretRef
.
Name
)
glog
.
Errorf
(
"Couldn't get secret %v/%v"
,
sv
.
podRef
.
Namespace
,
sv
.
secret
Name
)
return
err
return
err
}
}
...
...
pkg/volume/secret/secret_test.go
View file @
064b7dec
...
@@ -52,7 +52,7 @@ func TestCanSupport(t *testing.T) {
...
@@ -52,7 +52,7 @@ func TestCanSupport(t *testing.T) {
if
plugin
.
Name
()
!=
secretPluginName
{
if
plugin
.
Name
()
!=
secretPluginName
{
t
.
Errorf
(
"Wrong name: %s"
,
plugin
.
Name
())
t
.
Errorf
(
"Wrong name: %s"
,
plugin
.
Name
())
}
}
if
!
plugin
.
CanSupport
(
&
api
.
Volume
{
VolumeSource
:
api
.
VolumeSource
{
Secret
:
&
api
.
SecretVolumeSource
{
Target
:
api
.
ObjectReference
{}
}}})
{
if
!
plugin
.
CanSupport
(
&
api
.
Volume
{
VolumeSource
:
api
.
VolumeSource
{
Secret
:
&
api
.
SecretVolumeSource
{
SecretName
:
""
}}})
{
t
.
Errorf
(
"Expected true"
)
t
.
Errorf
(
"Expected true"
)
}
}
}
}
...
@@ -69,10 +69,7 @@ func TestPlugin(t *testing.T) {
...
@@ -69,10 +69,7 @@ func TestPlugin(t *testing.T) {
Name
:
testVolumeName
,
Name
:
testVolumeName
,
VolumeSource
:
api
.
VolumeSource
{
VolumeSource
:
api
.
VolumeSource
{
Secret
:
&
api
.
SecretVolumeSource
{
Secret
:
&
api
.
SecretVolumeSource
{
Target
:
api
.
ObjectReference
{
SecretName
:
testName
,
Namespace
:
testNamespace
,
Name
:
testName
,
},
},
},
},
},
}
}
...
...
test/e2e/secrets.go
View file @
064b7dec
...
@@ -81,11 +81,7 @@ var _ = Describe("Secrets", func() {
...
@@ -81,11 +81,7 @@ var _ = Describe("Secrets", func() {
Name
:
volumeName
,
Name
:
volumeName
,
VolumeSource
:
api
.
VolumeSource
{
VolumeSource
:
api
.
VolumeSource
{
Secret
:
&
api
.
SecretVolumeSource
{
Secret
:
&
api
.
SecretVolumeSource
{
Target
:
api
.
ObjectReference
{
SecretName
:
name
,
Kind
:
"Secret"
,
Namespace
:
ns
,
Name
:
name
,
},
},
},
},
},
},
},
...
...
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