kptdev / kpt

Automate Kubernetes Configuration Editing
https://kpt.dev
Apache License 2.0
1.69k stars 226 forks source link

Kpt TS SDK should handle function arguments that are flags #824

Open prachirp opened 4 years ago

prachirp commented 4 years ago
kpt pkg get https://github.com/istio/istio.git/galley/pkg/config/analysis/analyzers/testdata .
kpt fn source testdata/ | docker run -i gcr.io/kpt-functions/istioctl-analyze -d --use-kube=false   
usage: FUNC [-h] [-i INPUT] [-o OUTPUT] [-f FUNCTION_CONFIG]
            [-d [FUNCTION_CONFIG_LITERAL [FUNCTION_CONFIG_LITERAL ...]]]
            [--json] [--log-to-stderr]

FUNC: error: Unrecognized arguments: --use-kube=false.

The SDK is trying to parse the --use-kube=false itself instead of passing it to the istioctl-analyze function as a function config literal.

Shell32-Natsu commented 4 years ago

The parse is not doing by SDK but by this library. I don't find an option to resolve this ambiguity. However we can have 2 work arounds.

  1. Use -d='--use-kube=false ...'.
  2. Use -d ' --use-kube=false ...' (Note the leading space) then trim the string.

If we want to avoid such special ways, we may need to change to other arg parse library.

@frankfarzan Frank you committed the parser code, what do you think?

prachirp commented 4 years ago

Thanks, the e2e tests currently use a third workaround -d--use-kube=false (https://github.com/GoogleContainerTools/kpt-functions-catalog/blob/master/tests/istioctl_analyze.sh#L38)

Shell32-Natsu commented 4 years ago

@prachirp Is this still a blocker for you?

frankfarzan commented 4 years ago

Ideally, all functions should be run by kpt CLI and not directly by docker.

When running imperatively via the CLI, the flags are converted to a ConfigMap and passed as part .functionConfig field of the input ResourceList. As a result, there shouldn't be a flag parsing by the SDK.

Given this, what is this blocking exactly? istioctl example package should be using the CLI.