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
Create check to ensure PDB have MaxUnavailable and MinAvailable set effectively #507
Conversation
3707060
to
e3f0455
Compare
It's still not clear to me when and how this new check can be enabled. It seems it won't be enabled by default so will it be a custom check? |
@tremes the PR is still a WIP |
Tests currently are not working, adding a Deployment to the lintContext seems to not be working as the mocked object is showing that there's no Kind specified |
93fc9da
to
6d6cc89
Compare
fd7cbfa
to
0f2dfd2
Compare
replicas, _ := extract.Replicas(dl) | ||
if isPercent { | ||
// Calulate the actual value of the MinAvailable with respect to the Replica count if a percentage is set | ||
pdbMinAvailable = int(replicas) * (value / 100) |
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.
Won't it be always zero? I guess you need something like pdbMinAvailable = float64(replicas) * (float64(value) / float64(100))
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.
In the end this still has to be an integer. It doesn't matter too much though because as long as it's less than 100%, it should be a valid config. For accuracy though, I think this will work:
pdbMinAvailable = int(math.Floor(float64(replicas) * (float64(value) / float64(100))))
This finds the exact value of minavailable based on a percentage, and then rounds down so cases like 1 replica with a 50% minavaiable (which calculates to 0.5) won't cause this remediation to fire. I'm not sure exactly how kubernetes handles this sort of case, so I'm erring on the side of permissive at first. It might be a good place for iteration
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.
@tremes is right but if we change order (multiplication first) it will work without conversion and floor
pdbMinAvailable = (int(replicas) * value) / 100
0f2dfd2
to
73ceb30
Compare
if err != nil { | ||
return []diagnostic.Diagnostic{ | ||
{ | ||
Message: fmt.Sprintf("pdb has invalid MinAvailable value: %v", err), |
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.
in other places PDB is capital.
Message: fmt.Sprintf("pdb has invalid MinAvailable value: %v", err), | |
Message: fmt.Sprintf("PDB has invalid MinAvailable value: %w", err), |
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.
also in other places we use errors.Wrap
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.
Just minor things, otherwise LGTM!
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.
Just small comments. I think we should use errors.Wrap
to wrap errors.
replicas, _ := extract.Replicas(dl) | ||
if isPercent { | ||
// Calulate the actual value of the MinAvailable with respect to the Replica count if a percentage is set | ||
pdbMinAvailable = int(replicas) * (value / 100) |
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.
@tremes is right but if we change order (multiplication first) it will work without conversion and floor
pdbMinAvailable = (int(replicas) * value) / 100
tests/checks/pdb-min-available.yaml
Outdated
replicas: 1 | ||
selector: | ||
matchLabels: | ||
name: cloud-ingress-operator |
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.
I think we should add a check for EOL
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.
Can you clarify this a bit? I'm not sure what is being asked here
Creates two checks for PDBs:
This is a WIP. Tests still need to be added