Skip to content

Commit

Permalink
Merge pull request #24 from srntqn/feature/improve-logging
Browse files Browse the repository at this point in the history
Move logging to module level
  • Loading branch information
srntqn authored Feb 12, 2022
2 parents 07376a6 + dcd1855 commit 591fdf9
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@ jobs:
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 ./harmony ./tests --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
env:
CONFIG_LOCATION: test
VERIFY_SSL: True
K8S_API_SERVER_HOST: https://kubernetes.cluster.local
K8S_API_KEY: test
LOG_LEVEL: INFO
run: |
python -m pytest tests
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ RUN . /venv/bin/activate && \
FROM python:3.8

ENV PATH="/venv/bin:${PATH}"
ENV PYTHONWARNINGS="ignore:Unverified HTTPS request"

RUN groupadd -r harmony -g 433 && \
useradd -u 431 -r -g harmony -s /sbin/nologin -c "Docker image user" harmony
Expand All @@ -27,4 +26,4 @@ COPY --chown=harmony:harmony --from=builder /venv/ /venv
WORKDIR /app

USER harmony
ENTRYPOINT ["/venv/bin/python", "-m", "harmony", "run"]
ENTRYPOINT ["/venv/bin/python", "-m", "harmony", "run"]
4 changes: 2 additions & 2 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v1
appVersion: "0.8.0"
appVersion: "0.9.0"
description: Harmony helm chart
name: harmony
version: 0.2.0
version: 0.3.0
6 changes: 5 additions & 1 deletion chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ spec:
value: '{{ .Values.apiHost }}'
- name: LOG_LEVEL
value: '{{ .Values.logLevel }}'
- name: PYTHONUNBUFFERED
value: '1'
- name: PYTHONWARNINGS
value: 'ignore:Unverified HTTPS request'
volumeMounts:
- name: {{ .Values.name }}-conf
mountPath: /app/config
Expand All @@ -48,4 +52,4 @@ spec:
volumes:
- name: {{ .Values.name }}-conf
configMap:
name: {{ .Values.name }}-conf
name: {{ .Values.name }}-conf
5 changes: 0 additions & 5 deletions harmony/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import time
import typer
import logging
import sys

from . import __version__, __module_name__
from .libs.k8s_cluster import KubernetesCluster
Expand All @@ -17,9 +15,6 @@
CONFIG.k8s_api_server,
CONFIG.k8s_api_key)

logging.basicConfig(stream=sys.stdout,
level=logging.getLevelName(CONFIG.log_level))


cli = typer.Typer(name=__module_name__)

Expand Down
20 changes: 14 additions & 6 deletions harmony/libs/worker.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
from cmath import log
import logging
import requests
import sys
import yaml

from .k8s_deployment import K8sDeployment
from .k8s_cluster import KubernetesCluster
from .serializers.project import Project
from .serializers.image import Image
from .serializers.config import Config

logging.basicConfig(stream=sys.stdout,
level=logging.getLevelName(Config().log_level))

logger = logging.getLogger(__name__)


def read_projects_from_config(config_path: str):

with open(config_path) as file:
config = yaml.load(file, Loader=yaml.FullLoader)

logging.info(f"Reading the following projects data: {config}")
logger.info(f"Reading the following projects data: {config}")

return config

Expand All @@ -22,7 +30,7 @@ def fetch_app_version_from_vcs(vcs_url: str) -> str:

r = yaml.load(requests.get(vcs_url).content, Loader=yaml.FullLoader)

logging.debug(f"The content of {vcs_url} is {r}")
logger.debug(f"The content of {vcs_url} is {r}")

return r['version']

Expand All @@ -39,10 +47,10 @@ def sync_versions_in_vcs_and_cluster(project_name: str,
project.app_name,
project.app_namespace)

logging.info(f"""
Image version for {project_name} in cluster: {image.tag_in_cluster}.
Image version for {project_name} in git: {image.tag_in_vcs}.
logger.info(f"""
Image version for {project_name} in cluster: {image.tag_in_cluster}.
Image version for {project_name} in git: {image.tag_in_vcs}.
Updating deployment...
""")
else:
logging.info(f"Nothing was changed for {project_name}. Versions are equal.")
logger.info(f"Nothing was changed for {project_name}. Versions are equal.")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "harmony"
version = "0.8.0"
version = "0.9.0"
description = ""
authors = ["srntqn <[email protected]>"]

Expand Down
10 changes: 10 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from harmony.libs.k8s_cluster import KubernetesCluster
from harmony.libs.k8s_deployment import K8sDeployment
from harmony.libs.serializers.image import Image
from harmony.libs.serializers.config import Config

from kubernetes.client import V1Deployment, V1ObjectMeta, V1DeploymentSpec, V1Container, V1PodTemplateSpec, V1PodSpec

PROJECT = Project(
Expand Down Expand Up @@ -36,3 +38,11 @@ def generate_k8s_deployment() -> V1Deployment:
tag_in_cluster='1.0.0',
tag_in_vcs='1.0.1'
)

CONFIG = Config(
config_location='./',
verify_ssl=False,
k8s_api_server="https://kubernetes.io",
k8s_api_key="test_key",
log_level="INFO",
)

0 comments on commit 591fdf9

Please sign in to comment.