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 network configuration logic for Cloud Run V2 API
- Enhance VPC connectivity configuration to support both VPC connector and network interfaces
- Add logic to handle mutually exclusive VPC connector and network interface settings
- Improve logging for VPC configuration options
- Simplify and clarify VPC access configuration in service deployment
  • Loading branch information
dijarvrella committed Feb 27, 2025
commit 46bda6b9863664c5c1440b900092ed8635be237d
50 changes: 32 additions & 18 deletions cmd/cloud-run/pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
@@ -996,16 +996,30 @@ func updateServiceWithOptionsV2(service *run.GoogleCloudRunV2Service, opts confi
}

// Configure VPC connectivity if specified
if opts.VpcNetwork != "" && opts.VpcSubnetwork != "" || opts.VpcConnector != "" || opts.VpcEgress != "" {
if opts.VpcConnector != "" || opts.VpcEgress != "" || (opts.VpcNetwork != "" && opts.VpcSubnetwork != "") {
// Initialize VPC access if not already set
if service.Template.VpcAccess == nil {
service.Template.VpcAccess = &run.GoogleCloudRunV2VpcAccess{}
}

// Set VPC connector if specified
// According to the API requirements, we can set either connector OR network_interfaces, but not both
if opts.VpcConnector != "" {
// If connector is specified, use the connector approach
log.Printf("Setting VPC connector to %s\n", opts.VpcConnector)
service.Template.VpcAccess.Connector = opts.VpcConnector

// Add a note that network/subnetwork settings are ignored when connector is specified
if opts.VpcNetwork != "" && opts.VpcSubnetwork != "" {
log.Printf("Note: VPC network/subnetwork settings are ignored when a connector is specified\n")
}
} else if opts.VpcNetwork != "" && opts.VpcSubnetwork != "" {
// If no connector but network/subnetwork are specified, set up network interfaces
log.Printf("Setting VPC network interfaces for network: %s, subnetwork: %s\n", opts.VpcNetwork, opts.VpcSubnetwork)
networkInterface := &run.GoogleCloudRunV2NetworkInterface{
Network: opts.VpcNetwork,
Subnetwork: opts.VpcSubnetwork,
}
service.Template.VpcAccess.NetworkInterfaces = []*run.GoogleCloudRunV2NetworkInterface{networkInterface}
}

// Set VPC egress setting if specified
@@ -1017,13 +1031,6 @@ func updateServiceWithOptionsV2(service *run.GoogleCloudRunV2Service, opts confi
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
}
}
}

@@ -1207,13 +1214,27 @@ func buildServiceDefinitionV2(projectID string, opts config.DeployOptions) *run.
}

// Configure VPC connectivity if specified
if opts.VpcNetwork != "" && opts.VpcSubnetwork != "" || opts.VpcConnector != "" || opts.VpcEgress != "" {
if opts.VpcConnector != "" || opts.VpcEgress != "" || (opts.VpcNetwork != "" && opts.VpcSubnetwork != "") {
service.Template.VpcAccess = &run.GoogleCloudRunV2VpcAccess{}

// Set VPC connector if specified
// According to the API requirements, we can set either connector OR network_interfaces, but not both
if opts.VpcConnector != "" {
// If connector is specified, use the connector approach
log.Printf("Setting VPC connector to %s\n", opts.VpcConnector)
service.Template.VpcAccess.Connector = opts.VpcConnector

// Add a note that network/subnetwork settings are ignored when connector is specified
if opts.VpcNetwork != "" && opts.VpcSubnetwork != "" {
log.Printf("Note: VPC network/subnetwork settings are ignored when a connector is specified\n")
}
} else if opts.VpcNetwork != "" && opts.VpcSubnetwork != "" {
// If no connector but network/subnetwork are specified, set up network interfaces
log.Printf("Setting VPC network interfaces for network: %s, subnetwork: %s\n", opts.VpcNetwork, opts.VpcSubnetwork)
networkInterface := &run.GoogleCloudRunV2NetworkInterface{
Network: opts.VpcNetwork,
Subnetwork: opts.VpcSubnetwork,
}
service.Template.VpcAccess.NetworkInterfaces = []*run.GoogleCloudRunV2NetworkInterface{networkInterface}
}

// Set VPC egress setting if specified
@@ -1225,13 +1246,6 @@ func buildServiceDefinitionV2(projectID string, opts config.DeployOptions) *run.
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
}
}

// Process secrets if specified