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

Specify the network when deploying the VM from content library #2407

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions pkg/executables/config/deploy-opts.json

This file was deleted.

49 changes: 42 additions & 7 deletions pkg/executables/govc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ const (
vSpherePasswordKey = "EKSA_VSPHERE_PASSWORD"
vSphereServerKey = "VSPHERE_SERVER"
byteToGiB = 1073741824.0
deployOptsFile = "deploy-opts.json"
DeployOptsFile = "deploy-opts.json"
)

var requiredEnvs = []string{govcUsernameKey, govcPasswordKey, govcURLKey, govcInsecure}

//go:embed config/deploy-opts.json
var deployOpts []byte
type networkMapping struct {
Name string `json:"Name,omitempty"`
Network string `json:"Network,omitempty"`
}

type deployOption struct {
DiskProvisioning string `json:"DiskProvisioning,omitempty"`
NetworkMapping []networkMapping `json:"NetworkMapping,omitempty"`
}

type FolderType string

Expand Down Expand Up @@ -269,9 +276,9 @@ func (g *Govc) CreateLibrary(ctx context.Context, datastore, library string) err
return nil
}

func (g *Govc) DeployTemplateFromLibrary(ctx context.Context, templateDir, templateName, library, datacenter, datastore, resourcePool string, resizeBRDisk bool) error {
func (g *Govc) DeployTemplateFromLibrary(ctx context.Context, templateDir, templateName, library, datacenter, datastore, network, resourcePool string, resizeBRDisk bool) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Idk, if you have looked at my tink e2e PR yet, but I had to do very similar thing as I wanted to use this code to deploy OVA's in the lab. I tried to change as little as possible as I only needed it for the tests, but there are a ton more options in deploy options. Rather, than passing them individually why don't we just take deploy options as a param to account for all possible deploy options?

You can see the options I am using for tink e2e here: https://github.com/aws/eks-anywhere/pull/2031/files#diff-5dfd6bc5a441b6e4027710c63250668f8e0af8e594dfcb6c3c11067cca3e5845

But there are many more options available that we could support.

Copy link
Contributor

Choose a reason for hiding this comment

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

Link above is code in test package, actual govc changes I made were minimal to not disrupt. You can see them here: https://github.com/aws/eks-anywhere/pull/2031/files#diff-1b2bffa403bbd82a1ba98650cb15df32447b074ad23e1cc1cf7df592eca4554d

Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

oh just saw your comment. For CAPV provider, I think we only needed the network option. The disk provisioning option is static. But if more options are needed, then yeah we can make it more generic and provide a slice of options

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, cool. I'm fine revisiting later as if needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah seems like you already handled that in your PR. Will review it and try to get it merged tomorrow so you don't have to deal with a bunch of merge conflicts

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, I have to get code build in order before merging, but please do review as I want to merge before end of week.

logger.V(4).Info("Deploying template", "dir", templateDir, "templateName", templateName)
if err := g.deployTemplate(ctx, library, templateName, templateDir, datacenter, datastore, resourcePool); err != nil {
if err := g.deployTemplate(ctx, library, templateName, templateDir, datacenter, datastore, network, resourcePool); err != nil {
return err
}

Expand Down Expand Up @@ -343,7 +350,7 @@ func (g *Govc) ImportTemplate(ctx context.Context, library, ovaURL, name string)
return nil
}

func (g *Govc) deployTemplate(ctx context.Context, library, templateName, deployFolder, datacenter, datastore, resourcePool string) error {
func (g *Govc) deployTemplate(ctx context.Context, library, templateName, deployFolder, datacenter, datastore, network, resourcePool string) error {
envMap, err := g.validateAndSetupCreds()
if err != nil {
return fmt.Errorf("failed govc validations: %v", err)
Expand All @@ -354,7 +361,12 @@ func (g *Govc) deployTemplate(ctx context.Context, library, templateName, deploy
templateInLibraryPath = fmt.Sprintf("/%s", templateInLibraryPath)
}

deployOptsPath, err := g.writer.Write(deployOptsFile, deployOpts, filewriter.PersistentFile)
deployOpts, err := getDeployOptions(network)
if err != nil {
return err
}

deployOptsPath, err := g.writer.Write(DeployOptsFile, deployOpts, filewriter.PersistentFile)
if err != nil {
return fmt.Errorf("failed writing deploy options file to disk: %v", err)
}
Expand Down Expand Up @@ -897,3 +909,26 @@ func (g *Govc) createCategory(ctx context.Context, name string, objectTypes []ob
}
return nil
}

func getDeployOptions(network string) ([]byte, error) {
deployOptsStruct := deployOption{
DiskProvisioning: "thin",
NetworkMapping: []networkMapping{
{
Name: "nic0", // needed for Ubuntu
Network: network,
},
{
Name: "VM Network", // needed for Bottlerocket
Network: network,
},
},
}

deployOpts, err := json.Marshal(deployOptsStruct)
if err != nil {
return nil, fmt.Errorf("marshalling template deployment options: %v", err)
}

return deployOpts, err
}
Loading