-
Notifications
You must be signed in to change notification settings - Fork 41
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
Improve functionRunner interface #599
base: master
Are you sure you want to change the base?
Conversation
cc @zyy98 |
3e2e7d3
to
08a35ef
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.
A few thoughts, but I like the direction!
// `items` is parsed from the STDIN "ResourceList.Items". | ||
// `functionConfig` is from the STDIN "ResourceList.FunctionConfig". The value is parsed from a `CustomFnConfig` type | ||
// "owner" and "org" field. | ||
func (r *CustomFnConfig) Run(ctx *fn.Context, functionConfig *fn.KubeObject, items fn.KubeObjects) { |
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.
Do we need functionConfig
?
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'm thinking about some special handling. Like set-namespace supports variant constructor by accepting a kptfile.kpt.dev
named "ConfigMap"
|
||
// This example uses a CustomFnConfig object, which implements `Runner.Run` methods. | ||
func Example_asMainCustomFnConfig() { | ||
file, _ := os.Open("./data/runner-customFnConfig.yaml") |
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'd move these to golden tests, because that keeps the function itself cleaner and shows how to test!
// `functionConfig` is from the STDIN "ResourceList.FunctionConfig". The value has been assigned to the r.Labels | ||
// the functionConfig is validated to have kind "SetLabels" and apiVersion "fn.kpt.dev/v1alpha1" | ||
func (r *SetLabels) Run(ctx *fn.Context, functionConfig *fn.KubeObject, items []*fn.KubeObject) { | ||
// `functionConfig` is from the STDIN "ResourceList.FunctionConfig". The value is parsed from a `ConfigMap` type |
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.
Are we switching away from the "CRD" style for backwards compatibility? I find the ConfigMap approach much harder to think about, and we don't get any type-assistance.
I'd rather think about how to map from a ConfigMap to a CRD, which I think will also help with kptdev/kpt#3351
@@ -15,5 +15,5 @@ | |||
package fn | |||
|
|||
type Runner interface { | |||
Run(context *Context, functionConfig *KubeObject, items []*KubeObject) | |||
Run(context *Context, functionConfig *KubeObject, items KubeObjects) |
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 like it!
switch fnRunnerElem.Field(i).Kind() { | ||
case reflect.String: | ||
for k, v := range data { | ||
lowerKey := strings.ToLower(k) |
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 like this approach. We might consider also using the json
tag to get the ConfigMap field name.
items
from[]*KubeObject
toKubeObjects
. This aligns the resourceList.items with the latest change in 78748f0#diff-7b055320c11f07c233d6db3fec422e3059d52a0f295a12e02b489aa4a539a50dConfigMap.Data
and custom functionConfig in two formatsFor example, a
SetLabel
struct that implementsRunner
interface, have itsOwner
andOrg
value automatically parsed from either 1.SetLabels
type withowner
andorg
fields or 2.ConfigMap
type withData
fields having keysowner
andorg
FunctionConfig 1
FunctionConfig 2