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

Use output properties for await logic #2790

Merged
merged 19 commits into from
Feb 2, 2024
Merged

Conversation

EronWright
Copy link
Contributor

@EronWright EronWright commented Jan 29, 2024

Proposed changes

This PR changes the provider's await logic to get the object name from the output properties rather than the input properties, since the inputs may or may not contain an object name, to prepare to support generateName field (see #2539). Note that auto-naming populates the inputs, whereas generateName doesn't.

The awaiters continue to look to the inputs (not the live object) for the skipAwait and timeout annotations.

Related issues (optional)

Related: #2539

Copy link

Does the PR have any schema changes?

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

Copy link

codecov bot commented Jan 29, 2024

Codecov Report

Attention: 139 lines in your changes are missing coverage. Please review.

Comparison is base (ef6b07b) 24.72% compared to head (556e701) 24.67%.

Files Patch % Lines
provider/pkg/await/awaiters.go 0.00% 48 Missing ⚠️
provider/pkg/await/await.go 18.60% 35 Missing ⚠️
provider/pkg/openapi/openapi.go 0.00% 11 Missing ⚠️
provider/pkg/await/deployment.go 44.44% 10 Missing ⚠️
provider/pkg/await/ingress.go 10.00% 9 Missing ⚠️
provider/pkg/await/job.go 0.00% 7 Missing ⚠️
provider/pkg/await/statefulset.go 12.50% 7 Missing ⚠️
provider/pkg/await/pod.go 0.00% 6 Missing ⚠️
provider/pkg/provider/provider.go 0.00% 4 Missing ⚠️
provider/pkg/await/service.go 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2790      +/-   ##
==========================================
- Coverage   24.72%   24.67%   -0.05%     
==========================================
  Files          48       48              
  Lines        9651     9669      +18     
==========================================
  Hits         2386     2386              
- Misses       7109     7127      +18     
  Partials      156      156              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

// IgnoreChanges is a list of fields to ignore when diffing the old and new objects.
IgnoreChanges []string
}

type DeleteConfig struct {
ProviderConfig
Inputs *unstructured.Unstructured
Outputs *unstructured.Unstructured
Copy link
Contributor Author

@EronWright EronWright Feb 1, 2024

Choose a reason for hiding this comment

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

Important to note here that the Inputs field contained the old outputs (current). The deletion logic should therefore use Outputs to maintain the status-quo. Inputs is used only for meta-annotations (skipAwait, timeout).

@@ -105,19 +105,19 @@ func PatchForResourceUpdate(
if knownGV := kinds.KnownGroupVersions.Has(lastSubmitted.GetAPIVersion()); !knownGV {
// Use a JSON merge patch for CRD Kinds.
patch, patchType, err = MergePatch(
lastSubmitted, lastSubmittedJSON, currentSubmittedJSON, liveOldJSON,
liveOldObj, lastSubmittedJSON, currentSubmittedJSON, liveOldJSON,
Copy link
Contributor Author

@EronWright EronWright Feb 1, 2024

Choose a reason for hiding this comment

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

The MergePatch and StrategicMergePatch methods take a liveOld parameter to obtain the object's GVK (and object name) with which to get schema information for patch calculation. Here we see that the code was using the lastSubmitted, which is the old input (which may be an older API version?). The PR changes it to use the live object, which has the GVK of the new input. There's still the potential for a mismatch but it seems out of scope (see #2807).

Comment on lines +2476 to +2477
Inputs: oldInputs,
Outputs: current,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again note how Inputs was the old outputs.

Inputs *unstructured.Unstructured
Timeout float64
Preview bool
OldInputs *unstructured.Unstructured
Copy link
Contributor Author

@EronWright EronWright Feb 1, 2024

Choose a reason for hiding this comment

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

Previous is renamed to OldInputs for clarity, given there's a new property OldOutputs.

@@ -51,7 +51,6 @@ type createAwaitConfig struct {
initialAPIVersion string
logger *logging.DedupLogger
clientSet *clients.DynamicClientSet
currentInputs *unstructured.Unstructured
Copy link
Contributor Author

@EronWright EronWright Feb 1, 2024

Choose a reason for hiding this comment

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

I see no reason for the awaiters to have or to use the inputs, since they're used strictly after any desired changes have been applied. The awaiters often compare spec and status, and the output object is a reasonable basis for that. Similarly, the deployment awaiter compares the old/new specs to anticipate whether a rollout will occur, now using the last/current outputs.

The inputs are still used to get the timeout annotation, but more eagerly in the core await logic.

@@ -718,19 +733,22 @@ func Deletion(c DeleteConfig) error {
}

// Obtain client for the resource being deleted.
client, err := c.ClientSet.ResourceClientForObject(c.Inputs)
client, err := c.ClientSet.ResourceClientForObject(c.Outputs)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As tempting as it is to use c.Inputs here, it would change the status quo and create some code smell because the client is used with the c.Outputs in many places below.

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

@EronWright EronWright merged commit 33c84f9 into master Feb 2, 2024
20 checks passed
@EronWright EronWright deleted the eronwright/issue-2539-a branch February 2, 2024 20:43
EronWright added a commit that referenced this pull request Feb 3, 2024
<!--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 implements support for `.metadata.generateName` in CSA mode,
based on #2790.
1. Adjust the auto-naming logic to consider `.metadata.generateName` to
be a variant of auto-naming. Pulumi will not assign an auto-name to a
new resource that has `generateName`, and upon delete will use the
replace-then-delete technique.
2. Use outputs rather than inputs to fetch the live object or to obtain
the live object's name.
3. Fix an autonaming bug where the old auto-name would erroneously be
adopted, overwriting a new computed name.

### Tests
1. A new integration test is provided to test the use of
`metadata.generateName`. It tests creation, update, replacement, and
promotion from `.generateName` to `.name`.
([ref](https://github.com/pulumi/pulumi-kubernetes/pull/2808/files#diff-7e85ce707283b1d281d971a8e5b0c49b959b0803ba3437dc9dbd422552326835R269))
2. New test cases for the await logic.
3. The existing autonaming test is enhanced to test how autonaming takes
precedence over `generateName`, in the update case. This is to ensure
backwards compatibility, e.g. in the edge case that an existing object
has a `generateName` field (which Pulumi ignored until now).

### Related issues (optional)
Closes #2539
lumiere-bot bot added a commit to coolguy1771/home-ops that referenced this pull request Feb 24, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@pulumi/kubernetes](https://pulumi.com)
([source](https://togithub.com/pulumi/pulumi-kubernetes)) | dependencies
| minor | [`4.7.1` ->
`4.8.0`](https://renovatebot.com/diffs/npm/@pulumi%2fkubernetes/4.7.1/4.8.0)
|

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>pulumi/pulumi-kubernetes (@&#8203;pulumi/kubernetes)</summary>

###
[`v4.8.0`](https://togithub.com/pulumi/pulumi-kubernetes/blob/HEAD/CHANGELOG.md#480-February-22-2024)

[Compare
Source](https://togithub.com/pulumi/pulumi-kubernetes/compare/v4.7.1...v4.8.0)

- Fix DiffConfig issue when when provider's kubeconfig is set to file
path
([pulumi/pulumi-kubernetes#2771)
- Fix for replacement having incorrect status messages
([pulumi/pulumi-kubernetes#2810)
- Use output properties for await logic
([pulumi/pulumi-kubernetes#2790)
- Support for metadata.generateName (CSA)
([pulumi/pulumi-kubernetes#2808)
- Fix unmarshalling of Helm values yaml file
([pulumi/pulumi-kubernetes#2815)
- Handle unknowns in Helm Release resource
([pulumi/pulumi-kubernetes#2822)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMTAuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIxMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: lumiere-bot[bot] <98047013+lumiere-bot[bot]@users.noreply.github.com>
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.

None yet

3 participants