|
28 | 28 | from urllib3.exceptions import ReadTimeoutError |
29 | 29 |
|
30 | 30 | from airflow.providers.cncf.kubernetes.backcompat import get_logical_date_key |
| 31 | +from airflow.providers.cncf.kubernetes.exceptions import KubernetesApiPermissionError |
31 | 32 | from airflow.providers.cncf.kubernetes.executors.kubernetes_executor_types import ( |
32 | 33 | ADOPTED, |
33 | 34 | ALL_NAMESPACES, |
@@ -578,17 +579,29 @@ def run_next(self, next_job: KubernetesJob) -> None: |
578 | 579 | } |
579 | 580 | if workload.ti.map_index is not None and workload.ti.map_index >= 0: |
580 | 581 | 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()}, |
588 | 592 | ), |
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 |
592 | 605 | command = workload_to_command_args_json_path() |
593 | 606 | else: |
594 | 607 | raise ValueError( |
@@ -668,12 +681,23 @@ def run_next(self, next_job: KubernetesJob) -> None: |
668 | 681 | } |
669 | 682 | }, |
670 | 683 | ) |
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 | + ) |
677 | 701 |
|
678 | 702 | def delete_pod(self, pod_name: str, namespace: str) -> None: |
679 | 703 | """Delete Pod from a namespace; does not raise if it does not exist.""" |
|
0 commit comments