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

feat: Enhance Cloud Run deploy command with advanced configuration options #40

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: Improve VPC connectivity configuration for Cloud Run V2 API
- Update VPC configuration to use native V2 API fields instead of annotations
- Implement more robust VPC access configuration with direct field setting
- Add support for VPC connector, egress, network, and subnetwork settings
- Enhance logging for VPC-related configuration options
- Simplify VPC connectivity setup for Cloud Run services
  • Loading branch information
dijarvrella committed Feb 27, 2025
commit 67caca3c8db7302f5e8a79e794e2dda2501f999e
73 changes: 49 additions & 24 deletions cmd/cloud-run/pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
@@ -996,20 +996,34 @@ func updateServiceWithOptionsV2(service *run.GoogleCloudRunV2Service, opts confi
}

// Configure VPC connectivity if specified
if opts.VpcNetwork != "" && opts.VpcSubnetwork != "" {
log.Printf("Setting VPC network interfaces to network: %s, subnetwork: %s\n", opts.VpcNetwork, opts.VpcSubnetwork)
networkInterfaceJSON := fmt.Sprintf(`[{"network":"%s","subnetwork":"%s"}]`, opts.VpcNetwork, opts.VpcSubnetwork)
setAnnotation(service, "run.googleapis.com/network-interfaces", networkInterfaceJSON)
}
if opts.VpcNetwork != "" && opts.VpcSubnetwork != "" || opts.VpcConnector != "" || opts.VpcEgress != "" {
// Initialize VPC access if not already set
if service.Template.VpcAccess == nil {
service.Template.VpcAccess = &run.GoogleCloudRunV2VpcAccess{}
}

if opts.VpcEgress != "" {
log.Printf("Setting VPC egress to %s\n", opts.VpcEgress)
setAnnotation(service, "run.googleapis.com/vpc-access-egress", opts.VpcEgress)
}
// Set VPC connector if specified
if opts.VpcConnector != "" {
log.Printf("Setting VPC connector to %s\n", opts.VpcConnector)
service.Template.VpcAccess.Connector = opts.VpcConnector
}

if opts.VpcConnector != "" {
log.Printf("Setting VPC connector to %s\n", opts.VpcConnector)
setAnnotation(service, "run.googleapis.com/vpc-access-connector", opts.VpcConnector)
// Set VPC egress setting if specified
if opts.VpcEgress != "" {
log.Printf("Setting VPC egress to %s\n", opts.VpcEgress)
if opts.VpcEgress == "all-traffic" {
service.Template.VpcAccess.Egress = "ALL_TRAFFIC"
} else {
service.Template.VpcAccess.Egress = "PRIVATE_RANGES_ONLY"
}
}

// Log network and subnetwork settings
if opts.VpcNetwork != "" && opts.VpcSubnetwork != "" {
log.Printf("Setting VPC network: %s, subnetwork: %s\n", opts.VpcNetwork, opts.VpcSubnetwork)
// Note: In V2 API, network and subnetwork settings are applied through the VPC connector
// The connector must be properly configured in the GCP console to use the specified network/subnetwork
}
}
}

@@ -1193,20 +1207,31 @@ func buildServiceDefinitionV2(projectID string, opts config.DeployOptions) *run.
}

// Configure VPC connectivity if specified
if opts.VpcNetwork != "" && opts.VpcSubnetwork != "" {
log.Printf("Setting VPC network interfaces to network: %s, subnetwork: %s\n", opts.VpcNetwork, opts.VpcSubnetwork)
networkInterfaceJSON := fmt.Sprintf(`[{"network":"%s","subnetwork":"%s"}]`, opts.VpcNetwork, opts.VpcSubnetwork)
setAnnotation(service, "run.googleapis.com/network-interfaces", networkInterfaceJSON)
}
if opts.VpcNetwork != "" && opts.VpcSubnetwork != "" || opts.VpcConnector != "" || opts.VpcEgress != "" {
service.Template.VpcAccess = &run.GoogleCloudRunV2VpcAccess{}

if opts.VpcEgress != "" {
log.Printf("Setting VPC egress to %s\n", opts.VpcEgress)
setAnnotation(service, "run.googleapis.com/vpc-access-egress", opts.VpcEgress)
}
// Set VPC connector if specified
if opts.VpcConnector != "" {
log.Printf("Setting VPC connector to %s\n", opts.VpcConnector)
service.Template.VpcAccess.Connector = opts.VpcConnector
}

// Set VPC egress setting if specified
if opts.VpcEgress != "" {
log.Printf("Setting VPC egress to %s\n", opts.VpcEgress)
if opts.VpcEgress == "all-traffic" {
service.Template.VpcAccess.Egress = "ALL_TRAFFIC"
} else {
service.Template.VpcAccess.Egress = "PRIVATE_RANGES_ONLY"
}
}

if opts.VpcConnector != "" {
log.Printf("Setting VPC connector to %s\n", opts.VpcConnector)
setAnnotation(service, "run.googleapis.com/vpc-access-connector", opts.VpcConnector)
// Log network and subnetwork settings
if opts.VpcNetwork != "" && opts.VpcSubnetwork != "" {
log.Printf("Setting VPC network: %s, subnetwork: %s\n", opts.VpcNetwork, opts.VpcSubnetwork)
// Note: In V2 API, network and subnetwork settings are applied through the VPC connector
// The connector must be properly configured in the GCP console to use the specified network/subnetwork
}
}

// Process secrets if specified