Skip to content

Commit

Permalink
refactor(workspace): inject workspace path to containers
Browse files Browse the repository at this point in the history
  • Loading branch information
tunahanertekin authored Aug 7, 2023
2 parents 5c0204d + f043ba0 commit e5c75ac
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
## [Unreleased]


<a name="v0.2.5-alpha.31"></a>
## [v0.2.5-alpha.31] - 2023-08-07

<a name="v0.2.5-alpha.30"></a>
## [v0.2.5-alpha.30] - 2023-08-02
### Feat
Expand Down Expand Up @@ -214,7 +217,8 @@
- Merge pull request [#24](https://github.com/robolaunch/robot-operator/issues/24) from robolaunch/23-allow-multiple-launches


[Unreleased]: https://github.com/robolaunch/robot-operator/compare/v0.2.5-alpha.30...HEAD
[Unreleased]: https://github.com/robolaunch/robot-operator/compare/v0.2.5-alpha.31...HEAD
[v0.2.5-alpha.31]: https://github.com/robolaunch/robot-operator/compare/v0.2.5-alpha.30...v0.2.5-alpha.31
[v0.2.5-alpha.30]: https://github.com/robolaunch/robot-operator/compare/v0.2.5-alpha.29...v0.2.5-alpha.30
[v0.2.5-alpha.29]: https://github.com/robolaunch/robot-operator/compare/v0.2.5-alpha.28...v0.2.5-alpha.29
[v0.2.5-alpha.28]: https://github.com/robolaunch/robot-operator/compare/v0.2.5-alpha.27...v0.2.5-alpha.28
Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ kind: Kustomization
images:
- name: controller
newName: robolaunchio/robot-controller-manager
newTag: v0.2.5-alpha.31
newTag: v0.2.5-alpha.32
4 changes: 2 additions & 2 deletions hack/deploy/chart/robot-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.5-alpha.31
version: 0.2.5-alpha.32
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "v0.2.5-alpha.31"
appVersion: "v0.2.5-alpha.32"
2 changes: 1 addition & 1 deletion hack/deploy/chart/robot-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ controllerManager:
- ALL
image:
repository: robolaunchio/robot-controller-manager
tag: v0.2.5-alpha.31
tag: v0.2.5-alpha.32
resources:
limits:
cpu: 500m
Expand Down
2 changes: 1 addition & 1 deletion hack/deploy/manifests/robot_operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6948,7 +6948,7 @@ spec:
- --leader-elect
command:
- /manager
image: robolaunchio/robot-controller-manager:v0.2.5-alpha.31
image: robolaunchio/robot-controller-manager:v0.2.5-alpha.32
livenessProbe:
httpGet:
path: /healthz
Expand Down
27 changes: 27 additions & 0 deletions internal/configure/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func InjectGenericEnvironmentVariablesForPodSpec(podSpec *corev1.PodSpec, robot

for key, cont := range podSpec.Containers {
cont.Env = append(cont.Env, internal.Env("WORKSPACES_PATH", robot.Spec.WorkspaceManagerTemplate.WorkspacesPath))
cont.Env = append(cont.Env, internal.Env("ROS2_SETUP_PATH", "/opt/ros/"+string(robot.Spec.Distributions[0])+"/setup.bash"))
podSpec.Containers[key] = cont
}

Expand All @@ -20,6 +21,32 @@ func InjectGenericEnvironmentVariables(pod *corev1.Pod, robot robotv1alpha1.Robo

for key, cont := range pod.Spec.Containers {
cont.Env = append(cont.Env, internal.Env("WORKSPACES_PATH", robot.Spec.WorkspaceManagerTemplate.WorkspacesPath))
cont.Env = append(cont.Env, internal.Env("ROS2_SETUP_PATH", "/opt/ros/"+string(robot.Spec.Distributions[0])+"/setup.bash"))
pod.Spec.Containers[key] = cont
}

return pod
}

func InjectWorkspaceEnvironmentVariableForContainer(container *corev1.Container, robot robotv1alpha1.Robot, workspace string) *corev1.Container {
container.Env = append(container.Env, internal.Env("WORKSPACE", robot.Spec.WorkspaceManagerTemplate.WorkspacesPath+"/"+workspace))
return container
}

func InjectWorkspaceEnvironmentVariableForPodSpec(podSpec *corev1.PodSpec, robot robotv1alpha1.Robot, workspace string) *corev1.PodSpec {

for key, cont := range podSpec.Containers {
cont.Env = append(cont.Env, internal.Env("WORKSPACE", robot.Spec.WorkspaceManagerTemplate.WorkspacesPath+"/"+workspace))
podSpec.Containers[key] = cont
}

return podSpec
}

func InjectWorkspaceEnvironmentVariable(pod *corev1.Pod, robot robotv1alpha1.Robot, workspace string) *corev1.Pod {

for key, cont := range pod.Spec.Containers {
cont.Env = append(cont.Env, internal.Env("WORKSPACE", robot.Spec.WorkspaceManagerTemplate.WorkspacesPath+"/"+workspace))
pod.Spec.Containers[key] = cont
}

Expand Down
1 change: 1 addition & 0 deletions internal/resources/build_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func GetBuildJob(buildManager *robotv1alpha1.BuildManager, robot *robotv1alpha1.

configure.InjectGenericEnvironmentVariablesForPodSpec(&podSpec, *robot)
configure.InjectLinuxUserAndGroupForPodSpec(&podSpec, *robot)
configure.InjectWorkspaceEnvironmentVariableForPodSpec(&podSpec, *robot, step.Workspace)
configure.InjectRMWImplementationConfigurationForPodSpec(&podSpec, *robot)

job := batchv1.Job{
Expand Down
2 changes: 2 additions & 0 deletions internal/resources/launch_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func getContainer(launch robotv1alpha1.Launch, launchName string, robot robotv1a
},
}

configure.InjectWorkspaceEnvironmentVariableForContainer(&container, robot, launch.Workspace)

return container
}

Expand Down

0 comments on commit e5c75ac

Please sign in to comment.