krisnova / naml

Convert Kubernetes YAML to Golang
Apache License 2.0
1.26k stars 38 forks source link

Codify fails when the input yaml object names have a dash in it. #45

Closed fkautz closed 2 years ago

fkautz commented 3 years ago

Took the example stateless app from https://kubernetes.io/docs/tasks/run-application/run-stateless-application-deployment/ and ran it against naml.

[...]
kind: Deployment
metadata:
  name: nginx-deployment
[...]

Ran this through naml:

kubectl get deployments -oyaml | naml c
Error during codify: unable to auto format code: 88:2: expected identifier on left side of :=2021-08-01T18:41:03-07:00 [Critical  ]  unable to auto format code: 88:2: expected identifier on left side of :=

I disabled gofmt to see the actual error and found this:

nginx-deploymentDeployment := &appsv1.Deployment{

We should probably trim illegal characters, though this may in rare circumstances cause a duplicate name. e.g. two deployments on the same system with names nginx-deployment vs nginxdeplolyment

fkautz commented 3 years ago

Looks like we can safely rename all - characters in k8s object names to _ in go. K8s does not allow _ and go does not allow - in variable names.

krisnova commented 3 years ago

pull requests accepted :)

https://github.com/kris-nova/naml/blob/main/codify/codify.go#L140

fkautz commented 3 years ago

working on it :)

fkautz commented 2 years ago

46

fkautz commented 2 years ago

fixed in #46

krisnova commented 2 years ago

closed with #46 released binaries with the patch https://github.com/kris-nova/naml/releases/tag/0.2.4