Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Scoped config sources - protobuf & Bolt DB state #4191

Merged
merged 8 commits into from
Nov 23, 2022

Conversation

paladin-devops
Copy link
Contributor

@paladin-devops paladin-devops commented Nov 10, 2022

This PR updates the protobuf and the Bolt DB state implementation to support scoped configuration sources. Waypoint runners, the entrypoint, as well as the CLI continue to exclusively use the global scope, which continues to be the de facto scope in use with this PR. However, the changes in this PR lay the groundwork for forthcoming changes to the aforementioned "clients" of configuration sources. Some tests were also added for the config source Bolt DB state implementation.

The pr/no-changelog label is on this PR because there are no user-facing changes.

@paladin-devops paladin-devops requested review from a team November 10, 2022 21:17
@paladin-devops paladin-devops self-assigned this Nov 10, 2022
@github-actions github-actions bot added the core label Nov 10, 2022
@paladin-devops paladin-devops added the pr/no-changelog No automatic changelog entry required for this pull request label Nov 10, 2022
@paladin-devops paladin-devops marked this pull request as draft November 11, 2022 21:39
@paladin-devops paladin-devops marked this pull request as ready for review November 12, 2022 00:41
Comment on lines +75 to +86
// The scope and type of a config source is used to establish a unique record
// in the config sources table.
idHash, err := hashstructure.Hash(map[string]interface{}{
"scope": value.Scope,
"type": value.Type,
"workspace": value.Workspace,
}, hashstructure.FormatV2, nil)
if err != nil {
return err
}

id := s.configSourceId(idHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note for later readers, there is a note on configSourceId that it's only used for in memory indexes, so we aren't invalidating anything by changing the hash calculate algorithm.

…s scoped by application, project, or workspace, and continues support of the global scope. This commit also updates the Bolt DB state implementation to support these new scopes. The config source index table was updated in this commit to include additional indexes, for project and application, and adds an index dedicated to global config sources.
The config sources for the global scoped are merged with those from the project scope as well as the app scope. The config sources for the project scope are merged with those of the app scope.
The unique ID of a record in the config source "table" is no longer the "type" of config source. Instead, it is now the hash of the config source's type, scope, and configuration. This makes each entry that is added to the table unique, and thusly not overwritten by other config sources of the same type or scope.

This commit also adds another test, and fixes the ordering of params for require.Equal throughout the config source tests.
…ype.

The previous commit made the unique ID of a config source the hash of a config source's type, scope and configuration. This commit removes the configuration from that hash, because a change to a config source's configuration should not result in the creation of a new record, but the updation of an existing one for a specific "type" of plugin in the same "scope".

To accommodate this, the config source project index schema was also updated to include an indicator that a config source was specifically for the project level. This is because app-scoped config sources also have the project set, so the project index was matching on project-scoped AND app-scoped config sources - it now will only match on project-scoped config sources.
This commit updates the addition or update of a config source to consider the workspace scope that is set for the config source. This fixes an issue where setting the config source for a different workspace but at the same scope "level" as another config source of the same type would overwrite the existing entry.
Update the config sources returned by the server to be returned in such a way that the least-specific scope is first in the slice of config sources, and more-specific config sources are in ascending order.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/0.10.x core pr/no-changelog No automatic changelog entry required for this pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants