-
Notifications
You must be signed in to change notification settings - Fork 22
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
api: add api support for Update events #213
api: add api support for Update events #213
Conversation
There is no error reported if the user tries to update OBC fields other than additionalCongifData. |
Are these changes even needed any more given this comment? #195 (comment) |
Atleast at that time focus was needed for bucket notifications(decided to go with |
@jeffvance : I agree that other fields apart from |
|
d672fc5
to
e256965
Compare
So do we want to also support notification via additionalConfigData? |
From above:
This has not been addressed. @BlaineEXE what are your thoughts? |
Currently not planned to do so |
Good catch @BlaineEXE ! |
e256965
to
c02a43a
Compare
c02a43a
to
4f45e72
Compare
pkg/provisioner/controller.go
Outdated
overwriteAdditionalConfig(newObc.Spec.AdditionalConfig, oldSpecWithNewAdditionalConfig.AdditionalConfig) | ||
if !reflect.DeepEqual(newObc.Spec, oldObc.Spec) { | ||
// new OBC is changed | ||
if !reflect.DeepEqual(*oldSpecWithNewAdditionalConfig, newObc.Spec) { |
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 do you need to reference oldSpec... as a pointer?
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.
without pointer reference the check was always returning 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.
Is it always true now? You want to make sure you are not comparing an address with a spec.
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.
IMO oldSpecWithNewAdditionalConfig
is pointer than a Spec
. I have added following function to print Spec
values
diff --git a/pkg/provisioner/controller.go b/pkg/provisioner/controller.go
index 68f47e9..ddc4cc7 100644
--- a/pkg/provisioner/controller.go
+++ b/pkg/provisioner/controller.go
@@ -105,6 +105,7 @@ func NewController(provisionerName string, provisioner api.Provisioner, clientse
oldSpecWithNewAdditionalConfig := oldObc.Spec.DeepCopy()
overwriteAdditionalConfig(newObc.Spec.AdditionalConfig, oldSpecWithNewAdditionalConfig.AdditionalConfig)
if !reflect.DeepEqual(newObc.Spec, oldObc.Spec) {
+ printObcSpec(oldSpecWithNewAdditionalConfig)
// new OBC is changed
if !reflect.DeepEqual(*oldSpecWithNewAdditionalConfig, newObc.Spec) {
// new OBC has changed something other than additionalConfig
@@ -695,3 +696,13 @@ func overwriteAdditionalConfig(srcAdditionalConfig map[string]string, destAdditi
destAdditionalConfig[key] = value
}
}
+
+func printObcSpec(spec v1alpha1.ObjectBucketClaimSpec) {
+ logD.Info("storageclassName ", spec.StorageClassName)
+ logD.Info("bucketname ", spec.BucketName)
+ logD.Info("generatebucknam", spec.GenerateBucketName)
+ logD.Info("ObjectBucketName", spec.ObjectBucketName)
+ for key, value := range spec.AdditionalConfig {
+ logD.Info("key ", key, "value ", value)
+ }
+}
And give me following error :
go build'ing package ./pkg/...
# github.com/kube-object-storage/lib-bucket-provisioner/pkg/provisioner
pkg/provisioner/controller.go:108:17: cannot use oldSpecWithNewAdditionalConfig (type *"github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1".ObjectBucketClaimSpec) as type "github.com/kube-object-storage/lib-bucket-provisioner/pkg/apis/objectbucket.io/v1alpha1".ObjectBucketClaimSpec in argument to printObcSpec
Typo L133: "waith" -> "wait" |
4f45e72
to
4271c17
Compare
pkg/provisioner/controller.go
Outdated
log.Info("Additional config changed, hence updating OB") | ||
tmp := make(map[string]string) | ||
|
||
tmp = ob.Spec.Endpoint.AdditionalConfigData |
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 Go, maps need to be deep copied. This will only change the pointer, and tmp
will therefore be overwritten by overwriteAdditionalConfig
. If updating the object bucket fails, this will not properly reset the value.
See my test here: https://play.golang.org/p/z0BurgSZEM8
Given this potential bug, it would be best to have a unit test that verifies the provisioner is properly reset when updating the OB fails.
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 you are right! Sorry @thotz
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.
@BlaineEXE : I agree it is good to have a unit test. Sorry but I don't understand which function I need write the unit test.
Is it for overwriteAdditionalConfig()
with set of string maps like in ur example. Or for the handleUpdateClaim()
?
If it is handleUpdateClaim()
First I need to create OBC and then call handleUpdateClaim()
with that OBC for different test cases?
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 for handleUpdateClaim
and make sure the unit test coverage report activates the lines below
if err != nil {
log.Error(err, "updating OB failed, reverting provisioner to original value")
overwriteAdditionalConfig(tmp, ob.Spec.Endpoint.AdditionalConfigData)
err = c.provisioner.Update(ob)
}
And also verify that the additionalConfig
in the activated code is properly reset to the original value and doesn't still contain the updated additionalConfig
|
||
func updateSupported(old, new *v1alpha1.ObjectBucketClaim) bool { | ||
// The only field supported for update is obc.spec.additionalConfig | ||
if reflect.DeepEqual(new.Spec, old.Spec) { |
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.
Is it necessary to compare the whole spec if the only supported field is additionalConfig? Why not instead check if additionalConfig has changed?
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.
One of the goals is to log an error or warning if the user attempts to change anything in the obc other than .spec.additionalConfig
. I guess DeepEqual handles map compares in cases where they keys may be in different order, right?
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.
Nevermind, I believe it's just to short circuit the call if a non-spec field was changed, which can be ignored. Makes sense to me.
Signed-off-by: Jiffin Tony Thottan <thottanjiffin@gmail.com>
b041514
to
69d4000
Compare
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.
lgtm
(for future reference, I prefer to see pr changes in separate commits so that I can re-review only the code that has changed since my previous review)
Sure I keep this in mind while sending PR. Sorry for the trouble and thanks for your patience while reviewing the PR |
No worries @thotz - single commit PRs are common, but, IMO, there are advantages to multi-commit PRs with sensible squashing just before merging. |
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.
@thotz is Rook going to consume that? |
Yes I can update the library for Rook by adding necessary changes |
Adding support to handle Update Events of OBC, currently
AdditionalConfig
needs this change.Other fields are immutable
Fixes #195
Signed-off-by: Jiffin Tony Thottan thottanjiffin@gmail.com