rstudio / helm

Helm Resources for RStudio Products
MIT License
36 stars 28 forks source link

Connect: allow specifying resources in templates #306

Open pat-s opened 1 year ago

pat-s commented 1 year ago

Motivation: AKS has some azure-policies in place which deny spawning pods without a resource definition. This applies to the packrat-restore pods and eventually denies app deployment.

values.yml:

  templateValues:
    service:
      type: ClusterIP
      annotations: {}
      labels: {}
    pod:
      annotations: {}
      labels: {}
      serviceAccountName: ""
      volumes: []
      volumeMounts: []
      imagePullPolicy: ""
      imagePullSecrets: []
      initContainers: []
      extraContainers: []
      resources: {} # <---- NEW

As a workaround I am currently trying with

launcher:
  enabled: true
  useTemplates: false
  launcherKubernetesProfilesConf:
    "*":
      job-json-overrides:
        - name: resources
          target: /spec/template/spec/containers/resources
          json:
            requests:
              cpu: "100m"
              memory: "200Mi"
              ephemeral-storage: "200Mi"
            limits:
              cpu: "1000m"
              memory: "1Gi"
              ephemeral-storage: "2Gi"

but this specification results in a 500 from the launcher.

EDIT:

I see the values are just passed along as is and are not limited by the values.yml specification.

So the following

launcher:
  enabled: true
  useTemplates: false
  templateValues:
    pod:
      resources:

works!

colearendt commented 1 year ago

Howdy @pat-s ! Thanks for sending this along!

We actually have a slightly more native option for configuring resources today.

launcher:
  launcherKubernetesProfilesConf:
    "*":
      default-cpu: 2
      default-mem-mb: 2048
      cpu-request-ratio: 0.1
      memory-request-ratio: 0.2

https://docs.posit.co/job-launcher/kube.html#kube-profiles

Unfortunately this is global and not specified per content. We are shooting for an even-more-native implementation which will allow users to specify resources inside of the UI similar to "number of processes", "connection timeouts," etc. This will allow varying resource selection per content item using the API.

If you have any feedback on whether you would expect this resource-permission selection to be set by publishers or admins-only, or what mechanics would be ideal (i.e. a default value, and users can override, etc.), that would be most welcome!

AlexMapley commented 11 months ago

Just noting that we have a resource block in our helm connect values currently, but it's not referenced anywhere: https://github.com/rstudio/helm/blob/main/charts/rstudio-connect/values.yaml#L178-L188.

The commented out code examples are also causing helm template to silently fail in our ci with:

Error: Deployment in version "v1" cannot be handled as a Deployment: v1.Deployment.Spec: v1.DeploymentSpec.Template: v1.PodTemplateSpec.Spec: v1.PodSpec.Containers: []v1.Container: v1.Container.Resources: v1.ResourceRequirements.Limits: unmarshalerDecoder: quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$', error found in #10 byte of ...|led":false,"ephemera|..., bigger context ...|esources":{"limits":{"cpu":"2000m","enabled":false,"ephemeralStorage":"200Mi","memory":"2Gi"},"reque|...

If we want to get our ci fixed we should remove these bits, though we could fix forward and allow setting resource limits with a little effort.