diff --git a/deploy/app_service.go b/deploy/app_service.go index 9d22e20..5f54e7b 100644 --- a/deploy/app_service.go +++ b/deploy/app_service.go @@ -57,11 +57,13 @@ type ServiceAppArgs struct { } type ServiceAppDeployOptions struct { - SkipRunsd bool `json:"skip_runsd"` - CPULimit float64 `json:"cpu_limit" default:"1"` - MemoryLimit int `json:"memory_limit" default:"256"` - MinScale int `json:"min_scale" default:"0"` - MaxScale int `json:"max_scale" default:"100"` + SkipRunsd bool `json:"skip_runsd"` + CPULimit float64 `json:"cpu_limit" default:"1"` + MemoryLimit int `json:"memory_limit" default:"256"` + MinScale int `json:"min_scale" default:"0"` + MaxScale int `json:"max_scale" default:"100"` + CPUThrottling bool `json:"cpu_throttling" default:"true"` + ExecutionEnvironment string `json:"execution_environment" default:"gen1"` } func NewServiceAppDeployOptions(in map[string]interface{}) (*ServiceAppDeployOptions, error) { @@ -319,11 +321,13 @@ func (o *ServiceApp) Plan(ctx context.Context, pctx *config.PluginContext, r *re IsPublic: fields.Bool(!o.Props.Private), EnvVars: fields.Map(envVars), - CloudSQLInstances: fields.Sprintf(strings.Join(cloudSQLconnFmt, ","), cloudSQLconnNames...), - MinScale: fields.Int(o.DeployOpts.MinScale), - MaxScale: fields.Int(o.DeployOpts.MaxScale), - MemoryLimit: fields.String(fmt.Sprintf("%dMi", o.DeployOpts.MemoryLimit)), - CPULimit: fields.String(fmt.Sprintf("%dm", int(o.DeployOpts.CPULimit*1000))), + CloudSQLInstances: fields.Sprintf(strings.Join(cloudSQLconnFmt, ","), cloudSQLconnNames...), + MinScale: fields.Int(o.DeployOpts.MinScale), + MaxScale: fields.Int(o.DeployOpts.MaxScale), + MemoryLimit: fields.String(fmt.Sprintf("%dMi", o.DeployOpts.MemoryLimit)), + CPULimit: fields.String(fmt.Sprintf("%dm", int(o.DeployOpts.CPULimit*1000))), + ExecutionEnvironment: fields.String(o.DeployOpts.ExecutionEnvironment), + CPUThrottling: fields.Bool(o.DeployOpts.CPUThrottling), } _, err = r.RegisterAppResource(o.App, "cloud_run", o.CloudRun) diff --git a/gcp/cloud_run.go b/gcp/cloud_run.go index 27861ae..64a226b 100644 --- a/gcp/cloud_run.go +++ b/gcp/cloud_run.go @@ -36,7 +36,9 @@ type CloudRun struct { TimeoutSeconds fields.IntInputField `default:"300"` Port fields.IntInputField `default:"80"` EnvVars fields.MapInputField - Ingress fields.StringInputField `default:"all"` // options: internal-and-cloud-load-balancing + Ingress fields.StringInputField `default:"all"` // options: internal-and-cloud-load-balancing + ExecutionEnvironment fields.StringInputField `default:"gen1"` // options: gen2 + CPUThrottling fields.BoolInputField `default:"true"` } func (o *CloudRun) ReferenceID() string { @@ -88,6 +90,8 @@ func (o *CloudRun) Read(ctx context.Context, meta interface{}) error { // nolint o.MaxScale.UnsetCurrent() o.EnvVars.UnsetCurrent() o.Ingress.UnsetCurrent() + o.CPUThrottling.UnsetCurrent() + o.ExecutionEnvironment.UnsetCurrent() return nil } @@ -122,6 +126,8 @@ func (o *CloudRun) Read(ctx context.Context, meta interface{}) error { // nolint o.TimeoutSeconds.SetCurrent(int(svc.Spec.Template.Spec.TimeoutSeconds)) o.Port.SetCurrent(int(svc.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort)) o.Ingress.SetCurrent(svc.Metadata.Annotations["run.googleapis.com/ingress"]) + o.CPUThrottling.SetCurrent(svc.Metadata.Annotations["run.googleapis.com/cpu-throttling"] == "true") + o.ExecutionEnvironment.SetCurrent(svc.Metadata.Annotations["run.googleapis.com/execution-environment"]) v, _ := strconv.Atoi(svc.Spec.Template.Metadata.Annotations["autoscaling.knative.dev/minScale"]) o.MinScale.SetCurrent(v) @@ -253,6 +259,11 @@ func (o *CloudRun) makeRunService() *run.Service { argsStr[i] = v.(string) } + cpuThrottling := "false" + if o.CPUThrottling.Wanted() { + cpuThrottling = "true" + } + svc := &run.Service{ ApiVersion: "serving.knative.dev/v1", Kind: "Service", @@ -266,10 +277,12 @@ func (o *CloudRun) makeRunService() *run.Service { Template: &run.RevisionTemplate{ Metadata: &run.ObjectMeta{ Annotations: map[string]string{ - "run.googleapis.com/client-name": "outblocks", - "autoscaling.knative.dev/minScale": strconv.Itoa(o.MinScale.Wanted()), - "autoscaling.knative.dev/maxScale": strconv.Itoa(o.MaxScale.Wanted()), - "run.googleapis.com/cloudsql-instances": o.CloudSQLInstances.Wanted(), + "run.googleapis.com/client-name": "outblocks", + "autoscaling.knative.dev/minScale": strconv.Itoa(o.MinScale.Wanted()), + "autoscaling.knative.dev/maxScale": strconv.Itoa(o.MaxScale.Wanted()), + "run.googleapis.com/cloudsql-instances": o.CloudSQLInstances.Wanted(), + "run.googleapis.com/execution-environment": o.ExecutionEnvironment.Wanted(), + "run.googleapis.com/cpu-throttling": cpuThrottling, }, }, Spec: &run.RevisionSpec{ diff --git a/gcp/image.go b/gcp/image.go index 323af58..24a1a04 100644 --- a/gcp/image.go +++ b/gcp/image.go @@ -29,7 +29,8 @@ type Image struct { Source fields.StringInputField SourceHash fields.StringInputField - Pull bool `state:"-"` + Pull bool `state:"-"` + PullAuth bool `state:"-"` } func (o *Image) ReferenceID() string { @@ -171,9 +172,12 @@ func (o *Image) push(ctx context.Context, meta interface{}) error { if o.Pull { // Pull image from source. - reader, err := cli.ImagePull(ctx, o.Source.Wanted(), dockertypes.ImagePullOptions{ - RegistryAuth: authStr, - }) + pullOpts := dockertypes.ImagePullOptions{} + if o.PullAuth { + pullOpts.RegistryAuth = authStr + } + + reader, err := cli.ImagePull(ctx, o.Source.Wanted(), pullOpts) if err != nil { return err }