-
Notifications
You must be signed in to change notification settings - Fork 48
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
add flexibility around use of post-renderer #195
add flexibility around use of post-renderer #195
Conversation
d3865d3
to
5021146
Compare
Pull Request Test Coverage Report for Build 2974510048
💛 - Coveralls |
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, modulo an apparent minor logic error in a test and some nitpicks.
pkg/client/actionclient.go
Outdated
postRenderer postrender.PostRenderer | ||
} | ||
|
||
var _ ActionInterface = &actionClient{} | ||
|
||
func concat[T any](s1 []T, s2 ...T) []T { | ||
out := make([]T, len(s1)) |
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.
Would this work?
out := make([]T, len(s1)) | |
out := make([]T, len(s1)+len(s2)) |
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 it turns out, I don't think concat
is necessary at all: https://go.dev/play/p/sqvcMv8lStZ
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 thought its purpose was to separate the inputs from the outputs to prevent unexpected "action at a distance"?
With pure append
this can happen depending in case the first slice has capacity.
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.
Here the capacity of the default...
fields should in theory always match their len, so perhaps this is not a concern? WDYT @joelanford ?
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.
Ah you're right! I knew there was an edge case here. I think it's best to just go ahead and add the concat back in then. This seems like a potential footgun for our future selves if we don't get this 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.
Okay latest commit has a re-added concat method that I think has the optimal memory allocation.
if pr == nil { | ||
return extra | ||
} | ||
return chainedPostRenderer{pr, extra} |
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.
Wow, TIL I learned of a new way to extend a slice.
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.
This ends up being a potentially recursive sort of thing. pr
might itself be a chainedPostRenderer
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.
Well, if chainedPostRenderer
was a struct type, yes. But since it's a slice type, then after multiple calls eventually you just end up with a single long slice, 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.
chainedPostRenderer
is a slice of postrender.PostRenderer
. The way this is setup now, we always return a wrapper chainedPostRenderer
with exactly length 2. It just so happens that pr
might already be a chainedPostRenderer
, and if so, it is also of length 2.
So after two appends, you'd end up with:
out := chainedPostRender{
chainedPostRender{
defaultPostRenderer,
append1,
},
append2,
}
not
out := chainedPostRender{
defaultPostRenderer,
append1,
append2,
}
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.
Right, we get a slice whose first element is a slice. The underlying type of pr
does not matter here...
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.
So, should we do anything about this? If user stacks up four renderers, we end up with this leaning tree of two-element ChainedPostRenderers
, and the %d
on line 98 is going to be somewhat misleading/confusing - they will get a sequence of error messages all mentioning a combination of 1 and 0...
Perhaps use append
if pr
successfully type-asserts as a chainedPostRenderer?
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.
the %d on line 98 is going to be somewhat misleading/confusing
good point!
i had the type assertion thing in an early draft and dropped it for simplicity, but it does seems worthwhile, so i'll add that back in. thanks!
5021146
to
ef924e0
Compare
2a19ba1
to
f799cce
Compare
f799cce
to
0e7ad5a
Compare
With the helm-operator
pkg/client
libraries today, the amount of control users have for configuring post renders is somewhat minimal:This PR adds a new
chainedPostRenderer
and some helper functional options that simplify the process of overriding or chaining more post renderers during installs and upgrades.This PR also exposes the default post renderer as an overrideable function, making it possible to disable the default or provide an alternative.
This should help resolve and issue we are having in rukpak: operator-framework/rukpak#517 (comment)
Lastly, this PR bumps the repo to Go 1.18 (which was necessary to implement a generic slice
concat
function)Closes #194