diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c47af11..acb83259 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,7 +84,7 @@ jobs: python-version: ${{ matrix.python_version }} - name: Install molecule and openshift dependencies - run: pip install molecule yamllint openshift + run: pip install molecule yamllint openshift flake8 - name: Install ansible base (devel branch) run: pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 37f7c3bc..37cb0028 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -9,6 +9,7 @@ driver: lint: | set -e yamllint . + flake8 platforms: - name: instance-kind provisioner: diff --git a/plugins/connection/kubectl.py b/plugins/connection/kubectl.py index b320c494..71f21e2f 100644 --- a/plugins/connection/kubectl.py +++ b/plugins/connection/kubectl.py @@ -173,7 +173,6 @@ import os import os.path import subprocess -import ansible.constants as C from ansible.parsing.yaml.loader import AnsibleLoader from ansible.errors import AnsibleError, AnsibleFileNotFound from ansible.module_utils.six.moves import shlex_quote diff --git a/plugins/inventory/k8s.py b/plugins/inventory/k8s.py index 0c663b76..9c314562 100644 --- a/plugins/inventory/k8s.py +++ b/plugins/inventory/k8s.py @@ -317,7 +317,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable, K8sAnsibleM try: self.inventory.add_child(namespace_services_group, service_name) - except AnsibleError as e: + except AnsibleError: raise ports = [{'name': port.name, diff --git a/plugins/lookup/k8s.py b/plugins/lookup/k8s.py index bcedc976..68fa9df5 100644 --- a/plugins/lookup/k8s.py +++ b/plugins/lookup/k8s.py @@ -202,7 +202,6 @@ from ansible_collections.community.kubernetes.plugins.module_utils.common import try: - from openshift.dynamic import DynamicClient from openshift.dynamic.exceptions import NotFoundError HAS_K8S_MODULE_HELPER = True k8s_import_exception = None @@ -210,12 +209,6 @@ except ImportError as e: HAS_K8S_MODULE_HELPER = False k8s_import_exception = e -try: - import yaml - HAS_YAML = True -except ImportError: - HAS_YAML = False - class KubernetesLookup(K8sAnsibleMixin): @@ -226,11 +219,6 @@ class KubernetesLookup(K8sAnsibleMixin): "Requires the OpenShift Python client. Try `pip install openshift`. Detail: {0}".format(k8s_import_exception) ) - if not HAS_YAML: - raise Exception( - "Requires PyYAML. Try `pip install PyYAML`" - ) - self.kind = None self.name = None self.namespace = None diff --git a/plugins/module_utils/common.py b/plugins/module_utils/common.py index 6ea371bf..72046252 100644 --- a/plugins/module_utils/common.py +++ b/plugins/module_utils/common.py @@ -329,21 +329,21 @@ class KubernetesAnsibleModule(AnsibleModule, K8sAnsibleMixin): # Scaling up means that we also need to check that we're not in a # situation where status.replicas == status.availableReplicas # but spec.replicas != status.replicas - return (deployment.status and - deployment.spec.replicas == (deployment.status.replicas or 0) and - deployment.status.availableReplicas == deployment.status.replicas and - deployment.status.observedGeneration == deployment.metadata.generation and - not deployment.status.unavailableReplicas) + return (deployment.status + and deployment.spec.replicas == (deployment.status.replicas or 0) + and deployment.status.availableReplicas == deployment.status.replicas + and deployment.status.observedGeneration == deployment.metadata.generation + and not deployment.status.unavailableReplicas) def _pod_ready(pod): - return (pod.status and pod.status.containerStatuses is not None and - all([container.ready for container in pod.status.containerStatuses])) + return (pod.status and pod.status.containerStatuses is not None + and all([container.ready for container in pod.status.containerStatuses])) def _daemonset_ready(daemonset): - return (daemonset.status and daemonset.status.desiredNumberScheduled is not None and - daemonset.status.numberReady == daemonset.status.desiredNumberScheduled and - daemonset.status.observedGeneration == daemonset.metadata.generation and - not daemonset.status.unavailableReplicas) + return (daemonset.status and daemonset.status.desiredNumberScheduled is not None + and daemonset.status.numberReady == daemonset.status.desiredNumberScheduled + and daemonset.status.observedGeneration == daemonset.metadata.generation + and not daemonset.status.unavailableReplicas) def _custom_condition(resource): if not resource.status or not resource.status.conditions: diff --git a/plugins/module_utils/raw.py b/plugins/module_utils/raw.py index 775deef7..59dbdf3b 100644 --- a/plugins/module_utils/raw.py +++ b/plugins/module_utils/raw.py @@ -39,11 +39,6 @@ except ImportError: # Exceptions handled in common pass -try: - import kubernetes_validate - HAS_KUBERNETES_VALIDATE = True -except ImportError: - HAS_KUBERNETES_VALIDATE = False K8S_CONFIG_HASH_IMP_ERR = None try: diff --git a/plugins/modules/k8s_auth.py b/plugins/modules/k8s_auth.py index d225132c..3af297ba 100644 --- a/plugins/modules/k8s_auth.py +++ b/plugins/modules/k8s_auth.py @@ -251,7 +251,7 @@ class KubernetesAuthModule(AnsibleModule): self.openshift_auth_endpoint = oauth_info['authorization_endpoint'] self.openshift_token_endpoint = oauth_info['token_endpoint'] - except Exception as e: + except Exception: self.fail_json(msg="Something went wrong discovering OpenShift OAuth details.", exception=traceback.format_exc()) @@ -311,7 +311,7 @@ class KubernetesAuthModule(AnsibleModule): "kind": "DeleteOptions" } - ret = requests.delete(url, headers=headers, json=json, verify=self.con_verify_ca) + requests.delete(url, headers=headers, json=json, verify=self.con_verify_ca) # Ignore errors, the token will time out eventually anyway def fail(self, msg=None): diff --git a/plugins/modules/k8s_service.py b/plugins/modules/k8s_service.py index dcfd714b..6df0ab5e 100644 --- a/plugins/modules/k8s_service.py +++ b/plugins/modules/k8s_service.py @@ -181,7 +181,7 @@ import traceback from collections import defaultdict -from ansible_collections.community.kubernetes.plugins.module_utils.common import AUTH_ARG_SPEC, COMMON_ARG_SPEC +from ansible_collections.community.kubernetes.plugins.module_utils.common import AUTH_ARG_SPEC from ansible_collections.community.kubernetes.plugins.module_utils.raw import KubernetesRawModule diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..29c924b8 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[flake8] +max-line-length = 160 +ignore = W503,E402