-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
4939d20
25bf0d7
ae9cab7
6dcc4f5
2a9feaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
return reconcile.Result{}, nil | ||
} | ||
|
||
// Get or create the VM. | ||
vm, err := vmService.ReconcileVM(ctx) | ||
if err != nil { | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is Gateway6 check needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||
|
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.
use ctx.Logger which already have namespace/name.