-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Refactor Context into separate cloudup and nodeup types #14444
Conversation
/retest |
I really like this change, but since it introduces generics and such, I'll let others the opportunity to voice their opinions as well. /lgtm |
Let's keep this open until @justinsb has a chance to take a look. Also, keep in mind that KubeCon NA is next week. |
Is there a broader goal here @johngmyers ? I do think we should adopt generics, and I do like the idea of separating the cloud and node tasks from each other. But right now this puts relatively complex type signatures into every Task. I tried using a type alias ( |
@justinsb the goal is fundamentally to make it clear through the type system that the two different types of tasks have different things available to them. When I was refactoring the PKI code I was particularly frustrated by the fact that, without generics, I couldn't represent through the type system that cloudup tasks could create new keypairs, whereas nodeup tasks could only read the keypairs that already existed. I'm also a bit annoyed that nodeup tasks have to implement |
OK, I think it's a good goal, the generic syntax is just pretty awkward right now. I'm almost inclined to see if we can just make them different types and not use generics, but when I've tried it ends up with problems on the execution engine and localtarget. So I appreciate that you actually got this working :-) Can we discuss more in office hours? |
/hold |
I had a rough go in #14457, let's talk about the alternatives... I would really like to use generics BTW, the place which really bugs me is if we can replace our reflection-backed dispatching on the Render / Find etc methods with something like
|
We might be able to handle things like |
Could we implement a type DefaultDeltaRun[T SubContext] struct {
// Name *string ?
}
func (e *DefaultDeltaRun[T])) Run(c *fi.Context[T]) error {
//Similar to body of current DefaultDeltaRunMethod
} |
Might need to be type DefaultDeltaRun[T HasFind, C SubContext] struct {
// Name *string ?
}
func (e *DefaultDeltaRun[T, C])) Run(c *fi.Context[C]) error {
//Similar to body of current DefaultDeltaRunMethod
} |
To answer my question about I tried creating: type DeltaRun struct{}
var _ Task = &DeltaRun{}
func (d *DeltaRun) Run(c *Context) error {
return defaultDeltaRunMethod(d, c)
} I also had to make The problem was that I then tried: type HasFind interface {
Task
Find(c *Context) (HasFind, error)
} and then modifying if hasFind, ok := ts.task.(HasFind); ok {
results[index] = defaultDeltaRunMethod(hasFind, e.context)
} else {
results[index] = ts.task.Run(e.context)
} There were two problems:
In all, such a refactor doesn't look like it would gain much. |
I think I had a breakthrough ... I like the approach, my objection has always been about exposing the generic implementation to all the tasks etc. While type definitions didn't work right ( I've sent a PR to this PR: johngmyers#21 ... although I'm not sure that the tests are running there, so I might have to send a WIP PR here instead. Let me know what you think @johngmyers ... I can probably rebase if needed, but this would make me happy - we get generics, we split the types, and we don't have to repeat the generic type names everywhere. I don't love my name |
7f748eb
to
721ed2d
Compare
721ed2d
to
91da98b
Compare
/retest |
/hold cancel |
Failing e2e tests should be fixed by #14800 |
91da98b
to
7c3e323
Compare
/retest |
@justinsb is this good to go now? |
I'm good with it if you are :-) /approve /hold to make sure you're happy too @johngmyers This is really nice BTW - thanks for doing this! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: justinsb The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold cancel |
This separates the
Context
,Task
, and related types to distinguish those used in cloudup from those used in nodeup. Followup PRs will move some fields only used in cloudup intoCloudupContext
.The basics of this refactor are: