Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DNM: example runtime config usage #14561

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

Closed
wants to merge 15 commits into from

Conversation

dannykopping
Copy link
Contributor

@dannykopping dannykopping commented Sep 4, 2024

Demonstration of how #14470 could be used in practice.

This PR allows for the runtime reconfiguration of the notification webhook endpoint.
In reality, what we'd actually want it for this value to be configurable on a per-organization level, but the plumbing to get the org details into the Dispatch function complicates the demonstration.

NOTE: in codersdk/deployment.go you'll notice at the bottom that we're iterating over all fields and calling Initialize(opt.Env):

// Initialize runtime fields.
for _, opt := range opts {
	d, ok := opt.Value.(runtimeconfig.Initializer)
	if !ok {
		continue
	}

	if opt.Env == "" {
		panic(fmt.Sprintf("developer error: option %q must have Env value defined to be runtime-configurable", opt.Name))
	}

	d.Initialize(opt.Env)
}

This is because we need to assign a name to each wrapped field. This name is used to identify the field in the database, and this is the simplest approach @Emyrk and I could come up with. We need some stable identity for each field, and the field's Env value is stable.

NOTE: I've protected func (DeploymentValues) Options() with a sync.OnceFunc because this method gets called in several places and it's both inefficient and dangerous to run this code several times; once is enough.

TestRuntimeEndpointChange demonstrates how it all comes together. Besides the changes in coderd/notifications/dispatch/webhook.go, this is mostly boilerplate.

dannykopping and others added 11 commits September 4, 2024 10:26
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Signed-off-by: Danny Kopping <[email protected]>
Emyrk and others added 4 commits September 4, 2024 16:47
@dannykopping dannykopping force-pushed the dk/runtime-configs-usage branch from 5a24f7a to 9069a48 Compare September 4, 2024 14:50
@Emyrk Emyrk force-pushed the dk/runtime-configs branch from 0f7deba to 9f546d0 Compare September 6, 2024 15:19
@github-actions github-actions bot added the stale This issue is like stale bread. label Sep 14, 2024
@github-actions github-actions bot closed this Sep 18, 2024
@github-actions github-actions bot deleted the dk/runtime-configs-usage branch March 5, 2025 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale This issue is like stale bread.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants