Skip to content

Commit cde3d6b

Browse files
committed
feat(maintenance): add maintenance support for ingress
1 parent d488220 commit cde3d6b

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

rootfs/api/models/app.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -944,15 +944,18 @@ def maintenance_mode(self, mode):
944944
"""
945945
Turn application maintenance mode on/off
946946
"""
947-
service = self._fetch_service_config(self.id)
948-
old_service = service.copy() # in case anything fails for rollback
949-
950-
try:
951-
service['metadata']['annotations']['router.drycc.cc/maintenance'] = str(mode).lower()
952-
self._scheduler.svc.update(self.id, self.id, data=service)
953-
except KubeException as e:
954-
self._scheduler.svc.update(self.id, self.id, data=old_service)
955-
raise ServiceUnavailable(str(e)) from e
947+
if mode:
948+
namespace = ingress = self.id
949+
try:
950+
data = self._scheduler.ingress.get(namespace, ingress).json()
951+
for rule in data["spec"]["rules"]:
952+
for path in rule["http"]["paths"]:
953+
path["backend"]["serviceName"] = "drycc-maintenance-proxy"
954+
self._scheduler.ingress.patch(ingress, namespace, data)
955+
except KubeException:
956+
self.log("creating Ingress {}".format(namespace), level=logging.INFO)
957+
else:
958+
self.refresh_ingress_and_tls()
956959

957960
def routable(self, routable):
958961
"""

rootfs/scheduler/resources/ingress.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ def put(self, ingress, ingress_class, namespace, version, **kwargs):
135135
data = self.manifest(self.api_version, ingress, ingress_class, namespace, **kwargs)
136136
response = self.http_put(url, json=data)
137137

138+
if self.unhealthy(response.status_code):
139+
raise KubeHTTPException(response, "put Ingress {}".format(namespace))
140+
141+
return response
142+
143+
def patch(self, ingress, namespace, data):
144+
url = self.api("/namespaces/{}/ingresses/{}", namespace, ingress)
145+
response = self.http_put(url, json=data)
146+
138147
if self.unhealthy(response.status_code):
139148
raise KubeHTTPException(response, "patch Ingress {}".format(namespace))
140149

0 commit comments

Comments
 (0)