Change SecretVolumeSource to use a secret name instead of ObjRef

This commit is contained in:
Paul Morie
2015-03-24 13:17:14 -04:00
parent 1dc7bcf53b
commit e40ba109a1
13 changed files with 96 additions and 33 deletions

View File

@@ -1377,6 +1377,14 @@ func init() {
out.PodID = in.Name
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 one of the conversion functions is malformed, detect it immediately.

View File

@@ -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)
}
}

View File

@@ -171,7 +171,8 @@ type GitRepoVolumeSource struct {
// SecretVolumeSource adapts a Secret into a VolumeSource
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"`
}