Skip to content

Commit f4a1dc9

Browse files
committed
making error more explicit
1 parent c123e2c commit f4a1dc9

1 file changed

Lines changed: 40 additions & 16 deletions

File tree

‎providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/executors/kubernetes_executor_utils.py‎

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from urllib3.exceptions import ReadTimeoutError
2929

3030
from airflow.providers.cncf.kubernetes.backcompat import get_logical_date_key
31+
from airflow.providers.cncf.kubernetes.exceptions import KubernetesApiPermissionError
3132
from airflow.providers.cncf.kubernetes.executors.kubernetes_executor_types import (
3233
ADOPTED,
3334
ALL_NAMESPACES,
@@ -578,17 +579,29 @@ def run_next(self, next_job: KubernetesJob) -> None:
578579
}
579580
if workload.ti.map_index is not None and workload.ti.map_index >= 0:
580581
labels["map_index"] = str(workload.ti.map_index)
581-
self.kube_client.create_namespaced_secret(
582-
namespace=self.namespace,
583-
body=client.V1Secret(
584-
metadata=client.V1ObjectMeta(
585-
name=secret_name,
586-
namespace=self.namespace,
587-
labels=labels,
582+
try:
583+
self.kube_client.create_namespaced_secret(
584+
namespace=self.namespace,
585+
body=client.V1Secret(
586+
metadata=client.V1ObjectMeta(
587+
name=secret_name,
588+
namespace=self.namespace,
589+
labels=labels,
590+
),
591+
string_data={"workload.json": workload.model_dump_json()},
588592
),
589-
string_data={"workload.json": workload.model_dump_json()},
590-
),
591-
)
593+
)
594+
except ApiException as e:
595+
if e.status == 403:
596+
raise KubernetesApiPermissionError(
597+
f"Failed to create workload secret '{secret_name}' in namespace "
598+
f"'{self.namespace}': permission denied (HTTP 403). "
599+
"Ensure the RBAC pod-launcher-role has 'create' and 'patch' verbs for "
600+
"'secrets'. If you recently upgraded the cncf-kubernetes provider, "
601+
"update the pod-launcher-role in your helm charts or grant the missing "
602+
"permissions manually."
603+
) from e
604+
raise
592605
command = workload_to_command_args_json_path()
593606
else:
594607
raise ValueError(
@@ -668,12 +681,23 @@ def run_next(self, next_job: KubernetesJob) -> None:
668681
}
669682
},
670683
)
671-
except ApiException:
672-
self.log.warning(
673-
"Could not set ownerReference on workload secret %s; as a fallback the cleanup CronJob will delete it.",
674-
secret_name,
675-
exc_info=True,
676-
)
684+
except ApiException as e:
685+
if e.status == 403:
686+
self.log.warning(
687+
"Could not set ownerReference on workload secret %s: permission denied (HTTP 403). "
688+
"Ensure the scheduler's RBAC role grants the 'patch' verb on 'secrets'. "
689+
"If you recently upgraded the cncf-kubernetes provider, update the "
690+
"pod-launcher-role in your Helm chart. "
691+
"The cleanup CronJob will delete the secret as a fallback.",
692+
secret_name,
693+
)
694+
else:
695+
self.log.warning(
696+
"Could not set ownerReference on workload secret %s; "
697+
"as a fallback the cleanup CronJob will delete it.",
698+
secret_name,
699+
exc_info=True,
700+
)
677701

678702
def delete_pod(self, pod_name: str, namespace: str) -> None:
679703
"""Delete Pod from a namespace; does not raise if it does not exist."""

0 commit comments

Comments
 (0)