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) {
|
||||
// Handle population from a configmap key.
|
||||
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.
|
||||
vf := env.ValueFrom.ConfigMapKeyRef
|
||||
// Check whether the key reference is optional.
|
||||
@@ -401,9 +423,9 @@ func getEnvironmentVariableValueWithValueFrom(ctx context.Context, env *corev1.E
|
||||
}
|
||||
// Populate the environment variable and continue on to the next reference.
|
||||
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
|
||||
// Check whether the key reference is optional.
|
||||
// This will control whether we fail when unable to read the requested key.
|
||||
@@ -453,9 +475,10 @@ func getEnvironmentVariableValueWithValueFrom(ctx context.Context, env *corev1.E
|
||||
}
|
||||
// Populate the environment variable and continue on to the next reference.
|
||||
return pointer.StringPtr(string(keyValue)), nil
|
||||
}
|
||||
// Handle population from a field (downward API).
|
||||
if env.ValueFrom.FieldRef != nil {
|
||||
}
|
||||
|
||||
// Handle population from a field (downward API).
|
||||
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
|
||||
vf := env.ValueFrom.FieldRef
|
||||
|
||||
@@ -465,14 +488,6 @@ func getEnvironmentVariableValueWithValueFrom(ctx context.Context, env *corev1.E
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user