Skip to content

Commit

Permalink
fix merge option
Browse files Browse the repository at this point in the history
  • Loading branch information
okozachenko1203 committed Feb 13, 2025
1 parent b065639 commit ec25359
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions magnum_cluster_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from oslo_serialization import base64
from oslo_utils import encodeutils


from magnum_cluster_api import (
clients,
helm,
Expand Down Expand Up @@ -148,30 +149,30 @@ def apply(self) -> None:
resource = self.get_object()

# Check if resource exists
try:
existing_resource = resource.api.get(
**resource.api_kwargs()
)
exists = existing_resource.status_code == 200
except pykube.exceptions.HTTPError as e:
if e.response.status_code == 404:
exists = False # Resource does not exist
else:
raise # Other errors should be raised
existing_resource = resource.api.get(
**resource.api_kwargs()
)
exists = existing_resource.status_code == 200

if not exists:
# Create new resource with POST
resp = resource.api.post(
# Create new resource with server-side apply
resp = resource.api.patch(
**resource.api_kwargs(
headers={"Content-Type": "application/json"},
headers={
"Content-Type": "application/apply-patch+yaml",
},
params={
"fieldManager": "atmosphere-operator",
"force": True,
},
data=json.dumps(resource.obj),
)
)
else:
# Update existing resource with Strategic Merge Patch
resp = resource.api.patch(
**resource.api_kwargs(
headers={"Content-Type": "application/strategic-merge-patch+json"},
headers={"Content-Type": "application/merge-patch+json"},
data=json.dumps(resource.obj),
)
)
Expand Down

0 comments on commit ec25359

Please sign in to comment.