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

[WIP] wait for static ip allocation #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ RELEASE_REGISTRY := gcr.io/cluster-api-provider-vsphere/release
RELEASE_CONTROLLER_IMG := $(RELEASE_REGISTRY)/$(IMAGE_NAME)

# Development Docker variables
DEV_REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
DEV_REGISTRY ?= gcr.io/spectro-common-dev/${USER}
DEV_CONTROLLER_IMG ?= $(DEV_REGISTRY)/vsphere-$(IMAGE_NAME)
DEV_TAG ?= dev
DEV_MANIFEST_IMG := $(DEV_CONTROLLER_IMG)-$(ARCH)
Expand Down
27 changes: 27 additions & 0 deletions controllers/vspherevm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ func (r vmReconciler) reconcileNormal(ctx *context.VMContext) (reconcile.Result,
// TODO(akutz) Implement selection of VM service based on vSphere version
var vmService services.VirtualMachineService = &govmomi.VMService{}

if r.isWaitingForStaticIPAllocation(ctx) {
ctx.Logger.Info("vm is waiting for static ip to be available")
return reconcile.Result{}, nil
}

// Get or create the VM.
vm, err := vmService.ReconcileVM(ctx)
if err != nil {
Expand Down Expand Up @@ -349,6 +354,28 @@ func (r vmReconciler) reconcileNormal(ctx *context.VMContext) (reconcile.Result,
return reconcile.Result{}, nil
}

func (r vmReconciler) isWaitingForStaticIPAllocation(ctx *context.VMContext) bool {
// Requeue if the two DHCP flags are set to false
// and no static IP is set in the IPAddrs.
waitForIP := false
devices := ctx.VSphereVM.Spec.Network.Devices

for _, dev := range devices {
// If DHCP is set for any of the devices,
// assume DHCP as the default allocation type.
if dev.DHCP4 || dev.DHCP6 {
return false
} else {
if (!dev.DHCP4 && len(dev.Gateway4) <= 0) || (!dev.DHCP6 && len(dev.Gateway6) <= 0) || len(dev.IPAddrs) <= 0 {

Choose a reason for hiding this comment

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

should it be len()<= 0 ? or just len()==0 is enough?

// Static IP is not available yet
waitForIP = true
}
}
}

return waitForIP
}

func (r vmReconciler) reconcileNetwork(ctx *context.VMContext, vm infrav1.VirtualMachine) {
ctx.VSphereVM.Status.Network = vm.Network
ipAddrs := make([]string, 0, len(vm.Network))
Expand Down