Compute NumPropagatedObjects in HNCConfiguration status #542
/assign @adrianludwin
/assign @yiqigao217
Remove this test case because it is tested in the following test case.
Can we call this something a bit more descriptive? The Forest doesn't "know" about any of the configs; this name should indicate _why_ the forest is calling it. Eg something like PropagatedCountSink or something like that (e.g., "this is someone who wants to know when the number of objects has changed").
We can just make f.config public so you don't need getters and setters. I've tried to only use those when there's nontrivial logic.
Nice
I'm not sure how consistent this order will be. Maybe we should ensure the final list is sorted alphabetically or something?
Comment to say what this will be used for
Comment - what does this mutex protect? Or else, put it next to PropagatedObjects and call it PropagatedObjectsLock which is self-descriptive.
Better to say:
r.lock.Lock()
defer r.lock.Unlock()
If we're not using sync/atomic anymore, this should probably just be int now, right?
Why? I thought we just stopped reporting status for anything in Ignore?
But SetMode can only be called from the HNC config reconciler, right? Which means that it already knows we're in Ignore mode, and it can stop displaying all statistics?
Why is this here? Shouldn't we only call this in line 473, below?
Use defer
Use defer
Save these magic frequencies somewhere as named constants
Nice! Circling back to review the tests now but I wanted to send you what I already had.
Wait, why are we waiting this long? The object should show up right away, it only takes 3s for it to show up in the HNC Config status.
We should specify that we only use this when we're expecting something _not_ to happen. Otherwise, we just use Eventually.
This seems too high to me. From the time we make our _last_ change to an object, I would expect it would take no more than three seconds plus a little bit extra (e.g. four seconds should be enough): 3s for the HNC Config sleep to end, plus a bit of time for it to do its work. So if we said:
SetDefaultEventuallyTimeout(hncConfigReconciliationTime + 2 * time.Second)
Then Eventually will wait up to five seconds and that _should_ be more than enough time. (Or don't change the global default and just pass this into each Eventually) call.
Do you agree with this logic? And if so, do you know why it doesn't work?
Is there a way to restore this to what it used to be (e.g. in case it wasn't 2s for some reason)?
You're already overriding Eventually with the constants you've defined above, why do you need this too?
Eh, now I see the downside to putting the Sleep at the beginning of the Reconciler - it means that the regular business logic (e.g. adding/removing types) is also delayed by 3s. I'm not sure we want that. Sorry I missed that.
How about we write some logic to intercept the calls from the object reconcilers and make sure we only _trigger_ one reconciliation every N seconds? That way, most of the reconciler will still work ASAP. You'll have to write the deduping logic yourself but that should be pretty simple. Talk to Yiqi about how to trigger a periodic event using a long-running goroutine. It'll look something like this in the Setup function:
go func() {
for { // have some kind of way to break the loop when the controller exits
time.Sleep(3 * time.Second) // use constant instead
if r.objCountChanged {
r.objCountChanged = false
r.enqueueReconcile()
}
}
}()
Done
Done
If there are propagated objects on the apiserver before we install HNC, we will return ignore action here and those objects will not be counted by line 473 (write method will not be called).
For example, if we create namespace a and b, set a to be parent of b, add an object in a. The NumPropagatedObjects will be 1 as expected. Then if we reinstall (or restart) HNC, NumPropagatedObjects will be 0 if we don't have this line.
Added a comment to explain that.
There might be some complications here. config reconciler can set the mode to anything (even an invalid mode). Object reconciler will validate the mode and change it to a valid mode if it is invalid (see getValidateMode).
Ideally, the config reconciler can get a valid mode from an object reconciler by adding& calling GetMode via the TypeSyncer interface. However, if a config reconciler creates (instead of syncs) an object reconciler, the Mode field of the object reconciler will be set to the valid mode when the (first) reconcile is called. If config reconciler calls GetMode before any reconcile happens, it will still get an invalid mode.
This might not be an issue if we only want to know if the mode is propagate in config reconciler (check for propagate or unset mode), but it will be an issue if we want to know if the mode is ignore. To let config reconciler knows the valid mode, we can either move getValidateMode back to config reconciler so config reconciler will set a valid mode to an object reconciler. Or we can see if we can set the Mode field to a valid mode when creating the object reconciler, so that we don't need to wait for the first reconciler to happen.
WDYT?
I might misunderstand that. We agreed on only reporting NumSourceObjects for propagate mode. I thought that meant we would report NumPropagatedObjects for all modes. I will delete the logic if we decide to follow the same rule and only report NumPropagatedObjects for propagate mode as well.
WDYT?
Yes, we need int32 when we write to the status. Changed to int here and converted to int32 in the config reconciler.
Done
Changed to propagatedObjectsLock. Thanks for the suggestion!
Done.
Cool! Sorted in alphabetical order based on APIVersion.
Eh, now I see the downside to putting the Sleep at the beginning of the Reconciler - it means that the regular business logic (e.g. adding/removing types) is also delayed by 3s. I'm not sure we want that. Sorry I missed that.
> How about we write some logic to intercept the calls from the object reconcilers and make sure we only _trigger_ one reconciliation every N seconds? That way, most of the reconciler will still work ASAP. You'll have to write the deduping logic yourself but that should be pretty simple. Talk to Yiqi about how to trigger a periodic event using a long-running goroutine. It'll look something like this in the Setup function:
>> go func() { > for { // have some kind of way to break the loop when the controller exits > time.Sleep(3 * time.Second) // use constant instead > if r.objCountChanged { > r.objCountChanged = false > r.enqueueReconcile() > } > } > }() >
Thanks for the suggestion! I will resolve the comments about tests later after I change to this method. Hopefully it won't take that long after.
Hi @adrianludwin
Thanks so much for the review. I updated the code and replied to all your comments. Feel free to take a look!
Thank you!
Sorry for the terse comments, just trying to get this back to you ASAP. Almost ready to go, just a few last comments
/lgtm
/approve
/assign @rjbez17
/hold
/lgtm
/approve
/hold cancel
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: <a href="https://github.com/kubernetes-sigs/multi-tenancy/pull/542#pullrequestreview-382342732" title="Approved">adrianludwin</a>, <a href="https://github.com/kubernetes-sigs/multi-tenancy/pull/542#issuecomment-604658829" title="Approved">rjbez17</a>, <a href="https://github.com/kubernetes-sigs/multi-tenancy/pull/542#" title="Author self-approved">sophieliu15</a>
The full list of commands accepted by this bot can be found here.
The pull request process is described here
<details >
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
</details>
<!-- META={"approvers":[]} -->
sophieliu15
This PR computes NumPropagatedObjects as a part of HNCConfiguration status. NumPropagatedObjects indicates the number of propagated objects of a specific type created by HNC.
Tested:unit tests, GKE cluster
Issue: #411