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

Update owner references in reconcile resource util function #3574

Merged
merged 3 commits into from
Aug 4, 2020

Conversation

pebrc
Copy link
Collaborator

@pebrc pebrc commented Aug 3, 2020

We previously set owner references only on creation as they usually don't change. With the association model in ECK ownership can change though. The referenced resource can change and the controller e.g. the Elasticsearch controller for a Kibana -> Elasticsearch relationship relies on the owner referrence in its watch on secrets.

This PR takes this into account by resetting the owner reference on updates.

Fixes #3470

We previously set owner references only on creation as they usually don't change. With the association model in ECK ownership can change though. This commit takes this into account by resetting the owner reference on updates.
@pebrc pebrc added >bug Something isn't working v1.3.0 labels Aug 3, 2020
Copy link
Contributor

@barkbay barkbay left a comment

Choose a reason for hiding this comment

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

I was wondering why we are not reusing the logic of the ReconcileResource function:

  1. NeedsUpdate() detects if owners need to be updated
  2. UpdateReconciled() updates the owners

I guess this is because we want to do that for all the resources ? But is it not a bit inconsistent with the fact that NeedsUpdate() may prevent the ownership to be fixed, because it does not detect that owners needs to be updated ?

NeedsUpdate: func() bool {
// update if expected labels and annotations are not there
return !maps.IsSubset(expected.Labels, reconciled.Labels) ||
!maps.IsSubset(expected.Annotations, reconciled.Annotations) ||
// or if secret data is not strictly equal
!reflect.DeepEqual(expected.Data, reconciled.Data)
},

@@ -160,11 +160,24 @@ func ReconcileResource(params Params) error {
if err != nil {
return err
}

expectedMeta, err := meta.Accessor(params.Expected)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe move those lines a bit closer to where expectedMeta is used

@pebrc
Copy link
Collaborator Author

pebrc commented Aug 3, 2020

I was wondering why we are not reusing the logic of the ReconcileResource function:

I think that is a fair point. I guess the only problem with that approach is that we would have to remember at each use of the ReconcileResource function to include the OwnerReference in both the check whether an update needs to happen and in the actual update. My thinking was that thats somewhat inconsistent with the current signature of the function as it takes an owner as an argument which sort of indicates that it will handle the OwnerReference for the caller.

Regarding the question of whether we would miss the owner upgrade if it is not included in the NeedsUpdate function: I was kind of relying on the fact that if the owner changes this typically has an effect on other attributes as well (labels for example) which would make sure that the update happens.

I don't feel super strongly about both points and am happy to reconsider if we think an explicit inclusion of the owner reference in NeedsUpdate and UpdateReconciled is preferable.

Copy link
Contributor

@barkbay barkbay left a comment

Choose a reason for hiding this comment

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

My thinking was that thats somewhat inconsistent with the current signature of the function as it takes an owner as an argument which sort of indicates that it will handle the OwnerReference for the caller.

👍 I'm fine with keeping the PR as is

@pebrc pebrc merged commit 59c7639 into elastic:master Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug Something isn't working v1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User is not propagated to new ES if reference is changed
2 participants