Skip to content

Commit 490d278

Browse files
committed
Added quotas.json and limits.json as python code
1 parent 76bfc04 commit 490d278

File tree

4 files changed

+61
-60
lines changed

4 files changed

+61
-60
lines changed

src/coldfront_plugin_cloud/acct_mgt/moc_openshift.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ def validate_role(role):
5959
f"Invalid role, {role} is not one of {', '.join(OPENSHIFT_ROLES)}"
6060
)
6161

62-
def __init__(self, client, logger, config):
62+
def __init__(self, client, logger, config, quotas, limits):
6363
self.client = client
6464
self.logger = logger
6565
self.id_provider = config["IDENTITY_PROVIDER"]
66-
self.quotafile = config["QUOTA_DEF_FILE"]
67-
self.limitfile = config["LIMIT_DEF_FILE"]
66+
self.quotas = quotas
67+
self.limits = limits
6868
self.apis = {}
6969

7070
if not self.limitfile:
@@ -159,17 +159,15 @@ def update_moc_quota(self, project_name, new_quota, patch=False):
159159
return {"msg": "MOC quotas updated"}
160160

161161
def get_quota_definitions(self):
162-
self.logger.info("reading quotas from %s", self.quotafile)
163-
with open(self.quotafile, "r") as file:
164-
quota = json.load(file)
162+
163+
quota = self.quotas
165164
for k in quota:
166165
quota[k]["value"] = None
167166

168167
return quota
169168

170169
def get_limit_definitions(self):
171-
with open(self.limitfile, "r") as file:
172-
return json.load(file)
170+
return self.limits
173171

174172
def get_project(self, project_name):
175173
api = self.get_resource_api(API_PROJECT, "Project")

src/coldfront_plugin_cloud/openshift.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,59 @@
1919

2020
from coldfront_plugin_cloud import attributes, base, utils
2121

22+
QUOTA_OPENSHIFT = {
23+
":requests.cpu": { "base": 2, "coefficient": 0 },
24+
":requests.memory": { "base": 2, "coefficient": 0 },
25+
":limits.cpu": { "base": 2, "coefficient": 0 },
26+
":limits.memory": { "base": 2, "coefficient": 0 },
27+
":requests.storage": { "base": 2, "coefficient": 0, "units": "Gi" },
28+
":limits.storage": { "base": 2, "coefficient": 0, "units": "Gi" },
29+
":requests.ephemeral-storage": { "base": 2, "coefficient": 8, "units": "Gi" },
30+
":requests.nvidia.com/gpu": { "base": 0, "coefficient": 0 },
31+
":limits.ephemeral-storage": { "base": 2, "coefficient": 8, "units": "Gi" },
32+
":persistentvolumeclaims": { "base": 2, "coefficient": 0 },
33+
":replicationcontrollers": { "base": 2, "coefficient": 0 },
34+
":resourcequotas": { "base": 5, "coefficient": 0 },
35+
":services": { "base": 4, "coefficient": 0 },
36+
":services.loadbalancers": { "base": 2, "coefficient": 0 },
37+
":services.nodeports": { "base": 2, "coefficient": 0 },
38+
":secrets": { "base": 4, "coefficient": 0 },
39+
":configmaps": { "base": 4, "coefficient": 0 },
40+
":openshift.io/imagestreams": { "base": 2, "coefficient": 0 },
41+
"BestEffort:pods": { "base": 2, "coefficient": 2 },
42+
"NotBestEffort:pods": { "base": 2, "coefficient": 2 },
43+
"NotBestEffort:requests.memory": { "base": 2, "coefficient": 4, "units": "Gi" },
44+
"NotBestEffort:limits.memory": { "base": 2, "coefficient": 4, "units": "Gi" },
45+
"NotBestEffort:requests.cpu": { "base": 2, "coefficient": 2 },
46+
"NotBestEffort:limits.cpu": { "base": 2, "coefficient": 2 },
47+
"Terminating:pods": { "base": 2, "coefficient": 2 },
48+
"Terminating:requests.memory": { "base": 2, "coefficient": 4, "units": "Gi" },
49+
"Terminating:limits.memory": { "base": 2, "coefficient": 4, "units": "Gi" },
50+
"Terminating:requests.cpu": { "base": 2, "coefficient": 2 },
51+
"Terminating:limits.cpu": { "base": 2, "coefficient": 2 },
52+
"NotTerminating:pods": { "base": 2, "coefficient": 2 },
53+
"NotTerminating:requests.memory": { "base": 2, "coefficient": 4, "units": "Gi" },
54+
"NotTerminating:limits.memory": { "base": 2, "coefficient": 4, "units": "Gi" },
55+
"NotTerminating:requests.cpu": { "base": 2, "coefficient": 2 },
56+
"NotTerminating:limits.cpu": { "base": 2, "coefficient": 2 }
57+
}
58+
59+
LIMITS_OPENSHIFT = [
60+
{
61+
"type": "Container",
62+
"default": {
63+
"cpu": "2",
64+
"memory": "1024Mi",
65+
"nvidia.com/gpu": "0"
66+
},
67+
"defaultRequest": {
68+
"cpu": "1",
69+
"memory": "512Mi",
70+
"nvidia.com/gpu": "0"
71+
}
72+
}
73+
]
74+
2275
QUOTA_KEY_MAPPING = {
2376
attributes.QUOTA_LIMITS_CPU: lambda x: {":limits.cpu": f"{x * 1000}m"},
2477
attributes.QUOTA_LIMITS_MEMORY: lambda x: {":limits.memory": f"{x}Mi"},
@@ -76,10 +129,11 @@ def __init__(
76129
logger = logging.getLogger()
77130
else:
78131
logger = logging.getLogger("django")
132+
79133
config = env_config()
80134

81135
self.client = moc_openshift.MocOpenShift4x(
82-
DynamicClient(k8s_client), logger, config
136+
DynamicClient(k8s_client), logger, config, QUOTA_OPENSHIFT, LIMITS_OPENSHIFT
83137
)
84138

85139
@functools.cached_property

src/config/limits.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/config/quotas.json

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)