Skip to content

Commit

Permalink
fix: k8schaos: automatically include metadata.resourceVersion when up…
Browse files Browse the repository at this point in the history
…dating existing resources.
  • Loading branch information
wvdschel-f3 committed Nov 21, 2023
1 parent 9c1b15f commit bb64338
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions controllers/chaosimpl/k8schaos/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,21 @@ func (impl *Impl) Apply(ctx context.Context, index int, records []*v1alpha1.Reco
return v1alpha1.NotInjected, err
}

unstructured.RemoveNestedField(impl.initialValue.Object, "metadata", "creationTimestamp")
unstructured.RemoveNestedField(impl.initialValue.Object, "metadata", "resourceVersion")
unstructured.RemoveNestedField(impl.initialValue.Object, "metadata", "uid")
if impl.initialValue != nil {
var resourceVersion string
var found bool
resourceVersion, found, err = unstructured.NestedString(impl.initialValue.Object, "metadata", "resourceVersion")
if err != nil {
return v1alpha1.NotInjected, err
}
if found {
resource.SetResourceVersion(resourceVersion)
}

unstructured.RemoveNestedField(impl.initialValue.Object, "metadata", "creationTimestamp")
unstructured.RemoveNestedField(impl.initialValue.Object, "metadata", "resourceVersion")
unstructured.RemoveNestedField(impl.initialValue.Object, "metadata", "uid")
}

_, err = client.Resource(mapping.Resource).Namespace(resource.GetNamespace()).Update(ctx, resource, v1.UpdateOptions{})
} else {
Expand Down

0 comments on commit bb64338

Please sign in to comment.