Skip to content
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

[monitoring] Check pv minimum count #201

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

grem-li
Copy link

@grem-li grem-li commented Nov 22, 2024

Description

Why do we need it, and what problem does it solve?

What is the expected result?

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: Denis Shipkov <[email protected]>
@grem-li grem-li self-assigned this Nov 26, 2024
Signed-off-by: Denis Shipkov <[email protected]>
@grem-li grem-li changed the title Check pv minimum count [monitoring] Check pv minimum count Nov 27, 2024
ReconcileTieBreaker(ctx, log, lc, rdMap, rgMap)
pvsList, err := GetListPV(ctx, cl)
if err != nil {
log.Error(err, "[NewLinstorResourcesWatcher] unable to get Persistent Volumes")
Copy link
Member

Choose a reason for hiding this comment

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

log.Error returns normally and execution proceeds. It leads to a bunch of bugs, since any collection may be nil, because of a single transmission issue. Let's not reproduce it this time, but rather fix it in all places above.

log.Info("[ReconcilePVReplicas] starts work")

for _, pv := range pvs {
if pv.Spec.CSI != nil && pv.Spec.CSI.Driver == PVCSIDriver {
Copy link
Member

Choose a reason for hiding this comment

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

Inverse this condition to reduce nesting level of the code below.

replicasErrLevel := checkPVMinReplicasCount(ctx, log, lc, rg, res[pv.Name])

if pv.Labels == nil {
pv.Labels = make(map[string]string)
Copy link
Member

Choose a reason for hiding this comment

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

I'll choose this line as an example. Review point is about problem between ReconcileParams and ReconcilePVReplicas.

pv variable holds a local value, which was copied from the original slice pvs. It's not a pointer, and you're not accessing the original array element by index, so any modifications to it will affect only this local copy. I'll use term value semantics to refer to this effect.

Value semantics is fine for ReconcilePVReplicas on it's own, and it was fine for ReconcileParams, but after you've extended the scope of the state (moved pvs to the outer scope), it became a problem, since any change to labels won't affect the pvs collection. It will lead to second method ReconcilePVReplicas to overwrite the labels set by the ReconcileParams.

This should be fixed by using reference semantics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants