Skip to content

Commit

Permalink
feat(resources): Add port and cpuidle opts to cloud run struct
Browse files Browse the repository at this point in the history
  • Loading branch information
mahad-akhter committed Oct 31, 2023
1 parent d5333cc commit 8aec541
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/core/resources/gcp/cloudrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type (
Cpu string
Memory string
Generation uint8
Port int32
Envs map[string]string
OutputEnvs map[string]string
Region string // from blueprint
Expand All @@ -41,6 +42,7 @@ type (
MinInstances int32
MaxInstances int32
AllowUnauthenticatedAccess bool
CpuIdle bool
Project string
ServiceName string
}
Expand Down Expand Up @@ -85,10 +87,13 @@ func (c *CloudRunConstructor) Create(name string, region string, config string,
cr.AllowUnauthenticatedAccess = true
cr.Cpu = "2000m"
cr.Memory = "1024Mi"
cr.MinInstances = 1
cr.MaxInstances = 8
cr.MinInstances = 0
cr.MaxInstances = 5
cr.Generation = 2

cr.Port = 8000
cr.CpuIdle = true

// get gcp project from configuration
pconfig := new(GCPConfig)
err := json.Unmarshal([]byte(providerConfig), pconfig)
Expand Down Expand Up @@ -432,12 +437,13 @@ func (r *CloudRun) AllowAccessToAll(ctx context.Context) error {
func (r *CloudRun) GetServiceTemplate(ctx context.Context, wl *Workload) *runpb.Service {

activity.GetLogger(ctx).Info("setting service template for", "revision", r.Revision)
resources := &runpb.ResourceRequirements{Limits: map[string]string{"cpu": r.Cpu, "memory": r.Memory}}
resources := &runpb.ResourceRequirements{Limits: map[string]string{"cpu": r.Cpu, "memory": r.Memory}, CpuIdle: r.CpuIdle}

// unmarshaling the container here assuming that container definition will be specific to a resource
// this can be done at a common location if the container definition turns out to be same for all resources

container := &runpb.Container{Name: wl.Name, Image: wl.Image, Resources: resources}
containerPort := &runpb.ContainerPort{ContainerPort: r.Port}
container := &runpb.Container{Name: wl.Name, Image: wl.Image, Resources: resources, Ports: []*runpb.ContainerPort{containerPort}}

scaling := &runpb.RevisionScaling{MinInstanceCount: r.MinInstances, MaxInstanceCount: r.MaxInstances}

Expand Down

0 comments on commit 8aec541

Please sign in to comment.