Skip to content

Commit

Permalink
Merge pull request #288 from rpitonak/origin-backend-refactor
Browse files Browse the repository at this point in the history
OpenShift origin backend improvements, refactor, cleanup
  • Loading branch information
jpopelka authored Oct 23, 2018
2 parents b889bfa + d8d35ca commit b2875ee
Show file tree
Hide file tree
Showing 21 changed files with 502 additions and 170 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ usercont/conu:0.5.0 python3 /app/my_source.py

## OpenShift
- create new app using `oc new-app` command
- deploy pure image into openshift
- support building s2i images from remote repository
- support building s2i images from local path
- support creating new applications using OpenShift templates
- push images to internal OpenShift registry
- request service
- waiting until service is ready
- obtain logs from all pods
- get status of application
- check readiness of pods
- cleanup objects of specific application in current namespace

# Docker example
Expand Down
6 changes: 6 additions & 0 deletions conu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
DockerImage, S2IDockerImage, DockerImagePullPolicy, DockerImageViaArchiveFS
)

# k8s backend
from conu.backend.k8s.backend import K8sBackend, K8sCleanupPolicy

# OpenShift
from conu.backend.origin.backend import OpenshiftBackend

# utils
from conu.utils.filesystem import Directory
from conu.utils.probes import Probe, ProbeTimeout, CountExceeded
Expand Down
8 changes: 2 additions & 6 deletions conu/backend/k8s/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
"""
This is backend for kubernetes
"""
import string
import random
import logging
import enum

Expand All @@ -31,6 +29,7 @@
import conu.backend.k8s.client as k8s_client
from conu.exceptions import ConuException
from conu.utils.probes import Probe
from conu.utils import random_str

from kubernetes import client
from kubernetes.client.rest import ApiException
Expand Down Expand Up @@ -110,10 +109,7 @@ def create_namespace(self):
Create namespace with random name
:return: name of new created namespace
"""
random_string = ''.join(
random.choice(string.ascii_lowercase + string.digits) for _ in range(4))

name = 'namespace-{random_string}'.format(random_string=random_string)
name = 'namespace-{random_string}'.format(random_string=random_str(5))

namespace = client.V1Namespace(metadata=client.V1ObjectMeta(name=name))

Expand Down
8 changes: 4 additions & 4 deletions conu/backend/k8s/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ def get_logs(self):
"""
try:
api_response = self.core_api.read_namespaced_pod_log(self.name, self.namespace)
logger.info("Logs from pod: %s in namespace: %s", self.name, self.namespace)
logger.debug("Logs from pod: %s in namespace: %s", self.name, self.namespace)
for line in api_response.split('\n'):
logger.info(line)
logger.debug(line)
return api_response
except ApiException as e:
# no reason to throw exception when logs cannot be obtain, just notify user
logger.info("Cannot get pod logs because of "
"exception during calling Kubernetes API %s\n", e)
logger.debug("Cannot get pod logs because of "
"exception during calling Kubernetes API %s\n", e)

return None

Expand Down
Loading

0 comments on commit b2875ee

Please sign in to comment.