-
Notifications
You must be signed in to change notification settings - Fork 3
Implemented AttachISO task #4
Implemented AttachISO task #4
Conversation
…plete. This is partial implementation!
} | ||
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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("") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return here with nil?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Addressed review comments. |
KopsModelContext: modelContext, | ||
} | ||
|
||
l.Builders = append(l.Builders, |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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!
There was a problem hiding this 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.
upup/pkg/fi/cloudup/apply_cluster.go
Outdated
@@ -482,6 +476,7 @@ func (c *ApplyClusterCmd) Run() error { | |||
} | |||
|
|||
role := ig.Spec.Role | |||
glog.V(4).Infof("Generating renderNodeUpConfig for %s", role) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
BTW can we compile with this PR's change on MacOS now? |
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. |
Fix the type of vSphere fields in CloudConfig and update auto-generated conversion files.
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.
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.
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.
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.
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.
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:
2, "make ci" is successful.