-
Notifications
You must be signed in to change notification settings - Fork 26
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
neonvm-controller: make IPAM code production-ready #1278
Open
Omrigan
wants to merge
11
commits into
main
Choose a base branch
from
oleg/ipam-fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+438
−283
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
80ade18
neonvm-controller: ignore overlay IP allocation failure
Omrigan d8f0c26
neonvm-controller/ipam: erase leader election
Omrigan 5bba212
neonvm-controller/ipam: don't check connection
Omrigan b38b4c1
neonvm-controller/ipam: extract runIPAMRange
Omrigan 30a735f
neonvm-controller/ipam: little code cleanup
Omrigan 6998861
neonvm-controller: panic instead of exit(1)
Omrigan 92b57e5
neonvm-controller/ipam: create IPAM once
Omrigan 354a4ab
neonvm-controller/ipam: turn action into callback
Omrigan f8748ac
neonvm-controller/ipam: implement cleanup action
Omrigan 1cd4179
neonvm-controller/ipam: add test
Omrigan ffed348
neonvm/config: use new IPAM configuration
Omrigan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,7 @@ type VMReconciler struct { | |
Scheme *runtime.Scheme | ||
Recorder record.EventRecorder | ||
Config *ReconcilerConfig | ||
IPAM *ipam.IPAM | ||
|
||
Metrics ReconcilerMetrics `exhaustruct:"optional"` | ||
} | ||
|
@@ -238,27 +239,7 @@ func (r *VMReconciler) doFinalizerOperationsForVirtualMachine(ctx context.Contex | |
|
||
// Release overlay IP address | ||
if vm.Spec.ExtraNetwork != nil { | ||
// Create IPAM object | ||
nadName, err := nadIpamName() | ||
if err != nil { | ||
// ignore error | ||
log.Error(err, "ignored error") | ||
return | ||
} | ||
nadNamespace, err := nadIpamNamespace() | ||
if err != nil { | ||
// ignore error | ||
log.Error(err, "ignored error") | ||
return | ||
} | ||
ipam, err := ipam.New(ctx, nadName, nadNamespace) | ||
if err != nil { | ||
// ignore error | ||
log.Error(err, "ignored error") | ||
return | ||
} | ||
defer ipam.Close() | ||
ip, err := ipam.ReleaseIP(ctx, vm.Name, vm.Namespace) | ||
ip, err := r.IPAM.ReleaseIP(ctx, types.NamespacedName{Name: vm.Name, Namespace: vm.Namespace}) | ||
if err != nil { | ||
// ignore error | ||
log.Error(err, "fail to release IP, error ignored") | ||
|
@@ -347,23 +328,7 @@ func (r *VMReconciler) acquireOverlayIP(ctx context.Context, vm *vmv1.VirtualMac | |
} | ||
|
||
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) | ||
ip, err := r.IPAM.AcquireIP(ctx, types.NamespacedName{Name: vm.Name, Namespace: vm.Namespace}) | ||
if err != nil { | ||
log.Error(err, "fail to acquire IP") | ||
return err | ||
|
@@ -416,7 +381,9 @@ func (r *VMReconciler) doReconcile(ctx context.Context, vm *vmv1.VirtualMachine) | |
|
||
case "": | ||
if err := r.acquireOverlayIP(ctx, vm); err != nil { | ||
return err | ||
log.Error(err, "Failed to acquire overlay IP", "VirtualMachine", vm.Name) | ||
r.Recorder.Event(vm, "Warning", "OverlayNet", "Failed to acquire overlay IP") | ||
// Don't return error, we will keep running without an overlay IP | ||
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. question (blocking): IIUC this means that if we have some transient issue where we fail to initially acquire the overlay IP, we'll never get one? Is that accurate, and is that the behavior we want? |
||
} | ||
// VirtualMachine just created, change Phase to "Pending" | ||
vm.Status.Phase = vmv1.VmPending | ||
|
@@ -1710,15 +1677,7 @@ func podSpec( | |
if len(vm.Spec.ExtraNetwork.MultusNetwork) > 0 { // network specified in spec | ||
nadNetwork = vm.Spec.ExtraNetwork.MultusNetwork | ||
} else { // get network from env variables | ||
nadName, err := nadRunnerName() | ||
if err != nil { | ||
return nil, err | ||
} | ||
nadNamespace, err := nadRunnerNamespace() | ||
if err != nil { | ||
return nil, err | ||
} | ||
nadNetwork = fmt.Sprintf("%s/%s", nadNamespace, nadName) | ||
nadNetwork = fmt.Sprintf("%s/%s", config.NADConfig.RunnerNamespace, config.NADConfig.RunnerName) | ||
} | ||
pod.ObjectMeta.Annotations[nadapiv1.NetworkAttachmentAnnot] = fmt.Sprintf("%s@%s", nadNetwork, vm.Spec.ExtraNetwork.Interface) | ||
} | ||
|
@@ -1768,33 +1727,27 @@ func (r *VMReconciler) tryUpdateVM(ctx context.Context, vm *vmv1.VirtualMachine) | |
return r.Update(ctx, vm) | ||
} | ||
|
||
// return Network Attachment Definition name with IPAM settings | ||
func nadIpamName() (string, error) { | ||
return getEnvVarValue("NAD_IPAM_NAME") | ||
type NADConfig struct { | ||
IPAMName string | ||
IPAMNamespace string | ||
RunnerName string | ||
RunnerNamespace string | ||
} | ||
|
||
// return Network Attachment Definition namespace with IPAM settings | ||
func nadIpamNamespace() (string, error) { | ||
return getEnvVarValue("NAD_IPAM_NAMESPACE") | ||
} | ||
|
||
// return Network Attachment Definition name for second interface in Runner | ||
func nadRunnerName() (string, error) { | ||
return getEnvVarValue("NAD_RUNNER_NAME") | ||
} | ||
|
||
// return Network Attachment Definition namespace for second interface in Runner | ||
func nadRunnerNamespace() (string, error) { | ||
return getEnvVarValue("NAD_RUNNER_NAMESPACE") | ||
} | ||
|
||
// return env variable value | ||
func getEnvVarValue(envVarName string) (string, error) { | ||
value, found := os.LookupEnv(envVarName) | ||
if !found { | ||
return "", fmt.Errorf("unable to find %s environment variable", envVarName) | ||
func GetNADConfig() *NADConfig { | ||
getVar := func(envVarName string) string { | ||
value, ok := os.LookupEnv(envVarName) | ||
if !ok { | ||
panic(fmt.Errorf("unable to find %s environment variable", envVarName)) | ||
} | ||
return value | ||
} | ||
return &NADConfig{ | ||
IPAMName: getVar("NAD_IPAM_NAME"), | ||
IPAMNamespace: getVar("NAD_IPAM_NAMESPACE"), | ||
RunnerName: getVar("NAD_RUNNER_NAME"), | ||
RunnerNamespace: getVar("NAD_RUNNER_NAMESPACE"), | ||
} | ||
return value, nil | ||
} | ||
|
||
// sshKeygen generates a pair of public and private keys using the ed25519 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
question (maybe blocking?): This is no longer upheld, right? IIRC it's required due to releasing the leader election lease immediately when the manager exits