Skip to content

Commit

Permalink
Merge pull request teamhephy#25 from jianxiaoguo/main
Browse files Browse the repository at this point in the history
chore(ps):drycc ps:list show autoscale num
  • Loading branch information
duanhongyi authored Nov 17, 2020
2 parents bc5ea75 + c8e6556 commit 0b1861e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions rootfs/api/models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ def pod_name(size=5, chars=string.ascii_lowercase + string.digits):

def list_pods(self, *args, **kwargs):
"""Used to list basic information about pods running for a given application"""
autoscale = self.appsettings_set.latest().autoscale
try:
labels = self._scheduler_filter(**kwargs)

Expand All @@ -935,7 +936,6 @@ def list_pods(self, *args, **kwargs):
pods = []

data = []
exist_pod_type = []
for p in pods:
labels = p['metadata']['labels']
# specifically ignore run pods
Expand All @@ -962,9 +962,9 @@ def list_pods(self, *args, **kwargs):
else:
started = str(datetime.utcnow().strftime(settings.DRYCC_DATETIME_FORMAT))
item['started'] = started
item['replicas'] = self.structure.get(labels['type'])
if labels['type'] not in exist_pod_type:
exist_pod_type.append(labels['type'])
replicas = str(autoscale[labels['type']]['min']) + '-' + str(autoscale[labels['type']]['max']) \
if autoscale.get(labels['type']) is not None else self.structure.get(labels['type']) # noqa
item['replicas'] = str(replicas)
data.append(item)

# sorting so latest start date is first
Expand Down
2 changes: 1 addition & 1 deletion rootfs/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ class PodSerializer(serializers.BaseSerializer):
type = serializers.CharField()
release = serializers.CharField(required=False)
started = serializers.DateTimeField(required=False)
replicas = serializers.IntegerField(required=False)
replicas = serializers.CharField(required=False)

def to_representation(self, obj):
return obj
Expand Down
13 changes: 9 additions & 4 deletions rootfs/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,18 +342,23 @@ def list(self, *args, **kwargs):
data = self.get_serializer(pods, many=True).data

if not kwargs.get("type"):
autoscale = self.get_app().appsettings_set.latest().autoscale
exist_pod_type = list(set([_["type"] for _ in data if _["type"]]))
for _ in self.get_app().structure.keys():
structure = self.get_app().structure
procfile_structure = self.get_app().procfile_structure
for _ in structure.keys():
if _ not in exist_pod_type:
replicas = str(autoscale[_]['min']) + '-' + str(autoscale[_]['max']) \
if (autoscale.get(_) is not None and structure[_] !=0) else structure[_] # noqa
exist_pod_type.append(_)
data.append({"type": _,
"replicas": self.get_app().structure[_],
"replicas": str(replicas),
"state": "stopped"})

for _ in self.get_app().procfile_structure.keys():
for _ in procfile_structure:
if _ not in exist_pod_type:
data.append({"type": _,
"replicas": 0,
"replicas": str(0),
"state": "started"})

# # fake out pagination for now
Expand Down

0 comments on commit 0b1861e

Please sign in to comment.