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

Reorganize init configuration #138

Merged
merged 17 commits into from
Sep 18, 2023
Merged

Reorganize init configuration #138

merged 17 commits into from
Sep 18, 2023

Conversation

masnax
Copy link
Contributor

@masnax masnax commented Jul 13, 2023

In an effort to make it easier to debug the built-up configuration of microcloud init and microcloud add, and also easier to validate, this PR reorganizes the init configuration around a map of structs which will hold all the configuration obtained by the init prompts.

The main change here is the introduction of the InitSystem type which maintains a record of all configuration that is built up over the user prompts. The type holds lists of API structs to be included in the join config or run after cluster setup. The API structs are mainly boilerplate, so some template functions have been introduced to reduce duplication around that as well.

This will also help with the upcoming preseed PR which will just need to validate the yaml payload into the same map[string]InitSystem.

@masnax
Copy link
Contributor Author

masnax commented Jul 13, 2023

In order to fix a disk adding bug (which is also fixed in this refactor), I've created a new PR #139 and rebased this branch off of that one, so that one should now be merged first.

Copy link
Contributor

@markylaing markylaing left a comment

Choose a reason for hiding this comment

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

Overall this refactor looks much clearer and simpler. That being said, as you are already refactoring, I think now is a good time to add some tests to make sure the changes you have made are working as intended.

@tomponline
Copy link
Member

@markylaing yeah @masnax discussed a similar concern in our 1:1 this week.

@tomponline
Copy link
Member

tomponline commented Jul 14, 2023

It would be useful to get a test script, similar to canonical/lxd-ci#3 added for microcloud setup, then, at least for now, it can be run manually to check for regressions.

And when/if we get private GH runners that support VMs we can automate it.

Copy link
Member

@tomponline tomponline left a comment

Choose a reason for hiding this comment

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

A few small changes needed, but overall this looks much clearer and more maintainable, thanks!

One thing I did notice throughout, and something I've wondered about before, is where does microcloud log to? I didn't see much logging (if any at all), and I think it would be useful to log more so we can see where things are failing, what do you think?

@masnax
Copy link
Contributor Author

masnax commented Jul 14, 2023

Already working on tests :)

@masnax
Copy link
Contributor Author

masnax commented Jul 14, 2023

A few small changes needed, but overall this looks much clearer and more maintainable, thanks!

One thing I did notice throughout, and something I've wondered about before, is where does microcloud log to? I didn't see much logging (if any at all), and I think it would be useful to log more so we can see where things are failing, what do you think?

Just to syslog. microcluster automatically sets up a syslog logger when the daemon starts. It's used mainly around mdns at the moment, because that's the part that's most "magic". I'm not logging all that much in the CLI because its outputs are sort of are like logs printed directly to stdout anyway, and outside of that microcloud just calls the APIs to its services which have their own logs.

There is a bit of a dearth of logs though, so I'll try to think about how I can incorporate them some more.

@masnax
Copy link
Contributor Author

masnax commented Sep 12, 2023

@tomponline If you're OK with it, I think we can go ahead and merge this PR now, since the system tests have been running against the changes introduced here on my system.

@tomponline
Copy link
Member

@tomponline If you're OK with it, I think we can go ahead and merge this PR now, since the system tests have been running against the changes introduced here on my system.

I cannot merge it with the tests failing on compile errors though:

golangci-lint run --timeout 5m
Error: cmd/microcloud/ask.go:29:22: undefined: cli.AskBool (typecheck)
				retry, err = cli.AskBool(fmt.Sprintf("%s (yes/no) [default=yes]: ", question), "yes")
				                 ^
Error: cmd/microcloud/ask.go:56:24: undefined: cli.AskBool (typecheck)
			confirm, err := cli.AskBool(fmt.Sprintf("%s not found. Continue anyway? (yes/no) [default=yes]: ", serviceStr), "yes")
			                    ^
Error: cmd/microcloud/ask.go:131:22: undefined: cli.AskBool (typecheck)
		filter, err := cli.AskBool(fmt.Sprintf("Limit search for other MicroCloud servers to %s? (yes/no) [default=yes]: ", subnet.String()), "yes")
		                   ^
Error: cmd/microcloud/ask.go:647:24: undefined: cli.AskString (typecheck)
			gateway, err := cli.AskString(msg, "", validator)
			                    ^
Error: cmd/microcloud/ask.go:671:29: undefined: cli.AskString (typecheck)
					rangeStart, err := cli.AskString(fmt.Sprintf("Specify the first %s address in the range to use with LXD: ", ip), "", validator)
					                       ^
Error: cmd/microcloud/ask.go:676:27: undefined: cli.AskString (typecheck)
					rangeEnd, err := cli.AskString(fmt.Sprintf("Specify the last %s address in the range to use with LXD: ", ip), "", validator)
					                     ^
make: *** [Makefile:27: check-static] Error 1

https://github.com/canonical/microcloud/actions/runs/6164591577/job/16730614381?pr=138

Copy link
Member

@tomponline tomponline left a comment

Choose a reason for hiding this comment

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

the code doesn't current compile

@tomponline
Copy link
Member

Once its green, can you re-request a review by click the button next to my name as a reviewer so it appears in my todo list here https://github.com/pulls/review-requested

Thanks!

@masnax
Copy link
Contributor Author

masnax commented Sep 13, 2023

Ah, looks like the LXD cli change is the culprit because the workflow runs make update-gomod before building.

I'll need to send out some PRs for LXD Cloud, MicroOVN, and MicroCeph too.

This consolidates all the commonly used API structs by MicroCloud into a
set of helpers that build them and fill in the necessary boilerplate.
With multiple forms of creating a MicroCloud cluster (interactive, auto,
preseed, add), this can help consolidate a lot of duplicate code.

Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
InitSystem will represent all the init configuration collected by the
interactive CLI for each peer. A map of InitSystem will be passed around
the CLI functions and slowly added to, before it is finally used to
initialize the cluster.

This will hopefully make debugging MicroCloud much easier as we will
have a snapshot of all collected information throughout the init
process. It might also facilitate some testing of the CLI.

Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
…equests

Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
…m configuration

Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
tomponline
tomponline previously approved these changes Sep 18, 2023
@tomponline
Copy link
Member

Static analysis failures

Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
@masnax
Copy link
Contributor Author

masnax commented Sep 18, 2023

@tomponline Looks to be passing now, so you can merge when ready.

Copy link
Member

@tomponline tomponline left a comment

Choose a reason for hiding this comment

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

Thanks!

@tomponline tomponline dismissed markylaing’s stale review September 18, 2023 17:49

changes have been addressed

@tomponline tomponline merged commit c3a3820 into canonical:main Sep 18, 2023
8 checks passed
@masnax
Copy link
Contributor Author

masnax commented Sep 18, 2023

And just like that, MicroCloud edge got way less buggy!

@tomponline
Copy link
Member

Yay! Thanks

I turned off requiring signed commits for now btw

@tomponline
Copy link
Member

As that was preventing merging

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.

None yet

5 participants