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

[vsphere] Add ability to specify local templates for vsphere #12894

Merged
merged 14 commits into from
May 5, 2021

Conversation

gabriel-samfira
Copy link
Contributor

@gabriel-samfira gabriel-samfira commented Apr 19, 2021

This PR adds ability to specify local templates via simplestreams using the image-id format. I

QA steps

Steps are as follows:

  • Identify the region you want to generate simplestreams for: juju regions yourcloud
  • Create a template for a series inside that particular datacenter. The template should have the same characteristics as the ones Juju creates if no simplestreams is supplied by the user. As a quick hack, simply deploy a controller, and clone the resulting template in a different location.
  • Generate simplestreams
  • Deploy a new controller using the generated simplestreams
  • Check that Juju skips downloading the template and moves straight to cloning the template.

Generate tools metadata

mkdir -p $HOME/simplestreams/tools/proposed
cp $GOPATH/bin/jujud $HOME/simplestreams/tools/proposed
cd $HOME/simplestreams/tools/proposed
tar czf juju-`./jujud version`.tgz ./jujud
rm ./jujud
cd ~

juju-metadata generate-agents -d $HOME/simplestreams --stream proposed

Generate image metadata

When generating simplestreams, use the relative path to the template in relation to the datacenter path (/datacenter-name/vm):

juju-metadata generate-image -d $HOME/simplestreams/ -i "gsamfira/juju-focal-template" -s focal -r datacenter6.5 -u 10.107.8.11

This will generate the following: https://paste.ubuntu.com/p/9zk5hX7wR6/

Given the above simplesrteams, the provider will look for the template in:

/datacenter6.5/vm/gsamfira/juju-focal-template

then deploy a new controller:

juju bootstrap --metadata-source $HOME/simplestreams --debug --verbose --show-log  vsphere vsphere-controller

Bug reference

https://bugs.launchpad.net/juju/+bug/1867154

@hpidcock hpidcock added the 2.9 label Apr 20, 2021
}

func (c *Client) ListVMTemplates(ctx context.Context, path string) ([]*object.VirtualMachine, error) {
c.logger.Debugf("ListVMTemplates() path=%q", path)
Copy link
Member

Choose a reason for hiding this comment

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

Let's keep this log message at a Trace level

@gabriel-samfira gabriel-samfira marked this pull request as ready for review April 26, 2021 19:06
@gabriel-samfira
Copy link
Contributor Author

This PR still needs some new tests, but it should be ready for review.

@gabriel-samfira gabriel-samfira force-pushed the add-custom-simplestreams branch from a497b6e to 440bf3c Compare April 26, 2021 20:06
seriesTemplatesFolder := v.seriesTemplateFolder(series)
seriesTemplates, err := v.env.client.ListVMTemplates(ctx, path.Join(seriesTemplatesFolder, "*"))
if err != nil {
logger.Errorf("failed to fetch templates: %v", err)
Copy link
Member

@hmlanigan hmlanigan Apr 28, 2021

Choose a reason for hiding this comment

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

This causes misleading error messages during bootstrap, when the folder for the bootstrapping controller hasn't been created yet and not simplestreams supplied

...
Launching controller instance(s) on boston-vsphere/Boston...
ERROR failed to fetch templates: path not found: juju-ci-root/Juju Controller (baf1f6a2-f6d7-44f1-8916-7165113f7f8f)/templates/focal/* not found
 - juju-dc6839-0 (arch=amd64 mem=3.5G) f81b245c98d18fec1564e6b374c346f1ef14394c9e836ee77e1e58754242a4f9"
Installing Juju agent on bootstrap instance
...

@hmlanigan
Copy link
Member

During QA:

Bootstrap used the simplestreams defined template, but juju deploy ubuntu --series focal did not. A new template was added to the "Juju Controller (<uuid)/templates/focal) folder, which was not created beforehand. The simplestreams template is for focal: https://paste.ubuntu.com/p/VJsZTtVnV5/

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.

The one issue found during QA that needs to be resolved, as well as items listed below.

items, err := finder.VirtualMachineList(ctx, path)
if err != nil {
if _, ok := err.(*find.NotFoundError); ok {
return nil, errors.NotFoundf("path not found: %s", path)
Copy link
Member

Choose a reason for hiding this comment

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

Remove "not found" from error message, redundant as errors.NotFoundf() prints it at the end. Perhaps use errors.Annotatef instead?


type ImportOVAParameters struct {
StatusUpdateParams StatusUpdateParams
// ReadOVA returns the location of, and an io.ReadCloser for,
Copy link
Member

Choose a reason for hiding this comment

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

nit: new line above for consistency.

Clock clock.Clock
}

type ImportOVAParameters struct {
Copy link
Member

Choose a reason for hiding this comment

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

Comment header for struct

return arch, nil
}
}
return "", errors.NotFoundf("arch tag not found for VM")
Copy link
Member

Choose a reason for hiding this comment

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

"arch tag for VM" is clearer with ": not found" tacked to the end when the error is a string. otherwise error string is: "arch tag not found for VM: not found"

Comment on lines 115 to 120
for _, item := range desiredArches {
if item == arch {
return true
}
}
return false
Copy link
Member

Choose a reason for hiding this comment

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

return set.NewStrings(desiredArches...).Contains(arch)

}
logger.Debugf("Series templates: %v", seriesTemplates)
if len(seriesTemplates) == 0 {
return nil, "", errors.NotFoundf("no valid templates found")
Copy link
Member

Choose a reason for hiding this comment

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

"valid templates"

break
}
if vmTpl == nil {
return nil, "", errors.NotFoundf("no valid templates found")
Copy link
Member

Choose a reason for hiding this comment

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

"valid templates"

// vmTemplateManager implements a template registry that
// can return a proper VMware template given a series and
// image metadata.
type vmTemplateManager struct {
Copy link
Member

Choose a reason for hiding this comment

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

Where are the unit tests for the vmTemplateManager?

@gabriel-samfira
Copy link
Contributor Author

During QA:

Bootstrap used the simplestreams defined template, but juju deploy ubuntu --series focal did not. A new template was added to the "Juju Controller (<uuid)/templates/focal) folder, which was not created beforehand. The simplestreams template is for focal: https://paste.ubuntu.com/p/VJsZTtVnV5/

This is probably due to the fact that during bootstrap, juju grabbed the upstream jujud binary, which does not have the changes.

Make sure you also generate the agent metadata using:

juju-metadata generate-agents --stream proposed

This will look for packaged binaries in $HOME/.local/share/juju/tools/proposed/ and build appropriate metadata for whatever it finds in there. I will update the PR description.

@gabriel-samfira gabriel-samfira force-pushed the add-custom-simplestreams branch from 0fdb113 to 0ec66de Compare May 3, 2021 14:46
Windows can now be supported with the adition of local templates.
The template must conform to the following:

  * A supported version of Windows must be installed inside
  * vApp config settings must have the proper ovfenv (same ones as
Ubuntu - instance-id, userdata, etc)
  * VMware tools must be installed
  * Cloudbase-Init must be installed, and the
cloudbaseinit.metadata.services.ovfservice.OvfService set as the
only value in the metadata_services config option in both
cloudbase-init.conf and cloudbase-init-unattend.conf.
  * Sysprep the instance using: sysprep.exe /generalize /oobe
/unattend:C:\Program Files\Cloudbase
Solutions\Cloudbase-Init\Conf\unattend.xml /shutdown (copy that file in
C:\Unattend.xml if you encouner errors)
  * before cloning as template, network adapter must be removed,
and any ISO file attached to the CDROM must be detached.
@gabriel-samfira gabriel-samfira force-pushed the add-custom-simplestreams branch from 37e263f to ccf4222 Compare May 4, 2021 11:02
@hmlanigan
Copy link
Member

When using --build-agents, should need the juju metadata piece. Redid the QA, as expected: when deploying ubuntu with focal, no new template was created, when deploying ubuntu with bionic, a new template was created.

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.

A few small items to resolve, then I will approve and merge.

Comment on lines 7 to 11
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/imagemetadata"
"github.com/juju/juju/provider/vsphere/internal/vsphereclient"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/vim25/types"
Copy link
Member

Choose a reason for hiding this comment

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

should be 2 stanza of imports

provider/vsphere/userdata_test.go Outdated Show resolved Hide resolved
provider/vsphere/vm_template.go Outdated Show resolved Hide resolved
provider/vsphere/vm_template_test.go Outdated Show resolved Hide resolved
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.

LGTM now, all testing is good.

@hmlanigan
Copy link
Member

!!build!!

@hmlanigan
Copy link
Member

$$merge$$

@jujubot jujubot merged commit aaeeacd into juju:2.9 May 5, 2021
@wallyworld wallyworld mentioned this pull request May 12, 2021
jujubot added a commit that referenced this pull request May 12, 2021
#12963

Merge most recent 2.9 commits (up to commit d597250 for #12948) :

#12892 Add CLA checker GH action
#12937 Actions with errors queuing them can be listed
#12940 Fix ssh to sidecar charm container
#12941 Fix/lp 1925735
#12943 Ensure upgraded 2.8 models can start containers on machines
#12947 Remove redundant AddressConfigMethod
#12949 Remove redundant AddressConfigMethod
#12950 Fix non-linux network config source
#12894 Add ability to specify local templates for vsphere
#12948 Select default charm url depending on controller version

Conflicts were due to actions api changes from #12937
```
# apiserver/facades/agent/uniter/uniter_test.go
# apiserver/facades/client/action/action_test.go
# apiserver/facades/client/action/legacy_test.go
# apiserver/facades/client/action/operation.go
# apiserver/params/internal.go
# cmd/juju/application/deploy_test.go
# go.mod
# go.sum
# scripts/win-installer/setup.iss
# snap/snapcraft.yaml
# state/action.go
# state/action_test.go
# state/allwatcher_internal_test.go
# state/cleanup_test.go
# state/interface.go
# state/machine.go
# state/machine_test.go
# state/migration_export_test.go
# state/migration_import_test.go
# state/operation_test.go
# state/state_test.go
# state/unit.go
# state/unit_test.go
# state/watcher_test.go
# version/version.go
# worker/uniter/runner/context/context_test.go
# worker/uniter/runner/context/contextfactory_test.go
# worker/uniter/runner/factory_test.go
# worker/uniter/util_test.go
```

## QA steps

See PRs
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