Skip to content

Commit

Permalink
microcloud/cmd/microcloud: Don't fully overwrite the default profile
Browse files Browse the repository at this point in the history
Rather than overwriting the default profile when adding devices, this
appends the devices and config to the default profile. When adding a new
service to microcloud that was skipped during initial setup, we may have
to add a new device to the default profile but we shouldn't remove
anything we added during first init.

Signed-off-by: Max Asnaashari <[email protected]>
  • Loading branch information
masnax committed Apr 9, 2024
1 parent e71fd82 commit 8c79485
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions microcloud/cmd/microcloud/main_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,12 +772,34 @@ func setupCluster(s *service.Handler, systems map[string]InitSystem) 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
for k, v := range existingProfile.Config {
_, ok := profile.Config[k]
if !ok {
profile.Config[k] = v
}
}

for k, v := range existingProfile.Devices {
_, ok := profile.Devices[k]
if !ok {
profile.Devices[k] = v
}
}

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

Expand Down

0 comments on commit 8c79485

Please sign in to comment.