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
Changes from 1 commit
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
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) {
r.Logger.Info("vm is waiting for static ip to be available", "namespace", ctx.VSphereVM.Namespace, "name", ctx.VSphereVM.Name)

Choose a reason for hiding this comment

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

use ctx.Logger which already have namespace/name.

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 len(dev.Gateway4) <= 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.

is Gateway6 check needed?

Copy link
Author

Choose a reason for hiding this comment

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

Ack. The 2 gateways are required when the respective DHCP flags are false.

Copy link
Author

Choose a reason for hiding this comment

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

At this point we don't know if IPAddrs has ipv4 or ipv6. So we cant determine which specific gateway(4/6) needs to be available. May be the gateway check is not required here.

// 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