Skip to content

Commit

Permalink
Fix secret creation
Browse files Browse the repository at this point in the history
  • Loading branch information
romilbhardwaj committed Dec 23, 2024
1 parent 2bd7c3e commit c33d3cc
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions sky/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,26 @@ def setup_kubernetes_authentication(config: Dict[str, Any]) -> Dict[str, Any]:
secret = k8s.client.V1Secret(
metadata=k8s.client.V1ObjectMeta(**secret_metadata),
string_data={secret_field_name: public_key})
if kubernetes_utils.check_secret_exists(secret_name, namespace, context):
logger.debug(f'Key {secret_name} exists in the cluster, patching it...')
kubernetes.core_api(context).patch_namespaced_secret(
secret_name, namespace, secret)
else:
logger.debug(
f'Key {secret_name} does not exist in the cluster, creating it...')
kubernetes.core_api(context).create_namespaced_secret(namespace, secret)
try:
if kubernetes_utils.check_secret_exists(secret_name, namespace,
context):
logger.debug(f'Key {secret_name} exists in the cluster, '
'patching it...')
kubernetes.core_api(context).patch_namespaced_secret(
secret_name, namespace, secret)
else:
logger.debug(f'Key {secret_name} does not exist in the cluster, '
'creating it...')
kubernetes.core_api(context).create_namespaced_secret(
namespace, secret)
except kubernetes.api_exception() as e:
if e.status == 409 and e.reason == 'AlreadyExists':
logger.debug(f'Key {secret_name} was created concurrently, '
'patching it...')
kubernetes.core_api(context).patch_namespaced_secret(
secret_name, namespace, secret)
else:
raise e

private_key_path, _ = get_or_generate_keys()
if network_mode == nodeport_mode:
Expand Down

0 comments on commit c33d3cc

Please sign in to comment.