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

Diff against the old live state to enable drift correction #2403

Closed
wants to merge 22 commits into from

Conversation

rquitales
Copy link
Member

@rquitales rquitales commented May 13, 2023

Previously, external changes to Kubernetes resources managed by Pulumi would not be drift correctly by this provider when running pulumi up --refresh. This is because we were diff'ing the new inputs against the old inputs. In this scenario, Pulumi would not detect any changes. This PR addresses this by diffing against the old live state when we run pulumi up.

Fixes: #2404

@rquitales rquitales changed the title Add test cases to demonstrate pulumi up against external changes Diff against the old live state to enable drift correction May 15, 2023
@rquitales rquitales marked this pull request as ready for review May 15, 2023 08:01
Copy link
Member

@lblackstone lblackstone left a comment

Choose a reason for hiding this comment

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

I'm wary of this change since it affects old / well-tested code, and alters the core diffing functionality. I haven't had a chance to review in-depth, but some particular things to watch out for:

  1. CSA and SSA diffing work differently; CSA diff used the lastAppliedConfiguration annotation, while SSA diffing is based on apiserver responses, with a fallback to CSA during preview if the cluster is unavailable.
  2. Live state is not always available during previews; any changes need to account for that

That said, this change may indeed fix a longstanding bug, but we need to be extra careful here.


import * as k8s from "@pulumi/kubernetes";

// This test creates a Provider with `enableServerSideApply` enabled. The following scenarios are tested:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// This test creates a Provider with `enableServerSideApply` enabled. The following scenarios are tested:
// This test creates a Provider with `enableServerSideApply` disabled. The following scenarios are tested:

// 3. Rerun the pulumi program and verify that the labels are restored.

// Create provider with SSA enabled.
const provider = new k8s.Provider("k8s");
Copy link
Member

Choose a reason for hiding this comment

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

We should explicitly disable SSA here since the default will change in v4.

assert.Contains(t, string(out), "bar") // ConfigMap should have been created with data foo: bar.

// Update the ConfigMap and change the data foo: bar to foo: baz.
out, err = exec.Command("kubectl", "patch", "configmap", "-n", ns, cmName, "-p", `{"data":{"foo":"baz"}}`).CombinedOutput()
Copy link
Member

Choose a reason for hiding this comment

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

I just checked, and kubectl patch does not update the lastAppliedConfiguration annotation, which is used for CSA diffing. See #694 for a related issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

Only kubectl apply attaches that annotation iirc. This bug would also be triggered by out of band resource modifications by other controllers/tools that use client-go, or other libraries.

pulumi-bot and others added 2 commits May 15, 2023 20:24
Updates the workflow files to HEAD of ci-mgmt/$GITHUB_REF_NAME
(commit dca7b52d162b32ebe8cbf2652c3822981ca7725e)
@rquitales
Copy link
Member Author

Converting this to a draft PR for now. This will require slightly more work than what is in this first PR attempt.
More context: #2404 (comment)

@rquitales rquitales marked this pull request as draft May 16, 2023 20:16
The helm/v2 SDK is deprecated, and is now being removed. The helm/v3 SDK provides equivalent support, but uses the helm client library rather than shelling out to the helm CLI. The v2:Chart and v3:Chart resources are already aliased, so users can update the SDK in code without a disruptive update.
# Conflicts:
#	CHANGELOG.md
# Conflicts:
#	provider/pkg/provider/provider.go
As part of upgrading the client-go dependency, we need to drop support for Kubernetes versions older than v1.13.0 (released December 2018, EOL as of October 2019). client-go has dropped support [1] for the dry-run verifier because all cluster versions v1.13 and greater include this support. As a result, we drop the dry run check from the provider, and enforce a minimum version of v1.13.

Additionally, one of the options for kustomize support moved [2], so update the calling code to match.

[1] kubernetes/kubernetes#114294
[2] kubernetes-sigs/kustomize#4945
# Conflicts:
#	CHANGELOG.md
… fails (#2419)

Server-side apply previews currently require "patch" permission to run. For cases where the user doesn't have permission to perform a "patch" operation, attempt a graceful fallback to Client-side preview. The Client-side preview may not be 100% accurate, but is preferable to failing with a permission error.
Previously, the resource properties were not represented consistently across all Pulumi SDKs. In particular, the .NET and NodeJS SDKs represented all resource output properties as required, while Go, Python, and Java represented them as optional. This inconsistency causes problems for multi-language features and documentation.

This change unifies all SDKs to mark every top-level resource output as a required property.
@lblackstone lblackstone force-pushed the rquitales/fix-drift branch from 16a94ce to 628a755 Compare May 31, 2023 15:22
@github-actions
Copy link

github-actions bot commented May 31, 2023

Does the PR have any schema changes?

Found 2 breaking changes:
Resource "kubernetes:helm.sh/v2:Chart" missing
Type "kubernetes:helm.sh/v2:FetchOpts" missing
No new resources/functions.

@pulumi pulumi deleted a comment from github-actions bot May 31, 2023
@pulumi pulumi deleted a comment from github-actions bot May 31, 2023
@lblackstone lblackstone force-pushed the rquitales/fix-drift branch from 7a4a8e9 to ba2fc35 Compare June 6, 2023 19:30
@lblackstone
Copy link
Member

Closing in favor of #2445

@lblackstone lblackstone deleted the rquitales/fix-drift branch June 27, 2023 17:39
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.

Unable to correct drift with pulumi up --refresh after external changes
3 participants