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

Support for metadata.generateName (CSA) #2808

Merged
merged 9 commits into from
Feb 3, 2024
Merged

Conversation

EronWright
Copy link
Contributor

@EronWright EronWright commented Feb 1, 2024

Proposed changes

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)
  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

Copy link

github-actions bot commented Feb 1, 2024

Does the PR have any schema changes?

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

Copy link

codecov bot commented Feb 1, 2024

Codecov Report

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

Comparison is base (ef6b07b) 24.72% compared to head (f4e4d13) 24.64%.
Report is 1 commits behind head on master.

Files Patch % Lines
provider/pkg/provider/provider.go 0.00% 60 Missing ⚠️
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/metadata/naming.go 84.21% 2 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2808      +/-   ##
==========================================
- Coverage   24.72%   24.64%   -0.08%     
==========================================
  Files          48       48              
  Lines        9651     9710      +59     
==========================================
+ Hits         2386     2393       +7     
- Misses       7109     7160      +51     
- Partials      156      157       +1     

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

@EronWright EronWright changed the base branch from master to eronwright/issue-2539-a February 1, 2024 22:00
@EronWright EronWright marked this pull request as ready for review February 1, 2024 23:43
Base automatically changed from eronwright/issue-2539-a to master February 2, 2024 20:43
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

// This makes it possible to update the program to set `.metadata.name` to the name that was
// made by `.metadata.generateName` without triggering replacement.
if newInputs.GetName() != "" {
oldLivePruned.SetName(oldLive.GetName())
Copy link
Contributor

Choose a reason for hiding this comment

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

Admittedly, this took me a couple of passes to understand what's happening. Maybe it's worthwhile to expand the comment a bit? Something like, generateName will create and store a name, but the oldLivePruned object drops the name field to match the input, which we now need for diffing.

Though this could just be an artifact of code review only showing small chunks of code without context.


//
// User has now specified `.metadata.name`, so Pulumi should replace the resource, and NOT allocate
// a name to it.
// User has now specified `.metadata.generateName`, which Pulumi ignores because autonaming has already occurred,
Copy link
Contributor

Choose a reason for hiding this comment

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

In this scenario, could we emit a warning to the user that we won't honor generateName? I believe we just silently continue right?

const namespace = new k8s.core.v1.Namespace("test-namespace");

//
// The `.metadata.generateName` field has changed, but Pulumi does NOT automatically replace in that situation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a warning here too?

@EronWright EronWright merged commit cc3c25d into master Feb 3, 2024
20 checks passed
@EronWright EronWright deleted the eronwright/issue-2539 branch February 3, 2024 01:27
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>
@vavsab
Copy link

vavsab commented Mar 7, 2024

@EronWright did you test it for ConfigMap?
Is had generateName working for years in ConfigMap before this change. Today I get an error

the `.metadata.generateName` field is not supported in Server-Side Apply mode

Maybe I need to change anything in my provider?

@EronWright
Copy link
Contributor Author

@vavsab I would guess that your provider is configured to use server-side apply mode, which you can disable:
https://www.pulumi.com/registry/packages/kubernetes/how-to-guides/managing-resources-with-server-side-apply/

@gunzy83
Copy link

gunzy83 commented May 27, 2024

@vavsab I would guess that your provider is configured to use server-side apply mode, which you can disable: https://www.pulumi.com/registry/packages/kubernetes/how-to-guides/managing-resources-with-server-side-apply/

Is there a reason this is not supported with SSA? Will it be supported in the future?

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.

generate_name prefix seems to not be honored
4 participants