Add Pod UID (metadata.uid) to downward API env var

This commit is contained in:
xiangpengzhao
2017-06-27 16:54:35 +08:00
parent f39c1712c2
commit 0f65b218a0
5 changed files with 30 additions and 8 deletions

View File

@@ -2584,6 +2584,24 @@ func TestValidateEnv(t *testing.T) {
},
},
},
{
Name: "abc",
ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{
APIVersion: api.Registry.GroupOrDie(api.GroupName).GroupVersion.String(),
FieldPath: "metadata.namespace",
},
},
},
{
Name: "abc",
ValueFrom: &api.EnvVarSource{
FieldRef: &api.ObjectFieldSelector{
APIVersion: api.Registry.GroupOrDie(api.GroupName).GroupVersion.String(),
FieldPath: "metadata.uid",
},
},
},
{
Name: "abc",
ValueFrom: &api.EnvVarSource{
@@ -2644,7 +2662,7 @@ func TestValidateEnv(t *testing.T) {
},
}
if errs := ValidateEnv(successCase, field.NewPath("field")); len(errs) != 0 {
t.Errorf("expected success: %v", errs)
t.Errorf("expected success, got: %v", errs)
}
errorCases := []struct {
@@ -2823,7 +2841,7 @@ func TestValidateEnv(t *testing.T) {
},
},
}},
expectedError: `[0].valueFrom.fieldRef.fieldPath: Unsupported value: "metadata.labels": supported values: metadata.name, metadata.namespace, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP`,
expectedError: `[0].valueFrom.fieldRef.fieldPath: Unsupported value: "metadata.labels": supported values: metadata.name, metadata.namespace, metadata.uid, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP`,
},
{
name: "invalid fieldPath annotations",
@@ -2836,7 +2854,7 @@ func TestValidateEnv(t *testing.T) {
},
},
}},
expectedError: `[0].valueFrom.fieldRef.fieldPath: Unsupported value: "metadata.annotations": supported values: metadata.name, metadata.namespace, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP`,
expectedError: `[0].valueFrom.fieldRef.fieldPath: Unsupported value: "metadata.annotations": supported values: metadata.name, metadata.namespace, metadata.uid, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP`,
},
{
name: "unsupported fieldPath",
@@ -2849,7 +2867,7 @@ func TestValidateEnv(t *testing.T) {
},
},
}},
expectedError: `valueFrom.fieldRef.fieldPath: Unsupported value: "status.phase": supported values: metadata.name, metadata.namespace, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP`,
expectedError: `valueFrom.fieldRef.fieldPath: Unsupported value: "status.phase": supported values: metadata.name, metadata.namespace, metadata.uid, spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP`,
},
}
for _, tc := range errorCases {