Skip to content

fix: model migration from 3.6 to 4 with an LXD virtual machine#21651

Merged
jujubot merged 5 commits intojuju:4.0from
hmlanigan:subnet-provider-changes
Jan 28, 2026
Merged

fix: model migration from 3.6 to 4 with an LXD virtual machine#21651
jujubot merged 5 commits intojuju:4.0from
hmlanigan:subnet-provider-changes

Conversation

@hmlanigan
Copy link
Copy Markdown
Member

@hmlanigan hmlanigan commented Jan 24, 2026

Fixes model migration from 3.6 to 4 where the model contains LXD virtual-machines. Link layer device import fails with:
machine-0: 20:42:46 INFO juju.worker.migrationmaster.3af583 logger-tags:migration aborted, removing model from target controller: model data transfer failed, failed to import model into target controller: execute operation import link layer devices: importing link layer devices: converting device "enp5s0" on machine "0": converting address "10.74.147.39/24": no subnet found for provider subnet ID "subnet--10.74.147.0/24" The subnet does exist as subnet-lxdbr0-10.74.147.0/24.

3.6 contrives the provider subnet id and the network name was not available in all code paths. Thus the subnet saves the provider id as subnet-lxdbr0-10.74.147.0/24. However it was created as subnet--10.74.147.0/24. With lxd virtual machines, 3.6 allows the name of link layer devices to enp5s0 rather than eth0 and cannot match the lxd api returned data correctly between the two different names.

NOTE: model migration with an lxd virtual machine still fails if the k8s charm is deployed, the error has moved: 'migrating: aborted, removing model from target controller: model data transfer failed, failed to import model into target controller: execute operation import link layer devices: importing link layer devices: converting device "cilium_host" on machine "0": converting address "10.1.0.40/32": no subnet found'. In 3.6 this ip address is saved without a corresponding subnet.

The fix is in 3 parts: new deployments, model migration and controller upgrade with the same results. Provider subnet ids do not exist for lxd cloud models, and the prefix of net- is removed from the provider ids of networks. Neither bits of data is required and in the case of lxd, contrived and not provided by the provider.

Removing the provider subnet id uncovered one place where it was expected: addProviderLinkLayerDevice, part of MergeLinkLayerDevice. More investigation is warranted to ensure this is done correctly. JUJU-9106

TODO: Investigate why the subnet CIDR is set as the subnet's provider id on new 4.0.2 models.

TODO: Resolve issue with cilium_host address on virtual machines with k8s charm failing to migrate. JUJU-9101

Checklist

  • Code style: imports ordered, good names, simple structure, etc
  • Comments saying why design decisions were made
  • Go unit tests, with comments saying what you're testing
  • Integration tests, with comments saying what you're testing
  • doc.go added or updated in changed packages

QA steps

# 
# test provide subnet id not created for lxd
#
$ juju bootstrap localhost testing --build-agent
$ juju add-model test; juju deploy juju-qa-test qa   --constraints='virt-type=virtual-machine' ; juju deploy ubuntu
$ juju subnets
subnets:
  10.21.51.0/24:
    type: ipv4
    provider-id: 10.21.51.0/24
    provider-network-id: lxdbr0
    space: alpha
    zones:
    - ubuntu-nuc-two
  172.17.0.0/16:
    type: ipv4
    provider-id: 172.17.0.0/16
    provider-network-id: docker0
    space: alpha
    zones:
    - ubuntu-nuc-two
#
# test migration fix lxd
# 
$ juju bootstrap localhost dst
$ juju_36 bootstrap localhost three-six
$ juju_36 add-model moveme ; juju_36 deploy juju-qa-test qa   --constraints='virt-type=virtual-machine'; juju_36 deploy ubuntu
$ juju migrate moveme dst
$ juju switch dst:moveme
$ juju subnets
subnets:
  10.21.51.0/24:
    type: ipv4
    provider-network-id: lxdbr0
    space: alpha
    zones:
    - ubuntu-nuc-two
  172.17.0.0/16:
    type: ipv4
    provider-network-id: docker0
    space: alpha
    zones:
    - ubuntu-nuc-two
#
# test migration of non lxd model does not remove the provider subnet id, nor update the provider id
# 
#
# test upgrade of lxd updates data, remove the provider subnet id and update the provider id.
#
$ juju bootstrap localhost upgrade-test --agent-version 4.0.1
$ juju add-model test ; juju deploy juju-qa-test qa   --constraints='virt-type=virtual-machine' ; juju deploy ubuntu
$ juju subnets
subnets:
  10.21.51.0/24:
    type: ipv4
    provider-id: subnet-lxdbr0-10.21.51.0/24
    provider-network-id: net-lxdbr0
    space: alpha
    zones:
    - ubuntu-nuc-two
  172.17.0.0/16:
    type: ipv4
    provider-id: subnet-docker0-172.17.0.0/16
    provider-network-id: net-docker0
    space: alpha
    zones:
    - ubuntu-nuc-two
$ juju upgrade-controller --build-agent

# once the controller upgrade is complete
$ juju subnets
subnets:
  10.21.51.0/24:
    type: ipv4
    provider-network-id: lxdbr0
    space: alpha
    zones:
    - ubuntu-nuc-two
  172.17.0.0/16:
    type: ipv4
    provider-network-id: docker0
    space: alpha
    zones:
    - ubuntu-nuc-two

#
# test upgrade of non lxd model does not remove the provider subnet id, nor update the provider id
#

Links

Jira card: JUJU-9068

Copy link
Copy Markdown
Contributor

@gfouillet gfouillet left a comment

Choose a reason for hiding this comment

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

Looks good, thank you.

Comment thread domain/network/modelmigration/import_linklayerdevices.go Outdated
Comment thread domain/network/modelmigration/import_subnets.go Outdated
Comment thread domain/network/state/types.go Outdated
// The ProviderSubnetID is not required. The contrived values for LXD
// serve no purpose, remove them from the model data from 3.6.
var providerSubnetID string
if cloudType != "lxd" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be a constant somewhere.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There is not a generic constance for any of the provider types, not sure why. Even the register provider code uses strings.

Interestingly there is a set of K8SCloud* types, e.g. K8sCloudLXD.

Unfortunately the types in the cloud domain, are for the cloud_type id as integers. The String method converts with strings.

I completely clouds need type strings. However it should be done as a small project across the board and is outside of the scope of this PR.

Comment thread domain/network/modelmigration/import_subnets.go
Comment thread domain/network/modelmigration/import_subnets.go
Comment thread domain/network/state/import.go
Comment thread domain/network/state/types.go Outdated
@hmlanigan hmlanigan force-pushed the subnet-provider-changes branch from 3d9ddcb to fe4a63c Compare January 27, 2026 16:54
@hmlanigan hmlanigan force-pushed the subnet-provider-changes branch from fe4a63c to 411bfb4 Compare January 27, 2026 19:21
@hpidcock hpidcock changed the title fix: model migration from 3.6 to 4 with an lxd virtual machine fix: model migration from 3.6 to 4 with a lxd virtual machine Jan 28, 2026
@hpidcock hpidcock changed the title fix: model migration from 3.6 to 4 with a lxd virtual machine fix: model migration from 3.6 to 4 with an LXD virtual machine Jan 28, 2026
The provider subnet id is contrived and can contain incorrect data
depending on which lxd container type is in use. Nor it is required by
juju. Stop creating it. Same with provider id.

With provider subnet ids, remove the prefix of nic-, it is superfluous.
When importing link layer devices, do not use the subnet provide id as
the data by be incorrect from 3.6, preventing migration.

When importing subnets, do not save the provider id. It's
contrived and not real. Remove the prefix net- from provider network
ids. Again, it is contrived and not required.
The provider network id is not required, do not attempt to add rows for
empty string ids.
For lxd models, remove the subnet provider id and remove the net- prefix
from network provider ids. Neither value is required by juju. For lxd
they are contrived and sometimes inconsistent causing failures where at
attempt to match is made.
@hmlanigan hmlanigan force-pushed the subnet-provider-changes branch 2 times, most recently from 97df093 to 3a6b228 Compare January 28, 2026 18:44
@hmlanigan
Copy link
Copy Markdown
Member Author

/merge

@jujubot jujubot merged commit d717fca into juju:4.0 Jan 28, 2026
36 of 44 checks passed
@hmlanigan hmlanigan deleted the subnet-provider-changes branch January 28, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants