Skip to content

Commit

Permalink
feat(gpu): 🚀 support additional configs
Browse files Browse the repository at this point in the history
  • Loading branch information
tunahanertekin authored Sep 25, 2023
2 parents eb29883 + 3cc0a3a commit 7724753
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 115 deletions.
14 changes: 14 additions & 0 deletions config/crd/bases/robot.roboscale.io_robotartifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ spec:
template:
description: Holds Robot's `.spec`.
properties:
additionalConfigs:
additionalProperties:
properties:
configType:
default: Operator
description: Config type is by default `Operator`. Other options
are `Env` and `File`.
type: string
value:
description: Value of the corresponding config key.
type: string
type: object
description: Key value pairs that operator uses to extend configuration.
type: object
environment:
description: Holds environment's configuration. Applied if `.spec.type`
is `Environment` and must be `nil` otherwise.
Expand Down
117 changes: 14 additions & 103 deletions config/crd/bases/robot.roboscale.io_robots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ spec:
spec:
description: Specification of the desired behavior of the Robot.
properties:
additionalConfigs:
additionalProperties:
properties:
configType:
default: Operator
description: Config type is by default `Operator`. Other options
are `Env` and `File`.
type: string
value:
description: Value of the corresponding config key.
type: string
type: object
description: Key value pairs that operator uses to extend configuration.
type: object
environment:
description: Holds environment's configuration. Applied if `.spec.type`
is `Environment` and must be `nil` otherwise.
Expand Down Expand Up @@ -1755,109 +1769,6 @@ spec:
description: Main image of Robot. It is derived either from the specifications
or determined directly over labels.
type: string
initialBuildManagerStatus:
description: '[*alpha*] Initial build manager creation status if exists.'
properties:
created:
description: Shows if the owned resource is created.
type: boolean
phase:
description: Phase of the owned resource.
type: string
reference:
description: Reference to the owned resource.
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: 'If referring to a piece of an object instead
of an entire object, this string should contain a valid
JSON/Go field access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container within
a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that triggered
the event) or if no container name is specified "spec.containers[2]"
(container with index 2 in this pod). This syntax is chosen
only to have some well-defined way of referencing a part
of an object. TODO: this design is not final and this field
is subject to change in the future.'
type: string
kind:
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
type: string
namespace:
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
type: string
resourceVersion:
description: 'Specific resourceVersion to which this reference
is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
type: string
uid:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
x-kubernetes-map-type: atomic
required:
- created
type: object
initialLaunchManagerStatuses:
description: '[*alpha*] Initial launch manager creation status if
exists.'
items:
description: Generic status for any owned resource.
properties:
created:
description: Shows if the owned resource is created.
type: boolean
phase:
description: Phase of the owned resource.
type: string
reference:
description: Reference to the owned resource.
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: 'If referring to a piece of an object instead
of an entire object, this string should contain a valid
JSON/Go field access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container
within a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that
triggered the event) or if no container name is specified
"spec.containers[2]" (container with index 2 in this pod).
This syntax is chosen only to have some well-defined way
of referencing a part of an object. TODO: this design
is not final and this field is subject to change in the
future.'
type: string
kind:
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
type: string
namespace:
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
type: string
resourceVersion:
description: 'Specific resourceVersion to which this reference
is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
type: string
uid:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
x-kubernetes-map-type: atomic
required:
- created
type: object
type: array
loaderJobStatus:
description: Status of loader job that configures environment.
properties:
Expand Down
4 changes: 2 additions & 2 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: robolaunchio/robot-controller-manager
newTag: v0.2.6-alpha.6
newName: robolaunchio/robot-controller-manager-dev
newTag: platform-v0.7.23
46 changes: 46 additions & 0 deletions internal/configure/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@ func InjectGenericEnvironmentVariablesForPodSpec(podSpec *corev1.PodSpec, robot
podSpec.Containers[key] = cont
}

for cfgKey, cfg := range robot.Spec.AdditionalConfigs {
if cfg.ConfigType == robotv1alpha1.AdditionalConfigTypeEnv {
for key, cont := range podSpec.Containers {
cont.Env = append(cont.Env, internal.Env(cfgKey, cfg.Value))
podSpec.Containers[key] = cont
}
}
}

for key, cont := range podSpec.InitContainers {
cont.Env = append(cont.Env, internal.Env("WORKSPACES_PATH", robot.Spec.WorkspaceManagerTemplate.WorkspacesPath))
podSpec.InitContainers[key] = cont
}

for cfgKey, cfg := range robot.Spec.AdditionalConfigs {
if cfg.ConfigType == robotv1alpha1.AdditionalConfigTypeEnv {
for key, cont := range podSpec.InitContainers {
cont.Env = append(cont.Env, internal.Env(cfgKey, cfg.Value))
podSpec.InitContainers[key] = cont
}
}
}

return podSpec
}

Expand All @@ -33,6 +56,29 @@ func InjectGenericEnvironmentVariables(pod *corev1.Pod, robot robotv1alpha1.Robo
pod.Spec.Containers[key] = cont
}

for cfgKey, cfg := range robot.Spec.AdditionalConfigs {
if cfg.ConfigType == robotv1alpha1.AdditionalConfigTypeEnv {
for key, cont := range pod.Spec.Containers {
cont.Env = append(cont.Env, internal.Env(cfgKey, cfg.Value))
pod.Spec.Containers[key] = cont
}
}
}

for key, cont := range pod.Spec.InitContainers {
cont.Env = append(cont.Env, internal.Env("WORKSPACES_PATH", robot.Spec.WorkspaceManagerTemplate.WorkspacesPath))
pod.Spec.InitContainers[key] = cont
}

for cfgKey, cfg := range robot.Spec.AdditionalConfigs {
if cfg.ConfigType == robotv1alpha1.AdditionalConfigTypeEnv {
for key, cont := range pod.Spec.InitContainers {
cont.Env = append(cont.Env, internal.Env(cfgKey, cfg.Value))
pod.Spec.InitContainers[key] = cont
}
}
}

return pod
}

Expand Down
2 changes: 2 additions & 0 deletions internal/resources/robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func GetLoaderJobForRobot(robot *robotv1alpha1.Robot, jobNamespacedName *types.N
podSpec.NodeSelector = label.GetTenancyMap(robot)

configure.InjectImagePullPolicyForPodSpec(podSpec)
configure.InjectGenericEnvironmentVariablesForPodSpec(podSpec, *robot)

job := batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -342,6 +343,7 @@ func GetLoaderJobForEnvironment(robot *robotv1alpha1.Robot, jobNamespacedName *t
podSpec.NodeSelector = label.GetTenancyMap(robot)

configure.InjectImagePullPolicyForPodSpec(podSpec)
configure.InjectGenericEnvironmentVariablesForPodSpec(podSpec, *robot)

job := batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Expand Down
22 changes: 18 additions & 4 deletions pkg/api/roboscale.io/v1alpha1/robot_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,22 @@ type EnvironmentConfig struct {
DevSpaceImage DevSpaceImage `json:"devspace"`
}

type AdditionalConfigType string

const (
AdditionalConfigTypeEnv AdditionalConfigType = "Env"
AdditionalConfigTypeOperator AdditionalConfigType = "Operator"
AdditionalConfigTypeFile AdditionalConfigType = "File"
)

type AdditionalConfig struct {
// Config type is by default `Operator`. Other options are `Env` and `File`.
// +kubebuilder:default=Operator
ConfigType AdditionalConfigType `json:"configType,omitempty"`
// Value of the corresponding config key.
Value string `json:"value,omitempty"`
}

// RobotSpec defines the desired state of Robot.
type RobotSpec struct {
// Determines the object type.
Expand All @@ -297,6 +313,8 @@ type RobotSpec struct {
RobotDevSuiteTemplate RobotDevSuiteSpec `json:"robotDevSuiteTemplate,omitempty"`
// Workspace manager template to configure ROS 2 workspaces.
WorkspaceManagerTemplate WorkspaceManagerSpec `json:"workspaceManagerTemplate,omitempty"`
// Key value pairs that operator uses to extend configuration.
AdditionalConfigs map[string]AdditionalConfig `json:"additionalConfigs,omitempty"`
// [*alpha*] Root DNS configuration.
RootDNSConfig RootDNSConfig `json:"rootDNSConfig,omitempty"`
// [*alpha*] TLS secret reference.
Expand Down Expand Up @@ -378,10 +396,6 @@ type RobotStatus struct {
// and value of the target robot's name.
// Multiple LaunchManager could work together if they targeted the same Robot.
AttachedLaunchObjects []AttachedLaunchObject `json:"attachedLaunchObjects,omitempty"`
// [*alpha*] Initial build manager creation status if exists.
InitialBuildManagerStatus OwnedResourceStatus `json:"initialBuildManagerStatus,omitempty"`
// [*alpha*] Initial launch manager creation status if exists.
InitialLaunchManagerStatuses []OwnedResourceStatus `json:"initialLaunchManagerStatuses,omitempty"`
// [*alpha*] Attached dev object information.
AttachedDevObjects []AttachedDevObject `json:"attachedDevObjects,omitempty"`
}
Expand Down
28 changes: 22 additions & 6 deletions pkg/api/roboscale.io/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7724753

Please sign in to comment.