Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Never try to update read-only, system-populated metadata fields. #94

Merged
merged 1 commit into from
Sep 20, 2018

Conversation

enisoc
Copy link

@enisoc enisoc commented Sep 19, 2018

If the user asks us to update them, we will silently ignore the changes. The API server would ignore the changes anyway, but we need to account for that in advance because otherwise we'll either send needless no-op updates (for InPlace strategies) or needlessly delete and recreate objects (for Recreate strategies).

Fixes #76

if found {
unstructured.SetNestedField(newObj.UnstructuredContent(), val, "metadata", fieldName)
} else {
unstructured.RemoveNestedField(newObj.UnstructuredContent(), "metadata", fieldName)
Copy link
Contributor

@crimsonfaith91 crimsonfaith91 Sep 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To verify, we have to omit a field that cannot be found via NestedFieldNoCopy because user has added the read-only field, but we don't want to pick up the change. Am I right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. The goal is for the state of these system fields (set vs unset, and value if set) to exactly match the "before" object, so they cannot trigger a diff during DeepEqual. I'll add some more comments to record this.

return err
}
if found {
unstructured.SetNestedField(newObj.UnstructuredContent(), val, "metadata", fieldName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To verify, SetNestedField covers both cases of field value change and adding back removed field. Am I right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I'll add a comment to record that expectation. The unit test confirms it with the case "uid": "should bring back removed value".

dynamicapply.SetLastApplied(newObj, update.UnstructuredContent())
return newObj, nil
}

// objectMetaSystemFields is a list of JSON field names within ObjectMeta that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put this to a global file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by a global file? I put it here for now because I like to keep things close to where they're being used if they're only used once. We can always move it later.

I looked around in Kubernetes itself to see if there was any existing list or code to revert ObjectMeta system fields, but I didn't find anything reusable. It looks like they just hard-coded the steps to set the fields in various places.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, i mean a file that records all hard-coded attributes/structs. +1 on keeping things close if they are only used once.

@crimsonfaith91
Copy link
Contributor

In the long run, we may still have to fix the omitempty pointer issue. Should we file an issue in main Kubernetes repository?

If the user asks us to update them, we will silently ignore the
changes. The API server would ignore the changes anyway, but we
need to account for that in advance because otherwise we'll either
send needless no-op updates (for InPlace strategies) or needlessly
delete and recreate objects (for Recreate strategies).
@crimsonfaith91
Copy link
Contributor

/lgtm

@enisoc enisoc merged commit 7feb482 into GoogleCloudPlatform:master Sep 20, 2018
@enisoc enisoc deleted the recreate-hotloop branch September 20, 2018 19:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants