-
Notifications
You must be signed in to change notification settings - Fork 209
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
Add support for validation on AzureName and ResourceGroup immutability #2260
Conversation
...internal/codegen/testdata/ArmResource/Arm_test_dependent_resource_and_ownership_azure.golden
Outdated
Show resolved
Hide resolved
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.
see comment
Codecov Report
@@ Coverage Diff @@
## main #2260 +/- ##
==========================================
+ Coverage 53.11% 53.15% +0.04%
==========================================
Files 808 809 +1
Lines 248049 248769 +720
==========================================
+ Hits 131744 132238 +494
- Misses 97525 97700 +175
- Partials 18780 18831 +51
Continue to review full report at Codecov.
|
v2/api/authorization/v1alpha1api20200801preview/role_assignment_types_gen.go
Outdated
Show resolved
Hide resolved
newAzureName := "test123" | ||
old := acct.DeepCopy() | ||
acct.Spec.AzureName = newAzureName | ||
tc.PatchAndExpectError(old, acct) |
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.
Maybe instead of doing PatchAndExpectError
we should just have a Patch
that returns the error. Then you can actually assert that it has the right shape as well?
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.
We already have Patch
which expects error to be nil. Can make this one return error
and then assert on if error is not nil
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.
Totally agree that's the right approach
v2/tools/generator/internal/functions/kubernetes_admissions_validations.go
Outdated
Show resolved
Hide resolved
v2/pkg/genruntime/admissions.go
Outdated
} | ||
|
||
if oldObj.AzureName() != newObj.AzureName() { | ||
errs = append(errs, errors.Errorf("updating 'AzureName()' is not allowed for '%s", oldObj.GetName())) |
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.
Why is AzureName
written as though it's a method call?
errs = append(errs, errors.Errorf("updating 'AzureName()' is not allowed for '%s", oldObj.GetName())) | |
errs = append(errs, errors.Errorf("updating 'AzureName( is not allowed for '%s", oldObj.GetName())) |
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, does oldObj.GetName()
return a fully qualified GVK or only a partial name?
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 the partial name.. Have also added added kind as well now. Or do you think GVK is better?
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.
We probably dont need version as this error is for all versions always I think? But G + K is good.
} | ||
|
||
// validateImmutableProperties validates all immutable properties | ||
func (resource *FakeResource) validateImmutableProperties(old runtime.Object) error { |
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.
We suppress some pipeline stages for these golden tests as they focus on property structure and the functions are noise - perhaps validation should be suppressed too? #unsure
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.
We already have validateResourceReferences in the golden tests though
v2/pkg/genruntime/admissions.go
Outdated
@@ -26,3 +28,22 @@ type Defaulter interface { | |||
// CustomDefault performs custom defaults that are run in addition to the code generated defaults. | |||
CustomDefault() | |||
} | |||
|
|||
// ValidateImmutableProperties function validates the update on immutable properties. | |||
func ValidateImmutableProperties(oldObj MetaObject, newObj MetaObject) error { |
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'm not sure "Immutable" is quite the right term for these properties, but I'm having trouble coming up with a reasonable alternative.
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.
Approved but take a look at my test comments as I think there's 1 more test you should have.
ReceiverType: &dst.StarExpr{ | ||
X: receiverType, | ||
}, |
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's a helper function in astbuilder
for this.
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.
Updated to use astbuilder.Deference
v2/tools/generator/internal/functions/kubernetes_admissions_validations.go
Outdated
Show resolved
Hide resolved
cast := astbuilder.TypeAssert(obj, dst.NewIdent("old"), astbuilder.Dereference(receiver.AsType(codeGenerationContext))) | ||
checkAssert := astbuilder.ReturnIfNotOk(astbuilder.Nil()) | ||
|
||
returnStmt := astbuilder.Returns( |
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.
Suggest configuring this to have a blank line before the return statement.
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.
Added!
…lidations.go Co-authored-by: Bevan Arps <[email protected]>
…-service-operator into feature/immutability
Somewhat fixes #1443, but we still need support for more (custom) fields there. |
…-service-operator into feature/immutability
Closes #2134
What this PR does / why we need it:
We had an issue where changing AzureName and Resource groups would abandon the old resource and creates a new one. Which is solved using validation web-hook on UPDATE for immutable fields in this PR.
This PR includes: