Skip to content

Commit

Permalink
Improve running clusters reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
asmorodskyi committed Aug 2, 2022
1 parent 2d7639e commit 4469392
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ docker-container:
docker build . -t ${CONT_TAG}
podman-container:
podman build . -t ${CONT_TAG}

podman-container-devel:
podman build -f Dockerfile_dev -t pcw-devel
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ The PCW container supports two volumes to be mounted:

To create a container using e.g. the data directory `/srv/pcw` for both volumes and expose port 8000, run the following:

podman create --hostname pcw --name pcw -v /srv/pcw/pcw.ini:/etc/pcw.ini -v /srv/pcw/db:/pcw/db -p 8000:8000/tcp ghcr.io/suse/pcw:latest
podman create --hostname pcw --name pcw -v /srv/pcw/pcw.ini:/etc/pcw.ini -v /srv/pcw/db:/pcw/db -v <local creds storage>:/var/pcw -p 8000:8000/tcp ghcr.io/suse/pcw:latest
podman start pcw

For usage in docker simply replace `podman` by `docker` in the above command.
Expand All @@ -103,11 +103,21 @@ The `pcw` container runs by default the `/pcw/container-startup` startup helper

podman exec pcw /pcw/container-startup help

podman run -ti --rm --hostname pcw --name pcw -v /srv/pcw/pcw.ini:/etc/pcw.ini -v /srv/pcw/db:/pcw/db -p 8000:8000/tcp ghcr.io/suse/pcw:latest /pcw/container-startup help
podman run -ti --rm --hostname pcw --name pcw -v /srv/pcw/pcw.ini:/etc/pcw.ini -v <local creds storage>:/var/pcw -v /srv/pcw/db:/pcw/db -p 8000:8000/tcp ghcr.io/suse/pcw:latest /pcw/container-startup help

To create the admin superuser within the created container named `pcw`, run

podman run -ti --rm -v /srv/pcw/pcw.ini:/etc/pcw.ini -v /srv/pcw/db:/pcw/db -p 8000:8000/tcp ghcr.io/suse/pcw:latest /pcw/container-startup createsuperuser --email admin@example.com --username admin
podman run -ti --rm -v /srv/pcw/pcw.ini:/etc/pcw.ini -v /srv/pcw/db:/pcw/db -v <local creds storage>:/var/pcw -p 8000:8000/tcp ghcr.io/suse/pcw:latest /pcw/container-startup createsuperuser --email admin@example.com --username admin

## Devel version of container

There is [devel version](Dockerfile_dev) of container file. Main difference is that source files are not copied into image but expected to be mounted via volume. This ease development in environment close as much as possible to production run.

Expected use would be :

make podman-container-devel
podman run -v <local path to ini file>:/etc/pcw.ini -v <local creds storage>:/var/pcw -v <path to this folder>:/pcw -t pcw-devel <any target from [container-startup](container-startup)>


## Codecov

Expand Down
1 change: 0 additions & 1 deletion container-startup
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ case "$CMD" in
*)
python3 manage.py $@
esac

11 changes: 8 additions & 3 deletions ocw/lib/EC2.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ def eks_client(self, region):
return self.__eks_client[region]

def all_clusters(self):
clusters = list()
for region in self.all_regions:
clusters = dict()
if PCWConfig.has('clusters/ec2_regions'):
cluster_regions = ConfigFile().getList('clusters/ec2_regions')
else:
cluster_regions = self.get_all_regions()
for region in cluster_regions:
response = self.eks_client(region).list_clusters()
[clusters.append(cluster) for cluster in response['clusters']]
if len(response['clusters']):
clusters[region] = response['clusters']
return clusters

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion ocw/lib/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def check_credentials(self):
raise AuthenticationError("Invalid Azure credentials")

def bs_client(self):
if(self.__blob_service_client is None):
if (self.__blob_service_client is None):
storage_account = PCWConfig.get_feature_property(
'cleanup', 'azure-storage-account-name', self._namespace)
storage_key = self.get_storage_key(storage_account)
Expand Down
3 changes: 2 additions & 1 deletion ocw/lib/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def list_clusters():
for namespace in PCWConfig.get_namespaces_for('clusters'):
try:
clusters = EC2(namespace).all_clusters()
logger.info("%d clusters found", len(clusters))
quantity = sum(len(c1) for c1 in clusters.keys())
logger.info("%d clusters found", quantity)
send_cluster_notification(namespace, clusters)
except Exception as e:
logger.exception("[{}] List clusters failed!".format(namespace))
Expand Down
9 changes: 6 additions & 3 deletions ocw/lib/emailnotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ def send_leftover_notification():

def send_cluster_notification(namespace, clusters):
if len(clusters) and PCWConfig.has('notify'):
clusters_str = ' '.join([str(cluster) for cluster in clusters])
clusters_str = ''
for region in clusters:
clusters_list = ' '.join([str(cluster) for cluster in clusters[region]])
clusters_str = '{}\n{} : {}'.format(clusters_str, region, clusters_list)
logger.debug("Full clusters list - %s", clusters_str)
send_mail("EC2 clusters found", clusters_str,
receiver_email=PCWConfig.get_feature_property('cluster.notify', 'to', namespace))
send_mail("[{}] EC2 clusters found".format(namespace), clusters_str,
receiver_email=PCWConfig.get_feature_property('notify', 'to', namespace))


def send_mail(subject, message, receiver_email=None):
Expand Down
2 changes: 1 addition & 1 deletion ocw/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def age_formated(self):
return format_seconds(self.age.total_seconds())

def ttl_formated(self):
return format_seconds(self.ttl.total_seconds()) if(self.ttl) else ""
return format_seconds(self.ttl.total_seconds()) if (self.ttl) else ""

def all_time_fields(self):
all_time_pattern = "(age={}, first_seen={}, last_seen={}, ttl={})"
Expand Down

0 comments on commit 4469392

Please sign in to comment.