Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix continuous diff for Secret stringData field #2511

Merged
merged 3 commits into from
Jul 21, 2023

Conversation

lblackstone
Copy link
Member

Proposed changes

If the stringData field is set on a Secret resource, then Kubernetes will automatically replace it with an equivalent data field. This is causing a continuous diff with the updated logic from 6e329f3. This change updates the input diff logic to include this rewrite.

Related issues (optional)

Fix #2507

If the `stringData` field is set on a Secret resource, then Kubernetes will automatically replace it with an equivalent `data` field. This is causing a continuous diff with the updated logic from 6e329f3. This change updates the input diff logic to include this rewrite.
@lblackstone
Copy link
Member Author

The test fails without this change. It looks like it was erroneously expecting refresh changes before, which covered up this regression.

@lblackstone lblackstone requested a review from a team July 20, 2023 23:34
@github-actions
Copy link

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

@lblackstone

This comment was marked as outdated.

@@ -65,22 +65,35 @@ func ToUnstructured(object metav1.Object) (*unstructured.Unstructured, error) {
// This process normalizes semantically-equivalent resources into an identical output, which is important for diffing.
// If the scheme is not defined, then return the original resource.
func Normalize(uns *unstructured.Unstructured) (*unstructured.Unstructured, error) {
var result *unstructured.Unstructured

if IsCRD(uns) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: preference for switch case here, but will follow up in a later PR/discussion to get this fix out ASAP.

Copy link
Contributor

@rquitales rquitales left a comment

Choose a reason for hiding this comment

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

LGTM, minor comment that we can follow up later.

@rquitales rquitales merged commit aa4f576 into master Jul 21, 2023
18 checks passed
@rquitales rquitales deleted the lblackstone/secret-diff branch July 21, 2023 04:14
Copy link
Contributor

@EronWright EronWright left a comment

Choose a reason for hiding this comment

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

Leaving some remarks as I am reviewing this PR for an unrelated issue.

result, err = ToUnstructured(obj)
// Return the input resource rather than an error if this operation fails.
if err != nil {
return uns, err
Copy link
Contributor

Choose a reason for hiding this comment

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

Was it intentional to return the err here? The comment seems to say otherwise.

obj, err := FromUnstructured(uns)
// Return the input resource rather than an error if this operation fails.
if err != nil {
return uns, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Was it intentional to ignore all errors, e.g. a value parsing error? For example, given creationTimestamp: invalid_value, a time parser error is caught and ignored.

EronWright added a commit that referenced this pull request Sep 21, 2023
<!--Thanks for your contribution. See [CONTRIBUTING](CONTRIBUTING.md)
    for Pulumi's contribution guidelines.

    Help us merge your changes more quickly by adding more details such
    as labels, milestones, and reviewers.-->

### Proposed changes
<!--Give us a brief description of what you've done and what it solves.
-->

This PR improves the handling of the read-only metadata fields of
Kubernetes objects, such as `creationTimestamp` and `resourceVersion`.
The provider now ignores these fields when they appear as resource
inputs, to address a few quirks:
1. Unparseable values do not cause an API Server error during preview.
2. A subsequent refresh does not show a difference to the `__inputs`
property.
3. The behavior is now uniform for standard resource types and for
custom resource types.

An integration test is provided to show that such fields are ignored as
inputs, and are still available as outputs. Manual tests confirmed
identical behavior for custom resource objects.

### Related issues (optional)
Closes #2351

Related:
- #2511
- #2445

<!--Refer to related PRs or issues: #1234, or 'Fixes #1234' or 'Closes
#1234'.
Or link to full URLs to issues or pull requests in other GitHub
repositories. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v1/Secret always in diff when using stringData with v4.0.1
3 participants