operator-framework/helm-operator-plugins

:"error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go struct field Watch.reconcilePeriod of type time.Duration

camilamacedo86 opened this issue · 4 comments

An issue faced when the container started.

$ kubectl logs deployment.apps/nginx-operator-controller-manager -n nginx-operator-system -c manager
{"level":"info","ts":1592848356.2490077,"logger":"setup","msg":"version information","go":"go1.13.12","GOOS":"linux","GOARCH":"amd64","helm-operator":"0.0.0+git"}
{"level":"info","ts":1592848356.2490747,"logger":"setup","msg":"watching all namespaces"}
{"level":"info","ts":1592848356.6065652,"logger":"controller-runtime.metrics","msg":"metrics server is starting to listen","addr":"0.0.0.0:8383"}
{"level":"error","ts":1592848356.6477711,"logger":"setup","msg":"unable to load watches.yaml","path":"./watches.yaml","error":"error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go struct field Watch.reconcilePeriod of type time.Duration"}

However, should work; https://play.golang.org/p/VO0VOKnR7-A

See:

$ make run
go run ../main.go
{"level":"info","ts":1592863003.176841,"logger":"setup","msg":"version information","go":"go1.13.12","GOOS":"darwin","GOARCH":"amd64","helm-operator":"0.0.0+git"}
{"level":"info","ts":1592863003.176909,"logger":"setup","msg":"watching all namespaces"}
{"level":"info","ts":1592863003.541318,"logger":"controller-runtime.metrics","msg":"metrics server is starting to listen","addr":"0.0.0.0:8383"}
- group: helm.sdk.operatorframework.io
  version: v1
  kind: Nginx
  chart: ./helm-charts/nginx
  maxConcurrentReconciles: 4
  reconcilePeriod: 0s
  overrideValues:
    image.repository: nginx

{"level":"error","ts":1592863003.542636,"logger":"setup","msg":"unable to load watches.yaml","path":"./watches.yaml","error":"error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go struct field Watch.reconcilePeriod of type time.Duration"}
exit status 1
make: *** [Makefile:9: run] Error 1

The problem was the value used in the example.

Oh yeah, that's why I was using gopkg.in/yaml.v2. I updated to use the metav1.Duration type from k8s.io/apimachinery and added a unit test that will catch this regression in the future. See joelanford@9934e02

Catcher.