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

Implements delete cluster and toolbox dumper command #54

Merged
merged 1 commit into from
Apr 20, 2017

Conversation

abrarshivani
Copy link

This PR implements delete cluster and toolbox dump command for kops.
Fixes #14

@luomiao
Copy link

luomiao commented Apr 19, 2017

After deleting cluster A, the state store of cluster A should be deleted too.
Just wondering if the state store clean should be another PR?

@@ -329,6 +329,91 @@ func (c *VSphereCloud) FindVMUUID(vm *string) (string, error) {
return vmResult.Config.Uuid, nil
}

func (c *VSphereCloud) VirtualMachines(args []string) ([]*object.VirtualMachine, error) {

Choose a reason for hiding this comment

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

What is this method doing? It's not clear from the name of this method.

Also, please add relevant comments for methods.

Copy link
Author

Choose a reason for hiding this comment

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

Good Catch! Will add the comment

}

type vsphereListFn func() ([]*ResourceTracker, error)

func (c *AwsCluster) listResourcesVSphere() (map[string]*ResourceTracker, error) {

Choose a reason for hiding this comment

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

Why not use something generic like KubernetesCluster, or VSphereCluster if every cloud provider needs to have its own type name?

If possible, please address this in current PR. AwsCluster inside delete_cluster_vsphere.go doesn't look intuitive. Otherwise we can declare a new type that inherits AwsCluster.

Copy link
Author

Choose a reason for hiding this comment

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

Agreed, the type name AwsCluster doesn't look good in delete_cluster_vsphere. This will be changed in upstream. They have todo comment which says that.

return nil, nil
vsphereCloud := c.Cloud.(*vsphere.VSphereCloud)
if c.Region == "" {
c.Region = vsphereCloud.Cluster

Choose a reason for hiding this comment

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

Can you please explain where is this getting used?

Copy link
Author

Choose a reason for hiding this comment

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

It is used not anywhere for now.

Choose a reason for hiding this comment

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

Let's not set it, if it's not getting used anywhere.

d.listVMs,
}

for _, fn := range listFunctions {

Choose a reason for hiding this comment

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

Can you please explain what's the use of putting a single function in list and iterating over that list?

It would have made sense if we were trying to list VMs using multiple clusterDiscoveryVSphere instances. But with current usage, I am not able to see benefit of iterating over listFunctions.

Copy link
Author

Choose a reason for hiding this comment

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

This will help adding functions in future.

if _, ok := err.(*find.NotFoundError); !ok {
return nil, err
}
glog.Warning(err)

Choose a reason for hiding this comment

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

Return empty list at this point?

Copy link
Author

Choose a reason for hiding this comment

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

Let's discuss this offline

Choose a reason for hiding this comment

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

We didn't discuss this one. Can you please comment?

Copy link
Author

Choose a reason for hiding this comment

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

We discussed this later

func (d *clusterDiscoveryVSphere) listVMs() ([]*ResourceTracker, error) {
c := d.vsphereCloud

var trackers []*ResourceTracker

Choose a reason for hiding this comment

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

Nit: please move the declaration closer to usage, at line#93.

return nil
}

func DumpVM(r *ResourceTracker) (interface{}, error) {

Choose a reason for hiding this comment

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

What is this method dumping?

Can you please explain why is the return type interface{}, where as the type of the 'data' variable is map[string]interface{}?

Copy link
Author

Choose a reason for hiding this comment

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

This method is dumping VM info.

Copy link
Author

@abrarshivani abrarshivani Apr 19, 2017

Choose a reason for hiding this comment

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

Resource tracker requires this signature func (r *ResourceTracker) (interface{}, error) for function DumpVM. We are returning multiple values so we need a map or slice to store it. When this function returns map[string]interface{} datatype it gets converted into interface type.
Note: any type in golang can be converted into interface type.

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

vm := r.obj.(*object.VirtualMachine)

Choose a reason for hiding this comment

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

Can you please explain what this line is doing?

Copy link
Author

Choose a reason for hiding this comment

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

This typecast obj to struct object.VirtualMachine pointer

}

// passing empty cd-rom name so that the first one gets returned
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 this method be modified to get all cdrom devices and check backing.FileName for all of them. One that matches the iso name regex, that is being created by vSphere attachiso task, will get deleted.

This way there won't be necessity for this assumption that first cdrom should be the one that has the cloud-init's iso attached. Just in case user goes and messes up with the VM.

@abrarshivani
Copy link
Author

@luomiao the cluster state and kubeconfig gets deleted. So we don't need separate PR

@prashima
Copy link

LGTM.

@abrarshivani abrarshivani force-pushed the remote-delete_cluster branch from 110eb2d to 81c2a35 Compare April 20, 2017 18:53
@abrarshivani abrarshivani merged commit 4e1b2a5 into vsphere-develop Apr 20, 2017
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