summaryrefslogtreecommitdiffstats
path: root/k8s/k8splugin
diff options
context:
space:
mode:
authorMiroslav Los <miroslav.los@pantheon.tech>2019-12-18 18:28:59 +0100
committerMiroslav Los <miroslav.los@pantheon.tech>2020-01-17 19:02:50 +0100
commitb10bd92fc39633dbfffba2e5bd5c4630baf880e6 (patch)
treea58da0e1a1b53869553cb94f8619d97daf0bca09 /k8s/k8splugin
parent0208d99f681e2a0f00a4f0cd8e7a45f41ea67c1a (diff)
Address k8s plugin code smells reported by sonar
Make 'resources' argument to k8sclient.k8sclient.deploy an optional kwarg, update its uses and document it. Split off code reported complex from deploy into functions. Tweak a nested if in tasks. Signed-off-by: Miroslav Los <miroslav.los@pantheon.tech> Issue-ID: DCAEGEN2-2006 Change-Id: I13a091de9207bab1c7d4eee3179263c5d994ffbf
Diffstat (limited to 'k8s/k8splugin')
-rw-r--r--k8s/k8splugin/tasks.py44
1 files changed, 21 insertions, 23 deletions
diff --git a/k8s/k8splugin/tasks.py b/k8s/k8splugin/tasks.py
index 2bfd3e1..eff7d43 100644
--- a/k8s/k8splugin/tasks.py
+++ b/k8s/k8splugin/tasks.py
@@ -2,7 +2,7 @@
# org.onap.dcae
# ================================================================================
# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
-# Copyright (c) 2019 Pantheon.tech. All rights reserved.
+# Copyright (c) 2020 Pantheon.tech. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -279,19 +279,19 @@ def _create_and_start_container(container_name, image, **kwargs):
ctx.logger.info("Passing k8sconfig: {}".format(plugin_conf))
replicas = kwargs.get("replicas", 1)
resource_config = _get_resources(**kwargs)
- _,dep = k8sclient.deploy(DCAE_NAMESPACE,
+ _, dep = k8sclient.deploy(DCAE_NAMESPACE,
container_name,
image,
- replicas = replicas,
+ replicas=replicas,
always_pull=kwargs.get("always_pull_image", False),
k8sconfig=plugin_conf,
- resources = resource_config,
- volumes=kwargs.get("volumes",[]),
- ports=kwargs.get("ports",[]),
+ resources=resource_config,
+ volumes=kwargs.get("volumes", []),
+ ports=kwargs.get("ports", []),
msb_list=kwargs.get("msb_list"),
tls_info=kwargs.get("tls_info"),
- env = env,
- labels = kwargs.get("labels", {}),
+ env=env,
+ labels=kwargs.get("labels", {}),
log_info=kwargs.get("log_info"),
readiness=kwargs.get("readiness"),
liveness=kwargs.get("liveness"),
@@ -639,23 +639,21 @@ def _notify_container(**kwargs):
dc = kwargs["docker_config"]
resp = []
- if "policy" in dc:
- if dc["policy"]["trigger_type"] == "docker":
+ if "policy" in dc and dc["policy"].get("trigger_type") == "docker":
+ # Build the command to execute in the container
+ # SCRIPT_PATH policies {"policies" : ...., "updated_policies" : ..., "removed_policies": ...}
+ script_path = dc["policy"]["script_path"]
+ policy_data = {
+ "policies": kwargs["policies"],
+ "updated_policies": kwargs["updated_policies"],
+ "removed_policies": kwargs["removed_policies"]
+ }
- # Build the command to execute in the container
- # SCRIPT_PATH policies {"policies" : ...., "updated_policies" : ..., "removed_policies": ...}
- script_path = dc["policy"]["script_path"]
- policy_data = {
- "policies": kwargs["policies"],
- "updated_policies": kwargs["updated_policies"],
- "removed_policies": kwargs["removed_policies"]
- }
+ command = [script_path, "policies", json.dumps(policy_data)]
- command = [script_path, "policies", json.dumps(policy_data)]
-
- # Execute the command
- deployment_description = ctx.instance.runtime_properties[K8S_DEPLOYMENT]
- resp = k8sclient.execute_command_in_deployment(deployment_description, command)
+ # Execute the command
+ deployment_description = ctx.instance.runtime_properties[K8S_DEPLOYMENT]
+ resp = k8sclient.execute_command_in_deployment(deployment_description, command)
# else the default is no trigger