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

resource: make the populated registry available outside of server #18000

Closed
wants to merge 1 commit into from

Conversation

boxofrad
Copy link
Contributor

@boxofrad boxofrad commented Jul 4, 2023

Description

Moves type registration to an exported method, so that the registry can be used within the CLI for HCL validation, and inside the agent HTTP server for endpoint generation.

This does mean that we can no longer feature-flag the registration of experimental resource types, but I think that's fine, as long as the controller is still feature-flagged.

@boxofrad boxofrad added the pr/no-changelog PR does not need a corresponding .changelog entry label Jul 4, 2023
@boxofrad
Copy link
Contributor Author

boxofrad commented Jul 4, 2023

PR 18k! 🎉

Moves type registration to an exported method, so that the registry can
be used within the CLI for HCL validation, and inside the agent HTTP
server for endpoint generation.
@boxofrad boxofrad force-pushed the boxofrad/extract-type-registration branch from 854ae56 to 81fb575 Compare July 4, 2023 11:03
func NewTypeRegistry() resource.Registry {
registry := resource.NewRegistry()

demo.RegisterTypes(registry)
Copy link
Member

Choose a reason for hiding this comment

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

Previously we only made these resources available in dev mode, should we still do the same thing?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I guess dev mode is just another feature flag.

Copy link
Member

Choose a reason for hiding this comment

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

This actually makes me wonder whether enablement based on flags should be a feature of the resource service.

type Registration struct {
	// Type is the GVK of the resource type.
	Type *pbresource.Type

	// Proto is the resource's protobuf message type.
	Proto proto.Message

	// ACLs are hooks called to perform authorization on RPCs.
	ACLs *ACLHooks

	// Validate is called to structurally validate the resource (e.g.
	// check for required fields).
	Validate func(*pbresource.Resource) error

	// Mutate is called to fill out any autogenerated fields (e.g. UUIDs).
	Mutate func(*pbresource.Resource) error

	// RequireDevMode being set to true will only allow usage of this resource when in dev mode.
	RequireDevMode bool

	// RequireExperiment will cause the resource to only be allowed to be used if the corresponding experiment flag is set.
	RequireExperiment string      

	// In the future, we'll add hooks, the controller etc. here.
	// TODO: https://github.com/hashicorp/consul/pull/16622#discussion_r1134515909
}

@xwa153
Copy link
Member

xwa153 commented Jul 15, 2023

Closing this PR as it's implemented in this PR.

@xwa153 xwa153 closed this Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/no-backport pr/no-changelog PR does not need a corresponding .changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants