morooshka commented on code in PR #25787:
URL: https://github.com/apache/airflow/pull/25787#discussion_r976051758
##########
airflow/providers/cncf/kubernetes/hooks/kubernetes.py:
##########
@@ -301,36 +301,39 @@ def create_custom_object(
):
"""
Creates custom resource definition object in Kubernetes
-
:param group: api group
:param version: api version
:param plural: api plural
:param body: crd object definition
:param namespace: kubernetes namespace
"""
api = client.CustomObjectsApi(self.api_client)
+
if namespace is None:
namespace = self.get_namespace()
- if isinstance(body, str):
- body_dict = _load_body_to_dict(body)
- else:
- body_dict = body
- try:
- api.delete_namespaced_custom_object(
- group=group,
- version=version,
- namespace=namespace,
- plural=plural,
- name=body_dict["metadata"]["name"],
- )
- self.log.warning("Deleted SparkApplication with the same name.")
- except client.rest.ApiException:
- self.log.info("SparkApp %s not found.",
body_dict['metadata']['name'])
+
+ body_dict: dict = _load_body_to_dict(body) if isinstance(body, str)
else body
+
+ # Attribute "name" is not mandatory if "generateName" is used instead
+ if "name" in body_dict["metadata"]:
Review Comment:
Hi Daniel! Recently there was no functionality of removing already launched
objects. So no deleting is ok. Then it was implemented, but the author thought
the "name" attribute is mandatory. It is not true - "generateName" can be
used. So we have 2 cases:
1. "name" is used. OK, we can delete the old object if found
2. "name" is not used. It is possible if "generateName" is used. If so, we
can not delete the old object - we do not know its name (k8s will generate it
randomly using a name mask, but we cant guess it for sure). So we have nothing
to do there, the old object will be not touched if exists
Hope this sounds understandable, please ask further to clear the case
Thank you
--
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]