Skip to content

Commit

Permalink
feat(deployment): adds toggle to enable cloud params
Browse files Browse the repository at this point in the history
This commit adds the support to enable cloud params for deployments.
  • Loading branch information
pallabpain committed May 9, 2023
1 parent 5eee7d6 commit 9cc7981
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 33 deletions.
96 changes: 64 additions & 32 deletions riocli/deployment/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
from rapyuta_io.clients.native_network import NativeNetwork
from rapyuta_io.clients.package import ProvisionConfiguration, RestartPolicy, \
ExecutableMount
from rapyuta_io.clients.rosbag import ROSBagJob, ROSBagOptions, \
ROSBagCompression, UploadOptions, \
ROSBagOnDemandUploadOptions, ROSBagTimeRange, ROSBagUploadTypes, \
OverrideOptions, TopicOverrideInfo
from rapyuta_io.clients.rosbag import (
ROSBagJob, ROSBagOptions, ROSBagCompression,
UploadOptions, ROSBagOnDemandUploadOptions, ROSBagTimeRange,
ROSBagUploadTypes, OverrideOptions, TopicOverrideInfo)
from rapyuta_io.clients.routed_network import RoutedNetwork

from riocli.deployment.errors import ERRORS
Expand All @@ -43,24 +43,24 @@ class Deployment(Model):
}

def find_object(self, client: Client) -> typing.Any:
guid, obj = self.rc.find_depends({'kind': 'deployment', 'nameOrGUID': self.metadata.name})
if not guid:
return False

return obj
guid, obj = self.rc.find_depends(
{"kind": "deployment", "nameOrGUID": self.metadata.name})
return obj if guid else False

def create_object(self, client: Client) -> typing.Any:
pkg_guid, pkg = self.rc.find_depends(self.metadata.depends, self.metadata.depends.version)
pkg_guid, pkg = self.rc.find_depends(self.metadata.depends,
self.metadata.depends.version)

if pkg_guid:
pkg = client.get_package(pkg_guid)
pkg.update()

default_plan = pkg['plans'][0]
plan_id = default_plan['planId']
internal_component = default_plan['internalComponents'][0]

__planId = default_plan['planId']
__componentName = internal_component.componentName
component_name = internal_component.componentName
component = default_plan['components']['components'][0]
executables = component['executables']
runtime = internal_component['runtime']

if 'runtime' in self.spec and runtime != self.spec.runtime:
Expand All @@ -71,7 +71,7 @@ def create_object(self, client: Client) -> typing.Any:
), fg='red')
return

provision_config = pkg.get_provision_configuration(__planId)
provision_config = pkg.get_provision_configuration(plan_id)

# add label
if 'labels' in self.metadata:
Expand All @@ -81,7 +81,8 @@ def create_object(self, client: Client) -> typing.Any:
# Add envArgs
if 'envArgs' in self.spec:
for items in self.spec.envArgs:
provision_config.add_parameter(__componentName, items.name, items.value)
provision_config.add_parameter(component_name, items.name,
items.value)

# Add Dependent Deployment
if 'depends' in self.spec:
Expand All @@ -105,15 +106,17 @@ def create_object(self, client: Client) -> typing.Any:

if 'rosBagJobs' in self.spec:
for req_job in self.spec.rosBagJobs:
provision_config.add_rosbag_job(__componentName, self._form_rosbag_job(req_job))
provision_config.add_rosbag_job(component_name,
self._form_rosbag_job(req_job))

if self.spec.runtime == 'cloud':
if 'staticRoutes' in self.spec:
for stroute in self.spec.staticRoutes:
route_guid, route = self.rc.find_depends(stroute.depends)
if route is None and route_guid:
route = client.get_static_route(route_guid)
provision_config.add_static_route(__componentName, stroute.name, route)
provision_config.add_static_route(component_name,
stroute.name, route)

# Add Disk
if 'volumes' in self.spec:
Expand All @@ -128,8 +131,9 @@ def create_object(self, client: Client) -> typing.Any:

for disk_guid in disk_mounts.keys():
disk = client.get_volume_instance(disk_guid)
provision_config.mount_volume(__componentName, volume=disk,
executable_mounts=disk_mounts[disk_guid])
provision_config.mount_volume(component_name, volume=disk,
executable_mounts=
disk_mounts[disk_guid])

# TODO: Managed Services is currently limited to `cloud` deployments
# since we don't expose `elasticsearch` outside Openshift. This may
Expand All @@ -150,37 +154,66 @@ def create_object(self, client: Client) -> typing.Any:
"instance": "rio-internal-headscale"
}]

if 'params' in self.spec.features and self.spec.features.params.enabled:
component_id = internal_component.componentId
tree_names = self.spec.features.params.get('trees', [])
disable_sync = self.spec.features.params.get('disableSync',
False)

args = []
for e in executables:
args.append({
'executableId': e['id'],
'paramTreeNames': tree_names,
'enableParamSync': not disable_sync
})

context = provision_config.context
if 'component_context' not in context:
context['component_context'] = {}

component_context = context['component_context']
if component_id not in component_context:
component_context[component_id] = {}

component_context[component_id][
'param_sync_exec_args'] = args

if self.spec.runtime == 'device':
device_guid, device = self.rc.find_depends(
self.spec.device.depends)
if device is None and device_guid:
device = client.get_device(device_guid)
provision_config.add_device(__componentName, device=device,
set_component_alias=False)

provision_config.add_device(
component_name,
device=device,
set_component_alias=False
)

if 'restart' in self.spec:
provision_config.add_restart_policy(
__componentName,
component_name,
self.RESTART_POLICY[self.spec.restart.lower()])

# Add Network
# if self.spec.rosNetworks:
# for network in self.spec.rosNetworks:
# network_type =

# Add Disk
exec_mounts = []
if 'volumes' in self.spec:
for vol in self.spec.volumes:
exec_mounts.append(ExecutableMount(vol.execName, vol.mountPath, vol.subPath))
exec_mounts.append(
ExecutableMount(vol.execName, vol.mountPath,
vol.subPath))

if len(exec_mounts) > 0:
provision_config = add_mount_volume_provision_config(
provision_config, __componentName, device, exec_mounts)
provision_config, component_name, device, exec_mounts)

provision_config.set_component_alias(__componentName, self.metadata.name)
provision_config.set_component_alias(component_name,
self.metadata.name)

if os.environ.get('DEBUG'):
print(provision_config)

deployment = pkg.provision(self.metadata.name, provision_config)

try:
Expand All @@ -191,11 +224,10 @@ def create_object(self, client: Client) -> typing.Any:
raise e

deployment.get_status()

return deployment

def update_object(self, client: Client, obj: typing.Any) -> typing.Any:
if 'depends' in self.spec:
pass
pass

def delete_object(self, client: Client, obj: typing.Any) -> typing.Any:
Expand Down
14 changes: 13 additions & 1 deletion riocli/jsonschema/schemas/deployment-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,19 @@ definitions:
type: boolean
required:
- enabled

params:
type: object
properties:
enabled:
type: boolean
trees:
type: array
items:
type: string
disableSync:
type: boolean
required:
- enabled
envArgs:
type: array
items:
Expand Down

0 comments on commit 9cc7981

Please sign in to comment.