Skip to content

Commit

Permalink
lxd/patches: Add patch for entity type instance snapshot typo
Browse files Browse the repository at this point in the history
Signed-off-by: Kadin Sayani <[email protected]>
  • Loading branch information
kadinsayani committed Sep 4, 2024
1 parent 8dc8462 commit e5f0560
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lxd/patches.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ var patches = []patch{
{name: "storage_move_custom_iso_block_volumes_v2", stage: patchPostDaemonStorage, run: patchStorageRenameCustomISOBlockVolumesV2},
{name: "storage_unset_invalid_block_settings_v2", stage: patchPostDaemonStorage, run: patchStorageUnsetInvalidBlockSettingsV2},
{name: "config_remove_core_trust_password", stage: patchPreLoadClusterConfig, run: patchRemoveCoreTrustPassword},
{name: "entity_type_instance_snapshot_typo_fix", stage: patchPreLoadClusterConfig, run: patchEntityTypeInstanceSnapshotTypoFix},
{name: "instance_remove_volatile_last_state_ip_addresses", stage: patchPostDaemonStorage, run: patchInstanceRemoveVolatileLastStateIPAddresses},
}

Expand Down Expand Up @@ -1346,6 +1347,44 @@ func patchRemoveCoreTrustPassword(_ string, d *Daemon) error {
return nil
}

func patchEntityTypeInstanceSnapshotTypoFix(name string, d *Daemon) error {
for {
var localConfig *node.Config
var err error
err = d.db.Node.Transaction(context.TODO(), func(ctx context.Context, tx *db.NodeTx) error {
localConfig, err = node.ConfigLoad(ctx, tx)
return err
})

if err != nil {
return err
}

leaderAddress, err := d.gateway.LeaderAddress()
if err != nil {
if errors.Is(err, cluster.ErrNodeIsNotClustered) {
break // Apply change on standalone node.
}

return err
}

if localConfig.ClusterAddress() == leaderAddress {
break // Apply change on leader node.
}

logger.Warnf("Waiting for %q patch to be applied on leader cluster member", name)
time.Sleep(time.Second)
}

// Apply patch.
_, err := d.State().DB.Cluster.DB().Exec(`
DROP TRIGGER IF EXISTS on_instance_snaphot_delete
`)

return err
}

// patchInstanceRemoveVolatileLastStateIPAddresses removes the volatile.*.last_state.ip_addresses config key from instances.
func patchInstanceRemoveVolatileLastStateIPAddresses(_ string, d *Daemon) error {
s := d.State()
Expand Down

0 comments on commit e5f0560

Please sign in to comment.