-
Notifications
You must be signed in to change notification settings - Fork 4
[agent] Implement drbd-primary-controller #369
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
base: astef-prototype
Are you sure you want to change the base?
Conversation
Signed-off-by: Pavel Karpov <[email protected]>
Signed-off-by: Pavel Karpov <[email protected]>
Signed-off-by: Pavel Karpov <[email protected]>
Signed-off-by: Pavel Karpov <[email protected]>
Signed-off-by: Pavel Karpov <[email protected]>
Signed-off-by: Pavel Karpov <[email protected]>
Signed-off-by: Pavel Karpov <[email protected]>
Signed-off-by: Pavel Karpov <[email protected]>
Signed-off-by: Pavel Karpov <[email protected]>
Signed-off-by: Pavel Karpov <[email protected]>
Signed-off-by: Pavel Karpov <[email protected]>
Signed-off-by: Pavel Karpov <[email protected]>
| func BuildController(mgr manager.Manager) error { | ||
| cfg, err := env.GetConfig() |
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.
Я вроде делал чтобы он сюда аргументом приезжал?
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.
Как раз не делал (
Поэтому я сделал как у тебя было сделано.
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.
Я точно делал. Может в контроллере?
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.
В смерженном только тут images/agent/internal/controllers/rvr_status_config_address/controller.go.
В контроллере тишина grep -r cfg images/controller/internal/controllers/
| if needPrimary { | ||
| log.Info("Promoting to primary") | ||
| cmdErr = drbdadm.ExecutePrimary(ctx, rvr.Spec.ReplicatedVolumeName) | ||
| } else { | ||
| log.Info("Demoting to secondary") | ||
| cmdErr = drbdadm.ExecuteSecondary(ctx, rvr.Spec.ReplicatedVolumeName) | ||
| } | ||
|
|
||
| // Extract error details | ||
| if cmdErr != nil { | ||
| var exitErr *exec.ExitError | ||
| if errors.As(cmdErr, &exitErr) { | ||
| exitCode = exitErr.ExitCode() | ||
| } | ||
| // The error from drbdadm.ExecutePrimary/ExecuteSecondary is a joined error | ||
| // containing both the exec error and the command output | ||
| cmdOutput = cmdErr.Error() | ||
| log.Error(cmdErr, "executed command failed", "command", drbdadm.Command, "args", map[bool][]string{true: drbdadm.PrimaryArgs(rvr.Spec.ReplicatedVolumeName), false: drbdadm.SecondaryArgs(rvr.Spec.ReplicatedVolumeName)}[needPrimary], "output", cmdOutput) | ||
| } else { | ||
| log.V(4).Info("executed command successfully", "command", drbdadm.Command, "args", map[bool][]string{true: drbdadm.PrimaryArgs(rvr.Spec.ReplicatedVolumeName), false: drbdadm.SecondaryArgs(rvr.Spec.ReplicatedVolumeName)}[needPrimary]) | ||
| } |
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.
Пока норм. Но это техдолг. Тут по-хорошему надо мокать и тесты буду - конфетка
| if rvr.Status == nil { | ||
| rvr.Status = &v1alpha3.ReplicatedVolumeReplicaStatus{} | ||
| } | ||
| if rvr.Status.DRBD == nil { | ||
| rvr.Status.DRBD = &v1alpha3.DRBD{} | ||
| } | ||
| if rvr.Status.DRBD.Config == nil { | ||
| rvr.Status.DRBD.Config = &v1alpha3.DRBDConfig{} | ||
| } | ||
| if rvr.Status.DRBD.Status == nil { | ||
| rvr.Status.DRBD.Status = &v1alpha3.DRBDStatus{} | ||
| } | ||
| if rvr.Status.DRBD.Actual == nil { | ||
| rvr.Status.DRBD.Actual = &v1alpha3.DRBDActual{} | ||
| } |
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.
В следующий раз так не делай.
А может делай. Надо обсудить.
Co-authored-by: Anton Sergunov <[email protected]> Signed-off-by: Pavel Karpov <[email protected]>
Signed-off-by: Pavel Karpov <[email protected]>
Description
This PR introduces a new drbd-primary-controller in the agent component that manages DRBD role transitions (Primary/Secondary) for ReplicatedVolumeReplica resources. The controller monitors RVRs assigned to the current node and executes drbdadm primary or drbdadm secondary commands based on the desired state defined in rvr.Status.DRBD.Config.Primary. It also tracks command execution errors in the RVR status, storing them in rvr.Status.DRBD.Errors.LastPrimaryError or rvr.Status.DRBD.Errors.LastSecondaryError fields.
Why do we need it, and what problem does it solve?
The controller automates DRBD role management for replicated volumes.
What is the expected result?
After applying these changes:
rvr.Status.DRBD.Errors.LastPrimaryErrororrvr.Status.DRBD.Errors.LastSecondaryError.Checklist