Conversation
|
cc @zyy98 |
3e2e7d3 to
08a35ef
Compare
justinsb
left a comment
There was a problem hiding this comment.
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.
Do we need functionConfig?
There was a problem hiding this comment.
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.
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.
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
|
|
||
| type Runner interface { | ||
| Run(context *Context, functionConfig *KubeObject, items []*KubeObject) | ||
| Run(context *Context, functionConfig *KubeObject, items KubeObjects) |
| switch fnRunnerElem.Field(i).Kind() { | ||
| case reflect.String: | ||
| for k, v := range data { | ||
| lowerKey := strings.ToLower(k) |
There was a problem hiding this comment.
I like this approach. We might consider also using the json tag to get the ConfigMap field name.
itemsfrom[]*KubeObjecttoKubeObjects. This aligns the resourceList.items with the latest change in 78748f0#diff-7b055320c11f07c233d6db3fec422e3059d52a0f295a12e02b489aa4a539a50dConfigMap.Dataand custom functionConfig in two formatsFor example, a
SetLabelstruct that implementsRunnerinterface, have itsOwnerandOrgvalue automatically parsed from either 1.SetLabelstype withownerandorgfields or 2.ConfigMaptype withDatafields having keysownerandorgFunctionConfig 1
FunctionConfig 2