Skip to content

Commit

Permalink
Merge branch 'main' into fix-ca-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
sharnoff committed Nov 20, 2024
2 parents cf74ac0 + de028a6 commit 097ed30
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 76 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,12 @@ test: vet envtest ## Run tests.

.PHONY: build
build: vet bin/vm-builder ## Build all neonvm binaries.
GOOS=linux go build -o bin/controller neonvm/main.go
GOOS=linux go build -o bin/vxlan-controller neonvm/tools/vxlan/controller/main.go
GOOS=linux go build -o bin/runner neonvm/runner/*.go
GOOS=linux go build -o bin/controller neonvm-controller/cmd/main.go
GOOS=linux go build -o bin/vxlan-controller neonvm-vxlan-controller/cmd/main.go
GOOS=linux go build -o bin/runner neonvm-runner/cmd/main.go
GOOS=linux go build -o bin/daemon neonvm-daemon/cmd/main.go
GOOS=linux go build -o bin/autoscaler-agent autoscaler-agent/cmd/main.go
GOOS=linux go build -o bin/scheduler autoscale-scheduler/cmd/main.go

.PHONY: bin/vm-builder
bin/vm-builder: ## Build vm-builder binary.
Expand Down
98 changes: 38 additions & 60 deletions pkg/neonvm/controllers/vm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,42 @@ func (r *VMReconciler) updateVMStatusMemory(
}
}

func (r *VMReconciler) acquireOverlayIP(ctx context.Context, vm *vmv1.VirtualMachine) error {
if vm.Spec.ExtraNetwork == nil || !vm.Spec.ExtraNetwork.Enable || len(vm.Status.ExtraNetIP) != 0 {
// If the VM has extra network disabled or already has an IP, do nothing.
return nil
}

log := log.FromContext(ctx)

// Create IPAM object
nadName, err := nadIpamName()
if err != nil {
return err
}
nadNamespace, err := nadIpamNamespace()
if err != nil {
return err
}
ipam, err := ipam.New(ctx, nadName, nadNamespace)
if err != nil {
log.Error(err, "failed to create IPAM")
return err
}
defer ipam.Close()
ip, err := ipam.AcquireIP(ctx, vm.Name, vm.Namespace)
if err != nil {
log.Error(err, "fail to acquire IP")
return err
}
message := fmt.Sprintf("Acquired IP %s for overlay network interface", ip.String())
log.Info(message)
vm.Status.ExtraNetIP = ip.IP.String()
vm.Status.ExtraNetMask = fmt.Sprintf("%d.%d.%d.%d", ip.Mask[0], ip.Mask[1], ip.Mask[2], ip.Mask[3])
r.Recorder.Event(vm, "Normal", "OverlayNet", message)
return nil
}

func (r *VMReconciler) doReconcile(ctx context.Context, vm *vmv1.VirtualMachine) error {
log := log.FromContext(ctx)

Expand Down Expand Up @@ -342,35 +378,8 @@ func (r *VMReconciler) doReconcile(ctx context.Context, vm *vmv1.VirtualMachine)
switch vm.Status.Phase {

case "":
// Acquire overlay IP address
if vm.Spec.ExtraNetwork != nil &&
vm.Spec.ExtraNetwork.Enable &&
len(vm.Status.ExtraNetIP) == 0 {
// Create IPAM object
nadName, err := nadIpamName()
if err != nil {
return err
}
nadNamespace, err := nadIpamNamespace()
if err != nil {
return err
}
ipam, err := ipam.New(ctx, nadName, nadNamespace)
if err != nil {
log.Error(err, "failed to create IPAM")
return err
}
defer ipam.Close()
ip, err := ipam.AcquireIP(ctx, vm.Name, vm.Namespace)
if err != nil {
log.Error(err, "fail to acquire IP")
return err
}
message := fmt.Sprintf("Acquired IP %s for overlay network interface", ip.String())
log.Info(message)
vm.Status.ExtraNetIP = ip.IP.String()
vm.Status.ExtraNetMask = fmt.Sprintf("%d.%d.%d.%d", ip.Mask[0], ip.Mask[1], ip.Mask[2], ip.Mask[3])
r.Recorder.Event(vm, "Normal", "OverlayNet", message)
if err := r.acquireOverlayIP(ctx, vm); err != nil {
return err
}
// VirtualMachine just created, change Phase to "Pending"
vm.Status.Phase = vmv1.VmPending
Expand Down Expand Up @@ -492,15 +501,6 @@ func (r *VMReconciler) doReconcile(ctx context.Context, vm *vmv1.VirtualMachine)
Reason: "Reconciling",
Message: fmt.Sprintf("Pod (%s) for VirtualMachine (%s) failed", vm.Status.PodName, vm.Name),
})
case runnerUnknown:
vm.Status.Phase = vmv1.VmPending
meta.SetStatusCondition(&vm.Status.Conditions,
metav1.Condition{
Type: typeAvailableVirtualMachine,
Status: metav1.ConditionUnknown,
Reason: "Reconciling",
Message: fmt.Sprintf("Pod (%s) for VirtualMachine (%s) in Unknown phase", vm.Status.PodName, vm.Name),
})
default:
// do nothing
}
Expand Down Expand Up @@ -620,15 +620,6 @@ func (r *VMReconciler) doReconcile(ctx context.Context, vm *vmv1.VirtualMachine)
Reason: "Reconciling",
Message: fmt.Sprintf("Pod (%s) for VirtualMachine (%s) failed", vm.Status.PodName, vm.Name),
})
case runnerUnknown:
vm.Status.Phase = vmv1.VmPending
meta.SetStatusCondition(&vm.Status.Conditions,
metav1.Condition{
Type: typeAvailableVirtualMachine,
Status: metav1.ConditionUnknown,
Reason: "Reconciling",
Message: fmt.Sprintf("Pod (%s) for VirtualMachine (%s) in Unknown phase", vm.Status.PodName, vm.Name),
})
default:
// do nothing
}
Expand Down Expand Up @@ -683,16 +674,6 @@ func (r *VMReconciler) doReconcile(ctx context.Context, vm *vmv1.VirtualMachine)
Message: fmt.Sprintf("Pod (%s) for VirtualMachine (%s) failed", vm.Status.PodName, vm.Name),
})
return nil
case runnerUnknown:
vm.Status.Phase = vmv1.VmPending
meta.SetStatusCondition(&vm.Status.Conditions,
metav1.Condition{
Type: typeAvailableVirtualMachine,
Status: metav1.ConditionUnknown,
Reason: "Reconciling",
Message: fmt.Sprintf("Pod (%s) for VirtualMachine (%s) in Unknown phase", vm.Status.PodName, vm.Name),
})
return nil
default:
// do nothing
}
Expand Down Expand Up @@ -950,7 +931,6 @@ func (r *VMReconciler) doDIMMSlotsScaling(ctx context.Context, vm *vmv1.VirtualM
type runnerStatusKind string

const (
runnerUnknown runnerStatusKind = "Unknown"
runnerPending runnerStatusKind = "Pending"
runnerRunning runnerStatusKind = "Running"
runnerFailed runnerStatusKind = "Failed"
Expand All @@ -977,8 +957,6 @@ func runnerStatus(pod *corev1.Pod) runnerStatusKind {
return runnerSucceeded
case corev1.PodFailed:
return runnerFailed
case corev1.PodUnknown:
return runnerUnknown
case corev1.PodRunning:
return runnerRunning
default:
Expand Down
13 changes: 0 additions & 13 deletions pkg/neonvm/controllers/vmmigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,19 +388,6 @@ func (r *VirtualMachineMigrationReconciler) Reconcile(ctx context.Context, req c
})
migration.Status.Phase = vmv1.VmmFailed
return r.updateMigrationStatus(ctx, migration)
case runnerUnknown:
message := fmt.Sprintf("Target Pod (%s) in Unknown phase", targetRunner.Name)
log.Info(message)
r.Recorder.Event(migration, "Warning", "Unknown", message)
meta.SetStatusCondition(&migration.Status.Conditions,
metav1.Condition{
Type: typeAvailableVirtualMachineMigration,
Status: metav1.ConditionUnknown,
Reason: "Reconciling",
Message: message,
})
migration.Status.Phase = vmv1.VmmPending
return r.updateMigrationStatus(ctx, migration)
default:
// not sure what to do, so try rqueue
return ctrl.Result{RequeueAfter: time.Second}, nil
Expand Down

0 comments on commit 097ed30

Please sign in to comment.