Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def failed_to_connect_to_cluster(in_cluster_value, exc):
return DatabandConfigError(
"Could not connect to kubernetes cluster! Exception: %s" % (exc,),
help_msg="in-cluster is set to '%s'. Are you running %s cluster?"
% (in_cluster_value, "inside" if in_cluster_value else "outside"),
)
def wrong_store_name(name):
return DatabandConfigError(
"Unsupported tracking store: '{}', use one of file/console/api".format(name),
help_msg="Please check you configuration at [core] tracker.",
)
def airflow_bad_user_configuration(ex, file_path):
return DatabandConfigError(
"Error while trying to load additional airflow configuration from %s"
% file_path,
help_msg="Please make sure that the configuration file %s does exist."
% file_path,
nested_exceptions=ex,
show_exc_info=False,
)
def task_not_found_in_pipeline(task, tasks, task_regex):
all_tasks_names = ",".join([t.task_id for t in tasks])
return DatabandConfigError(
"None of '%s' tasks have been found at current pipeline!" % task_regex,
help_msg="check your --run-task switch, "
"select one of following tasks: %s" % all_tasks_names,
show_exc_info=False,
)
def kubernetes_pod_unschedulable(kub_message, extra_help=None):
help_msg = ""
if "taints" in kub_message:
help_msg = "Either remove taints from at least one of the Kubernetes nodes or add tolerations to the Kubernetes engine config."
if extra_help:
help_msg = help_msg + "\n" + extra_help
return DatabandConfigError(
"Failed to start Kubernetes pod because it couldn't be scheduled. Reason: %s"
% kub_message,
help_msg=help_msg,
)
args = [
textwrap.dedent(
"""
trap "touch {trap_file}" EXIT
{command}
""".format(
trap_file=self.trap_exit_file_flag,
command=subprocess.list2cmdline(cmds),
)
)
]
# we update cmd now
cmds = ["/bin/bash", "-c"]
if not self.container_tag:
raise DatabandConfigError(
"Your container tag is None, please check your configuration",
help_msg="Container tag should be assigned",
)
pod = Pod(
namespace=self.namespace,
name=pod_name,
envs=env_vars,
image=image,
cmds=cmds,
args=args,
labels=labels,
image_pull_policy=self.image_pull_policy,
image_pull_secrets=self.image_pull_secrets,
secrets=secrets,
service_account_name=self.service_account_name,
def kubernetes_image_not_found(image_name, message):
return DatabandConfigError(
"Failed to start Kubernetes pod because the configured image (%s) could not be pulled by Kubernetes: %s"
% (image_name, message),
help_msg="Make sure you built and pushed your image. If the image is in a private repository make sure you "
"configured image pull secrets for it in the Kubernetes cluster and configured image_pull_secrets in the Kubernetes engine config.",
configs = []
if not in_quiet_mode():
logger.info(
"Reading configuration from: \n\t%s\n", "\n\t".join(map(str, files_to_load))
)
for f in files_to_load:
if not f.exists():
raise DatabandConfigError(
"Failed to read configuration file at %s, file not found!" % f
)
try:
configs.append(read_from_config_file(f))
except Exception as ex:
raise DatabandConfigError(
"Failed to read configuration file at %s: %s" % (f, ex),
nested_exceptions=ex,
)
merged_file_config = functools.reduce((lambda x, y: x.update(y)), configs)
return merged_file_config
"""
if isinstance(config_values, _ConfigStore):
return config_values
new_config = _ConfigStore()
new_config.source = source
for section, section_values in six.iteritems(config_values):
if isinstance(section, six.string_types):
if auto_section_parse:
m = _SECTION_NAME_RE.match(section)
if m: # section contains key!
section, key = m.group(1), m.group(2)
section_values = {key: section_values}
if not isinstance(section_values, Mapping):
raise DatabandConfigError(
"can't convert '%s' to configuration " % config_values
)
elif isinstance(section, ParameterDefinition):
# this is parameter -> Spark.jars = ["jars"]
section_values = {section.name: section_values}
section = section.task_config_section
else:
raise Exception("section='%s' not supported" % section)
new_section = new_config[section]
for key, value in six.iteritems(section_values):
if key in new_section:
raise Exception(
"multiple definition of {section}.{key} at {config}".format(
section=section, key=key, config=config_values
def parse_from_str(self, x):
"""
Parses an immutable and ordered ``dict`` from a JSON string using standard JSON library.
Parse an individual value from the input.
"""
# if isinstance(value, Mapping):
# # we are good to go, it'x dictionary already
# return value
if not x:
return self._generate_empty_default()
# this is string and we need to parse it
if not isinstance(x, six.string_types):
raise DatabandConfigError(
"Can't parse '%x' into parameter. Value should be string" % x
)
x = x.strip()
if not x:
return self._generate_empty_default()
if x[0] in _PARSABLE_PARAM_PREFIX:
value = json_utils.loads(x)
else:
value = self._parse_from_str_simple(x)
if not self.is_type_of(value):
raise DatabandConfigError(
"Can't parse '%s' into %s" % (value, self.type)
)