skaffold icon indicating copy to clipboard operation
skaffold copied to clipboard

Cloud Run Port Forwarding Fails with Templating

Open alexwilson1 opened this issue 1 year ago • 1 comments

Bug Report

Description

The skaffold.yaml configuration below is intended to set up port forwarding for a specific Cloud Run service using dynamic USER-based naming. The configuration appears to resolve the service name correctly, but the port forwarding still fails with a "service not found" error.

Configuration

apiVersion: skaffold/v4beta11
kind: Config

manifests:
  helm:
    releases:
      - name: test
        chartPath: "./skaffold/test"
        setValueTemplates:
          "service.name": "{{ .USER }}-test"

build:
  local:
    push: true

  artifacts:
    - image: us-central1-docker.pkg.dev/.../test
      context: context
      docker:
        dockerfile: Dockerfile

deploy:
  cloudrun:
    projectid: ID
    region: REGION

portForward:
  - resourceType: service
    resourceName: "{{ .USER }}-test"
    localPort: 9001

Environment

  • Skaffold Version: v2.13.1
  • Installation Method: Installed via Cloud Code
  • Operating System: macOS 15.0.1

Error Logs

Forwarding service projects/project-id/locations/us-central1/services/user-test to local port 8080
Forwarding service projects/project-id/locations/us-central1/services/user-processing to local port 8081
could not map pods to service default/user-test/0: getting service default/user-test: services "user-test" not found

Expected Behavior

The portForward directive should map the dynamically generated {{ .USER }}-test service name to the specified local port without errors.

Actual Behavior

Despite correctly resolving the {{ .USER }} placeholder in the logs, the port forwarding fails with a "service not found" error.

alexwilson1 avatar Oct 30 '24 19:10 alexwilson1

Even when running skaffold diagnose we get the exact same output (checked MD5/diff) but the templated forwarding field still does not work. Minimal reproducible example included.

Works:

skaffold.yaml

apiVersion: skaffold/v4beta12
kind: Config

manifests:
  rawYaml:
    - resources/*

deploy:
  cloudrun:
    projectid: eng-xxxxxx 
    region: us-central1

portForward:
  - resourceType: service
    resourceName: 'cloud-run-service-name'
    localPort: 9001

Output

skaffold run --port-forward

No tags generated
Starting test...
Starting deploy...
Deploying Cloud Run service:
         cloud-run-service-name
Cloud Run Service cloud-run-service-name finished: Service started. 0/1 deployment(s) still pending
Forwarding service projects/eng-xxxxxx/locations/us-central1/services/cloud-run-service-name to local port 9001
Press Ctrl+C to exit
Proxying to Cloud Run service [cloud-run-service-name] in project [eng-xxxxxx] region [us-central1]
http://127.0.0.1:9001 proxies to https://cloud-run-service-name-98grhvdsak-uc.a.run.app

skaffold diagnose --enable-templating --yaml-only

apiVersion: skaffold/v4beta12
kind: Config
build:
  tagPolicy:
    gitCommit: {}
  local: {}
manifests:
  rawYaml:
    - /Users/yyy/Repos/eng/resources/*
deploy:
  cloudrun:
    projectid: eng-xxxxxx
    region: us-central1
  logs:
    prefix: container
portForward:
  - resourceType: service
    resourceName: cloud-run-service-name
    address: 127.0.0.1
    localPort: 9001

Does not work

apiVersion: skaffold/v4beta12
kind: Config

manifests:
  rawYaml:
    - resources/*

deploy:
  cloudrun:
    projectid: eng-xxxxxx
    region: us-central1

portForward:
  - resourceType: service
    resourceName: '{{ .PREPENDEDNAME }}-run-service-name'
    localPort: 9001

skaffold.env PREPENDEDNAME=cloud

Output:

skaffold run --port-forward

No tags generated
Starting test...
Starting deploy...
Deploying Cloud Run service:
         cloud-run-service-name
Cloud Run Service cloud-run-service-name finished: Service started. 0/1 deployment(s) still pending
Forwarding service projects/eng-xxxxxx/locations/us-central1/services/cloud-run-service-name to local port 8080
Press Ctrl+C to exit
Proxying to Cloud Run service [cloud-run-service-name] in project [eng-xxxxxx] region [us-central1]
http://127.0.0.1:8080 proxies to https://cloud-run-service-name-98grhvdsak-uc.a.run.app

skaffold diagnose --enable-templating --yaml-only

apiVersion: skaffold/v4beta12
kind: Config
build:
  tagPolicy:
    gitCommit: {}
  local: {}
manifests:
  rawYaml:
    - /Users/yyy/Repos/eng/resources/*
deploy:
  cloudrun:
    projectid: eng-xxxxxx
    region: us-central1
  logs:
    prefix: container
portForward:
  - resourceType: service
    resourceName: cloud-run-service-name
    address: 127.0.0.1
    localPort: 9001

Common File

./resources/cloud-run-service.yaml

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: cloud-run-service-name
spec:
  template:
    spec:
      containers:
      - image: gcr.io/cloudrun/hello

alexwilson1 avatar Jan 23 '25 23:01 alexwilson1