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

Implement autonaming configuration protocol #3377

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mikhailshilkov
Copy link
Member

Proposed changes

This PR implement the Kubernetes part of pulumi/pulumi#1518. See pulumi/pulumi#17592 for the full design.

In short, pulumi/pulumi#17810 introduced the protobuf changes required for the provider-side implementation. With those, a provider can:

  • Declare that it supports autonaming configurations with a response flag in Configure
  • Accept two extra properties in CheckRequest: a proposed name and a mode to apply it

This PR applies those parameters to auto-name calculation if they are specified:

  • In Disabled mode, we don't calculate auto-names at all
  • In Enforce or Propose mode, we use whatever ProposedName is supplied by the engine

Related issues (optional)

Resolves #3363

Copy link

Does the PR have any schema changes?

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

Copy link

codecov bot commented Dec 18, 2024

Codecov Report

Attention: Patch coverage is 82.60870% with 4 lines in your changes missing coverage. Please review.

Project coverage is 41.18%. Comparing base (02c6a40) to head (87f84ae).

Files with missing lines Patch % Lines
provider/pkg/provider/provider.go 42.85% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3377      +/-   ##
==========================================
+ Coverage   41.17%   41.18%   +0.01%     
==========================================
  Files          85       85              
  Lines       12764    12773       +9     
==========================================
+ Hits         5255     5261       +6     
- Misses       7120     7122       +2     
- Partials      389      390       +1     

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

@mikhailshilkov mikhailshilkov marked this pull request as ready for review December 18, 2024 22:03
Copy link
Contributor

@blampe blampe left a comment

Choose a reason for hiding this comment

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

Is this worth a quick yaml e2e test or are we confident in the unit behavior?

CHANGELOG.md Outdated
Comment on lines 3 to 6
- Respect autonaming configuration specified by the engine.
(https://github.com/pulumi/pulumi-kubernetes/issues/3363)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Respect autonaming configuration specified by the engine.
(https://github.com/pulumi/pulumi-kubernetes/issues/3363)
### Added
- Added support for autonaming configuration specified by the engine.
(https://github.com/pulumi/pulumi-kubernetes/issues/3363)

Comment on lines 102 to 119
// o7 has no name, but autonaming is disabled by the engine, so autonaming fails.
o7 := &unstructured.Unstructured{}
autonamingDisabled := &pulumirpc.CheckRequest_AutonamingOptions{
Mode: pulumirpc.CheckRequest_AutonamingOptions_DISABLE,
}
AssignNameIfAutonamable(nil, autonamingDisabled, o7, pm1, resource.NewURN(tokens.QName("teststack"), tokens.PackageName("testproj"),
tokens.Type(""), tokens.Type("bang:boom/fizzle:MajorResource"), "foo"))
assert.False(t, IsAutonamed(o7))
assert.Equal(t, "", o7.GetGenerateName())
assert.Equal(t, "", o7.GetName())
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 case autonaming doesn't fail, the object just doesn't get a name. That will ultimately become an error when we try to apply the object to the cluster, since the name is required.

If we encounter this situation we should return an error to the user instead of letting them apply the invalid object. Something like "Autonaming is disabled so XYZ requires a .metadata.name". It would make sense to modify AssignNameIfAutonamable to return error for this situation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it always an error if a name is not specified, for all resource types? I assumed that some objects may allow that? But it sounds like that's not true? If name/generateName are always required, an error makes sense to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added an error on Disabled

Comment on lines 37 to 39
case pulumirpc.CheckRequest_AutonamingOptions_ENFORCE, pulumirpc.CheckRequest_AutonamingOptions_PROPOSE:
autoname = engineAutonaming.ProposedName
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should also probably validate the proposed name, since the user could specify a template that isn't valid for k8s.

I think that would be IsDNS1123Subdomain but @rquitales should double check this!

https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we validate urn.Name() anywhere?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, IsDNS1123Subdomain is the correct validator.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we validate urn.Name() anywhere?

That's a good question, I don't think we do! I guess we offload all of that to the cluster, so maybe we don't need to validate anything here.

I'm curious what the user experience looks like in that situation? If it's pretty clear how to resolve the issue then this is probably fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the error that one gets in both cases:

error: resource "urn:pulumi:dev::kubernetes-ts::kubernetes:apps/v1:Deployment::nginx!!!!" was not successfully created by the Kubernetes API server: Deployment.apps "nginx!!!!-6626ce94" is invalid: metadata.name: Invalid value: "nginx!!!!-6626ce94": a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is 'a-z0-9?(.a-z0-9?)*')

@blampe
Copy link
Contributor

blampe commented Dec 19, 2024

Rebasing should fix your build failure.

@mikhailshilkov mikhailshilkov force-pushed the mikhailshilkov/autonaming branch from d6c5b8b to 87f84ae Compare December 20, 2024 07:49
@mikhailshilkov
Copy link
Member Author

Is this worth a quick yaml e2e test or are we confident in the unit behavior?

@blampe Could you point me to an existing example that I could copy?

@blampe
Copy link
Contributor

blampe commented Dec 20, 2024

Is this worth a quick yaml e2e test or are we confident in the unit behavior?

@blampe Could you point me to an existing example that I could copy?

This simplest/fasted would probably be to copy on of the yaml tests that live (confusingly) under tests/java

https://github.com/pulumi/pulumi-kubernetes/blob/master/tests/sdk/java/yamlv2_test.go
https://github.com/pulumi/pulumi-kubernetes/tree/master/tests/sdk/java/testdata/yamlv2

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.

Implement autonaming configuration protocol
3 participants