Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quoted-strings - support JSON encoded data in single quotes #668

Open
Constantin07 opened this issue Apr 25, 2024 · 2 comments
Open

quoted-strings - support JSON encoded data in single quotes #668

Constantin07 opened this issue Apr 25, 2024 · 2 comments

Comments

@Constantin07
Copy link

For some Kubernetes manifests there are annotation with values in JSON format which have to be quoted in single quotes.

One example is AWS Load balancer Controller: https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.2/guide/ingress/annotations/

Annotation keys and values can only be strings. Advanced format should be encoded as below:
...
json: 'jsonContent'

Linting this fails:

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: echoserver
  annotations:
   ...
    alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS": 443}]'

with error:

aws-loadbalancer-controller/test.yml
  83:53     error    string value is not quoted with double quotes  (quoted-strings)
  86:45     error    string value is not quoted with double quotes  (quoted-strings)

Would be possible to add support for this case instead of settigng quote-type: any (by default we use double)?

@andrewimeson
Copy link
Contributor

What would the logic for this have to look like to be reliable? Suppose quote-type is double, would you expect that a string that contains one or more literal " characters should be exempt from the rule? Would some users not like this, because you can still escape " if you really want to keep strict double quoting?

alb.ingress.kubernetes.io/actions.ssl-redirect: "{\"Type\": \"redirect\", \"RedirectConfig\": { \"Protocol\": \"HTTPS\", \"Port\": \"443\", \"StatusCode\": \"HTTP_301\"}}"

Another workaround is to make it a multiline scalar.

alb.ingress.kubernetes.io/actions.ssl-redirect: >-
  {"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}

I would personally style it with the JSON pretty-printed.

alb.ingress.kubernetes.io/actions.ssl-redirect: >-
  {
    "Type": "redirect",
    "RedirectConfig": {
      "Protocol": "HTTPS",
      "Port": "443",
      "StatusCode": "HTTP_301"
    }
  }

@Constantin07
Copy link
Author

Thanks @andrewimeson, I think your suggestion with JSON pretty-printed works just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants