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

[JUJU-390] Transfer machine DisplayName through migration #13645

Merged
merged 7 commits into from Jan 28, 2022

Conversation

cderici
Copy link
Member

@cderici cderici commented Jan 23, 2022

Description

This allows the machines (usually provided by OCI or MAAS) to be able to transfer their DisplayName fields through a migration.

Fixes:

LP #1954969.

Requires:

QA Steps

You'll need either Oracle OCI or MAAS controllers for this one. (Other providers don't use display name)
I tested it with the OCI, like as follows (I used the compartment&tenancy ids from within the cloud-city):

juju bootstrap --config compartment-id=$OCID_COMPARTMENT oci-canonical oci-test-controller2

juju bootstrap --config compartment-id=$OCID_COMPARTMENT oci-canonical oci-test-controller1

juju add-model --config compartment-id=$OCID_COMPARTMENT test-model1

juju deploy ubuntu

Note the machine Inst Id in juju status, or do db.instanceData.find().pretty() in mongodb and look for the display-name field.

juju migrate test-model1 oci-test-controller2
  1. Migration should be successful,
  2. After the migration is complete you should be able to see the same id in the juju status or the db.

Notes & Discussion

This PR also includes temporary code that will be removed before the PR lands:

  • go.mod for external changed dependency (description pkg), and
  • provider/oci/environ.go for quick fix to allow the PR to run

@@ -322,7 +322,7 @@ func (e *Environ) Create(ctx envcontext.ProviderCallContext, params environs.Cre

// AdoptResources implements environs.Environ.
func (e *Environ) AdoptResources(ctx envcontext.ProviderCallContext, controllerUUID string, fromVersion version.Number) error {
return errors.NotImplementedf("AdoptResources")
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we do not longer return NotImplemented? Even if this is not necessary for OCI, this is more useful than returning nil.

Copy link
Member Author

@cderici cderici Jan 24, 2022

Choose a reason for hiding this comment

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

That NYI error is breaking migration on the OCI, and unrelated to this PR, and returning nil is just a temporary patch to be able to run and test this PR. (I believe the people filed the bug were using maas). See LP #1958459. I might go tackle that afterwards too. But currently returning nil here is just temporary and again, will be reverted before landing.

go.mod Outdated
@@ -144,6 +144,8 @@ require (

replace github.com/altoros/gosigma => github.com/juju/gosigma v0.0.0-20200420012028-063911838a9e

replace github.com/juju/description/v3 => github.com/cderici/description/machine-display-name
Copy link
Contributor

Choose a reason for hiding this comment

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

To be changed after juju/description is merged

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is to allow this PR to use another PR on my description fork, which is a requirement of this PR and will be landed before, so I'll revert this back as well 👍

Copy link
Contributor

@juanmanuel-tirado juanmanuel-tirado left a comment

Choose a reason for hiding this comment

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

After running QA I'm OK with the changes.

Do not merge before passing tests and replacing go.mod reference to the original description repo.

state/machine.go Outdated Show resolved Hide resolved
@cderici cderici added 2.9 do not merge Even if a PR has been approved, do not merge the PR! labels Jan 24, 2022
Copy link
Member

@hmlanigan hmlanigan left a comment

Choose a reason for hiding this comment

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

Doing QA now.

Please add updated unit tests migration import and export.

@@ -577,6 +577,10 @@ func (i *importer) machineInstanceOp(mdoc *machineDoc, inst description.CloudIns
if arch := inst.Architecture(); arch != "" {
doc.Arch = &arch
}
if displayName := inst.DisplayName(); displayName != "" {
doc.DisplayName = displayName
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: since display name is not a pointer, nor is it labeled omit empty in state, you can just do
DisplayName: inst.DisplayName(), above, in ln 571-574.

jujubot added a commit that referenced this pull request Jan 25, 2022
#13653

#### Description

Migration fails on some providers (e.g. oci) because of some not yet
implemented/optional features. This unblocks it by returning nil
whenever it sees an nyi. All the other errors are raised as usual.

Fixes: https://bugs.launchpad.net/juju/+bug/1958459

#### QA steps

Migration on oci should succeed. (use the compartment&tenancy ids from within the cloud-city)

```sh
juju bootstrap --config compartment-id=$OCID_COMPARTMENT oci-canonical oci-test-controller2

juju bootstrap --config compartment-id=$OCID_COMPARTMENT oci-canonical oci-test-controller1

juju add-model --config compartment-id=$OCID_COMPARTMENT test-model1

juju deploy ubuntu

juju migrate test-model1 oci-test-controller2
```

#### Notes & Discussion

This is sort of a requirement for #13645, as we need the migration to be working for that to take effect.
@cderici cderici removed the do not merge Even if a PR has been approved, do not merge the PR! label Jan 26, 2022
@cderici cderici force-pushed the migration-transfers-display-name branch from 93fa60e to 7ae1a8f Compare January 26, 2022 17:20
Copy link
Member

@manadart manadart left a comment

Choose a reason for hiding this comment

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

Minor change required.

state/machine.go Outdated
@@ -279,6 +279,14 @@ func (m *Machine) HardwareCharacteristics() (*instance.HardwareCharacteristics,
return hardwareCharacteristics(instData), nil
}

func (m *Machine) DisplayName() (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

We don't want to add this exported method just for tests. Someone will end up using it in production code and we've got a double access for machine then instance data.

Instead, add a public method, GetInstanceData to package_test.go that wraps the private method getInstanceData and call that to get it directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah ok that makes sense, I'll make the change 👍 thanks for the review!

Copy link
Member Author

Choose a reason for hiding this comment

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

I just realized we already have a method called InstanceNames in the machine package that I didn't know before, so I just used that one in the tests instead of redundantly adding a new method. Thanks for the catch!

includes temporary code that will be removed before the PR lands:

- go.mod for external changed dependency (description pkg), and
- provider/oci/environ.go for quick fix to allow the PR to run
To use the juju/description edge
DisplayName field is not a pointer, nor omitempty, so no need to check
creating extra variables
Includes a helper function DisplayName() for state.Machine, normally
not available since DisplayName is a field of instanceData (i.e. not
Machine)
Using existing Machine.InstanceNames() method instead of exporting a
new one
@cderici cderici force-pushed the migration-transfers-display-name branch from 5edc7c4 to 25ad393 Compare January 28, 2022 17:34
@cderici
Copy link
Member Author

cderici commented Jan 28, 2022

$$merge$$

@jujubot jujubot merged commit 4d65952 into juju:2.9 Jan 28, 2022
@cderici cderici deleted the migration-transfers-display-name branch February 16, 2022 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants