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

@@ -265,8 +265,8 @@ type GitRepoVolumeSource struct {
// 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.
type SecretVolumeSource struct {
// Reference to a Secret
Target ObjectReference `json:"target"`
// Name of the secret in the pod's namespace to use
SecretName string `json:"secretName"`
}
// NFSVolumeSource represents an NFS Mount that lasts the lifetime of a pod

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"`
}

View File

@@ -1305,6 +1305,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

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

View File

@@ -110,7 +110,8 @@ const (
//
// https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/design/secrets.md
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"`
}

View File

@@ -274,9 +274,11 @@ type GitRepoVolumeSource struct {
}
// SecretVolumeSource adapts a Secret into a VolumeSource
//
// https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/design/secrets.md
type SecretVolumeSource struct {
// Reference to a Secret
Target ObjectReference `json:"target" description:"target is a reference to a secret"`
// Name of the secret in the pod's namespace to use
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

View File

@@ -331,14 +331,8 @@ func validateGCEPersistentDiskVolumeSource(PD *api.GCEPersistentDiskVolumeSource
func validateSecretVolumeSource(secretSource *api.SecretVolumeSource) errs.ValidationErrorList {
allErrs := errs.ValidationErrorList{}
if secretSource.Target.Name == "" {
allErrs = append(allErrs, errs.NewFieldRequired("target.name"))
}
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"))
if secretSource.SecretName == "" {
allErrs = append(allErrs, errs.NewFieldRequired("secretName"))
}
return allErrs
}

View File

@@ -211,7 +211,7 @@ func TestValidateVolumes(t *testing.T) {
{Name: "empty", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}},
{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: "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)
if len(errs) != 0 {