Skip to content

Commit 89e6c5b

Browse files
Changes in docs for release: v0.7.0
1 parent ba780da commit 89e6c5b

File tree

4 files changed

+242
-6
lines changed

4 files changed

+242
-6
lines changed

docs/cluster/auth.html

+34-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
5454

5555
import abc
5656
from kubernetes import client, config
57+
import os
58+
from ..utils.kube_api_helpers import _kube_api_error_handling
5759

5860
global api_client
5961
api_client = None
@@ -194,8 +196,23 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
194196
&#34;&#34;&#34;
195197
global config_path
196198
global api_client
199+
home_directory = os.path.expanduser(&#34;~&#34;)
197200
if config_path == None and api_client == None:
198-
config.load_kube_config()
201+
if os.path.isfile(&#34;%s/.kube/config&#34; % home_directory):
202+
try:
203+
config.load_kube_config()
204+
except Exception as e: # pragma: no cover
205+
_kube_api_error_handling(e)
206+
elif &#34;KUBERNETES_PORT&#34; in os.environ:
207+
try:
208+
config.load_incluster_config()
209+
except Exception as e: # pragma: no cover
210+
_kube_api_error_handling(e)
211+
else:
212+
raise PermissionError(
213+
&#34;Action not permitted, have you put in correct/up-to-date auth credentials?&#34;
214+
)
215+
199216
if config_path != None and api_client == None:
200217
return config_path
201218

@@ -253,8 +270,23 @@ <h2 class="section-title" id="header-functions">Functions</h2>
253270
&#34;&#34;&#34;
254271
global config_path
255272
global api_client
273+
home_directory = os.path.expanduser(&#34;~&#34;)
256274
if config_path == None and api_client == None:
257-
config.load_kube_config()
275+
if os.path.isfile(&#34;%s/.kube/config&#34; % home_directory):
276+
try:
277+
config.load_kube_config()
278+
except Exception as e: # pragma: no cover
279+
_kube_api_error_handling(e)
280+
elif &#34;KUBERNETES_PORT&#34; in os.environ:
281+
try:
282+
config.load_incluster_config()
283+
except Exception as e: # pragma: no cover
284+
_kube_api_error_handling(e)
285+
else:
286+
raise PermissionError(
287+
&#34;Action not permitted, have you put in correct/up-to-date auth credentials?&#34;
288+
)
289+
258290
if config_path != None and api_client == None:
259291
return config_path</code></pre>
260292
</details>

docs/cluster/cluster.html

+145
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,39 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
9393
self.app_wrapper_yaml = self.create_app_wrapper()
9494
self.app_wrapper_name = self.app_wrapper_yaml.split(&#34;.&#34;)[0]
9595

96+
def evaluate_config(self):
97+
if not self.evaluate_dispatch_priority():
98+
return False
99+
else:
100+
return True
101+
102+
def evaluate_dispatch_priority(self):
103+
priority_class = self.config.dispatch_priority
104+
if priority_class is None:
105+
return True
106+
else:
107+
try:
108+
config_check()
109+
api_instance = client.CustomObjectsApi(api_config_handler())
110+
priority_classes = api_instance.list_cluster_custom_object(
111+
group=&#34;scheduling.k8s.io&#34;,
112+
version=&#34;v1&#34;,
113+
plural=&#34;priorityclasses&#34;,
114+
)
115+
available_priority_classes = [
116+
i[&#34;metadata&#34;][&#34;name&#34;] for i in priority_classes[&#34;items&#34;]
117+
]
118+
except Exception as e: # pragma: no cover
119+
return _kube_api_error_handling(e)
120+
121+
if priority_class in available_priority_classes:
122+
return True
123+
else:
124+
print(
125+
f&#34;Priority class {priority_class} is not available in the cluster&#34;
126+
)
127+
return False
128+
96129
def create_app_wrapper(self):
97130
&#34;&#34;&#34;
98131
Called upon cluster object creation, creates an AppWrapper yaml based on
@@ -123,6 +156,7 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
123156
env = self.config.envs
124157
local_interactive = self.config.local_interactive
125158
image_pull_secrets = self.config.image_pull_secrets
159+
dispatch_priority = self.config.dispatch_priority
126160
return generate_appwrapper(
127161
name=name,
128162
namespace=namespace,
@@ -139,6 +173,7 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
139173
env=env,
140174
local_interactive=local_interactive,
141175
image_pull_secrets=image_pull_secrets,
176+
dispatch_priority=dispatch_priority,
142177
)
143178

144179
# creates a new cluster with the provided or default spec
@@ -147,6 +182,12 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
147182
Applies the AppWrapper yaml, pushing the resource request onto
148183
the MCAD queue.
149184
&#34;&#34;&#34;
185+
186+
# Before attempting to bring up the cluster let&#39;s evaluate the ClusterConfig
187+
if not self.evaluate_config():
188+
print(&#34;Invalid Cluster Configuration&#34;)
189+
return False
190+
150191
namespace = self.config.namespace
151192
try:
152193
config_check()
@@ -787,6 +828,39 @@ <h2 class="section-title" id="header-classes">Classes</h2>
787828
self.app_wrapper_yaml = self.create_app_wrapper()
788829
self.app_wrapper_name = self.app_wrapper_yaml.split(&#34;.&#34;)[0]
789830

831+
def evaluate_config(self):
832+
if not self.evaluate_dispatch_priority():
833+
return False
834+
else:
835+
return True
836+
837+
def evaluate_dispatch_priority(self):
838+
priority_class = self.config.dispatch_priority
839+
if priority_class is None:
840+
return True
841+
else:
842+
try:
843+
config_check()
844+
api_instance = client.CustomObjectsApi(api_config_handler())
845+
priority_classes = api_instance.list_cluster_custom_object(
846+
group=&#34;scheduling.k8s.io&#34;,
847+
version=&#34;v1&#34;,
848+
plural=&#34;priorityclasses&#34;,
849+
)
850+
available_priority_classes = [
851+
i[&#34;metadata&#34;][&#34;name&#34;] for i in priority_classes[&#34;items&#34;]
852+
]
853+
except Exception as e: # pragma: no cover
854+
return _kube_api_error_handling(e)
855+
856+
if priority_class in available_priority_classes:
857+
return True
858+
else:
859+
print(
860+
f&#34;Priority class {priority_class} is not available in the cluster&#34;
861+
)
862+
return False
863+
790864
def create_app_wrapper(self):
791865
&#34;&#34;&#34;
792866
Called upon cluster object creation, creates an AppWrapper yaml based on
@@ -817,6 +891,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
817891
env = self.config.envs
818892
local_interactive = self.config.local_interactive
819893
image_pull_secrets = self.config.image_pull_secrets
894+
dispatch_priority = self.config.dispatch_priority
820895
return generate_appwrapper(
821896
name=name,
822897
namespace=namespace,
@@ -833,6 +908,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
833908
env=env,
834909
local_interactive=local_interactive,
835910
image_pull_secrets=image_pull_secrets,
911+
dispatch_priority=dispatch_priority,
836912
)
837913

838914
# creates a new cluster with the provided or default spec
@@ -841,6 +917,12 @@ <h2 class="section-title" id="header-classes">Classes</h2>
841917
Applies the AppWrapper yaml, pushing the resource request onto
842918
the MCAD queue.
843919
&#34;&#34;&#34;
920+
921+
# Before attempting to bring up the cluster let&#39;s evaluate the ClusterConfig
922+
if not self.evaluate_config():
923+
print(&#34;Invalid Cluster Configuration&#34;)
924+
return False
925+
844926
namespace = self.config.namespace
845927
try:
846928
config_check()
@@ -1181,6 +1263,7 @@ <h3>Methods</h3>
11811263
env = self.config.envs
11821264
local_interactive = self.config.local_interactive
11831265
image_pull_secrets = self.config.image_pull_secrets
1266+
dispatch_priority = self.config.dispatch_priority
11841267
return generate_appwrapper(
11851268
name=name,
11861269
namespace=namespace,
@@ -1197,6 +1280,7 @@ <h3>Methods</h3>
11971280
env=env,
11981281
local_interactive=local_interactive,
11991282
image_pull_secrets=image_pull_secrets,
1283+
dispatch_priority=dispatch_priority,
12001284
)</code></pre>
12011285
</details>
12021286
</dd>
@@ -1246,6 +1330,59 @@ <h3>Methods</h3>
12461330
return _kube_api_error_handling(e)</code></pre>
12471331
</details>
12481332
</dd>
1333+
<dt id="codeflare_sdk.cluster.cluster.Cluster.evaluate_config"><code class="name flex">
1334+
<span>def <span class="ident">evaluate_config</span></span>(<span>self)</span>
1335+
</code></dt>
1336+
<dd>
1337+
<div class="desc"></div>
1338+
<details class="source">
1339+
<summary>
1340+
<span>Expand source code</span>
1341+
</summary>
1342+
<pre><code class="python">def evaluate_config(self):
1343+
if not self.evaluate_dispatch_priority():
1344+
return False
1345+
else:
1346+
return True</code></pre>
1347+
</details>
1348+
</dd>
1349+
<dt id="codeflare_sdk.cluster.cluster.Cluster.evaluate_dispatch_priority"><code class="name flex">
1350+
<span>def <span class="ident">evaluate_dispatch_priority</span></span>(<span>self)</span>
1351+
</code></dt>
1352+
<dd>
1353+
<div class="desc"></div>
1354+
<details class="source">
1355+
<summary>
1356+
<span>Expand source code</span>
1357+
</summary>
1358+
<pre><code class="python">def evaluate_dispatch_priority(self):
1359+
priority_class = self.config.dispatch_priority
1360+
if priority_class is None:
1361+
return True
1362+
else:
1363+
try:
1364+
config_check()
1365+
api_instance = client.CustomObjectsApi(api_config_handler())
1366+
priority_classes = api_instance.list_cluster_custom_object(
1367+
group=&#34;scheduling.k8s.io&#34;,
1368+
version=&#34;v1&#34;,
1369+
plural=&#34;priorityclasses&#34;,
1370+
)
1371+
available_priority_classes = [
1372+
i[&#34;metadata&#34;][&#34;name&#34;] for i in priority_classes[&#34;items&#34;]
1373+
]
1374+
except Exception as e: # pragma: no cover
1375+
return _kube_api_error_handling(e)
1376+
1377+
if priority_class in available_priority_classes:
1378+
return True
1379+
else:
1380+
print(
1381+
f&#34;Priority class {priority_class} is not available in the cluster&#34;
1382+
)
1383+
return False</code></pre>
1384+
</details>
1385+
</dd>
12491386
<dt id="codeflare_sdk.cluster.cluster.Cluster.from_k8_cluster_object"><code class="name flex">
12501387
<span>def <span class="ident">from_k8_cluster_object</span></span>(<span>rc)</span>
12511388
</code></dt>
@@ -1486,6 +1623,12 @@ <h3>Methods</h3>
14861623
Applies the AppWrapper yaml, pushing the resource request onto
14871624
the MCAD queue.
14881625
&#34;&#34;&#34;
1626+
1627+
# Before attempting to bring up the cluster let&#39;s evaluate the ClusterConfig
1628+
if not self.evaluate_config():
1629+
print(&#34;Invalid Cluster Configuration&#34;)
1630+
return False
1631+
14891632
namespace = self.config.namespace
14901633
try:
14911634
config_check()
@@ -1570,6 +1713,8 @@ <h4><code><a title="codeflare_sdk.cluster.cluster.Cluster" href="#codeflare_sdk.
15701713
<li><code><a title="codeflare_sdk.cluster.cluster.Cluster.create_app_wrapper" href="#codeflare_sdk.cluster.cluster.Cluster.create_app_wrapper">create_app_wrapper</a></code></li>
15711714
<li><code><a title="codeflare_sdk.cluster.cluster.Cluster.details" href="#codeflare_sdk.cluster.cluster.Cluster.details">details</a></code></li>
15721715
<li><code><a title="codeflare_sdk.cluster.cluster.Cluster.down" href="#codeflare_sdk.cluster.cluster.Cluster.down">down</a></code></li>
1716+
<li><code><a title="codeflare_sdk.cluster.cluster.Cluster.evaluate_config" href="#codeflare_sdk.cluster.cluster.Cluster.evaluate_config">evaluate_config</a></code></li>
1717+
<li><code><a title="codeflare_sdk.cluster.cluster.Cluster.evaluate_dispatch_priority" href="#codeflare_sdk.cluster.cluster.Cluster.evaluate_dispatch_priority">evaluate_dispatch_priority</a></code></li>
15731718
<li><code><a title="codeflare_sdk.cluster.cluster.Cluster.from_k8_cluster_object" href="#codeflare_sdk.cluster.cluster.Cluster.from_k8_cluster_object">from_k8_cluster_object</a></code></li>
15741719
<li><code><a title="codeflare_sdk.cluster.cluster.Cluster.job_logs" href="#codeflare_sdk.cluster.cluster.Cluster.job_logs">job_logs</a></code></li>
15751720
<li><code><a title="codeflare_sdk.cluster.cluster.Cluster.job_status" href="#codeflare_sdk.cluster.cluster.Cluster.job_status">job_status</a></code></li>

docs/cluster/config.html

+10-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.config</code></h1>
7878
envs: dict = field(default_factory=dict)
7979
image: str = &#34;quay.io/project-codeflare/ray:2.5.0-py38-cu116&#34;
8080
local_interactive: bool = False
81-
image_pull_secrets: list = field(default_factory=list)</code></pre>
81+
image_pull_secrets: list = field(default_factory=list)
82+
dispatch_priority: str = None</code></pre>
8283
</details>
8384
</section>
8485
<section>
@@ -92,7 +93,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
9293
<dl>
9394
<dt id="codeflare_sdk.cluster.config.ClusterConfiguration"><code class="flex name class">
9495
<span>class <span class="ident">ClusterConfiguration</span></span>
95-
<span>(</span><span>name: str, namespace: str = None, head_info: list = &lt;factory&gt;, machine_types: list = &lt;factory&gt;, min_cpus: int = 1, max_cpus: int = 1, num_workers: int = 1, min_memory: int = 2, max_memory: int = 2, num_gpus: int = 0, template: str = '/home/runner/work/codeflare-sdk/codeflare-sdk/src/codeflare_sdk/templates/base-template.yaml', instascale: bool = False, envs: dict = &lt;factory&gt;, image: str = 'quay.io/project-codeflare/ray:2.5.0-py38-cu116', local_interactive: bool = False, image_pull_secrets: list = &lt;factory&gt;)</span>
96+
<span>(</span><span>name: str, namespace: str = None, head_info: list = &lt;factory&gt;, machine_types: list = &lt;factory&gt;, min_cpus: int = 1, max_cpus: int = 1, num_workers: int = 1, min_memory: int = 2, max_memory: int = 2, num_gpus: int = 0, template: str = '/home/runner/work/codeflare-sdk/codeflare-sdk/src/codeflare_sdk/templates/base-template.yaml', instascale: bool = False, envs: dict = &lt;factory&gt;, image: str = 'quay.io/project-codeflare/ray:2.5.0-py38-cu116', local_interactive: bool = False, image_pull_secrets: list = &lt;factory&gt;, dispatch_priority: str = None)</span>
9697
</code></dt>
9798
<dd>
9899
<div class="desc"><p>This dataclass is used to specify resource requirements and other details, and
@@ -122,10 +123,15 @@ <h2 class="section-title" id="header-classes">Classes</h2>
122123
envs: dict = field(default_factory=dict)
123124
image: str = &#34;quay.io/project-codeflare/ray:2.5.0-py38-cu116&#34;
124125
local_interactive: bool = False
125-
image_pull_secrets: list = field(default_factory=list)</code></pre>
126+
image_pull_secrets: list = field(default_factory=list)
127+
dispatch_priority: str = None</code></pre>
126128
</details>
127129
<h3>Class variables</h3>
128130
<dl>
131+
<dt id="codeflare_sdk.cluster.config.ClusterConfiguration.dispatch_priority"><code class="name">var <span class="ident">dispatch_priority</span> : str</code></dt>
132+
<dd>
133+
<div class="desc"></div>
134+
</dd>
129135
<dt id="codeflare_sdk.cluster.config.ClusterConfiguration.envs"><code class="name">var <span class="ident">envs</span> : dict</code></dt>
130136
<dd>
131137
<div class="desc"></div>
@@ -211,6 +217,7 @@ <h1>Index</h1>
211217
<li>
212218
<h4><code><a title="codeflare_sdk.cluster.config.ClusterConfiguration" href="#codeflare_sdk.cluster.config.ClusterConfiguration">ClusterConfiguration</a></code></h4>
213219
<ul class="two-column">
220+
<li><code><a title="codeflare_sdk.cluster.config.ClusterConfiguration.dispatch_priority" href="#codeflare_sdk.cluster.config.ClusterConfiguration.dispatch_priority">dispatch_priority</a></code></li>
214221
<li><code><a title="codeflare_sdk.cluster.config.ClusterConfiguration.envs" href="#codeflare_sdk.cluster.config.ClusterConfiguration.envs">envs</a></code></li>
215222
<li><code><a title="codeflare_sdk.cluster.config.ClusterConfiguration.head_info" href="#codeflare_sdk.cluster.config.ClusterConfiguration.head_info">head_info</a></code></li>
216223
<li><code><a title="codeflare_sdk.cluster.config.ClusterConfiguration.image" href="#codeflare_sdk.cluster.config.ClusterConfiguration.image">image</a></code></li>

0 commit comments

Comments
 (0)