uselagoon / build-deploy-tool

Tool to generate build resources
2 stars 5 forks source link

fix: tls cleanup error on ingress with no tls #245

Closed rocketeerbkw closed 8 months ago

rocketeerbkw commented 8 months ago

Fixes an error introduced in #241 where attempting to cleanup tls certificates for an ingress that already doesn't have any tls certificates will fail the build.

The build failure error is: jq: error (at <stdin>:175): Cannot iterate over null (null) which is thrown at https://github.com/uselagoon/build-deploy-tool/blob/main/legacy/build-deploy-docker-compose.sh#L1769. The jq sequence includes .spec.tls[] which is not guaranteed to exist.

The fix is to use []? to make jq treat it as optional.

Example ingress with a secret that needs to be cleaned

{
  "ingressClassName": "nginx",
  "rules": [
    {
      "host": "redacted",
      "http": {
        "paths": [
          {
            "backend": {
              "service": {
                "name": "nginx",
                "port": {
                  "name": "http"
                }
              }
            },
            "path": "/",
            "pathType": "Prefix"
          }
        ]
      }
    }
  ],
  "tls": [
    {
      "hosts": [
        "redacted"
      ],
      "secretName": "redacted-tls"
    }
  ]
}

Example ingress with no tls secrets

{
  "ingressClassName": "nginx",
  "rules": [
    {
      "host": "redacted",
      "http": {
        "paths": [
          {
            "backend": {
              "service": {
                "name": "nginx",
                "port": {
                  "name": "http"
                }
              }
            },
            "path": "/",
            "pathType": "Prefix"
          }
        ]
      }
    }
  ]
}