Skip to content

Commit

Permalink
service add and service list (#355)
Browse files Browse the repository at this point in the history
Closed the old PR to start fresh.

Adds two new commands:
* `microcloud service list` will list the cluster members for every
installed service, or report if it is not initialized. This will
effectively be the same as calling all of the following in succession:
```
lxc cluster list
microcloud cluster list
microceph cluster list
microovn cluster list
```

The information shown will be the name, address, dqlite role, and
current status of each member.

* `microcloud service add` will try to setup MicroOVN and MicroCeph on
all existing MicroCloud cluster members, optionally setting up storage
and networks for LXD. This is useful if MicroOVN or MicroCeph was at one
point not installed on the systems and skipped during `microcloud init`.
LXD and MicroCloud itself are required to already be set up.
Thanks to #259 we can also try to re-use a service that partially covers
existing MicroCloud cluster members. So if a MicroCloud is set up
without MicroCeph, and then the user manually configures MicroCeph to
partially cover the cluster, the user can then use `microcloud service
add` to further configure MicroCeph to work with MicroCloud, and set up
storage pools for LXD.
  • Loading branch information
masnax committed Jul 26, 2024
2 parents 32254b8 + 6d35e1c commit a9f70aa
Show file tree
Hide file tree
Showing 12 changed files with 619 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/microcloud/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (c *cmdAdd) Run(cmd *cobra.Command, args []string) error {
}

// Ask to reuse existing clusters.
err = cfg.askClustered(s)
err = cfg.askClustered(s, services)
if err != nil {
return err
}
Expand Down
9 changes: 2 additions & 7 deletions cmd/microcloud/ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,13 +1230,8 @@ func (c *initConfig) askCephNetwork(sh *service.Handler) error {
// If a service is already initialized on some systems, we will offer to add the remaining systems, or skip that service.
// In auto setup, we will expect no initialized services so that we can be opinionated about how we configure the cluster without user input.
// This works by deleting the record for the service from the `service.Handler`, thus ignoring it for the remainder of the setup.
func (c *initConfig) askClustered(s *service.Handler) error {
expectedServices := make(map[types.ServiceType]struct{}, len(s.Services))
for k := range s.Services {
expectedServices[k] = struct{}{}
}

for serviceType := range expectedServices {
func (c *initConfig) askClustered(s *service.Handler, expectedServices []types.ServiceType) error {
for _, serviceType := range expectedServices {
for name, info := range c.state {
_, newSystem := c.systems[name]
if !newSystem {
Expand Down
3 changes: 3 additions & 0 deletions cmd/microcloud/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ EOF`)
var cmdRemove = cmdRemove{common: &commonCmd}
app.AddCommand(cmdRemove.Command())

var cmdService = cmdServices{common: &commonCmd}
app.AddCommand(cmdService.Command())

var cmdPeers = cmdClusterMembers{common: &commonCmd}
app.AddCommand(cmdPeers.Command())

Expand Down
55 changes: 50 additions & 5 deletions cmd/microcloud/main_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (c *initConfig) RunInteractive(cmd *cobra.Command, args []string) error {
}

// Ask to reuse existing clusters.
err = c.askClustered(s)
err = c.askClustered(s, services)
if err != nil {
return err
}
Expand Down Expand Up @@ -952,12 +952,57 @@ func (c *initConfig) setupCluster(s *service.Handler) error {

if !shared.ValueInSlice(profile.Name, profiles) {
err = lxdClient.CreateProfile(profile)
if err != nil {
return err
}
} else {
err = lxdClient.UpdateProfile(profile.Name, profile.ProfilePut, "")
}
// Ensure any pre-existing devices and config are carried over to the new profile, unless we are managing them.
existingProfile, _, err := lxdClient.GetProfile("default")
if err != nil {
return err
}

if err != nil {
return err
askConflictingConfig := []string{}
askConflictingDevices := []string{}
for k, v := range profile.Config {
_, ok := existingProfile.Config[k]
if !ok {
existingProfile.Config[k] = v
} else {
askConflictingConfig = append(askConflictingConfig, k)
}
}

for k, v := range profile.Devices {
_, ok := existingProfile.Devices[k]
if !ok {
existingProfile.Devices[k] = v
} else {
askConflictingDevices = append(askConflictingDevices, k)
}
}

if !c.autoSetup && len(askConflictingConfig) > 0 || len(askConflictingDevices) > 0 {
replace, err := c.asker.AskBool("Replace existing default profile configuration? (yes/no) [default=no]: ", "no")
if err != nil {
return err
}

if replace {
for _, key := range askConflictingConfig {
existingProfile.Config[key] = profile.Config[key]
}

for _, key := range askConflictingDevices {
existingProfile.Devices[key] = profile.Devices[key]
}
}
}

err = lxdClient.UpdateProfile(profile.Name, existingProfile.Writable(), "")
if err != nil {
return err
}
}
}

Expand Down
Loading

0 comments on commit a9f70aa

Please sign in to comment.