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

fix(gcp): add cloud run cpu service configuration. #653

Merged
merged 3 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
2 changes: 2 additions & 0 deletions cloud/gcp/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type GcpImports struct {
}

type GcpCloudRunConfig struct {
Cpus float64
Memory int
Timeout int
MinInstances int `mapstructure:"min-instances"`
Expand All @@ -49,6 +50,7 @@ type GcpConfig struct {
}

var defaultCloudRunConfig = &GcpCloudRunConfig{
Cpus: 0.25,
Memory: 512,
Timeout: 300,
MinInstances: 0,
Expand Down
1 change: 1 addition & 0 deletions cloud/gcp/deploy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func (p *NitricGcpPulumiProvider) Service(ctx *pulumi.Context, parent pulumi.Res
},
Resources: cloudrun.ServiceTemplateSpecContainerResourcesArgs{
Limits: pulumi.StringMap{
"cpu": pulumi.Sprintf("%2f", unitConfig.CloudRun.Cpus),
"memory": pulumi.Sprintf("%dMi", unitConfig.CloudRun.Memory),
},
},
Expand Down
2 changes: 1 addition & 1 deletion cloud/gcp/deploytf/.nitric/modules/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ resource "google_cloud_run_service" "service" {
resources {
limits = {
# TODO: enable cpu configuration
tjholm marked this conversation as resolved.
Show resolved Hide resolved
# cpu = "1000m"
cpu = "${var.cpus}"
memory = "${var.memory_mb}Mi"
}
}
Expand Down
6 changes: 6 additions & 0 deletions cloud/gcp/deploytf/.nitric/modules/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ variable "memory_mb" {
default = 512
}

variable "cpus" {
description = "The amount of cpus to allocate to the CloudRun service"
type = number
default = 0.25
}

variable "container_concurrency" {
description = "The number of concurrent requests the CloudRun service can handle"
type = number
Expand Down
Binary file modified cloud/gcp/deploytf/generated/api/jsii/api-0.0.0.tgz
Binary file not shown.
Binary file modified cloud/gcp/deploytf/generated/bucket/jsii/bucket-0.0.0.tgz
Binary file not shown.
Binary file not shown.
Binary file modified cloud/gcp/deploytf/generated/policy/jsii/policy-0.0.0.tgz
Binary file not shown.
Binary file modified cloud/gcp/deploytf/generated/queue/jsii/queue-0.0.0.tgz
Binary file not shown.
Binary file modified cloud/gcp/deploytf/generated/schedule/jsii/schedule-0.0.0.tgz
Binary file not shown.
Binary file modified cloud/gcp/deploytf/generated/secret/jsii/secret-0.0.0.tgz
Binary file not shown.
20 changes: 20 additions & 0 deletions cloud/gcp/deploytf/generated/service/Service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type Service interface {
ConstructNodeMetadata() *map[string]interface{}
ContainerConcurrency() *float64
SetContainerConcurrency(val *float64)
Cpus() *float64
SetCpus(val *float64)
// Experimental.
DependsOn() *[]*string
// Experimental.
Expand Down Expand Up @@ -138,6 +140,16 @@ func (j *jsiiProxy_Service) ContainerConcurrency() *float64 {
return returns
}

func (j *jsiiProxy_Service) Cpus() *float64 {
var returns *float64
_jsii_.Get(
j,
"cpus",
&returns,
)
return returns
}

func (j *jsiiProxy_Service) DependsOn() *[]*string {
var returns *[]*string
_jsii_.Get(
Expand Down Expand Up @@ -414,6 +426,14 @@ func (j *jsiiProxy_Service) SetContainerConcurrency(val *float64) {
)
}

func (j *jsiiProxy_Service) SetCpus(val *float64) {
_jsii_.Set(
j,
"cpus",
val,
)
}

func (j *jsiiProxy_Service) SetDependsOn(val *[]*string) {
_jsii_.Set(
j,
Expand Down
2 changes: 2 additions & 0 deletions cloud/gcp/deploytf/generated/service/ServiceConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type ServiceConfig struct {
StackId *string `field:"required" json:"stackId" yaml:"stackId"`
// The number of concurrent requests the CloudRun service can handle 80.
ContainerConcurrency *float64 `field:"optional" json:"containerConcurrency" yaml:"containerConcurrency"`
// The amount of cpus to allocate to the CloudRun service 0.25.
Cpus *float64 `field:"optional" json:"cpus" yaml:"cpus"`
// The amount of memory to allocate to the CloudRun service in MB 512.
MemoryMb *float64 `field:"optional" json:"memoryMb" yaml:"memoryMb"`
// The timeout for the CloudRun service in seconds 10.
Expand Down
Binary file modified cloud/gcp/deploytf/generated/service/jsii/service-0.0.0.tgz
Binary file not shown.
1 change: 1 addition & 0 deletions cloud/gcp/deploytf/generated/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func init() {
_jsii_.MemberProperty{JsiiProperty: "cdktfStack", GoGetter: "CdktfStack"},
_jsii_.MemberProperty{JsiiProperty: "constructNodeMetadata", GoGetter: "ConstructNodeMetadata"},
_jsii_.MemberProperty{JsiiProperty: "containerConcurrency", GoGetter: "ContainerConcurrency"},
_jsii_.MemberProperty{JsiiProperty: "cpus", GoGetter: "Cpus"},
_jsii_.MemberProperty{JsiiProperty: "dependsOn", GoGetter: "DependsOn"},
_jsii_.MemberProperty{JsiiProperty: "environment", GoGetter: "Environment"},
_jsii_.MemberProperty{JsiiProperty: "eventTokenOutput", GoGetter: "EventTokenOutput"},
Expand Down
Binary file modified cloud/gcp/deploytf/generated/stack/jsii/stack-0.0.0.tgz
Binary file not shown.
Binary file modified cloud/gcp/deploytf/generated/topic/jsii/topic-0.0.0.tgz
Binary file not shown.
1 change: 1 addition & 0 deletions cloud/gcp/deploytf/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (a *NitricGcpTerraformProvider) Service(stack cdktf.TerraformStack, name st
Image: jsii.String(imageId),
Environment: &jsiiEnv,
StackId: a.Stack.StackIdOutput(),
Cpus: jsii.Number(typeConfig.CloudRun.Cpus),
MemoryMb: jsii.Number(typeConfig.CloudRun.Memory),
TimeoutSeconds: jsii.Number(typeConfig.CloudRun.Timeout),
BaseComputeRole: a.Stack.BaseComputeRoleOutput(),
Expand Down
Loading