Split out each of getEnvironmentVariableValueWithValueFrom*
This takes the multiple mechanisms to do getEnvironmentVariableValueWithValueFrom* and splits them out into their own functions.
This commit is contained in:
@@ -351,6 +351,28 @@ func getEnvironmentVariableValue(ctx context.Context, env *corev1.EnvVar, mappin
|
|||||||
func getEnvironmentVariableValueWithValueFrom(ctx context.Context, env *corev1.EnvVar, mappingFunc func(string) string, pod *corev1.Pod, container *corev1.Container, rm *manager.ResourceManager, recorder record.EventRecorder) (*string, error) {
|
func getEnvironmentVariableValueWithValueFrom(ctx context.Context, env *corev1.EnvVar, mappingFunc func(string) string, pod *corev1.Pod, container *corev1.Container, rm *manager.ResourceManager, recorder record.EventRecorder) (*string, error) {
|
||||||
// Handle population from a configmap key.
|
// Handle population from a configmap key.
|
||||||
if env.ValueFrom.ConfigMapKeyRef != nil {
|
if env.ValueFrom.ConfigMapKeyRef != nil {
|
||||||
|
return getEnvironmentVariableValueWithValueFromConfigMapKeyRef(ctx, env, mappingFunc, pod, container, rm, recorder)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle population from a secret key.
|
||||||
|
if env.ValueFrom.SecretKeyRef != nil {
|
||||||
|
return getEnvironmentVariableValueWithValueFromSecretKeyRef(ctx, env, mappingFunc, pod, container, rm, recorder)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle population from a field (downward API).
|
||||||
|
if env.ValueFrom.FieldRef != nil {
|
||||||
|
return getEnvironmentVariableValueWithValueFromFieldRef(ctx, env, mappingFunc, pod, container, rm, recorder)
|
||||||
|
}
|
||||||
|
if env.ValueFrom.ResourceFieldRef != nil {
|
||||||
|
// TODO Implement populating resource requests.
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.G(ctx).WithField("env", env).Error("Unhandled environment variable with non-nil env.ValueFrom, do not know how to populate")
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEnvironmentVariableValueWithValueFromConfigMapKeyRef(ctx context.Context, env *corev1.EnvVar, mappingFunc func(string) string, pod *corev1.Pod, container *corev1.Container, rm *manager.ResourceManager, recorder record.EventRecorder) (*string, error) {
|
||||||
// The environment variable must be set from a configmap.
|
// The environment variable must be set from a configmap.
|
||||||
vf := env.ValueFrom.ConfigMapKeyRef
|
vf := env.ValueFrom.ConfigMapKeyRef
|
||||||
// Check whether the key reference is optional.
|
// Check whether the key reference is optional.
|
||||||
@@ -402,8 +424,8 @@ func getEnvironmentVariableValueWithValueFrom(ctx context.Context, env *corev1.E
|
|||||||
// Populate the environment variable and continue on to the next reference.
|
// Populate the environment variable and continue on to the next reference.
|
||||||
return pointer.StringPtr(keyValue), nil
|
return pointer.StringPtr(keyValue), nil
|
||||||
}
|
}
|
||||||
// Handle population from a secret key.
|
|
||||||
if env.ValueFrom.SecretKeyRef != nil {
|
func getEnvironmentVariableValueWithValueFromSecretKeyRef(ctx context.Context, env *corev1.EnvVar, mappingFunc func(string) string, pod *corev1.Pod, container *corev1.Container, rm *manager.ResourceManager, recorder record.EventRecorder) (*string, error) {
|
||||||
vf := env.ValueFrom.SecretKeyRef
|
vf := env.ValueFrom.SecretKeyRef
|
||||||
// Check whether the key reference is optional.
|
// Check whether the key reference is optional.
|
||||||
// This will control whether we fail when unable to read the requested key.
|
// This will control whether we fail when unable to read the requested key.
|
||||||
@@ -454,8 +476,9 @@ func getEnvironmentVariableValueWithValueFrom(ctx context.Context, env *corev1.E
|
|||||||
// Populate the environment variable and continue on to the next reference.
|
// Populate the environment variable and continue on to the next reference.
|
||||||
return pointer.StringPtr(string(keyValue)), nil
|
return pointer.StringPtr(string(keyValue)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle population from a field (downward API).
|
// Handle population from a field (downward API).
|
||||||
if env.ValueFrom.FieldRef != nil {
|
func getEnvironmentVariableValueWithValueFromFieldRef(ctx context.Context, env *corev1.EnvVar, mappingFunc func(string) string, pod *corev1.Pod, container *corev1.Container, rm *manager.ResourceManager, recorder record.EventRecorder) (*string, error) {
|
||||||
// https://github.com/virtual-kubelet/virtual-kubelet/issues/123
|
// https://github.com/virtual-kubelet/virtual-kubelet/issues/123
|
||||||
vf := env.ValueFrom.FieldRef
|
vf := env.ValueFrom.FieldRef
|
||||||
|
|
||||||
@@ -466,14 +489,6 @@ func getEnvironmentVariableValueWithValueFrom(ctx context.Context, env *corev1.E
|
|||||||
|
|
||||||
return pointer.StringPtr(runtimeVal), nil
|
return pointer.StringPtr(runtimeVal), nil
|
||||||
}
|
}
|
||||||
if env.ValueFrom.ResourceFieldRef != nil {
|
|
||||||
// TODO Implement populating resource requests.
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
log.G(ctx).WithField("env", env).Error("Unhandled environment variable with non-nil env.ValueFrom, do not know how to populate")
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// podFieldSelectorRuntimeValue returns the runtime value of the given
|
// podFieldSelectorRuntimeValue returns the runtime value of the given
|
||||||
// selector for a pod.
|
// selector for a pod.
|
||||||
|
|||||||
Reference in New Issue
Block a user