Skip to content

Commit

Permalink
fix: use apply patch strategy for kube api resource update
Browse files Browse the repository at this point in the history
  • Loading branch information
okozachenko1203 committed Mar 21, 2024
1 parent b2f23e1 commit 904abff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
9 changes: 5 additions & 4 deletions magnum_cluster_api/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def resize_cluster(
machine.obj["metadata"]["annotations"][
"cluster.x-k8s.io/delete-machine"
] = "yes"
machine.update()
utils.kube_apply_patch(machine)

self._update_nodegroup(context, cluster, nodegroup)

Expand Down Expand Up @@ -347,7 +347,8 @@ def create_nodegroup(
current_generation = resources.Cluster(
context, self.k8s_api, cluster
).get_observed_generation()
cluster_resource.update()
utils.kube_apply_patch(cluster_resource)

self.wait_capi_cluster_reconciliation_start(
context, cluster, current_generation
)
Expand Down Expand Up @@ -454,7 +455,7 @@ def _update_nodegroup(
current_generation = resources.Cluster(
context, self.k8s_api, cluster
).get_observed_generation()
cluster_resource.update()
utils.kube_apply_patch(cluster_resource)
self.wait_capi_cluster_reconciliation_start(
context, cluster, current_generation
)
Expand Down Expand Up @@ -492,7 +493,7 @@ def delete_nodegroup(
current_generation = resources.Cluster(
context, self.k8s_api, cluster
).get_observed_generation()
cluster_resource.update()
utils.kube_apply_patch(cluster_resource)
self.wait_capi_cluster_reconciliation_start(
context, cluster, current_generation
)
Expand Down
17 changes: 17 additions & 0 deletions magnum_cluster_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,20 @@ def get_keystone_auth_default_policy(cluster: magnum_objects.Cluster):
return json.loads(f.read())
except Exception:
return default_policy

def kube_apply_patch(resource):
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),
)
)

resource.api.raise_for_status(resp)
resource.set_obj(resp.json())

0 comments on commit 904abff

Please sign in to comment.