Skip to content

Commit 5a7b57f

Browse files
Changes in docs for release: v0.16.2
1 parent f96c3e3 commit 5a7b57f

File tree

3 files changed

+182
-31
lines changed

3 files changed

+182
-31
lines changed

docs/detailed-documentation/cluster/auth.html

+63-11
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
6565
global config_path
6666
config_path = None
6767

68+
WORKBENCH_CA_CERT_PATH = &#34;/etc/pki/tls/custom-certs/ca-bundle.crt&#34;
69+
6870

6971
class Authentication(metaclass=abc.ABCMeta):
7072
&#34;&#34;&#34;
@@ -124,7 +126,17 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
124126
self.token = token
125127
self.server = server
126128
self.skip_tls = skip_tls
127-
self.ca_cert_path = ca_cert_path
129+
self.ca_cert_path = self._gen_ca_cert_path(ca_cert_path)
130+
131+
def _gen_ca_cert_path(self, ca_cert_path: str):
132+
if ca_cert_path is not None:
133+
return ca_cert_path
134+
elif &#34;CF_SDK_CA_CERT_PATH&#34; in os.environ:
135+
return os.environ.get(&#34;CF_SDK_CA_CERT_PATH&#34;)
136+
elif os.path.exists(WORKBENCH_CA_CERT_PATH):
137+
return WORKBENCH_CA_CERT_PATH
138+
else:
139+
return None
128140

129141
def login(self) -&gt; str:
130142
&#34;&#34;&#34;
@@ -139,10 +151,20 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
139151
configuration.api_key_prefix[&#34;authorization&#34;] = &#34;Bearer&#34;
140152
configuration.host = self.server
141153
configuration.api_key[&#34;authorization&#34;] = self.token
142-
if self.skip_tls == False and self.ca_cert_path == None:
154+
155+
if not self.skip_tls:
156+
if self.ca_cert_path is None:
157+
configuration.ssl_ca_cert = None
158+
elif os.path.isfile(self.ca_cert_path):
159+
print(
160+
f&#34;Authenticated with certificate located at {self.ca_cert_path}&#34;
161+
)
162+
configuration.ssl_ca_cert = self.ca_cert_path
163+
else:
164+
raise FileNotFoundError(
165+
f&#34;Certificate file not found at {self.ca_cert_path}&#34;
166+
)
143167
configuration.verify_ssl = True
144-
elif self.skip_tls == False:
145-
configuration.ssl_ca_cert = self.ca_cert_path
146168
else:
147169
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
148170
print(&#34;Insecure request warnings have been disabled&#34;)
@@ -551,7 +573,17 @@ <h3>Methods</h3>
551573
self.token = token
552574
self.server = server
553575
self.skip_tls = skip_tls
554-
self.ca_cert_path = ca_cert_path
576+
self.ca_cert_path = self._gen_ca_cert_path(ca_cert_path)
577+
578+
def _gen_ca_cert_path(self, ca_cert_path: str):
579+
if ca_cert_path is not None:
580+
return ca_cert_path
581+
elif &#34;CF_SDK_CA_CERT_PATH&#34; in os.environ:
582+
return os.environ.get(&#34;CF_SDK_CA_CERT_PATH&#34;)
583+
elif os.path.exists(WORKBENCH_CA_CERT_PATH):
584+
return WORKBENCH_CA_CERT_PATH
585+
else:
586+
return None
555587

556588
def login(self) -&gt; str:
557589
&#34;&#34;&#34;
@@ -566,10 +598,20 @@ <h3>Methods</h3>
566598
configuration.api_key_prefix[&#34;authorization&#34;] = &#34;Bearer&#34;
567599
configuration.host = self.server
568600
configuration.api_key[&#34;authorization&#34;] = self.token
569-
if self.skip_tls == False and self.ca_cert_path == None:
601+
602+
if not self.skip_tls:
603+
if self.ca_cert_path is None:
604+
configuration.ssl_ca_cert = None
605+
elif os.path.isfile(self.ca_cert_path):
606+
print(
607+
f&#34;Authenticated with certificate located at {self.ca_cert_path}&#34;
608+
)
609+
configuration.ssl_ca_cert = self.ca_cert_path
610+
else:
611+
raise FileNotFoundError(
612+
f&#34;Certificate file not found at {self.ca_cert_path}&#34;
613+
)
570614
configuration.verify_ssl = True
571-
elif self.skip_tls == False:
572-
configuration.ssl_ca_cert = self.ca_cert_path
573615
else:
574616
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
575617
print(&#34;Insecure request warnings have been disabled&#34;)
@@ -622,10 +664,20 @@ <h3>Methods</h3>
622664
configuration.api_key_prefix[&#34;authorization&#34;] = &#34;Bearer&#34;
623665
configuration.host = self.server
624666
configuration.api_key[&#34;authorization&#34;] = self.token
625-
if self.skip_tls == False and self.ca_cert_path == None:
667+
668+
if not self.skip_tls:
669+
if self.ca_cert_path is None:
670+
configuration.ssl_ca_cert = None
671+
elif os.path.isfile(self.ca_cert_path):
672+
print(
673+
f&#34;Authenticated with certificate located at {self.ca_cert_path}&#34;
674+
)
675+
configuration.ssl_ca_cert = self.ca_cert_path
676+
else:
677+
raise FileNotFoundError(
678+
f&#34;Certificate file not found at {self.ca_cert_path}&#34;
679+
)
626680
configuration.verify_ssl = True
627-
elif self.skip_tls == False:
628-
configuration.ssl_ca_cert = self.ca_cert_path
629681
else:
630682
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
631683
print(&#34;Insecure request warnings have been disabled&#34;)

docs/detailed-documentation/cluster/cluster.html

+53-20
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
573573
mcad=mcad,
574574
write_to_file=write_to_file,
575575
verify_tls=verify_tls,
576+
local_queue=rc[&#34;metadata&#34;]
577+
.get(&#34;labels&#34;, dict())
578+
.get(&#34;kueue.x-k8s.io/queue-name&#34;, None),
576579
)
577580
return Cluster(cluster_config)
578581

@@ -592,10 +595,10 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
592595
.get(&#34;headGroupSpec&#34;, {})
593596
.get(&#34;enableIngress&#34;)
594597
)
595-
if resource[&#34;kind&#34;] == &#34;RayCluster&#34; and enable_ingress is not False:
598+
if resource[&#34;kind&#34;] == &#34;RayCluster&#34; and enable_ingress is True:
596599
name = resource[&#34;metadata&#34;][&#34;name&#34;]
597600
print(
598-
f&#34;Forbidden: RayCluster &#39;{name}&#39; has &#39;enableIngress&#39; set to &#39;True&#39; or is unset.&#34;
601+
f&#34;Forbidden: RayCluster &#39;{name}&#39; has &#39;enableIngress&#39; set to &#39;True&#39;.&#34;
599602
)
600603
return
601604
_create_resources(yamls, namespace, api_instance)
@@ -662,14 +665,26 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
662665
print(&#34;Unable to find current namespace&#34;)
663666
return None
664667
else:
665-
try:
666-
_, active_context = config.list_kube_config_contexts(config_check())
667-
except Exception as e:
668-
return _kube_api_error_handling(e)
669-
try:
670-
return active_context[&#34;context&#34;][&#34;namespace&#34;]
671-
except KeyError:
672-
return None
668+
if os.path.isfile(&#34;/var/run/secrets/kubernetes.io/serviceaccount/namespace&#34;):
669+
try:
670+
file = open(
671+
&#34;/var/run/secrets/kubernetes.io/serviceaccount/namespace&#34;, &#34;r&#34;
672+
)
673+
active_context = file.readline().strip(&#34;\n&#34;)
674+
return active_context
675+
except Exception as e:
676+
print(
677+
&#34;unable to gather namespace from /var/run/secrets/kubernetes.io/serviceaccount/namespace trying to gather from current context&#34;
678+
)
679+
else:
680+
try:
681+
_, active_context = config.list_kube_config_contexts(config_check())
682+
except Exception as e:
683+
return _kube_api_error_handling(e)
684+
try:
685+
return active_context[&#34;context&#34;][&#34;namespace&#34;]
686+
except KeyError:
687+
return None
673688

674689

675690
def get_cluster(
@@ -1070,14 +1085,26 @@ <h2 class="section-title" id="header-functions">Functions</h2>
10701085
print(&#34;Unable to find current namespace&#34;)
10711086
return None
10721087
else:
1073-
try:
1074-
_, active_context = config.list_kube_config_contexts(config_check())
1075-
except Exception as e:
1076-
return _kube_api_error_handling(e)
1077-
try:
1078-
return active_context[&#34;context&#34;][&#34;namespace&#34;]
1079-
except KeyError:
1080-
return None</code></pre>
1088+
if os.path.isfile(&#34;/var/run/secrets/kubernetes.io/serviceaccount/namespace&#34;):
1089+
try:
1090+
file = open(
1091+
&#34;/var/run/secrets/kubernetes.io/serviceaccount/namespace&#34;, &#34;r&#34;
1092+
)
1093+
active_context = file.readline().strip(&#34;\n&#34;)
1094+
return active_context
1095+
except Exception as e:
1096+
print(
1097+
&#34;unable to gather namespace from /var/run/secrets/kubernetes.io/serviceaccount/namespace trying to gather from current context&#34;
1098+
)
1099+
else:
1100+
try:
1101+
_, active_context = config.list_kube_config_contexts(config_check())
1102+
except Exception as e:
1103+
return _kube_api_error_handling(e)
1104+
try:
1105+
return active_context[&#34;context&#34;][&#34;namespace&#34;]
1106+
except KeyError:
1107+
return None</code></pre>
10811108
</details>
10821109
</dd>
10831110
<dt id="codeflare_sdk.cluster.cluster.list_all_clusters"><code class="name flex">
@@ -1640,6 +1667,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
16401667
mcad=mcad,
16411668
write_to_file=write_to_file,
16421669
verify_tls=verify_tls,
1670+
local_queue=rc[&#34;metadata&#34;]
1671+
.get(&#34;labels&#34;, dict())
1672+
.get(&#34;kueue.x-k8s.io/queue-name&#34;, None),
16431673
)
16441674
return Cluster(cluster_config)
16451675

@@ -1659,10 +1689,10 @@ <h2 class="section-title" id="header-classes">Classes</h2>
16591689
.get(&#34;headGroupSpec&#34;, {})
16601690
.get(&#34;enableIngress&#34;)
16611691
)
1662-
if resource[&#34;kind&#34;] == &#34;RayCluster&#34; and enable_ingress is not False:
1692+
if resource[&#34;kind&#34;] == &#34;RayCluster&#34; and enable_ingress is True:
16631693
name = resource[&#34;metadata&#34;][&#34;name&#34;]
16641694
print(
1665-
f&#34;Forbidden: RayCluster &#39;{name}&#39; has &#39;enableIngress&#39; set to &#39;True&#39; or is unset.&#34;
1695+
f&#34;Forbidden: RayCluster &#39;{name}&#39; has &#39;enableIngress&#39; set to &#39;True&#39;.&#34;
16661696
)
16671697
return
16681698
_create_resources(yamls, namespace, api_instance)
@@ -2010,6 +2040,9 @@ <h3>Methods</h3>
20102040
mcad=mcad,
20112041
write_to_file=write_to_file,
20122042
verify_tls=verify_tls,
2043+
local_queue=rc[&#34;metadata&#34;]
2044+
.get(&#34;labels&#34;, dict())
2045+
.get(&#34;kueue.x-k8s.io/queue-name&#34;, None),
20132046
)
20142047
return Cluster(cluster_config)</code></pre>
20152048
</details>

docs/detailed-documentation/utils/generate_yaml.html

+66
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,26 @@ <h1 class="title">Module <code>codeflare_sdk.utils.generate_yaml</code></h1>
339339
)
340340

341341

342+
def local_queue_exists(namespace: str, local_queue_name: str):
343+
# get all local queues in the namespace
344+
try:
345+
config_check()
346+
api_instance = client.CustomObjectsApi(api_config_handler())
347+
local_queues = api_instance.list_namespaced_custom_object(
348+
group=&#34;kueue.x-k8s.io&#34;,
349+
version=&#34;v1beta1&#34;,
350+
namespace=namespace,
351+
plural=&#34;localqueues&#34;,
352+
)
353+
except Exception as e: # pragma: no cover
354+
return _kube_api_error_handling(e)
355+
# check if local queue with the name provided in cluster config exists
356+
for lq in local_queues[&#34;items&#34;]:
357+
if lq[&#34;metadata&#34;][&#34;name&#34;] == local_queue_name:
358+
return True
359+
return False
360+
361+
342362
def write_components(
343363
user_yaml: dict,
344364
output_file_name: str,
@@ -355,6 +375,10 @@ <h1 class="title">Module <code>codeflare_sdk.utils.generate_yaml</code></h1>
355375
open(output_file_name, &#34;w&#34;).close()
356376
lq_name = local_queue or get_default_kueue_name(namespace)
357377
cluster_labels = labels
378+
if not local_queue_exists(namespace, lq_name):
379+
raise ValueError(
380+
&#34;local_queue provided does not exist or is not in this namespace. Please provide the correct local_queue name in Cluster Configuration&#34;
381+
)
358382
with open(output_file_name, &#34;a&#34;) as outfile:
359383
for component in components:
360384
if &#34;generictemplate&#34; in component:
@@ -386,6 +410,10 @@ <h1 class="title">Module <code>codeflare_sdk.utils.generate_yaml</code></h1>
386410
components = user_yaml.get(&#34;spec&#34;, &#34;resources&#34;)[&#34;resources&#34;].get(&#34;GenericItems&#34;)
387411
lq_name = local_queue or get_default_kueue_name(namespace)
388412
cluster_labels = labels
413+
if not local_queue_exists(namespace, lq_name):
414+
raise ValueError(
415+
&#34;local_queue provided does not exist or is not in this namespace. Please provide the correct local_queue name in Cluster Configuration&#34;
416+
)
389417
for component in components:
390418
if &#34;generictemplate&#34; in component:
391419
if (
@@ -748,6 +776,10 @@ <h2 class="section-title" id="header-functions">Functions</h2>
748776
components = user_yaml.get(&#34;spec&#34;, &#34;resources&#34;)[&#34;resources&#34;].get(&#34;GenericItems&#34;)
749777
lq_name = local_queue or get_default_kueue_name(namespace)
750778
cluster_labels = labels
779+
if not local_queue_exists(namespace, lq_name):
780+
raise ValueError(
781+
&#34;local_queue provided does not exist or is not in this namespace. Please provide the correct local_queue name in Cluster Configuration&#34;
782+
)
751783
for component in components:
752784
if &#34;generictemplate&#34; in component:
753785
if (
@@ -770,6 +802,35 @@ <h2 class="section-title" id="header-functions">Functions</h2>
770802
return user_yaml</code></pre>
771803
</details>
772804
</dd>
805+
<dt id="codeflare_sdk.utils.generate_yaml.local_queue_exists"><code class="name flex">
806+
<span>def <span class="ident">local_queue_exists</span></span>(<span>namespace: str, local_queue_name: str)</span>
807+
</code></dt>
808+
<dd>
809+
<div class="desc"></div>
810+
<details class="source">
811+
<summary>
812+
<span>Expand source code</span>
813+
</summary>
814+
<pre><code class="python">def local_queue_exists(namespace: str, local_queue_name: str):
815+
# get all local queues in the namespace
816+
try:
817+
config_check()
818+
api_instance = client.CustomObjectsApi(api_config_handler())
819+
local_queues = api_instance.list_namespaced_custom_object(
820+
group=&#34;kueue.x-k8s.io&#34;,
821+
version=&#34;v1beta1&#34;,
822+
namespace=namespace,
823+
plural=&#34;localqueues&#34;,
824+
)
825+
except Exception as e: # pragma: no cover
826+
return _kube_api_error_handling(e)
827+
# check if local queue with the name provided in cluster config exists
828+
for lq in local_queues[&#34;items&#34;]:
829+
if lq[&#34;metadata&#34;][&#34;name&#34;] == local_queue_name:
830+
return True
831+
return False</code></pre>
832+
</details>
833+
</dd>
773834
<dt id="codeflare_sdk.utils.generate_yaml.read_template"><code class="name flex">
774835
<span>def <span class="ident">read_template</span></span>(<span>template)</span>
775836
</code></dt>
@@ -1091,6 +1152,10 @@ <h2 class="section-title" id="header-functions">Functions</h2>
10911152
open(output_file_name, &#34;w&#34;).close()
10921153
lq_name = local_queue or get_default_kueue_name(namespace)
10931154
cluster_labels = labels
1155+
if not local_queue_exists(namespace, lq_name):
1156+
raise ValueError(
1157+
&#34;local_queue provided does not exist or is not in this namespace. Please provide the correct local_queue name in Cluster Configuration&#34;
1158+
)
10941159
with open(output_file_name, &#34;a&#34;) as outfile:
10951160
for component in components:
10961161
if &#34;generictemplate&#34; in component:
@@ -1158,6 +1223,7 @@ <h1>Index</h1>
11581223
<li><code><a title="codeflare_sdk.utils.generate_yaml.is_openshift_cluster" href="#codeflare_sdk.utils.generate_yaml.is_openshift_cluster">is_openshift_cluster</a></code></li>
11591224
<li><code><a title="codeflare_sdk.utils.generate_yaml.load_appwrapper" href="#codeflare_sdk.utils.generate_yaml.load_appwrapper">load_appwrapper</a></code></li>
11601225
<li><code><a title="codeflare_sdk.utils.generate_yaml.load_components" href="#codeflare_sdk.utils.generate_yaml.load_components">load_components</a></code></li>
1226+
<li><code><a title="codeflare_sdk.utils.generate_yaml.local_queue_exists" href="#codeflare_sdk.utils.generate_yaml.local_queue_exists">local_queue_exists</a></code></li>
11611227
<li><code><a title="codeflare_sdk.utils.generate_yaml.read_template" href="#codeflare_sdk.utils.generate_yaml.read_template">read_template</a></code></li>
11621228
<li><code><a title="codeflare_sdk.utils.generate_yaml.update_affinity" href="#codeflare_sdk.utils.generate_yaml.update_affinity">update_affinity</a></code></li>
11631229
<li><code><a title="codeflare_sdk.utils.generate_yaml.update_custompodresources" href="#codeflare_sdk.utils.generate_yaml.update_custompodresources">update_custompodresources</a></code></li>

0 commit comments

Comments
 (0)