garden-io / garden

Automation for Kubernetes development and testing. Spin up production-like environments for development, testing, and CI on demand. Use the same configuration and workflows at every step of the process. Speed up your builds and test runs via shared result caching
https://garden.io
Mozilla Public License 2.0
3.38k stars 273 forks source link

Garden does not support stringified number for service port name #3441

Open worldofgeese opened 1 year ago

worldofgeese commented 1 year ago

Bug

Garden will fail on validation when a port name used in a Helm chart can't be a stringified number e.g. "5000".

Current Behavior

If port name is any stringified number, garden deploy will error:

web-service.yaml

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert -f compose-roachless.yml -f compose-roachless.override.yml -c
    kompose.version: 1.27.0 (b0ed6a2c9)
  creationTimestamp: null
  labels:
    io.kompose.service: web
  name: web
spec:
  ports:
    - name: "5000"
      port: 5000
      targetPort: 5000
  selector:
    io.kompose.service: web
status:
  loadBalancer: {}

Result of garden deploy

🌍  Running in namespace default in environment default
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

βœ” providers                 β†’ Getting status... β†’ Cached
   β„Ή Run with --force-refresh to force a refresh of provider statuses.
βœ” graph                     β†’ Resolving 1 modules... β†’ Done
βœ” compose-roachless         β†’ Building version v-0c13045269... β†’ Done (took 0 sec)

Failed getting status for service 'compose-roachless' (from module 'compose-roachless'). Here is the output:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Error validating getServiceStatus helm output from provider local-kubernetes: key .forwardablePorts[0][name]
 with value "5000" fails to match the required pattern: /^(?![0-9]+$)(?!.*-$)(?!-)[a-z0-9-]{1,63}$/
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1 deploy action(s) failed!

Expected behavior

Garden should validate stringified numbers as correct and not error on deploy.

Reproducible example

Create a minimal project example then use the module and deployment/service manifests contained in this gist to deploy: https://gist.github.com/worldofgeese/be0f5b7d4907aef14aab53d8e41e65eb

Workaround

Rename port name to e.g. "http".

Suggested solution(s)

Loosen regex validation to allow for stringified numbers.

Your environment

garden version 0.12.47

vvagaytsev commented 1 year ago

In order to address this we can improve the output error message to be more explanatory. The error comes from identifierRegex in constants.ts.