Skip to content

Commit

Permalink
[All] Don't default function argument to config value (#1350)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hedingber committed Sep 24, 2021
1 parent 53c3f49 commit a144858
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 23 deletions.
4 changes: 3 additions & 1 deletion mlrun/api/api/endpoints/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def delete_artifact(

@router.get("/artifacts")
def list_artifacts(
project: str = config.default_project,
project: str = None,
name: str = None,
tag: str = None,
kind: str = None,
Expand All @@ -147,6 +147,8 @@ def list_artifacts(
auth_verifier: deps.AuthVerifierDep = Depends(deps.AuthVerifierDep),
db_session: Session = Depends(deps.get_db_session),
):
if project is None:
project = config.default_project
mlrun.api.utils.clients.opa.Client().query_project_permissions(
project, mlrun.api.schemas.AuthorizationAction.read, auth_verifier.auth_info,
)
Expand Down
4 changes: 3 additions & 1 deletion mlrun/api/api/endpoints/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,15 @@ def delete_function(

@router.get("/funcs")
def list_functions(
project: str = config.default_project,
project: str = None,
name: str = None,
tag: str = None,
labels: List[str] = Query([], alias="label"),
auth_verifier: deps.AuthVerifierDep = Depends(deps.AuthVerifierDep),
db_session: Session = Depends(deps.get_db_session),
):
if project is None:
project = config.default_project
mlrun.api.utils.clients.opa.Client().query_project_permissions(
project, mlrun.api.schemas.AuthorizationAction.read, auth_verifier.auth_info,
)
Expand Down
12 changes: 9 additions & 3 deletions mlrun/api/api/endpoints/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)
def list_pipelines(
project: str,
namespace: str = config.namespace,
namespace: str = None,
sort_by: str = "",
page_token: str = "",
filter_: str = Query("", alias="filter"),
Expand All @@ -39,6 +39,8 @@ def list_pipelines(
),
db_session: Session = Depends(deps.get_db_session),
):
if namespace is None:
namespace = config.namespace
if project != "*":
mlrun.api.utils.clients.opa.Client().query_project_permissions(
project,
Expand Down Expand Up @@ -84,13 +86,15 @@ def list_pipelines(
# TODO: remove when 0.6.6 is no longer relevant
async def submit_pipeline_legacy(
request: Request,
namespace: str = config.namespace,
namespace: str = None,
experiment_name: str = Query("Default", alias="experiment"),
run_name: str = Query("", alias="run"),
auth_verifier: mlrun.api.api.deps.AuthVerifierDep = Depends(
mlrun.api.api.deps.AuthVerifierDep
),
):
if namespace is None:
namespace = config.namespace
response = await _create_pipeline(
auth_verifier.auth_info, request, namespace, experiment_name, run_name,
)
Expand All @@ -101,13 +105,15 @@ async def submit_pipeline_legacy(
async def create_pipeline(
project: str,
request: Request,
namespace: str = config.namespace,
namespace: str = None,
experiment_name: str = Query("Default", alias="experiment"),
run_name: str = Query("", alias="run"),
auth_verifier: mlrun.api.api.deps.AuthVerifierDep = Depends(
mlrun.api.api.deps.AuthVerifierDep
),
):
if namespace is None:
namespace = config.namespace
response = await _create_pipeline(
auth_verifier.auth_info, request, namespace, experiment_name, run_name, project
)
Expand Down
21 changes: 14 additions & 7 deletions mlrun/db/httpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def delete_runtime_resources(
kind: Optional[str] = None,
object_id: Optional[str] = None,
force: bool = False,
grace_period: int = config.runtime_resources_deletion_grace_period,
grace_period: int = None,
) -> mlrun.api.schemas.GroupedByProjectRuntimeResourcesOutput:
""" Delete all runtime resources which are in terminal state.
Expand All @@ -818,6 +818,8 @@ def delete_runtime_resources(
:returns: :py:class:`~mlrun.api.schemas.GroupedByProjectRuntimeResourcesOutput` listing the runtime resources
that were removed.
"""
if grace_period is None:
grace_period = config.runtime_resources_deletion_grace_period

params = {
"label-selector": label_selector,
Expand All @@ -843,10 +845,7 @@ def delete_runtime_resources(
return structured_dict

def delete_runtimes(
self,
label_selector: str = None,
force: bool = False,
grace_period: int = config.runtime_resources_deletion_grace_period,
self, label_selector: str = None, force: bool = False, grace_period: int = None,
):
""" Deprecated use :py:func:`~delete_runtime_resources` instead
"""
Expand All @@ -856,6 +855,8 @@ def delete_runtimes(
# TODO: Remove in 0.9.0
DeprecationWarning,
)
if grace_period is None:
grace_period = config.runtime_resources_deletion_grace_period
params = {
"label_selector": label_selector,
"force": force,
Expand All @@ -869,7 +870,7 @@ def delete_runtime(
kind: str,
label_selector: str = None,
force: bool = False,
grace_period: int = config.runtime_resources_deletion_grace_period,
grace_period: int = None,
):
""" Deprecated use :py:func:`~delete_runtime_resources` (with kind filter) instead
"""
Expand All @@ -880,6 +881,9 @@ def delete_runtime(
DeprecationWarning,
)

if grace_period is None:
grace_period = config.runtime_resources_deletion_grace_period

params = {
"label_selector": label_selector,
"force": force,
Expand All @@ -895,7 +899,7 @@ def delete_runtime_object(
object_id: str,
label_selector: str = None,
force: bool = False,
grace_period: int = config.runtime_resources_deletion_grace_period,
grace_period: int = None,
):
""" Deprecated use :py:func:`~delete_runtime_resources` (with kind and object_id filter) instead
"""
Expand All @@ -905,6 +909,9 @@ def delete_runtime_object(
# TODO: Remove in 0.9.0
DeprecationWarning,
)

if grace_period is None:
grace_period = config.runtime_resources_deletion_grace_period
params = {
"label_selector": label_selector,
"force": force,
Expand Down
21 changes: 16 additions & 5 deletions mlrun/runtimes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,8 +1032,10 @@ def delete_resources(
db_session: Session,
label_selector: str = None,
force: bool = False,
grace_period: int = config.runtime_resources_deletion_grace_period,
grace_period: int = None,
):
if grace_period is None:
grace_period = config.runtime_resources_deletion_grace_period
# We currently don't support removing runtime resources in non k8s env
if not mlrun.k8s_utils.get_k8s_helper(
silent=True
Expand Down Expand Up @@ -1070,8 +1072,10 @@ def delete_runtime_object_resources(
object_id: str,
label_selector: str = None,
force: bool = False,
grace_period: int = config.runtime_resources_deletion_grace_period,
grace_period: int = None,
):
if grace_period is None:
grace_period = config.runtime_resources_deletion_grace_period
label_selector = self._add_object_label_selector_if_needed(
object_id, label_selector
)
Expand Down Expand Up @@ -1165,11 +1169,14 @@ def _delete_resources(
deleted_resources: List[Dict],
label_selector: str = None,
force: bool = False,
grace_period: int = config.runtime_resources_deletion_grace_period,
grace_period: int = None,
):
"""
Override this to handle deletion of resources other then pods or CRDs (which are handled by the base class)
Note that this is happening before the deletion of the CRDs or the pods
Note to add this at the beginning:
if grace_period is None:
grace_period = config.runtime_resources_deletion_grace_period
"""
pass

Expand Down Expand Up @@ -1417,8 +1424,10 @@ def _delete_pod_resources(
namespace: str,
label_selector: str = None,
force: bool = False,
grace_period: int = config.runtime_resources_deletion_grace_period,
grace_period: int = None,
) -> List[Dict]:
if grace_period is None:
grace_period = config.runtime_resources_deletion_grace_period
k8s_helper = get_k8s_helper()
pods = k8s_helper.v1api.list_namespaced_pod(
namespace, label_selector=label_selector
Expand Down Expand Up @@ -1477,8 +1486,10 @@ def _delete_crd_resources(
namespace: str,
label_selector: str = None,
force: bool = False,
grace_period: int = config.runtime_resources_deletion_grace_period,
grace_period: int = None,
) -> List[Dict]:
if grace_period is None:
grace_period = config.runtime_resources_deletion_grace_period
k8s_helper = get_k8s_helper()
crd_group, crd_version, crd_plural = self._get_crd_info()
deleted_crds = []
Expand Down
4 changes: 3 additions & 1 deletion mlrun/runtimes/daskjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,11 +678,13 @@ def _delete_resources(
deleted_resources: List[Dict],
label_selector: str = None,
force: bool = False,
grace_period: int = config.runtime_resources_deletion_grace_period,
grace_period: int = None,
):
"""
Handling services deletion
"""
if grace_period is None:
grace_period = config.runtime_resources_deletion_grace_period
service_names = []
for pod_dict in deleted_resources:
dask_component = (
Expand Down
6 changes: 1 addition & 5 deletions mlrun/runtimes/sparkjob/spark2job.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from mlrun.config import config

from ...utils import update_in
from .abstract import AbstractSparkJobSpec, AbstractSparkRuntime

Expand All @@ -27,9 +25,7 @@ def _enrich_job(self, job):
update_in(job, "spec.serviceAccount", "sparkapp")
return

def with_priority_class(
self, name: str = config.default_function_priority_class_name
):
def with_priority_class(self, name: str = None):
raise NotImplementedError("Not supported in spark 2 operator")

def _get_spark_version(self):
Expand Down

0 comments on commit a144858

Please sign in to comment.