diegoalvarez-clarity opened a new pull request, #58391:
URL: https://github.com/apache/airflow/pull/58391
## Problem
Kubernetes automatically creates a label `batch.kubernetes.io/job-name` with
the job name as its value. This label value must not exceed 63 characters,
which effectively means the job name itself must be ≤ 63 characters.
Previously, the KubernetesJobOperator added the "job-" prefix after
truncating the name to 63 characters, which could result in job names exceeding
the limit (e.g., 67 characters). This caused Kubernetes API validation errors
indicating that the label value exceeded 63 characters.
## Solution
This PR fixes the issue by:
1. Accounting for the prefix before truncation: Calculate the available
length for the base name (POD_NAME_MAX_LENGTH - len(JOB_NAME_PREFIX) = 59) and
pass this reduced max_length to create_unique_id and add_unique_suffix
functions.
2. Adding the prefix after name generation: The "job-" prefix is added after
the name has been properly truncated, ensuring the final name never exceeds 63
characters.
3. Using a constant for maintainability: Introduced JOB_NAME_PREFIX = "job-"
as a module-level constant to avoid magic strings.
## Testing
- Updated test_task_id_as_name_with_suffix_very_long to expect 50 'a's
instead of 71, reflecting the correct behavior where the prefix is accounted
for before truncation.
- All existing tests continue to pass, confirming backward compatibility for
names that don't require truncation.
## Contributors
- @diego15ag (co-author)
- @jprieto92 (co-author)
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]