nephio-project / nephio

Nephio is a Kubernetes-based automation platform for deploying and managing highly distributed, interconnected workloads such as 5G Network Functions, and the underlying infrastructure on which those workloads depend.
Apache License 2.0
93 stars 52 forks source link

WASM compiled functions don't like non-strings in YAML #675

Open liamfallon opened 2 months ago

liamfallon commented 2 months ago

Original issue URL: https://github.com/kptdev/kpt/issues/3626 Original issue user: https://github.com/wleese Original issue created at: 2022-10-17T13:13:02Z Original issue last updated at: 2022-11-15T21:49:53Z Original issue body: ### Expected behavior

Render should succeed regardless of "123" or 123 values in yaml.

Actual behavior

Package "numbers":
[RUNNING] WASM "eu.gcr.io/bolcom-stg-bb8-infra-6e4/set-namespace:unstable"
panic: ValueOf: invalid value

goroutine 6 [running]:
syscall/js.ValueOf({0xcb960, 0x119ed80})
    /usr/local/go/src/syscall/js/js.go:208 +0xf7
syscall/js.Value.Set({{}, 0x7ff8000100000012, 0x1140690}, {0x1a8ec8, 0x6}, {0xcb960, 0x119ed80})
    /usr/local/go/src/syscall/js/js.go:303 +0x8
syscall/js.handleEvent()
    /usr/local/go/src/syscall/js/func.go:95 +0x27
[FAIL] "eu.gcr.io/bolcom-stg-bb8-infra-6e4/set-namespace:unstable" in 0s
Error: wrong Node Kind for  expected: MappingNode was ScalarNode: value: {s(<nil>}

Information

kptfile

apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
  name: numbers
  annotations:
    config.kubernetes.io/local-config: "true"
info:
  description: sample description
pipeline:
  mutators:
  - image: eu.gcr.io/xxxx/set-namespace:unstable
    configPath: package-context.yaml

set-namespace is compiled to WASM.

package-context.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: kptfile.kpt.dev
  annotations:
    config.kubernetes.io/local-config: "true"
data:
  name: example
  namespace: 1234

Saw the behavior with apply-replacements as well.

Steps to reproduce the behavior

Use the above resources with a WASM compiled function such as set-namespace.

Original issue comments: Comment user: https://github.com/wmuizelaar Comment created at: 2022-10-17T18:40:02Z Comment last updated at: 2022-10-17T18:40:02Z Comment body: To add to this: I can also reproduce this without using the WASM function, and in above example only chante the mutator-image to gcr.io/kpt-fn/set-namespace:v0.4.1

Package "kpt-test":
[RUNNING] "gcr.io/kpt-fn/set-namespace:v0.4.1"
[FAIL] "gcr.io/kpt-fn/set-namespace:v0.4.1" in 800ms
  Results:
    [error]: SubObject has unmatched field type: `data/namespace
  Stderr:
    "failed to evaluate function: SubObject has unmatched field type: `data/namespace"
  Exit code: 1

This seems to be caused by YAML automatically thinking that a numeric field should be considered as pure numeric. Should this always be casted as a string (and is this therefore a bug), or should we as a user make sure that when there is a potential for all numeric fields, that we quote those values to enforce them to be read as a string?