Skip to content

Conversation

@krpsh123
Copy link
Contributor

@krpsh123 krpsh123 commented Dec 8, 2025

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:

  • When an RVR's desired primary state changes, the controller should automatically execute the appropriate drbdadm command.
  • Command execution errors should be visible in rvr.Status.DRBD.Errors.LastPrimaryError or rvr.Status.DRBD.Errors.LastSecondaryError.
  • When the role already matches the desired state, any previous errors should be cleared from the status.

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

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]>
@krpsh123 krpsh123 self-assigned this Dec 8, 2025
@krpsh123 krpsh123 added the enhancement New feature or request label Dec 8, 2025
@krpsh123 krpsh123 linked an issue Dec 8, 2025 that may be closed by this pull request
@krpsh123 krpsh123 marked this pull request as ready for review December 8, 2025 13:49
@krpsh123 krpsh123 requested a review from asergunov December 8, 2025 13:49
Comment on lines +31 to +32
func BuildController(mgr manager.Manager) error {
cfg, err := env.GetConfig()
Copy link
Contributor

Choose a reason for hiding this comment

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

Я вроде делал чтобы он сюда аргументом приезжал?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Как раз не делал (
Поэтому я сделал как у тебя было сделано.

Copy link
Contributor

Choose a reason for hiding this comment

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

Я точно делал. Может в контроллере?

Copy link
Contributor Author

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/

Comment on lines +126 to +146
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])
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Пока норм. Но это техдолг. Тут по-хорошему надо мокать и тесты буду - конфетка

Comment on lines +283 to +297
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{}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

В следующий раз так не делай.

А может делай. Надо обсудить.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[agent] Implement drbd-primary-controller

3 participants