Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions magnum_cluster_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,33 @@ def __init__(self, api: pykube.HTTPClient, namespace="magnum-system"):

def apply(self) -> None:
resource = self.get_object()
resp = resource.api.patch(
**resource.api_kwargs(
headers={
"Content-Type": "application/apply-patch+yaml",
},
params={
"fieldManager": "atmosphere-operator",
"force": True,
},
data=json.dumps(resource.obj),

# Check if resource exists
existing_resource = resource.api.get(**resource.api_kwargs())
exists = existing_resource.status_code == 200

if not exists:
# Create new resource with server-side apply
resp = resource.api.patch(
**resource.api_kwargs(
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/merge-patch+json"},
data=json.dumps(resource.obj),
)
)
)

resource.api.raise_for_status(resp)
resource.set_obj(resp.json())
Expand Down
Loading