-
Notifications
You must be signed in to change notification settings - Fork 236
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
fix/linting for percentage based values #546
Conversation
@fahlmant PTAL |
Since the MR is importing |
Message: maxUnavailableZeroMsg, | ||
}, | ||
if pdb.Spec.MaxUnavailable == nil { | ||
if pdb.Spec.MaxUnavailable.IntVal == 0 { |
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 the first condition is satisfied then the second one will fail with panic.
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.
done.
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.
Thank you
if pdb.Spec.MaxUnavailable == nil { | ||
if pdb.Spec.MaxUnavailable.IntVal == 0 { | ||
return []diagnostic.Diagnostic{{ | ||
Message: "MaxUnavailable is undefined", |
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 this is "undesired" diagnostic. I mean we would like to report when MaxUnavailable
is 0, otherwise do nothing.
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.
still have a bit of mixed feeling on this one but a "missing" maxUnavailable is valid. skipping validation on nil. please take a look
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.
yes it's valid. Thanks. Looks good.
My name is Martin and I work at Red Hat along with Tomas. We're quite eager to see these changes merged as we bellieve PDB check could be quite helpful for our SRE organization. Would you mind letting me know your estimate in terms of when would you have time look at comments from Tomas and fixing the code? I'd like to also offer our help finishing this up should it be your preference due to other priorities you might have. Many thanks in advance for letting me know Martin Klika |
Hi @mklika Thanks for the heads up. Changes & fixes submitted. Please review |
Looks good to me. Thank you @bmiguel-teixeira . |
@@ -28,11 +28,49 @@ func (p *PDBTestSuite) SetupTest() { | |||
p.ctx = mocks.NewMockContext() | |||
} | |||
|
|||
func (p *PDBTestSuite) TestPDBMaxUnavailableZero() { | |||
func (p *PDBTestSuite) TestPDBMaxUnavailableZeroAsInteger() { |
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.
How about converting this tests to table driven tests?
func (p *PDBTestSuite) TestPDB() {
testCases := []struct {
Name string
Message string
MaxUnavailable intstr.IntOrString
}{
{
Name: "Invalid Value String",
Message: "maxUnavailable has invalid value [invalid-value]",
MaxUnavailable: intstr.FromString("invalid-value"),
},
{
Name: "Invalid Value String",
Message: "maxUnavailable has invalid value [0]",
MaxUnavailable: intstr.FromString("0"),
},
{
Name: "One As String Percentage",
MaxUnavailable: intstr.FromString("1%"),
},
{
Name: "One As Integer",
MaxUnavailable: intstr.FromInt(1),
},
{
Name: "Zero As String Percentage",
Message: "MaxUnavailable is set to 0",
MaxUnavailable: intstr.FromString("0%"),
},
{
Name: "Zero As Integer",
Message: "MaxUnavailable is set to 0",
MaxUnavailable: intstr.FromInt(0),
},
}
for _, tc := range testCases {
tc := tc
p.Run(tc.Name, func() {
p.ctx.AddMockPodDisruptionBudget(p.T(), "test-pdb")
p.ctx.ModifyPodDisruptionBudget(p.T(), "test-pdb", func(pdb *pdbV1.PodDisruptionBudget) {
pdb.Spec.MaxUnavailable = &tc.MaxUnavailable
})
expected := map[string][]diagnostic.Diagnostic{}
if tc.Message != "" {
expected = map[string][]diagnostic.Diagnostic{
"test-pdb": {{Message: tc.Message}},
}
}
p.Validate(p.ctx, []templates.TestCase{
{
Param: params.Params{},
Diagnostics: expected,
ExpectInstantiationError: false,
},
})
})
}
}
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.
make sense. done
31a0376
to
1af66f0
Compare
This PR fixes the PDB validation to include support for % based values.
OldBehavior:
maxUnavailable was set to 10% was failing since the field is IntOrString. The IntVal defaults to 0 when the field is of String Values, thus causing false positives.
NewBehaviour:
int and string values are taken into account, parsed into a single integer value for validation.