in cli/src/klio_cli/commands/job/gke.py [0:0]
def _apply_resource(self, resource_config):
"""Create a namespaced resource if the resource does not already exist.
If the namespaced resource already exists then
`self.run_job_config.update` will determine if the
resource will be updated or not.
"""
api_version = resource_config["apiVersion"]
kind = resource_config["kind"]
resource_name = glom.glom(resource_config, "metadata.name")
namespace = glom.glom(resource_config, "metadata.namespace")
if self._resource_exists(resource_config):
if self.run_job_config.update:
self._update_resource(resource_config)
else:
logging.warning(
f"Cannot apply {kind} for {resource_name}. "
"To update an existing resource, run "
"`klio job run --update`, or set `pipeline_options.update`"
" to `True` in the job's`klio-job.yaml` file. "
"Run `klio job stop` to scale a deployment down to 0. "
"Run `klio job delete` to delete a deployment entirely."
)
return
else:
api_instance = self.dynamic_client.resources.get(
api_version=api_version, kind=kind
)
api_instance.create(
namespace=namespace, body=resource_config,
)
current_cluster = self.kubernetes_active_context["name"]
logging.info(
f"Created {kind} {resource_name} "
f"in cluster {current_cluster}."
)