jsonnet-libs / k8s

Code generator for Jsonnet Kubernetes libraries.
Apache License 2.0
172 stars 98 forks source link

Generator can not properly handle keys/values with operand characters (ie $) #307

Open tyler-adam opened 1 year ago

tyler-adam commented 1 year ago

In the process of trying to create a jsonnet-lib for the Azure Service Operator v2, I discovered that they label one of their attributes $propertyBag. By doing this, the generator trips over itself. Here is an example of the output (trimmed for visibility):

66:11-12 Expected token OPERATOR but got "$": {
    <trimmed>
    '#workspaceCapping':: d.obj(help="\"Storage version of v1api20210601.WorkspaceCapping The daily volume cap for ingestion.\""),
    workspaceCapping: {
      '#with$PropertyBag':: d.fn(help="\"PropertyBag is an unordered set of stashed information that used for properties not directly supported by storage resources, allowing for full fidelity round trip conversions\"", args=[d.arg(name="$propertyBag", type=d.T.object)]),
      with$PropertyBag($propertyBag): { spec+: { workspaceCapping+: { $propertyBag: $propertyBag } } },
      '#with$PropertyBagMixin':: d.fn(help="\"PropertyBag is an unordered set of stashed information that used for properties not directly supported by storage resources, allowing for full fidelity round trip conversions\"\n\n**Note:** This function appends passed data to existing values", args=[d.arg(name="$propertyBag", type=d.T.object)]),
      with$PropertyBagMixin($propertyBag): { spec+: { workspaceCapping+: { $propertyBag+: $propertyBag } } },
      '#withDailyQuotaGb':: d.fn(help="", args=[d.arg(name="dailyQuotaGb", type=d.T.number)]),
      withDailyQuotaGb(dailyQuotaGb): { spec+: { workspaceCapping+: { dailyQuotaGb: dailyQuotaGb } } }
    }
  },
  '#mixin': "ignore",
  mixin: self
}
make: *** [Makefile:55: libs/azure-service-operator] Error 1

There should to be a way for k8s-gen to be aware of invalid characters and fix them however necessary (wrapping keys in quotes, etc - stripping them from variable names).

Duologic commented 1 year ago

Thanks for the report.

For maintainers: this was discussed and verified on Slack, would be an interesting fix.

xvzf commented 1 year ago

I've noticed the same issue for the Aiven operator, where . are included as a field name, expecting something like:

myConfig:
  field.name: "myname"