Skip to content

Commit

Permalink
Make delete node work for vsphere (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
karan authored and k8s-ci-robot committed Jun 5, 2018
1 parent 5a03ce3 commit 6aecf9c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cloud/vsphere/cmd/vsphere-machine-controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GCR_BUCKET = k8s-cluster-api
PREFIX = gcr.io/$(GCR_BUCKET)
DEV_PREFIX ?= gcr.io/$(shell gcloud config get-value project)
NAME = vsphere-machine-controller
TAG = 0.0.5
TAG = 0.0.6

image:
docker build -t "$(PREFIX)/$(NAME):$(TAG)" -f ./Dockerfile ../../../..
Expand Down
19 changes: 15 additions & 4 deletions cloud/vsphere/machineactuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,36 +433,47 @@ func runTerraformCmd(stdout bool, workingDir string, arg ...string) (bytes.Buffe
return out, nil
}

func (vc *VsphereClient) Delete(_ *clusterv1.Cluster, machine *clusterv1.Machine) error {
func (vc *VsphereClient) Delete(cluster *clusterv1.Cluster, machine *clusterv1.Machine) error {
// Check if the instance exists, return if it doesn't
instance, err := vc.instanceIfExists(machine)
if err != nil {
return err
}

if instance == nil {
return nil
}

homedir, err := getHomeDir()
clusterConfig, err := vc.clusterproviderconfig(cluster.Spec.ProviderConfig)
if err != nil {
return err
}
machinePath := path.Join(homedir, fmt.Sprintf(".terraform.d/kluster/machines/%s", machine.ObjectMeta.Name))

machinePath, err := vc.prepareStageMachineDir(machine)

// The machine HCL reads the startup script, so we need to have something there for terraform
// to not fail.
if err := saveFile("", path.Join("/tmp", "machine-startup.sh"), 0644); err != nil {
return errors.New(fmt.Sprintf("Could not write startup script %s", err))
}

// destroy it
args := []string{
"destroy",
"-auto-approve",
"-input=false",
"-var", fmt.Sprintf("vm_name=%s", machine.ObjectMeta.Name),
"-var", fmt.Sprintf("vsphere_user=%s", clusterConfig.VsphereUser),
"-var", fmt.Sprintf("vsphere_password=%s", clusterConfig.VspherePassword),
"-var", fmt.Sprintf("vsphere_server=%s", clusterConfig.VsphereServer),
"-var-file=variables.tfvars",
}
_, err = runTerraformCmd(false, machinePath, args...)
if err != nil {
return fmt.Errorf("could not run terraform: %s", err)
}

vc.cleanUpStagingDir(machine)

// remove finalizer
if vc.machineClient != nil {
machine.ObjectMeta.Finalizers = util.Filter(machine.ObjectMeta.Finalizers, clusterv1.MachineFinalizer)
Expand Down
2 changes: 1 addition & 1 deletion cloud/vsphere/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

var apiServerImage = "gcr.io/k8s-cluster-api/cluster-apiserver:0.0.5"
var controllerManagerImage = "gcr.io/k8s-cluster-api/controller-manager:0.0.6"
var machineControllerImage = "gcr.io/k8s-cluster-api/vsphere-machine-controller:0.0.5"
var machineControllerImage = "gcr.io/k8s-cluster-api/vsphere-machine-controller:0.0.6"

func init() {
if img, ok := os.LookupEnv("MACHINE_CONTROLLER_IMAGE"); ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ spec:
cpu: 100m
memory: 30Mi
- name: vsphere-machine-controller
image: gcr.io/k8s-cluster-api/vsphere-machine-controller:0.0.5
image: gcr.io/k8s-cluster-api/vsphere-machine-controller:0.0.6
volumeMounts:
- name: config
mountPath: /etc/kubernetes
Expand Down

0 comments on commit 6aecf9c

Please sign in to comment.