Add status.podIP as a valid downward API target
Getting the public IP a container is supposed to use is O(hard), and usually involves ugly gyrations in python or with interfaces. Using the downward API means that the IP Kube is announcing to other endpoints is also visible inside the container for pods to identify themselves.
This commit is contained in:
@@ -44,6 +44,7 @@ func addConversionFuncs() {
|
||||
case "metadata.name",
|
||||
"metadata.namespace",
|
||||
"status.phase",
|
||||
"status.podIP",
|
||||
"spec.nodeName":
|
||||
return label, value, nil
|
||||
// This is for backwards compatibility with old v1 clients which send spec.host
|
||||
|
@@ -680,7 +680,7 @@ func validateEnvVarValueFrom(ev api.EnvVar) errs.ValidationErrorList {
|
||||
return allErrs
|
||||
}
|
||||
|
||||
var validFieldPathExpressions = util.NewStringSet("metadata.name", "metadata.namespace")
|
||||
var validFieldPathExpressions = util.NewStringSet("metadata.name", "metadata.namespace", "status.podIP")
|
||||
|
||||
func validateObjectFieldSelector(fs *api.ObjectFieldSelector) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
|
@@ -667,7 +667,7 @@ func TestValidateEnv(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}},
|
||||
expectedError: "[0].valueFrom.fieldRef.fieldPath: unsupported value 'status.phase', Details: supported values: metadata.name, metadata.namespace",
|
||||
expectedError: "[0].valueFrom.fieldRef.fieldPath: unsupported value 'status.phase', Details: supported values: metadata.name, metadata.namespace, status.podIP",
|
||||
},
|
||||
}
|
||||
for _, tc := range errorCases {
|
||||
|
@@ -1051,7 +1051,10 @@ func (kl *Kubelet) podFieldSelectorRuntimeValue(fs *api.ObjectFieldSelector, pod
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
switch internalFieldPath {
|
||||
case "status.podIP":
|
||||
return pod.Status.PodIP, nil
|
||||
}
|
||||
return fieldpath.ExtractFieldPathAsString(pod, internalFieldPath)
|
||||
}
|
||||
|
||||
|
@@ -1187,6 +1187,15 @@ func TestMakeEnvironmentVariables(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "POD_IP",
|
||||
ValueFrom: &api.EnvVarSource{
|
||||
FieldRef: &api.ObjectFieldSelector{
|
||||
APIVersion: testapi.Version(),
|
||||
FieldPath: "status.podIP",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
masterServiceNs: "nothing",
|
||||
@@ -1194,6 +1203,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
|
||||
expectedEnvs: []kubecontainer.EnvVar{
|
||||
{Name: "POD_NAME", Value: "dapi-test-pod-name"},
|
||||
{Name: "POD_NAMESPACE", Value: "downward-api"},
|
||||
{Name: "POD_IP", Value: "1.2.3.4"},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -1345,6 +1355,7 @@ func TestMakeEnvironmentVariables(t *testing.T) {
|
||||
Name: "dapi-test-pod-name",
|
||||
},
|
||||
}
|
||||
testPod.Status.PodIP = "1.2.3.4"
|
||||
|
||||
result, err := kl.makeEnvironmentVariables(testPod, tc.container)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user