Skip to content
This repository has been archived by the owner on Dec 18, 2020. It is now read-only.

Implemented AttachISO task #4

Merged

Conversation

SandeepPissay
Copy link

AttachISO task creates the user-data/meta-data cloud init files and creates cloud-init.iso file using "genisoimage" tool. It then uploads it to the datastore where the master/worker VM resides and inserts it into the cd-rom device of the master/worker VM. When the master/worker VM powers on, the cloud-init package in it runs the bootstrap script that downloads nodeup and runs it.

Testing done:

  1. Tested end to end that the master and worker VMs executes the cloud-init script successfully.
    2, "make ci" is successful.

}
p := soap.DefaultUpload
glog.V(2).Infof("Uploading ISO file %s to datastore %+v\n", isoFile, dsObj)
err = dsObj.UploadFile(ctx, isoFile, *vm+"/cloud-init.iso", &p)

Choose a reason for hiding this comment

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

Please define a constant for loose string. Also putting name construction in a separate method would be nice. We might have to reuse this name in case we need to do any further ISO related operations.

Nit: variable names like localIsoFile, dstIsoFile or something similar would help understand the method usage better. Also it might be useful to log the destination iso file name, along with local.

Copy link
Author

Choose a reason for hiding this comment

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

Done

return err
}

cdrom, err := devices.FindCdrom("")

Choose a reason for hiding this comment

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

Can you please explain with does empty string argument signifies here?

Copy link
Author

Choose a reason for hiding this comment

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

Done

if err != nil {
return err
}
iso := dsObj.Path(*vm + "/cloud-init.iso")

Choose a reason for hiding this comment

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

Nit: log here that the iso uploaded successfully would be helpful. Also same variable can be used for the destination iso file name here, as the one used for upload.

Copy link
Author

Choose a reason for hiding this comment

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

Here we are inserting the iso into the cd-rom. Will add a log.

write_files:
- content: |
$SCRIPT
owner: root:root

Choose a reason for hiding this comment

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

Over the period this user data is going to become bigger and crowd this file. Let's keep this in a separate file where we only have cloud-init related strings specified.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -57,6 +94,73 @@ func (_ *AttachISO) CheckChanges(a, e, changes *AttachISO) error {
}

func (_ *AttachISO) RenderVC(t *vsphere.VSphereAPITarget, a, e, changes *AttachISO) error {

Choose a reason for hiding this comment

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

VirtualMachine task has 'RenderVSphere' method defined on it, where as AttachISO and VMPowerOn tasks have 'RenderVC' method defined on it. Can you please fix it?

My understanding was that 'RenderVSphere' method name will be constructed and called using reflection, based on the target name. I am wondering how 'RenderVC' is getting invoked for AttachISO and VMPowerOn.

Copy link
Author

Choose a reason for hiding this comment

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

Task framework calls Render* method. I'll rename RenderVC method to RenderVSphere to keep it consistent with "VSphere" we have been using everywhere else.

createMetaData(dir, *changes.VM)

isoFile := filepath.Join(dir, *changes.VM+".iso")
cmd := exec.Command("genisoimage", "-o", isoFile, "-volid", "cidata", "-joliet", "-rock", dir)

Choose a reason for hiding this comment

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

Please check for the availability of "genisonimage". Also, genisoimage is not available for mac. For VCS prototype I was using mkisofs, if genisoimage was not present. If both are not available we will have to fail with appropriate error.

Copy link
Author

Choose a reason for hiding this comment

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

I would need a mac to check how mkisofs works. I'll come to your place for some experiments. I'll enhance this code.


err := cmd.Run()
if err != nil {
glog.Fatalf("Error %s occurred while executing command %+v", err, cmd)

Choose a reason for hiding this comment

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

Return here with nil?

Copy link
Author

Choose a reason for hiding this comment

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

Not needed as err not being nil is fatal and will stop kops.

dir, err := ioutil.TempDir("", *changes.VM)
defer os.RemoveAll(dir)

isoFile := createISO(changes, startupStr, dir)

Choose a reason for hiding this comment

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

I see that createISO method is not returning any error. It would be good to either return an error or check isoFile to be not nil.

Copy link
Author

Choose a reason for hiding this comment

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

If there is an error in createISO we fail the execution by invoking glog.Fatalf method. Basically there is no point in continuing if they fail.

}
startupStr = strings.Join(strArray, "\n")

data := strings.Replace(userData, "$SCRIPT", startupStr, -1)

Choose a reason for hiding this comment

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

It would be better to do this using go templates. If you don't want to make this change in this PR, please feel free to add an issue for improving this method and createMetaData to make use of template.

Copy link
Author

Choose a reason for hiding this comment

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

Filed an issue

glog.V(4).Infof("User data file content: %s", data)

if err := ioutil.WriteFile(userDataFile, []byte(data), 0644); err != nil {
glog.Fatalf("Unable to write user-data into file %s", userDataFile)

Choose a reason for hiding this comment

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

Errors from createUserData and createMetaData are not getting propagated to createISO. How do you plan on handling them?

Copy link
Author

Choose a reason for hiding this comment

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

They fail the kops command. See the usage of glog.Fatalf method in error conditions in those methods.

@SandeepPissay
Copy link
Author

Addressed review comments.

KopsModelContext: modelContext,
}

l.Builders = append(l.Builders,
Copy link

Choose a reason for hiding this comment

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

wait we would need this builder for PKI model...

Copy link
Author

Choose a reason for hiding this comment

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

Depending on who checks in first, one of us can add it!

Copy link

@prashima prashima left a comment

Choose a reason for hiding this comment

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

LGTM.

Please address comments before merging.

@@ -482,6 +476,7 @@ func (c *ApplyClusterCmd) Run() error {
}

role := ig.Spec.Role
glog.V(4).Infof("Generating renderNodeUpConfig for %s", role)

Choose a reason for hiding this comment

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

Nit: Please move this log statement after if-block. If role is nil then anyways the program is exiting with error.

"Generating Nodeup config for role..." would be a more appropriate message.

Copy link
Author

Choose a reason for hiding this comment

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

I did not intend to checkin this. It was added for debugging. Will remove this log,

)

// AttachISO represents the cloud-init ISO file attached to a VMware VM
//go:generate fitask -type=AttachISO
type AttachISO struct {
Name *string
VM *VirtualMachine
Name *string

Choose a reason for hiding this comment

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

I see that you have updated code to use VM.Name. Do you still need this string 'Name' field?

Copy link
Author

Choose a reason for hiding this comment

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

I think every task struct need to have the task Name. This was added in my previous checkin and I remember that not having this field was having problems executing the tasks.

}
glog.V(4).Infof("genisoimage std output : %s\n", out.String())
glog.V(4).Infof("genisoimage std error : %s\n", stderr.String())
return isoFile

Choose a reason for hiding this comment

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

Please save command name in a variable and use that for logging. It could be genisoimage or mkisofs.

Copy link
Author

Choose a reason for hiding this comment

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

Done

@luomiao
Copy link

luomiao commented Mar 23, 2017

BTW can we compile with this PR's change on MacOS now?

@SandeepPissay
Copy link
Author

Compilation is never a problem. The issue was the tool used to generate ISO file. If we run kops on mac you would need mkisofs tool and it should be in your PATH env variable.

@SandeepPissay SandeepPissay merged commit 990c60f into vmware-archive:vsphere-develop Mar 23, 2017
prashima pushed a commit to prashima/kops that referenced this pull request Mar 28, 2017
Fix the type of vSphere fields in CloudConfig and update auto-generated conversion files.
luomiao pushed a commit that referenced this pull request Mar 30, 2017
AttachISO task creates the user-data/meta-data cloud init files and creates cloud-init.iso file using "genisoimage" tool. It then uploads it to the datastore where the master/worker VM resides and inserts it into the cd-rom device of the master/worker VM. When the master/worker VM powers on, the cloud-init package in it runs the bootstrap script that downloads nodeup and runs it.

Also removed redundant VirtualMachineModelBuilder that does nothing.

Testing done:
1. Tested end to end that the master and worker VMs executes the cloud-init script successfully.
2, "make ci" is successful.
luomiao pushed a commit that referenced this pull request Apr 7, 2017
AttachISO task creates the user-data/meta-data cloud init files and creates cloud-init.iso file using "genisoimage" tool. It then uploads it to the datastore where the master/worker VM resides and inserts it into the cd-rom device of the master/worker VM. When the master/worker VM powers on, the cloud-init package in it runs the bootstrap script that downloads nodeup and runs it.

Also removed redundant VirtualMachineModelBuilder that does nothing.

Testing done:
1. Tested end to end that the master and worker VMs executes the cloud-init script successfully.
2, "make ci" is successful.
luomiao pushed a commit that referenced this pull request Apr 10, 2017
AttachISO task creates the user-data/meta-data cloud init files and creates cloud-init.iso file using "genisoimage" tool. It then uploads it to the datastore where the master/worker VM resides and inserts it into the cd-rom device of the master/worker VM. When the master/worker VM powers on, the cloud-init package in it runs the bootstrap script that downloads nodeup and runs it.

Also removed redundant VirtualMachineModelBuilder that does nothing.

Testing done:
1. Tested end to end that the master and worker VMs executes the cloud-init script successfully.
2, "make ci" is successful.
msterin pushed a commit that referenced this pull request Apr 11, 2017
AttachISO task creates the user-data/meta-data cloud init files and creates cloud-init.iso file using "genisoimage" tool. It then uploads it to the datastore where the master/worker VM resides and inserts it into the cd-rom device of the master/worker VM. When the master/worker VM powers on, the cloud-init package in it runs the bootstrap script that downloads nodeup and runs it.

Also removed redundant VirtualMachineModelBuilder that does nothing.

Testing done:
1. Tested end to end that the master and worker VMs executes the cloud-init script successfully.
2, "make ci" is successful.
luomiao pushed a commit that referenced this pull request Apr 21, 2017
AttachISO task creates the user-data/meta-data cloud init files and creates cloud-init.iso file using "genisoimage" tool. It then uploads it to the datastore where the master/worker VM resides and inserts it into the cd-rom device of the master/worker VM. When the master/worker VM powers on, the cloud-init package in it runs the bootstrap script that downloads nodeup and runs it.

Also removed redundant VirtualMachineModelBuilder that does nothing.

Testing done:
1. Tested end to end that the master and worker VMs executes the cloud-init script successfully.
2, "make ci" is successful.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants