Slide 38
Slide 38 text
Diff between desired and existing objects
https://github.com/google/go-cmp
import "github.com/google/go-cmp/cmp"
if r.isOwnedBy(existing, owner) {
desired.SetResourceVersion(existing.GetResourceVersion())
diff := cmp.Diff(existing, desired, options)
if diff != "" {
err = r.client.Update(ctx, desired)
if err != nil {
return errors.Wrap(err, "failed to update "+kind+" "+namespace+"/"+name)
}
logger.Debug(kind + " " + namespace + "/" + name + " updated")
} else {
logger.Debug(existing.GetSelfLink() + " unchanged")
}
return nil
}
ignoredFields = [...]string{
"ObjectMeta.SelfLink",
"ObjectMeta.UID",
"ObjectMeta.ResourceVersion",
"ObjectMeta.Generation",
"ObjectMeta.CreationTimestamp",
"ObjectMeta.Finalizers",
"ObjectMeta.ManagedFields",
"TypeMeta.APIVersion",
}