Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
f0e382ad
"docs/vscode:/vscode.git/clone" did not exist on "0432aad83dbf857e41ba7b8d7891fa762c45200d"
Unverified
Commit
f0e382ad
authored
Jul 24, 2025
by
julienmancuso
Committed by
GitHub
Jul 24, 2025
Browse files
fix: Merge env vars correctly (#2096)
parent
2bbbd44f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
43 deletions
+21
-43
deploy/cloud/operator/internal/controller/dynamocomponentdeployment_controller.go
...ternal/controller/dynamocomponentdeployment_controller.go
+3
-37
deploy/cloud/operator/internal/controller/dynamocomponentdeployment_controller_test.go
...l/controller/dynamocomponentdeployment_controller_test.go
+14
-2
deploy/cloud/operator/internal/dynamo/graph.go
deploy/cloud/operator/internal/dynamo/graph.go
+3
-3
deploy/cloud/operator/internal/dynamo/graph_test.go
deploy/cloud/operator/internal/dynamo/graph_test.go
+1
-1
No files found.
deploy/cloud/operator/internal/controller/dynamocomponentdeployment_controller.go
View file @
f0e382ad
...
@@ -1214,11 +1214,7 @@ func (r *DynamoComponentDeploymentReconciler) generatePodTemplateSpec(ctx contex
...
@@ -1214,11 +1214,7 @@ func (r *DynamoComponentDeploymentReconciler) generatePodTemplateSpec(ctx contex
containerPort
:=
commonconsts
.
DynamoServicePort
containerPort
:=
commonconsts
.
DynamoServicePort
var
envs
[]
corev1
.
EnvVar
envsSeen
:=
make
(
map
[
string
]
struct
{})
resourceAnnotations
:=
opt
.
dynamoComponentDeployment
.
Spec
.
Annotations
resourceAnnotations
:=
opt
.
dynamoComponentDeployment
.
Spec
.
Annotations
specEnvs
:=
opt
.
dynamoComponentDeployment
.
Spec
.
Envs
if
resourceAnnotations
==
nil
{
if
resourceAnnotations
==
nil
{
resourceAnnotations
=
make
(
map
[
string
]
string
)
resourceAnnotations
=
make
(
map
[
string
]
string
)
...
@@ -1226,34 +1222,6 @@ func (r *DynamoComponentDeploymentReconciler) generatePodTemplateSpec(ctx contex
...
@@ -1226,34 +1222,6 @@ func (r *DynamoComponentDeploymentReconciler) generatePodTemplateSpec(ctx contex
isDebugModeEnabled
:=
checkIfIsDebugModeEnabled
(
resourceAnnotations
)
isDebugModeEnabled
:=
checkIfIsDebugModeEnabled
(
resourceAnnotations
)
if
specEnvs
!=
nil
{
envs
=
make
([]
corev1
.
EnvVar
,
0
,
len
(
specEnvs
)
+
1
)
for
_
,
env
:=
range
specEnvs
{
if
_
,
ok
:=
envsSeen
[
env
.
Name
];
ok
{
continue
}
if
env
.
Name
==
commonconsts
.
EnvDynamoServicePort
{
// nolint: gosec
containerPort
,
err
=
strconv
.
Atoi
(
env
.
Value
)
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"invalid port value %s"
,
env
.
Value
)
}
}
envsSeen
[
env
.
Name
]
=
struct
{}{}
envVar
:=
corev1
.
EnvVar
{
Name
:
env
.
Name
,
}
if
env
.
Value
!=
""
{
envVar
.
Value
=
env
.
Value
}
if
env
.
ValueFrom
!=
nil
{
envVar
.
ValueFrom
=
env
.
ValueFrom
}
envs
=
append
(
envs
,
envVar
)
}
}
defaultEnvs
:=
[]
corev1
.
EnvVar
{
defaultEnvs
:=
[]
corev1
.
EnvVar
{
{
{
Name
:
commonconsts
.
EnvDynamoServicePort
,
Name
:
commonconsts
.
EnvDynamoServicePort
,
...
@@ -1275,11 +1243,7 @@ func (r *DynamoComponentDeploymentReconciler) generatePodTemplateSpec(ctx contex
...
@@ -1275,11 +1243,7 @@ func (r *DynamoComponentDeploymentReconciler) generatePodTemplateSpec(ctx contex
})
})
}
}
for
_
,
env
:=
range
defaultEnvs
{
envs
:=
dynamo
.
MergeEnvs
(
opt
.
dynamoComponentDeployment
.
Spec
.
Envs
,
defaultEnvs
)
if
_
,
ok
:=
envsSeen
[
env
.
Name
];
!
ok
{
envs
=
append
(
envs
,
env
)
}
}
var
livenessProbe
*
corev1
.
Probe
var
livenessProbe
*
corev1
.
Probe
if
opt
.
dynamoComponentDeployment
.
Spec
.
LivenessProbe
!=
nil
{
if
opt
.
dynamoComponentDeployment
.
Spec
.
LivenessProbe
!=
nil
{
...
@@ -1470,6 +1434,8 @@ func (r *DynamoComponentDeploymentReconciler) generatePodTemplateSpec(ctx contex
...
@@ -1470,6 +1434,8 @@ func (r *DynamoComponentDeploymentReconciler) generatePodTemplateSpec(ctx contex
err
=
errors
.
Wrapf
(
err
,
"failed to merge extraPodSpecMainContainer into container"
)
err
=
errors
.
Wrapf
(
err
,
"failed to merge extraPodSpecMainContainer into container"
)
return
nil
,
err
return
nil
,
err
}
}
// finally merge the envs from extraPodSpecMainContainer into container
container
.
Env
=
dynamo
.
MergeEnvs
(
container
.
Env
,
extraPodSpecMainContainer
.
Env
)
}
}
}
}
...
...
deploy/cloud/operator/internal/controller/dynamocomponentdeployment_controller_test.go
View file @
f0e382ad
...
@@ -824,6 +824,12 @@ func TestDynamoComponentDeploymentReconciler_generateLeaderWorkerSet(t *testing.
...
@@ -824,6 +824,12 @@ func TestDynamoComponentDeploymentReconciler_generateLeaderWorkerSet(t *testing.
DynamoComponent
:
"test-lws-component"
,
DynamoComponent
:
"test-lws-component"
,
DynamoTag
:
"test-tag"
,
DynamoTag
:
"test-tag"
,
DynamoComponentDeploymentSharedSpec
:
v1alpha1
.
DynamoComponentDeploymentSharedSpec
{
DynamoComponentDeploymentSharedSpec
:
v1alpha1
.
DynamoComponentDeploymentSharedSpec
{
Envs
:
[]
corev1
.
EnvVar
{
{
Name
:
"TEST_ENV_FROM_DYNAMO_COMPONENT_DEPLOYMENT_SPEC"
,
Value
:
"test_value_from_dynamo_component_deployment_spec"
,
},
},
ServiceName
:
"test-lws-deploy-service"
,
ServiceName
:
"test-lws-deploy-service"
,
DynamoNamespace
:
&
[]
string
{
"default"
}[
0
],
DynamoNamespace
:
&
[]
string
{
"default"
}[
0
],
Annotations
:
map
[
string
]
string
{
Annotations
:
map
[
string
]
string
{
...
@@ -845,6 +851,12 @@ func TestDynamoComponentDeploymentReconciler_generateLeaderWorkerSet(t *testing.
...
@@ -845,6 +851,12 @@ func TestDynamoComponentDeploymentReconciler_generateLeaderWorkerSet(t *testing.
Args
:
[]
string
{
Args
:
[]
string
{
"some dynamo command"
,
"some dynamo command"
,
},
},
Env
:
[]
corev1
.
EnvVar
{
{
Name
:
"TEST_ENV_FROM_EXTRA_POD_SPEC"
,
Value
:
"test_value_from_extra_pod_spec"
,
},
},
},
},
},
},
},
},
...
@@ -896,7 +908,7 @@ func TestDynamoComponentDeploymentReconciler_generateLeaderWorkerSet(t *testing.
...
@@ -896,7 +908,7 @@ func TestDynamoComponentDeploymentReconciler_generateLeaderWorkerSet(t *testing.
Image
:
"test-image:latest"
,
Image
:
"test-image:latest"
,
Command
:
[]
string
{
"sh"
,
"-c"
},
Command
:
[]
string
{
"sh"
,
"-c"
},
Args
:
[]
string
{
"ray start --head --port=6379 && some dynamo command"
},
Args
:
[]
string
{
"ray start --head --port=6379 && some dynamo command"
},
Env
:
[]
corev1
.
EnvVar
{{
Name
:
"DYNAMO_PORT"
,
Value
:
fmt
.
Sprintf
(
"%d"
,
commonconsts
.
DynamoServicePort
)}},
Env
:
[]
corev1
.
EnvVar
{{
Name
:
"DYNAMO_PORT"
,
Value
:
fmt
.
Sprintf
(
"%d"
,
commonconsts
.
DynamoServicePort
)}
,
{
Name
:
"TEST_ENV_FROM_DYNAMO_COMPONENT_DEPLOYMENT_SPEC"
,
Value
:
"test_value_from_dynamo_component_deployment_spec"
},
{
Name
:
"TEST_ENV_FROM_EXTRA_POD_SPEC"
,
Value
:
"test_value_from_extra_pod_spec"
}
},
VolumeMounts
:
[]
corev1
.
VolumeMount
{
VolumeMounts
:
[]
corev1
.
VolumeMount
{
{
{
Name
:
"shared-memory"
,
MountPath
:
"/dev/shm"
,
Name
:
"shared-memory"
,
MountPath
:
"/dev/shm"
,
...
@@ -948,7 +960,7 @@ func TestDynamoComponentDeploymentReconciler_generateLeaderWorkerSet(t *testing.
...
@@ -948,7 +960,7 @@ func TestDynamoComponentDeploymentReconciler_generateLeaderWorkerSet(t *testing.
Image
:
"test-image:latest"
,
Image
:
"test-image:latest"
,
Command
:
[]
string
{
"sh"
,
"-c"
},
Command
:
[]
string
{
"sh"
,
"-c"
},
Args
:
[]
string
{
"ray start --address=$(LWS_LEADER_ADDRESS):6379 --block"
},
Args
:
[]
string
{
"ray start --address=$(LWS_LEADER_ADDRESS):6379 --block"
},
Env
:
[]
corev1
.
EnvVar
{{
Name
:
"DYNAMO_PORT"
,
Value
:
fmt
.
Sprintf
(
"%d"
,
commonconsts
.
DynamoServicePort
)}},
Env
:
[]
corev1
.
EnvVar
{{
Name
:
"DYNAMO_PORT"
,
Value
:
fmt
.
Sprintf
(
"%d"
,
commonconsts
.
DynamoServicePort
)}
,
{
Name
:
"TEST_ENV_FROM_DYNAMO_COMPONENT_DEPLOYMENT_SPEC"
,
Value
:
"test_value_from_dynamo_component_deployment_spec"
},
{
Name
:
"TEST_ENV_FROM_EXTRA_POD_SPEC"
,
Value
:
"test_value_from_extra_pod_spec"
}
},
VolumeMounts
:
[]
corev1
.
VolumeMount
{{
Name
:
"shared-memory"
,
MountPath
:
"/dev/shm"
}},
VolumeMounts
:
[]
corev1
.
VolumeMount
{{
Name
:
"shared-memory"
,
MountPath
:
"/dev/shm"
}},
Ports
:
[]
corev1
.
ContainerPort
{{
Protocol
:
corev1
.
ProtocolTCP
,
Name
:
commonconsts
.
DynamoServicePortName
,
ContainerPort
:
commonconsts
.
DynamoServicePort
},
{
Ports
:
[]
corev1
.
ContainerPort
{{
Protocol
:
corev1
.
ProtocolTCP
,
Name
:
commonconsts
.
DynamoServicePortName
,
ContainerPort
:
commonconsts
.
DynamoServicePort
},
{
Protocol
:
corev1
.
ProtocolTCP
,
Name
:
commonconsts
.
DynamoHealthPortName
,
ContainerPort
:
commonconsts
.
DynamoHealthPort
,
Protocol
:
corev1
.
ProtocolTCP
,
Name
:
commonconsts
.
DynamoHealthPortName
,
ContainerPort
:
commonconsts
.
DynamoHealthPort
,
...
...
deploy/cloud/operator/internal/dynamo/graph.go
View file @
f0e382ad
...
@@ -176,7 +176,7 @@ func GenerateDynamoComponentsDeployments(ctx context.Context, parentDynamoGraphD
...
@@ -176,7 +176,7 @@ func GenerateDynamoComponentsDeployments(ctx context.Context, parentDynamoGraphD
}
}
// merge the envs from the parent deployment with the envs from the service
// merge the envs from the parent deployment with the envs from the service
if
len
(
parentDynamoGraphDeployment
.
Spec
.
Envs
)
>
0
{
if
len
(
parentDynamoGraphDeployment
.
Spec
.
Envs
)
>
0
{
deployment
.
Spec
.
Envs
=
m
ergeEnvs
(
parentDynamoGraphDeployment
.
Spec
.
Envs
,
deployment
.
Spec
.
Envs
)
deployment
.
Spec
.
Envs
=
M
ergeEnvs
(
parentDynamoGraphDeployment
.
Spec
.
Envs
,
deployment
.
Spec
.
Envs
)
}
}
err
:=
updateDynDeploymentConfig
(
deployment
,
commonconsts
.
DynamoServicePort
)
err
:=
updateDynDeploymentConfig
(
deployment
,
commonconsts
.
DynamoServicePort
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -279,7 +279,7 @@ func overrideWithDynDeploymentConfig(ctx context.Context, dynamoDeploymentCompon
...
@@ -279,7 +279,7 @@ func overrideWithDynDeploymentConfig(ctx context.Context, dynamoDeploymentCompon
return
nil
return
nil
}
}
func
m
ergeEnvs
(
common
,
specific
[]
corev1
.
EnvVar
)
[]
corev1
.
EnvVar
{
func
M
ergeEnvs
(
common
,
specific
[]
corev1
.
EnvVar
)
[]
corev1
.
EnvVar
{
envMap
:=
make
(
map
[
string
]
corev1
.
EnvVar
)
envMap
:=
make
(
map
[
string
]
corev1
.
EnvVar
)
// Add all common environment variables.
// Add all common environment variables.
...
@@ -362,7 +362,7 @@ func GenerateGrovePodGangSet(ctx context.Context, dynamoDeployment *v1alpha1.Dyn
...
@@ -362,7 +362,7 @@ func GenerateGrovePodGangSet(ctx context.Context, dynamoDeployment *v1alpha1.Dyn
}
}
// merge the envs from the parent deployment with the envs from the service
// merge the envs from the parent deployment with the envs from the service
if
len
(
dynamoDeployment
.
Spec
.
Envs
)
>
0
{
if
len
(
dynamoDeployment
.
Spec
.
Envs
)
>
0
{
container
.
Env
=
m
ergeEnvs
(
dynamoDeployment
.
Spec
.
Envs
,
container
.
Env
)
container
.
Env
=
M
ergeEnvs
(
dynamoDeployment
.
Spec
.
Envs
,
container
.
Env
)
}
}
container
.
Env
=
append
(
container
.
Env
,
corev1
.
EnvVar
{
container
.
Env
=
append
(
container
.
Env
,
corev1
.
EnvVar
{
Name
:
commonconsts
.
EnvDynamoServicePort
,
Name
:
commonconsts
.
EnvDynamoServicePort
,
...
...
deploy/cloud/operator/internal/dynamo/graph_test.go
View file @
f0e382ad
...
@@ -1106,7 +1106,7 @@ func Test_mergeEnvs(t *testing.T) {
...
@@ -1106,7 +1106,7 @@ func Test_mergeEnvs(t *testing.T) {
}
}
for
_
,
tt
:=
range
tests
{
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
got
:=
m
ergeEnvs
(
tt
.
args
.
common
,
tt
.
args
.
specific
)
got
:=
M
ergeEnvs
(
tt
.
args
.
common
,
tt
.
args
.
specific
)
sort
.
Slice
(
got
,
func
(
i
,
j
int
)
bool
{
sort
.
Slice
(
got
,
func
(
i
,
j
int
)
bool
{
return
got
[
i
]
.
Name
<
got
[
j
]
.
Name
return
got
[
i
]
.
Name
<
got
[
j
]
.
Name
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment