Skip to content

feat: add basic mem store boot-time initialization#103

Open
rainest wants to merge 3 commits intomainfrom
rainest/mem-from-file
Open

feat: add basic mem store boot-time initialization#103
rainest wants to merge 3 commits intomainfrom
rainest/mem-from-file

Conversation

@rainest
Copy link
Copy Markdown
Contributor

@rainest rainest commented Apr 27, 2026

Description

Provide the initial contents of a memstore from a set of files, using a basic "unmarshal YAML into the structs" strategy. Adds YAML tags matching existing JSON tags.

The newer metadata-service storage system doesn't allow as much direct control over its storage, and adding equivalent functionality upstream would affect other services, so adding it here lets me provide a per-repo implementation.

My manual version of the unit test is to deploy the local.yaml in example_ci_mem.tar.gz and then create a map to mount:

kubectl create configmap cic --from-file=groups.yaml --from-file=clusterdefaults.yaml --from-file=instances.yaml

Port-forwarding and curl -sv http://localhost:27777/admin/groups/compute and so on will then return the loaded resources.


Design thoughts in lieu of a proper issue. tl;dr is that this tries to avoid much new UX surface, while still providing a means for static file configuration for test scenarios:

  • Saving ConfigMaps or Secrets is easier for Kubernetes installs than using a pile of bash and resource files to load in after start. IDK if I can distribute a fully self-contained test env with (kubevirt wants to handle its own cloudinit config), but this is simpler for my other environments.
  • MEM_PATH mirrors DB_PATH and serves as a de facto switch: it defaults to empty string, and if not set mem retains its existing, empty on start behavior.
  • Using simple name-mapped struct unmarshals does not allow for a particularly easy to use format, since the bulk of content is trapped behind base64 and is not directly editable (YAML in YAML probably works, but is painful).
  • Similarly, Kubernetes limits on ConfigMap/Secret sizes mean you can only fit so much into the resources.

The limits of using files per resource still work okay for making it easier to reproduce E2E test scenarios (did a set of deploy manifests correctly hook up SMD and cloud-init, does cloud-init serve something to a node in one or more groups, etc.) and don't require any additional types, however, so it largely avoids new UX surface that we'd need to consider for breaking changes.

This still allows room for expansion via cascading configuration in the directory, e.g. by placing a fancier.yaml in the directory and loading configuration from that rather than the basic resource files.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have added/updated comments where needed
  • I have added tests that prove my fix is effective or my feature works
  • I have run make test (or equivalent) locally and all tests pass
  • DCO Sign-off: All commits are signed off (git commit -s) with my real name and email
  • REUSE Compliance:
    • Each new/modified source file has SPDX copyright and license headers
    • Any non-commentable files include a <filename>.license sidecar
    • All referenced licenses are present in the LICENSES/ directory

Currently nothing in this repo has the SPDX stuff, so I did not make the files here the odd ones out.

@rainest rainest mentioned this pull request Apr 27, 2026
Copy link
Copy Markdown
Collaborator

@nbhosle nbhosle left a comment

Choose a reason for hiding this comment

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

Suggested a helper function, to keep the code simplified and easy to read.

Comment thread internal/memstore/ciMemStore.go
rainest added 3 commits April 29, 2026 15:06
Signed-off-by: Travis Raines <571832+rainest@users.noreply.github.com>
Signed-off-by: Travis Raines <571832+rainest@users.noreply.github.com>
Add support for a MEM_PATH envvar. When set, server startup expects
groups.yaml, instances.yaml, and clusterdefaults.yaml files under the
path from the variable, and pre-populates the memory store with their
contents.

Signed-off-by: Travis Raines <571832+rainest@users.noreply.github.com>
@rainest rainest force-pushed the rainest/mem-from-file branch from fc5fcdd to 7ccbf26 Compare April 29, 2026 22:18
@rainest
Copy link
Copy Markdown
Contributor Author

rainest commented Apr 29, 2026

Force push to incorporate the unrelated Go version bump and golangci-lint version bump, as well as incorporate some lint fixes in the test.

@rainest rainest requested a review from nbhosle April 29, 2026 22:53
Copy link
Copy Markdown
Collaborator

@nbhosle nbhosle left a comment

Choose a reason for hiding this comment

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

Thanks for the context, @rainest. I understand wanting to keep the flow flat for these three files.

However, I've marked this as 'Request Changes' because the current error handling in NewMemStoreFromPath returns the store object alongside an error. This is risky as the caller might attempt to use a partially initialized store if they aren't careful.

If we're sticking with the flat structure, please update those blocks to return nil, err and use the full Path variables in the error strings to make debugging easier.

}
err = yaml.Unmarshal(groups, &store.Groups)
if err != nil {
return store, fmt.Errorf("error unmarshaling groups.yaml: %w", err)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this intended to return store object along with an Error? Returning store object on failure is a bit risky for the caller.
Following make more sense, which returns nil along with the error message that including the full path of the file.

		return store, fmt.Errorf("error unmarshaling %q: %w", groupsPath, err)

Comment thread internal/memstore/ciMemStore.go
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.

2 participants