def deploy(self, source='', dashboard='', project='', tag='', kind=None): self.set_config('metadata.labels.mlrun/class', self.kind) spec = nuclio.ConfigSpec(env=self.spec.env, config=self.spec.config) spec.cmd = self.spec.build_commands kind = kind or self.spec.function_kind project = project or self.metadata.project or 'mlrun' source = source or self.spec.source handler = self.spec.function_handler if self.spec.base_spec: config = nuclio.config.extend_config(self.spec.base_spec, spec, tag, self.spec.source) update_in(config, 'metadata.name', self.metadata.name) update_in(config, 'spec.volumes', self.spec.volumes) addr = nuclio.deploy.deploy_config( config, dashboard, name=self.metadata.name, project=project, tag=tag, verbose=self.verbose, create_new=True) else: name, config, code = nuclio.build_file(source, name=self.metadata.name, project=project, handler=handler, tag=tag, spec=spec, kind=kind, verbose=self.verbose) update_in(config, 'spec.volumes', self.spec.volumes) addr = deploy_config(config, dashboard_url=dashboard, name=name, project=project, tag=tag, verbose=self.verbose, create_new=True) self.spec.command = 'http://{}'.format(addr) return self.spec.command
def deploy(self, dashboard='', project='', tag='', kind=None): self.set_config('metadata.labels.mlrun/class', self.kind) env_dict = { get_item_name(v): get_item_name(v, 'value') for v in self.spec.env } spec = nuclio.ConfigSpec(env=env_dict, config=self.spec.config) spec.cmd = self.spec.build.commands or [] project = project or self.metadata.project or 'default' handler = self.spec.function_handler if self.spec.no_cache: spec.set_config('spec.build.noCache', True) if self.spec.base_spec: if kind: raise ValueError('kind cannot be specified on built functions') config = nuclio.config.extend_config(self.spec.base_spec, spec, tag, self.spec.build.code_origin) update_in(config, 'metadata.name', self.metadata.name) update_in(config, 'spec.volumes', self.spec.to_nuclio_vol()) logger.info('deploy started') addr = nuclio.deploy.deploy_config(config, dashboard, name=self.metadata.name, project=project, tag=tag, verbose=self.verbose, create_new=True) else: kind = kind if kind is not None else self.spec.function_kind name, config, code = nuclio.build_file(self.spec.source, name=self.metadata.name, project=project, handler=handler, tag=tag, spec=spec, kind=kind, verbose=self.verbose) update_in(config, 'spec.volumes', self.spec.to_nuclio_vol()) addr = deploy_config(config, dashboard_url=dashboard, name=name, project=project, tag=tag, verbose=self.verbose, create_new=True) self.spec.command = 'http://{}'.format(addr) return self.spec.command
def compile_function_config(function: RemoteRuntime): function.set_config("metadata.labels.mlrun/class", function.kind) # Add vault configurations to function's pod spec, if vault secret source was added. # Needs to be here, since it adds env params, which are handled in the next lines. function.add_secrets_config_to_spec() env_dict = {get_item_name(v): get_item_name(v, "value") for v in function.spec.env} for key, value in function._get_runtime_env().items(): env_dict[key] = value spec = nuclio.ConfigSpec(env=env_dict, config=function.spec.config) spec.cmd = function.spec.build.commands or [] project = function.metadata.project or "default" tag = function.metadata.tag handler = function.spec.function_handler # In Nuclio >= 1.6.x default serviceType has changed to "ClusterIP". spec.set_config("spec.serviceType", mlconf.httpdb.nuclio.default_service_type) if function.spec.readiness_timeout: spec.set_config("spec.readinessTimeoutSeconds", function.spec.readiness_timeout) if function.spec.resources: spec.set_config("spec.resources", function.spec.resources) if function.spec.no_cache: spec.set_config("spec.build.noCache", True) if function.spec.build.functionSourceCode: spec.set_config( "spec.build.functionSourceCode", function.spec.build.functionSourceCode ) if function.spec.replicas: spec.set_config("spec.minReplicas", function.spec.replicas) spec.set_config("spec.maxReplicas", function.spec.replicas) else: spec.set_config("spec.minReplicas", function.spec.min_replicas) spec.set_config("spec.maxReplicas", function.spec.max_replicas) if function.spec.base_spec or function.spec.build.functionSourceCode: config = function.spec.base_spec if not config: # if base_spec was not set (when not using code_to_function) and we have base64 code # we create the base spec with essential attributes config = nuclio.config.new_config() update_in(config, "spec.handler", handler or "main:handler") config = nuclio.config.extend_config( config, spec, tag, function.spec.build.code_origin ) update_in(config, "metadata.name", function.metadata.name) update_in(config, "spec.volumes", function.spec.generate_nuclio_volumes()) base_image = get_in(config, "spec.build.baseImage") or function.spec.image if base_image: update_in(config, "spec.build.baseImage", enrich_image_url(base_image)) logger.info("deploy started") name = get_fullname(function.metadata.name, project, tag) function.status.nuclio_name = name update_in(config, "metadata.name", name) else: name, config, code = nuclio.build_file( function.spec.source, name=function.metadata.name, project=project, handler=handler, tag=tag, spec=spec, kind=function.spec.function_kind, verbose=function.verbose, ) update_in(config, "spec.volumes", function.spec.generate_nuclio_volumes()) if function.spec.image: update_in( config, "spec.build.baseImage", enrich_image_url(function.spec.image) ) name = get_fullname(name, project, tag) function.status.nuclio_name = name update_in(config, "metadata.name", name) return name, project, config
def deploy_nuclio_function(function: RemoteRuntime, dashboard="", watch=False): function.set_config("metadata.labels.mlrun/class", function.kind) env_dict = { get_item_name(v): get_item_name(v, "value") for v in function.spec.env } for key, value in function._get_runtime_env().items(): env_dict[key] = value spec = nuclio.ConfigSpec(env=env_dict, config=function.spec.config) spec.cmd = function.spec.build.commands or [] project = function.metadata.project or "default" tag = function.metadata.tag handler = function.spec.function_handler # In Nuclio 1.6.0 default serviceType changed to "ClusterIP", make sure we're using NodePort spec.set_config("spec.serviceType", "NodePort") if function.spec.readiness_timeout: spec.set_config("spec.readinessTimeoutSeconds", function.spec.readiness_timeout) if function.spec.resources: spec.set_config("spec.resources", function.spec.resources) if function.spec.no_cache: spec.set_config("spec.build.noCache", True) if function.spec.replicas: spec.set_config("spec.minReplicas", function.spec.replicas) spec.set_config("spec.maxReplicas", function.spec.replicas) else: spec.set_config("spec.minReplicas", function.spec.min_replicas) spec.set_config("spec.maxReplicas", function.spec.max_replicas) dashboard = dashboard or mlconf.nuclio_dashboard_url if function.spec.base_spec: config = nuclio.config.extend_config(function.spec.base_spec, spec, tag, function.spec.build.code_origin) update_in(config, "metadata.name", function.metadata.name) update_in(config, "spec.volumes", function.spec.to_nuclio_vol()) base_image = get_in(config, "spec.build.baseImage") or function.spec.image if base_image: update_in(config, "spec.build.baseImage", enrich_image_url(base_image)) logger.info("deploy started") name = get_fullname(function.metadata.name, project, tag) function.status.nuclio_name = name update_in(config, "metadata.name", name) return nuclio.deploy.deploy_config( config, dashboard, name=name, project=project, tag=tag, verbose=function.verbose, create_new=True, watch=watch, ) else: name, config, code = nuclio.build_file( function.spec.source, name=function.metadata.name, project=project, handler=handler, tag=tag, spec=spec, kind=function.spec.function_kind, verbose=function.verbose, ) update_in(config, "spec.volumes", function.spec.to_nuclio_vol()) if function.spec.image: update_in(config, "spec.build.baseImage", enrich_image_url(function.spec.image)) name = get_fullname(name, project, tag) function.status.nuclio_name = name update_in(config, "metadata.name", name) return deploy_config( config, dashboard_url=dashboard, name=name, project=project, tag=tag, verbose=function.verbose, create_new=True, watch=watch, )
def __init__(self, metadata=None, spec=None): super().__init__(metadata, spec) self._config = nuclio.ConfigSpec() self.verbose = False self.dashboard = '' self.kind = ''
def compile_function_config(function: RemoteRuntime): labels = function.metadata.labels or {} labels.update({"mlrun/class": function.kind}) for key, value in labels.items(): function.set_config(f"metadata.labels.{key}", value) # Add vault configurations to function's pod spec, if vault secret source was added. # Needs to be here, since it adds env params, which are handled in the next lines. function.add_secrets_config_to_spec() env_dict, external_source_env_dict = function.get_nuclio_config_spec_env() spec = nuclio.ConfigSpec( env=env_dict, external_source_env=external_source_env_dict, config=function.spec.config, ) spec.cmd = function.spec.build.commands or [] project = function.metadata.project or "default" tag = function.metadata.tag handler = function.spec.function_handler # In Nuclio >= 1.6.x default serviceType has changed to "ClusterIP". spec.set_config("spec.serviceType", mlconf.httpdb.nuclio.default_service_type) if function.spec.readiness_timeout: spec.set_config("spec.readinessTimeoutSeconds", function.spec.readiness_timeout) if function.spec.resources: spec.set_config("spec.resources", function.spec.resources) if function.spec.no_cache: spec.set_config("spec.build.noCache", True) if function.spec.build.functionSourceCode: spec.set_config("spec.build.functionSourceCode", function.spec.build.functionSourceCode) # don't send node selections if nuclio is not compatible if validate_nuclio_version_compatibility("1.5.20", "1.6.10"): if function.spec.node_selector: spec.set_config("spec.nodeSelector", function.spec.node_selector) if function.spec.node_name: spec.set_config("spec.nodeName", function.spec.node_name) if function.spec.affinity: spec.set_config("spec.affinity", function.spec._get_sanitized_affinity()) # don't send default or any priority class name if nuclio is not compatible if (function.spec.priority_class_name and validate_nuclio_version_compatibility("1.6.18") and len(mlconf.get_valid_function_priority_class_names())): spec.set_config("spec.priorityClassName", function.spec.priority_class_name) if function.spec.replicas: spec.set_config("spec.minReplicas", function.spec.replicas) spec.set_config("spec.maxReplicas", function.spec.replicas) else: spec.set_config("spec.minReplicas", function.spec.min_replicas) spec.set_config("spec.maxReplicas", function.spec.max_replicas) if function.spec.service_account: spec.set_config("spec.serviceAccount", function.spec.service_account) if function.spec.base_spec or function.spec.build.functionSourceCode: config = function.spec.base_spec if not config: # if base_spec was not set (when not using code_to_function) and we have base64 code # we create the base spec with essential attributes config = nuclio.config.new_config() update_in(config, "spec.handler", handler or "main:handler") config = nuclio.config.extend_config(config, spec, tag, function.spec.build.code_origin) update_in(config, "metadata.name", function.metadata.name) update_in(config, "spec.volumes", function.spec.generate_nuclio_volumes()) base_image = (get_in(config, "spec.build.baseImage") or function.spec.image or function.spec.build.base_image) if base_image: update_in(config, "spec.build.baseImage", enrich_image_url(base_image)) logger.info("deploy started") name = get_fullname(function.metadata.name, project, tag) function.status.nuclio_name = name update_in(config, "metadata.name", name) else: name, config, code = nuclio.build_file( function.spec.source, name=function.metadata.name, project=project, handler=handler, tag=tag, spec=spec, kind=function.spec.function_kind, verbose=function.verbose, ) update_in(config, "spec.volumes", function.spec.generate_nuclio_volumes()) base_image = function.spec.image or function.spec.build.base_image if base_image: update_in( config, "spec.build.baseImage", enrich_image_url(base_image), ) name = get_fullname(name, project, tag) function.status.nuclio_name = name update_in(config, "metadata.name", name) return name, project, config
def deploy(self, dashboard='', project='', tag='', kind=None): def get_fullname(config, name, project, tag): if project: name = '{}-{}'.format(project, name) if tag: name = '{}-{}'.format(name, tag) update_in(config, 'metadata.name', name) return name self.set_config('metadata.labels.mlrun/class', self.kind) env_dict = { get_item_name(v): get_item_name(v, 'value') for v in self.spec.env } spec = nuclio.ConfigSpec(env=env_dict, config=self.spec.config) spec.cmd = self.spec.build.commands or [] project = project or self.metadata.project or 'default' handler = self.spec.function_handler if self.spec.no_cache: spec.set_config('spec.build.noCache', True) if self.spec.replicas: spec.set_config('spec.minReplicas', self.spec.replicas) spec.set_config('spec.maxReplicas', self.spec.replicas) else: spec.set_config('spec.minReplicas', self.spec.min_replicas) spec.set_config('spec.maxReplicas', self.spec.max_replicas) dashboard = get_auth_filled_platform_dashboard_url(dashboard) if self.spec.base_spec: if kind: raise ValueError('kind cannot be specified on built functions') config = nuclio.config.extend_config(self.spec.base_spec, spec, tag, self.spec.build.code_origin) update_in(config, 'metadata.name', self.metadata.name) update_in(config, 'spec.volumes', self.spec.to_nuclio_vol()) base_image = get_in(config, 'spec.build.baseImage') if base_image: update_in(config, 'spec.build.baseImage', tag_image(base_image)) logger.info('deploy started') name = get_fullname(config, self.metadata.name, project, tag) addr = nuclio.deploy.deploy_config( config, dashboard, name=name, project=project, tag=tag, verbose=self.verbose, create_new=True, ) else: kind = kind if kind is not None else self.spec.function_kind name, config, code = nuclio.build_file( self.spec.source, name=self.metadata.name, project=project, handler=handler, tag=tag, spec=spec, kind=kind, verbose=self.verbose, ) update_in(config, 'spec.volumes', self.spec.to_nuclio_vol()) name = get_fullname(config, name, project, tag) addr = deploy_config( config, dashboard_url=dashboard, name=name, project=project, tag=tag, verbose=self.verbose, create_new=True, ) self.spec.command = 'http://{}'.format(addr) self.status.nuclio_name = name if addr: self.status.state = 'ready' self.status.address = addr self.save() return self.spec.command