-
Notifications
You must be signed in to change notification settings - Fork 38.9k
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
[Federation] Add a SchedulingAdapter that can extend the FederatedTypeAdapter and that provides hooks for scheduling objects into clusters. #45563
Conversation
Hi @perotinus. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
@k8s-bot ok to test |
774b40a
to
83ebb8e
Compare
Good progress! I think I'd like to see this work follow #45374's example of keeping functions small enough to be unit tested. It may be worth considering rebasing on that work to ensure that reconcile with the proposed hook methods remains testable. Reviewed 12 of 13 files at r1, 11 of 11 files at r2. federation/pkg/federatedtypes/adapter.go, line 58 at r2 (raw file):
Consider following the approach suggested in #45497 (comment) to minimize unnecessary no-ops in adapters that don't need these functions. federation/pkg/federatedtypes/replicaset.go, line 95 at r2 (raw file):
Remove? federation/pkg/federatedtypes/replicaset.go, line 172 at r2 (raw file):
I reviewed @irfanurrehman's PR first, which used more specific hook methods instead of the generic events you propose here. Consider coordinating with him to come to agreement on a mutually acceptable path forward. federation/pkg/federatedtypes/replicaset.go, line 173 at r2 (raw file):
Why is it desirable to return the function vs having the client call invoke it directly? Same comment for the other hook implementations. Are you intending to ensure unit test coverage for the hook methods? federation/pkg/federation-controller/sync/controller.go, line 335 at r2 (raw file):
As per our offline discussion, I think it is preferable to minimize the scope of any one function such that logging can be done inline and testing can still reliably validate failure modes without having to look at error text. federation/pkg/federation-controller/sync/controller.go, line 473 at r2 (raw file):
I switched to returning 'ok' in #45374. Unless I'm missing something, 'double sure' won't do anything but mask potential errors. federation/pkg/federation-controller/sync/replicasetcontroller_test.go, line 47 at r2 (raw file):
Should this be removed? I'm guessing #44525 ensures this anyway, consider rebasing on top of that. federation/pkg/federation-controller/util/podanalyzer/pod_helper.go, line 20 at r2 (raw file):
It looks like the changes to this package impact the deployment controller, but there are no changes to that controller included in this PR. Consider submitting the pod changes in a separate PR to simplify life for your reviewers. Comments from Reviewable |
83ebb8e
to
f0d9d89
Compare
a4d9a4d
to
bb0510d
Compare
bb0510d
to
72d85bb
Compare
Review status: 5 of 22 files reviewed at latest revision, 8 unresolved discussions, some commit checks failed. federation/pkg/federatedtypes/adapter.go, line 58 at r2 (raw file): Previously, marun (Maru Newby) wrote…
Done. federation/pkg/federatedtypes/replicaset.go, line 95 at r2 (raw file): Previously, marun (Maru Newby) wrote…
Done. federation/pkg/federatedtypes/replicaset.go, line 173 at r2 (raw file): Previously, marun (Maru Newby) wrote…
I've modified this I have to think a bit more about test coverage for the hook methods: I agree that it makes sense and should be done, but passing in the federated informer will make these tests a bit more ugly. Perhaps the solution here is to have the hooks be lightweight wrappers that call into other methods. federation/pkg/federation-controller/sync/controller.go, line 335 at r2 (raw file): Previously, marun (Maru Newby) wrote…
Done. federation/pkg/federation-controller/sync/controller.go, line 473 at r2 (raw file): Previously, marun (Maru Newby) wrote…
I rebased on top of your PR, so this should be good now. federation/pkg/federation-controller/sync/replicasetcontroller_test.go, line 47 at r2 (raw file): Previously, marun (Maru Newby) wrote…
Done. federation/pkg/federation-controller/util/podanalyzer/pod_helper.go, line 20 at r2 (raw file): Previously, marun (Maru Newby) wrote…
These changes should be isolated to the first commit which is being reviewed in #45252. However, that PR may be dropped because of testing issues, in which case the code to modify the pod analysis method will potentially be moved here. Comments from Reviewable |
72d85bb
to
d8129ed
Compare
@k8s-bot test this |
d06a639
to
4323531
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.
Hope u can take care of these.
thanks in advance!
NewTestObject(namespace string) pkgruntime.Object | ||
} | ||
|
||
// SchedulingStatus contains the status of the objects that are being | ||
// scheduled into joined clusters. | ||
type SchedulingStatus struct { |
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.
Please update these to generic types (or make them interfaces, where they are passed/used).
|
||
// SchedulingInfo wraps the information that a SchedulingAdapter needs | ||
// to update objects per a schedule. | ||
type SchedulingInfo struct { |
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.
as above, hpa has different set of properties to pass around!
glog.Fatalf("Adapter for kind %q does not properly implement SchedulingAdapter.", kind) | ||
return statusError | ||
} | ||
schedulingInfo, err = schedulingAdapter.GetSchedule(obj, key, selectedClusters, informer) |
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.
Please ensure that, the cluster objects are queried and passed as one set here (probably as a map), indicating which cluster has the object, and which does not (one way is use a map of same size as current available clusters with nil values identifying absence of object in that cluster).
Other option I could think of is; don't query the objects here at all; just pass the informer here (as you are doing), and let this interface or any other one in the flow later return the existing set vs scheduled set of objects (or only scheduled set of objects indicating, in which cluster to update, into which cluster to delete and which cluster to create ... (Or else I can't think of how exactly to do it ).
Probably u can think of on these lines:
say in the rs controller schedule, as a result of schedule, the local cluster rs can be deleted from some clusters also
so there has to be some way for this reconcile to be able to finalise the result comparing the original set of object vs new set of objects including all three conditions:
- if not exist in a cluster in existing set, schedule says create it.
- if exist in a cluster in existing set, schedule says update it.
- if exist in a cluster in existing set, schedule says delete it.
Also the above to be done without race conditions (means objects or set of cluster objects queried at one location to come up with the schedule result); and probably then the originally queried set and the newly scheduled set compared to arrive at cluster operations.
While I think further refinement is possible, code freeze is looming and I think supporting replicasets with the sync controller represents is a necessary evolution towards a more maintainable codebase. Modulo the minor concerns inline, and the need for a test-specific equivalency check on the adapter interface, I'll be ready to lgtm. Reviewed 7 of 20 files at r4, 7 of 22 files at r6, 7 of 7 files at r7. federation/pkg/federatedtypes/adapter.go, line 63 at r7 (raw file):
(No action required) Would it make sense to put the scheduling-specific stuff into its own file? federation/pkg/federatedtypes/adapter.go, line 65 at r7 (raw file): Previously, irfanurrehman wrote…
I think it would be preferable to merge this very specific proposal and have your follow-on make it generic. federation/pkg/federation-controller/sync/controller.go, line 449 at r7 (raw file):
(No action required) Consider simplifying as follows: schedulingInfo, err := getSchedulingInfo(adapter, obj, key, selectedClusters, informer)
if err {
return statusError
} federation/pkg/federation-controller/sync/controller.go, line 453 at r7 (raw file):
Is this return statement necessary given that federation/pkg/federation-controller/sync/controller.go, line 470 at r7 (raw file):
ditto federation/pkg/federation-controller/sync/controller.go, line 522 at r7 (raw file):
Saving a copy of the kind could be done outside of the loop. federation/pkg/federation-controller/sync/controller.go, line 537 at r7 (raw file):
Again, not sure what the point is of returning past federation/pkg/federation-controller/sync/controller.go, line 570 at r7 (raw file):
Why is it desirable to separating clusters into a slice for each of selected and unselected? Did you consider using a mapping of cluster name to a boolean indicating selection status? If separate iteration is preferable, consider breaking this functiondecomposing this function to simplify testing: operations := make([]util.FederatedOperation, 0)
getOperationsForSelectedClusters(operations, ...)
getOperationsForUnselectedClusters(operations, ...) federation/pkg/federation-controller/sync/controller.go, line 573 at r7 (raw file):
s/adapter.Kind()/kind/ federation/pkg/federation-controller/sync/controller_test.go, line 163 at r7 (raw file):
Are there more test changes pending? The changes to Comments from Reviewable |
4323531
to
6b26f0a
Compare
…eAdapter and that provides hooks for scheduling objects into clusters.
6b26f0a
to
1130b36
Compare
Review status: 6 of 7 files reviewed at latest revision, 15 unresolved discussions. federation/pkg/federatedtypes/adapter.go, line 63 at r7 (raw file): Previously, marun (Maru Newby) wrote…
Done. federation/pkg/federatedtypes/adapter.go, line 65 at r7 (raw file): Previously, marun (Maru Newby) wrote…
I'm inclined to agree: I don't understand the HPA use case as fully as you do, so my efforts to make this generic would probably not be as effective and clean as yours. federation/pkg/federatedtypes/adapter.go, line 74 at r7 (raw file): Previously, irfanurrehman wrote…
That makes sense. In light of Maru's comment above, I think I'd prefer to defer this work to you, since you understand your use case better. federation/pkg/federation-controller/sync/controller.go, line 449 at r7 (raw file): Previously, marun (Maru Newby) wrote…
Do you mean extract a method that gets the scheduling info and hides the logic for casting and checking for isScheduleObject? I can do that, but it seems a bit odd to extract just this one scheduling method call and leave the other two inline below. federation/pkg/federation-controller/sync/controller.go, line 453 at r7 (raw file): Previously, marun (Maru Newby) wrote…
Done. federation/pkg/federation-controller/sync/controller.go, line 455 at r7 (raw file): Previously, irfanurrehman wrote…
I agree that this is a good strategy. In the interest of getting this PR into 1.7 and not blocking, I'd prefer to defer this work. federation/pkg/federation-controller/sync/controller.go, line 470 at r7 (raw file): Previously, marun (Maru Newby) wrote…
Done. federation/pkg/federation-controller/sync/controller.go, line 522 at r7 (raw file): Previously, marun (Maru Newby) wrote…
Done. federation/pkg/federation-controller/sync/controller.go, line 537 at r7 (raw file): Previously, marun (Maru Newby) wrote…
This is probably an old habit from my Objective-C days, where C assertions were disabled in release-mode code so the pattern was to assert and then return. Removed. federation/pkg/federation-controller/sync/controller.go, line 570 at r7 (raw file): Previously, marun (Maru Newby) wrote…
This seemed simpler in my head. I think it would have been nice to express this with set operations, but in the absence of that, the two slices seemed like a good solution. Also, not that this code went in in a different PR. Would you be OK deferring changing this until a later PR? I don't really want to bolt testing onto this PR, I'd rather get this in and then think about how to factor it cleanly for good tests without a looming deadline. federation/pkg/federation-controller/sync/controller.go, line 573 at r7 (raw file): Previously, marun (Maru Newby) wrote…
Done. federation/pkg/federation-controller/sync/controller_test.go, line 163 at r7 (raw file): Previously, marun (Maru Newby) wrote…
Yes, I agree. Since the code freeze is looming, are you OK doing more extensive test changes in a follow up? federation/pkg/federatedtypes/replicaset.go, line 172 at r2 (raw file): Previously, marun (Maru Newby) wrote…
Done. Comments from Reviewable |
Thanks for the review! I'm working on the test equivalency change now. Review status: 6 of 7 files reviewed at latest revision, 15 unresolved discussions. Comments from Reviewable |
@perotinus: The following test(s) failed:
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
@k8s-bot pull-kubernetes-e2e-gce-etcd3 test this |
OK, the test equivalency changes are pushed, and will soon be added to #46527. |
/lgtm Reviewed 4 of 4 files at r9. federation/pkg/federation-controller/sync/controller.go, line 449 at r7 (raw file): Previously, perotinus (Jonathan MacMillan) wrote…
(No action required) I meant to suggest that you do the same for the other 2 methods as well. I think it would be cleaner, but it can be done in the future if at all. federation/pkg/federation-controller/sync/controller.go, line 570 at r7 (raw file): Previously, perotinus (Jonathan MacMillan) wrote…
Yeah, it's fine for now. federation/pkg/federation-controller/sync/controller_test.go, line 163 at r7 (raw file): Previously, perotinus (Jonathan MacMillan) wrote…
I'm ok with that given that the proposed change shouldn't result in a change in coverage, just that the coverage could stand to be improved. Comments from Reviewable |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: marun, perotinus Assign the PR to them by writing
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
Review status: all files reviewed at latest revision, 8 unresolved discussions. federation/pkg/federation-controller/sync/controller.go, line 449 at r7 (raw file): Previously, marun (Maru Newby) wrote…
OK, SGTM. Comments from Reviewable |
/approved |
Automatic merge from submit-queue (batch tested with PRs 46801, 45184, 45930, 46192, 45563) |
Automatic merge from submit-queue (batch tested with PRs 47403, 46646, 46906, 46527, 46792) [Federation] Convert the ReplicaSet controller to a sync controller. See #45563 for previous discussion: that PR was split into two, with this one containing the actual conversion work and that one containing the implementation of the scheduling methods in the sync controller. **Release note**: ```release-note NONE ```
Release note: