Skip to content

Changes in docs for release: v0.16.2 #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 63 additions & 11 deletions docs/detailed-documentation/cluster/auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
global config_path
config_path = None

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


class Authentication(metaclass=abc.ABCMeta):
&#34;&#34;&#34;
Expand Down Expand Up @@ -124,7 +126,17 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
self.token = token
self.server = server
self.skip_tls = skip_tls
self.ca_cert_path = ca_cert_path
self.ca_cert_path = self._gen_ca_cert_path(ca_cert_path)

def _gen_ca_cert_path(self, ca_cert_path: str):
if ca_cert_path is not None:
return ca_cert_path
elif &#34;CF_SDK_CA_CERT_PATH&#34; in os.environ:
return os.environ.get(&#34;CF_SDK_CA_CERT_PATH&#34;)
elif os.path.exists(WORKBENCH_CA_CERT_PATH):
return WORKBENCH_CA_CERT_PATH
else:
return None

def login(self) -&gt; str:
&#34;&#34;&#34;
Expand All @@ -139,10 +151,20 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.auth</code></h1>
configuration.api_key_prefix[&#34;authorization&#34;] = &#34;Bearer&#34;
configuration.host = self.server
configuration.api_key[&#34;authorization&#34;] = self.token
if self.skip_tls == False and self.ca_cert_path == None:

if not self.skip_tls:
if self.ca_cert_path is None:
configuration.ssl_ca_cert = None
elif os.path.isfile(self.ca_cert_path):
print(
f&#34;Authenticated with certificate located at {self.ca_cert_path}&#34;
)
configuration.ssl_ca_cert = self.ca_cert_path
else:
raise FileNotFoundError(
f&#34;Certificate file not found at {self.ca_cert_path}&#34;
)
configuration.verify_ssl = True
elif self.skip_tls == False:
configuration.ssl_ca_cert = self.ca_cert_path
else:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
print(&#34;Insecure request warnings have been disabled&#34;)
Expand Down Expand Up @@ -551,7 +573,17 @@ <h3>Methods</h3>
self.token = token
self.server = server
self.skip_tls = skip_tls
self.ca_cert_path = ca_cert_path
self.ca_cert_path = self._gen_ca_cert_path(ca_cert_path)

def _gen_ca_cert_path(self, ca_cert_path: str):
if ca_cert_path is not None:
return ca_cert_path
elif &#34;CF_SDK_CA_CERT_PATH&#34; in os.environ:
return os.environ.get(&#34;CF_SDK_CA_CERT_PATH&#34;)
elif os.path.exists(WORKBENCH_CA_CERT_PATH):
return WORKBENCH_CA_CERT_PATH
else:
return None

def login(self) -&gt; str:
&#34;&#34;&#34;
Expand All @@ -566,10 +598,20 @@ <h3>Methods</h3>
configuration.api_key_prefix[&#34;authorization&#34;] = &#34;Bearer&#34;
configuration.host = self.server
configuration.api_key[&#34;authorization&#34;] = self.token
if self.skip_tls == False and self.ca_cert_path == None:

if not self.skip_tls:
if self.ca_cert_path is None:
configuration.ssl_ca_cert = None
elif os.path.isfile(self.ca_cert_path):
print(
f&#34;Authenticated with certificate located at {self.ca_cert_path}&#34;
)
configuration.ssl_ca_cert = self.ca_cert_path
else:
raise FileNotFoundError(
f&#34;Certificate file not found at {self.ca_cert_path}&#34;
)
configuration.verify_ssl = True
elif self.skip_tls == False:
configuration.ssl_ca_cert = self.ca_cert_path
else:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
print(&#34;Insecure request warnings have been disabled&#34;)
Expand Down Expand Up @@ -622,10 +664,20 @@ <h3>Methods</h3>
configuration.api_key_prefix[&#34;authorization&#34;] = &#34;Bearer&#34;
configuration.host = self.server
configuration.api_key[&#34;authorization&#34;] = self.token
if self.skip_tls == False and self.ca_cert_path == None:

if not self.skip_tls:
if self.ca_cert_path is None:
configuration.ssl_ca_cert = None
elif os.path.isfile(self.ca_cert_path):
print(
f&#34;Authenticated with certificate located at {self.ca_cert_path}&#34;
)
configuration.ssl_ca_cert = self.ca_cert_path
else:
raise FileNotFoundError(
f&#34;Certificate file not found at {self.ca_cert_path}&#34;
)
configuration.verify_ssl = True
elif self.skip_tls == False:
configuration.ssl_ca_cert = self.ca_cert_path
else:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
print(&#34;Insecure request warnings have been disabled&#34;)
Expand Down
73 changes: 53 additions & 20 deletions docs/detailed-documentation/cluster/cluster.html
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
mcad=mcad,
write_to_file=write_to_file,
verify_tls=verify_tls,
local_queue=rc[&#34;metadata&#34;]
.get(&#34;labels&#34;, dict())
.get(&#34;kueue.x-k8s.io/queue-name&#34;, None),
)
return Cluster(cluster_config)

Expand All @@ -592,10 +595,10 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
.get(&#34;headGroupSpec&#34;, {})
.get(&#34;enableIngress&#34;)
)
if resource[&#34;kind&#34;] == &#34;RayCluster&#34; and enable_ingress is not False:
if resource[&#34;kind&#34;] == &#34;RayCluster&#34; and enable_ingress is True:
name = resource[&#34;metadata&#34;][&#34;name&#34;]
print(
f&#34;Forbidden: RayCluster &#39;{name}&#39; has &#39;enableIngress&#39; set to &#39;True&#39; or is unset.&#34;
f&#34;Forbidden: RayCluster &#39;{name}&#39; has &#39;enableIngress&#39; set to &#39;True&#39;.&#34;
)
return
_create_resources(yamls, namespace, api_instance)
Expand Down Expand Up @@ -662,14 +665,26 @@ <h1 class="title">Module <code>codeflare_sdk.cluster.cluster</code></h1>
print(&#34;Unable to find current namespace&#34;)
return None
else:
try:
_, active_context = config.list_kube_config_contexts(config_check())
except Exception as e:
return _kube_api_error_handling(e)
try:
return active_context[&#34;context&#34;][&#34;namespace&#34;]
except KeyError:
return None
if os.path.isfile(&#34;/var/run/secrets/kubernetes.io/serviceaccount/namespace&#34;):
try:
file = open(
&#34;/var/run/secrets/kubernetes.io/serviceaccount/namespace&#34;, &#34;r&#34;
)
active_context = file.readline().strip(&#34;\n&#34;)
return active_context
except Exception as e:
print(
&#34;unable to gather namespace from /var/run/secrets/kubernetes.io/serviceaccount/namespace trying to gather from current context&#34;
)
else:
try:
_, active_context = config.list_kube_config_contexts(config_check())
except Exception as e:
return _kube_api_error_handling(e)
try:
return active_context[&#34;context&#34;][&#34;namespace&#34;]
except KeyError:
return None


def get_cluster(
Expand Down Expand Up @@ -1070,14 +1085,26 @@ <h2 class="section-title" id="header-functions">Functions</h2>
print(&#34;Unable to find current namespace&#34;)
return None
else:
try:
_, active_context = config.list_kube_config_contexts(config_check())
except Exception as e:
return _kube_api_error_handling(e)
try:
return active_context[&#34;context&#34;][&#34;namespace&#34;]
except KeyError:
return None</code></pre>
if os.path.isfile(&#34;/var/run/secrets/kubernetes.io/serviceaccount/namespace&#34;):
try:
file = open(
&#34;/var/run/secrets/kubernetes.io/serviceaccount/namespace&#34;, &#34;r&#34;
)
active_context = file.readline().strip(&#34;\n&#34;)
return active_context
except Exception as e:
print(
&#34;unable to gather namespace from /var/run/secrets/kubernetes.io/serviceaccount/namespace trying to gather from current context&#34;
)
else:
try:
_, active_context = config.list_kube_config_contexts(config_check())
except Exception as e:
return _kube_api_error_handling(e)
try:
return active_context[&#34;context&#34;][&#34;namespace&#34;]
except KeyError:
return None</code></pre>
</details>
</dd>
<dt id="codeflare_sdk.cluster.cluster.list_all_clusters"><code class="name flex">
Expand Down Expand Up @@ -1640,6 +1667,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
mcad=mcad,
write_to_file=write_to_file,
verify_tls=verify_tls,
local_queue=rc[&#34;metadata&#34;]
.get(&#34;labels&#34;, dict())
.get(&#34;kueue.x-k8s.io/queue-name&#34;, None),
)
return Cluster(cluster_config)

Expand All @@ -1659,10 +1689,10 @@ <h2 class="section-title" id="header-classes">Classes</h2>
.get(&#34;headGroupSpec&#34;, {})
.get(&#34;enableIngress&#34;)
)
if resource[&#34;kind&#34;] == &#34;RayCluster&#34; and enable_ingress is not False:
if resource[&#34;kind&#34;] == &#34;RayCluster&#34; and enable_ingress is True:
name = resource[&#34;metadata&#34;][&#34;name&#34;]
print(
f&#34;Forbidden: RayCluster &#39;{name}&#39; has &#39;enableIngress&#39; set to &#39;True&#39; or is unset.&#34;
f&#34;Forbidden: RayCluster &#39;{name}&#39; has &#39;enableIngress&#39; set to &#39;True&#39;.&#34;
)
return
_create_resources(yamls, namespace, api_instance)
Expand Down Expand Up @@ -2010,6 +2040,9 @@ <h3>Methods</h3>
mcad=mcad,
write_to_file=write_to_file,
verify_tls=verify_tls,
local_queue=rc[&#34;metadata&#34;]
.get(&#34;labels&#34;, dict())
.get(&#34;kueue.x-k8s.io/queue-name&#34;, None),
)
return Cluster(cluster_config)</code></pre>
</details>
Expand Down
66 changes: 66 additions & 0 deletions docs/detailed-documentation/utils/generate_yaml.html
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,26 @@ <h1 class="title">Module <code>codeflare_sdk.utils.generate_yaml</code></h1>
)


def local_queue_exists(namespace: str, local_queue_name: str):
# get all local queues in the namespace
try:
config_check()
api_instance = client.CustomObjectsApi(api_config_handler())
local_queues = api_instance.list_namespaced_custom_object(
group=&#34;kueue.x-k8s.io&#34;,
version=&#34;v1beta1&#34;,
namespace=namespace,
plural=&#34;localqueues&#34;,
)
except Exception as e: # pragma: no cover
return _kube_api_error_handling(e)
# check if local queue with the name provided in cluster config exists
for lq in local_queues[&#34;items&#34;]:
if lq[&#34;metadata&#34;][&#34;name&#34;] == local_queue_name:
return True
return False


def write_components(
user_yaml: dict,
output_file_name: str,
Expand All @@ -355,6 +375,10 @@ <h1 class="title">Module <code>codeflare_sdk.utils.generate_yaml</code></h1>
open(output_file_name, &#34;w&#34;).close()
lq_name = local_queue or get_default_kueue_name(namespace)
cluster_labels = labels
if not local_queue_exists(namespace, lq_name):
raise ValueError(
&#34;local_queue provided does not exist or is not in this namespace. Please provide the correct local_queue name in Cluster Configuration&#34;
)
with open(output_file_name, &#34;a&#34;) as outfile:
for component in components:
if &#34;generictemplate&#34; in component:
Expand Down Expand Up @@ -386,6 +410,10 @@ <h1 class="title">Module <code>codeflare_sdk.utils.generate_yaml</code></h1>
components = user_yaml.get(&#34;spec&#34;, &#34;resources&#34;)[&#34;resources&#34;].get(&#34;GenericItems&#34;)
lq_name = local_queue or get_default_kueue_name(namespace)
cluster_labels = labels
if not local_queue_exists(namespace, lq_name):
raise ValueError(
&#34;local_queue provided does not exist or is not in this namespace. Please provide the correct local_queue name in Cluster Configuration&#34;
)
for component in components:
if &#34;generictemplate&#34; in component:
if (
Expand Down Expand Up @@ -748,6 +776,10 @@ <h2 class="section-title" id="header-functions">Functions</h2>
components = user_yaml.get(&#34;spec&#34;, &#34;resources&#34;)[&#34;resources&#34;].get(&#34;GenericItems&#34;)
lq_name = local_queue or get_default_kueue_name(namespace)
cluster_labels = labels
if not local_queue_exists(namespace, lq_name):
raise ValueError(
&#34;local_queue provided does not exist or is not in this namespace. Please provide the correct local_queue name in Cluster Configuration&#34;
)
for component in components:
if &#34;generictemplate&#34; in component:
if (
Expand All @@ -770,6 +802,35 @@ <h2 class="section-title" id="header-functions">Functions</h2>
return user_yaml</code></pre>
</details>
</dd>
<dt id="codeflare_sdk.utils.generate_yaml.local_queue_exists"><code class="name flex">
<span>def <span class="ident">local_queue_exists</span></span>(<span>namespace: str, local_queue_name: str)</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def local_queue_exists(namespace: str, local_queue_name: str):
# get all local queues in the namespace
try:
config_check()
api_instance = client.CustomObjectsApi(api_config_handler())
local_queues = api_instance.list_namespaced_custom_object(
group=&#34;kueue.x-k8s.io&#34;,
version=&#34;v1beta1&#34;,
namespace=namespace,
plural=&#34;localqueues&#34;,
)
except Exception as e: # pragma: no cover
return _kube_api_error_handling(e)
# check if local queue with the name provided in cluster config exists
for lq in local_queues[&#34;items&#34;]:
if lq[&#34;metadata&#34;][&#34;name&#34;] == local_queue_name:
return True
return False</code></pre>
</details>
</dd>
<dt id="codeflare_sdk.utils.generate_yaml.read_template"><code class="name flex">
<span>def <span class="ident">read_template</span></span>(<span>template)</span>
</code></dt>
Expand Down Expand Up @@ -1091,6 +1152,10 @@ <h2 class="section-title" id="header-functions">Functions</h2>
open(output_file_name, &#34;w&#34;).close()
lq_name = local_queue or get_default_kueue_name(namespace)
cluster_labels = labels
if not local_queue_exists(namespace, lq_name):
raise ValueError(
&#34;local_queue provided does not exist or is not in this namespace. Please provide the correct local_queue name in Cluster Configuration&#34;
)
with open(output_file_name, &#34;a&#34;) as outfile:
for component in components:
if &#34;generictemplate&#34; in component:
Expand Down Expand Up @@ -1158,6 +1223,7 @@ <h1>Index</h1>
<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>
<li><code><a title="codeflare_sdk.utils.generate_yaml.load_appwrapper" href="#codeflare_sdk.utils.generate_yaml.load_appwrapper">load_appwrapper</a></code></li>
<li><code><a title="codeflare_sdk.utils.generate_yaml.load_components" href="#codeflare_sdk.utils.generate_yaml.load_components">load_components</a></code></li>
<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>
<li><code><a title="codeflare_sdk.utils.generate_yaml.read_template" href="#codeflare_sdk.utils.generate_yaml.read_template">read_template</a></code></li>
<li><code><a title="codeflare_sdk.utils.generate_yaml.update_affinity" href="#codeflare_sdk.utils.generate_yaml.update_affinity">update_affinity</a></code></li>
<li><code><a title="codeflare_sdk.utils.generate_yaml.update_custompodresources" href="#codeflare_sdk.utils.generate_yaml.update_custompodresources">update_custompodresources</a></code></li>
Expand Down