From 858ee5a9e34a47e78295fa811ea709fb7690819e Mon Sep 17 00:00:00 2001 From: Meghana Janapareddy Date: Sat, 21 Nov 2026 12:27:30 -0800 Subject: [PATCH] feat: add hyperpod-compute-configuration subchart, disabled by default Installs the ComputeConfiguration CRD and its admission webhook: an admin defines named compute shapes in a namespace, and a RayJob, HyperPodPyTorchJob or InferenceEndpointConfig that references one gets its compute filled in and checked. The webhook image is resolved per region from the HyperPod ECR accounts, by tag (default 1.0.24.0_1.0.5.0) or by digest; an override must be pinned by digest. --- helm_chart/HyperPodHelmChart/Chart.yaml | 4 + .../hyperpod-compute-configuration/Chart.yaml | 14 + .../templates/NOTES.txt | 45 +++ .../templates/_helpers.tpl | 323 ++++++++++++++++++ .../templates/cert-manager/certificate.yaml | 17 + .../templates/cert-manager/issuer.yaml | 11 + ...configuration.sagemaker.amazonaws.com.yaml | 241 +++++++++++++ .../rbac/computeconfiguration-admin.yaml | 27 ++ .../rbac/computeconfiguration-editor.yaml | 33 ++ .../rbac/computeconfiguration-viewer.yaml | 29 ++ .../templates/webhook/deployment.yaml | 101 ++++++ .../mutating-webhook-configuration.yaml | 17 + .../webhook/poddisruptionbudget.yaml | 14 + .../templates/webhook/rbac.yaml | 35 ++ .../templates/webhook/service.yaml | 18 + .../templates/webhook/serviceaccount.yaml | 9 + .../webhook/unsupported-kinds-policy.yaml | 76 +++++ .../validating-webhook-configuration.yaml | 18 + .../templates/webhook/workloads-policy.yaml | 81 +++++ .../values.yaml | 119 +++++++ helm_chart/HyperPodHelmChart/values.yaml | 23 ++ helm_chart/readme.md | 1 + 22 files changed, 1256 insertions(+) create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/Chart.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/NOTES.txt create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/_helpers.tpl create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/cert-manager/certificate.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/cert-manager/issuer.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/crds/computeconfigurations.compute.configuration.sagemaker.amazonaws.com.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/rbac/computeconfiguration-admin.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/rbac/computeconfiguration-editor.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/rbac/computeconfiguration-viewer.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/deployment.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/mutating-webhook-configuration.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/poddisruptionbudget.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/rbac.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/service.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/serviceaccount.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/unsupported-kinds-policy.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/validating-webhook-configuration.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/workloads-policy.yaml create mode 100644 helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/values.yaml diff --git a/helm_chart/HyperPodHelmChart/Chart.yaml b/helm_chart/HyperPodHelmChart/Chart.yaml index 7742efd6..ac5f3b65 100644 --- a/helm_chart/HyperPodHelmChart/Chart.yaml +++ b/helm_chart/HyperPodHelmChart/Chart.yaml @@ -100,3 +100,7 @@ dependencies: version: "0.1.0" repository: "file://charts/hyperpod-kubernetes-resource-monitor" condition: hyperpod-kubernetes-resource-monitor.enabled + - name: hyperpod-compute-configuration + version: "0.1.0" + repository: "file://charts/hyperpod-compute-configuration" + condition: hyperpod-compute-configuration.enabled diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/Chart.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/Chart.yaml new file mode 100644 index 00000000..4896f4b9 --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/Chart.yaml @@ -0,0 +1,14 @@ +apiVersion: v2 +name: hyperpod-compute-configuration +description: The HyperPod ComputeConfiguration CRD and its admission webhook +type: application + +version: 0.1.0 +appVersion: "0.1.0" +# CRD validation rules (x-kubernetes-validations) are on by default from 1.25. +# The -0 suffix lets EKS versions such as v1.33.13-eks-cfb47f5 match. +kubeVersion: ">=1.30.0-0" + +keywords: + - kubernetes + - hyperpod diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/NOTES.txt b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/NOTES.txt new file mode 100644 index 00000000..b546595c --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/NOTES.txt @@ -0,0 +1,45 @@ +Thank you for installing {{ .Chart.Name }}. + +Your release is named {{ .Release.Name }}. +{{- if (.Values.crd | default dict).enable }} + +The ComputeConfiguration CRD has been installed. + +To verify the installation: + + kubectl get customresourcedefinitions computeconfigurations.compute.configuration.sagemaker.amazonaws.com + kubectl get computeconfigurations --all-namespaces +{{- else }} + +crd.enable is false, so this release did not install the ComputeConfiguration CRD. +{{- end }} +{{- if .Values.webhook.enable }} + +The compute configuration admission webhook is installed (image {{ include "hyperpod-compute-configuration.webhookImage" . }}). +It handles RayJob, PyTorchJob, HyperPodPyTorchJob and InferenceEndpointConfig creates and +updates that carry the compute.configuration.sagemaker.amazonaws.com/name label, in every +namespace except kube-system: +- The mutating webhook fills in compute and never blocks a workload (failurePolicy Ignore). +- The validating webhook runs only in namespaces labelled + {{ include "hyperpod-compute-configuration.enforcementLabel" . }}=enabled and rejects workloads + it can't check (failurePolicy Fail). +- A ValidatingAdmissionPolicy rejects labelled objects of other kinds in those namespaces, unless + a controller created them (they have an owner, or come from webhook.workloadControllers). +- A second ValidatingAdmissionPolicy requires every RayJob, PyTorchJob, HyperPodPyTorchJob and + InferenceEndpointConfig there to use a compute configuration, and accepts them only in API + version v1 (in any namespace when they reference a compute configuration). +The webhook can read compute configurations and namespaces (read-only ClusterRole).{{ if .Values.certManager.enable }} +Its TLS certificate is issued by cert-manager, which must be installed in the cluster.{{ end }} + +To verify the webhook: + + kubectl -n {{ include "hyperpod-compute-configuration.namespaceName" . }} rollout status deployment/{{ include "hyperpod-compute-configuration.webhookName" . }} + kubectl -n {{ include "hyperpod-compute-configuration.namespaceName" . }} get certificate {{ include "hyperpod-compute-configuration.webhookName" . }}-cert + kubectl get mutatingwebhookconfiguration,validatingwebhookconfiguration {{ include "hyperpod-compute-configuration.webhookName" . }} + kubectl -n {{ include "hyperpod-compute-configuration.namespaceName" . }} logs deployment/{{ include "hyperpod-compute-configuration.webhookName" . }} | grep "Webhook version" +{{- end }} + +To learn more about the release, try: + + $ helm status {{ .Release.Name }} -n {{ .Release.Namespace }} + $ helm get all {{ .Release.Name }} -n {{ .Release.Namespace }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/_helpers.tpl b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/_helpers.tpl new file mode 100644 index 00000000..79191018 --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/_helpers.tpl @@ -0,0 +1,323 @@ +{{/* +Chart name, truncated to 63 characters (Kubernetes name limit). +*/}} +{{- define "hyperpod-compute-configuration.name" -}} +{{- .Chart.Name | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Name for a webhook resource: "-webhook", truncated to 63 characters. All webhook +resources (ServiceAccount, Deployment, Service, PodDisruptionBudget, Certificate) share it. +*/}} +{{- define "hyperpod-compute-configuration.webhookName" -}} +{{- printf "%s-webhook" (include "hyperpod-compute-configuration.name" .) | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Labels on every webhook resource. +*/}} +{{- define "hyperpod-compute-configuration.webhookLabels" -}} +app.kubernetes.io/name: {{ include "hyperpod-compute-configuration.name" . }} +app.kubernetes.io/component: webhook +app.kubernetes.io/instance: {{ .Release.Name }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} +{{- end }} + +{{/* +Selector labels: the subset that identifies the webhook pods (must not change across upgrades). +*/}} +{{- define "hyperpod-compute-configuration.webhookSelectorLabels" -}} +app.kubernetes.io/name: {{ include "hyperpod-compute-configuration.name" . }} +app.kubernetes.io/component: webhook +{{- end }} + +{{/* +Webhook image tag: webhook.image.tag, or the published tag this chart version is tested with. +*/}} +{{- define "hyperpod-compute-configuration.webhookImageTag" -}} +{{- .Values.webhook.image.tag | default "1.0.24.0_1.0.5.0" }} +{{- end }} + +{{/* +Namespace the webhook and its objects are installed into: .Values.namespace (default +aws-hyperpod). The parent HyperPodHelmChart is installed into kube-system, so this subchart doesn't +use the release namespace, as the Ray endpoint operator and resource ownership subcharts do. +*/}} +{{- define "hyperpod-compute-configuration.namespaceName" -}} +{{- .Values.namespace | default "aws-hyperpod" }} +{{- end }} + +{{/* +Region of the cluster: .Values.region, global.region, then the nodes' +topology.kubernetes.io/region label (lookup only answers against a live cluster, so helm template +and client-side dry runs need region or global.region). Empty when none is found. +*/}} +{{- define "hyperpod-compute-configuration.requestedRegion" -}} +{{- $region := .Values.region -}} +{{- if and (not $region) .Values.global .Values.global.region -}} +{{- $region = .Values.global.region -}} +{{- end -}} +{{- if not $region -}} +{{- $nodes := lookup "v1" "Node" "" "" -}} +{{- if $nodes -}} +{{- range $nodes.items -}} +{{- if and (not $region) .metadata.labels (index .metadata.labels "topology.kubernetes.io/region") -}} +{{- $region = index .metadata.labels "topology.kubernetes.io/region" -}} +{{- end -}} +{{- end -}} +{{- end -}} +{{- end -}} +{{- $region -}} +{{- end -}} + +{{/* +Resolve the webhook image URI. +Priority for region: + 1. .Values.region (explicit setting) + 2. .Values.global.region (global setting from parent chart) + 3. the nodes' topology.kubernetes.io/region label (detected at install, as the resource + monitor and health monitoring agent subcharts do) + 4. fail — region is required +A region that isn't in the region→account mapping fails rendering and lists the supported ones. + +Priority for image URI: + 1. .Values.webhook.image.override (full URI override, skips all resolution) + 2. Constructed from region→account mapping + repository name + tag +*/}} +{{- define "hyperpod-compute-configuration.webhookImage" -}} +{{- if .Values.webhook.image.override -}} +{{- if not (regexMatch "@sha256:[a-f0-9]{64}$" .Values.webhook.image.override) -}} + {{- fail (printf "webhook.image.override must pin a digest, @sha256:<64 hex>; got %q" .Values.webhook.image.override) -}} +{{- end -}} + {{- .Values.webhook.image.override -}} +{{- else -}} +{{- $region := include "hyperpod-compute-configuration.requestedRegion" . -}} +{{- if not $region -}} + {{- fail "region is required when webhook.image.override is not set and it could not be detected from the nodes' topology.kubernetes.io/region label. Set region or global.region." -}} +{{- end -}} + +{{/* Region to ECR account ID mapping */}} +{{- $regionAccountMap := dict + "ap-northeast-1" "167660772520" + "ap-south-1" "350868604920" + "ap-south-2" "682032008207" + "ap-southeast-1" "238902833166" + "ap-southeast-2" "410543484366" + "eu-central-1" "259738048750" + "eu-north-1" "939593443514" + "eu-west-1" "124013160849" + "eu-west-2" "414154849790" + "sa-east-1" "720443608875" + "us-east-1" "955788910749" + "us-east-2" "945058679767" + "us-west-1" "194358183338" + "us-west-2" "756082469455" +-}} + +{{- $accountId := index $regionAccountMap $region -}} +{{- if not $accountId -}} + {{- fail (printf "Unsupported AWS region: %s (supported: %s). Set webhook.image.override explicitly for non-standard regions." $region (keys $regionAccountMap | sortAlpha | join ", ")) -}} +{{- end -}} + +{{- if .Values.webhook.image.digest -}} +{{- if not (regexMatch "^sha256:[a-f0-9]{64}$" .Values.webhook.image.digest) -}} + {{- fail (printf "webhook.image.digest must be sha256:<64 hex>; got %q" .Values.webhook.image.digest) -}} +{{- end -}} +{{- printf "%s.dkr.ecr.%s.amazonaws.com/hyperpod-compute-configuration-webhook@%s" $accountId $region .Values.webhook.image.digest -}} +{{- else -}} +{{- printf "%s.dkr.ecr.%s.amazonaws.com/hyperpod-compute-configuration-webhook:%s" $accountId $region (include "hyperpod-compute-configuration.webhookImageTag" .) -}} +{{- end -}} +{{- end -}} +{{- end }} + +{{/* +Value for WEBHOOK_VERSION, which the webhook logs at startup: the override URI, else the digest, +else the tag. +*/}} +{{- define "hyperpod-compute-configuration.webhookImageVersion" -}} +{{- if .Values.webhook.image.override }} +{{- .Values.webhook.image.override }} +{{- else if .Values.webhook.image.digest }} +{{- .Values.webhook.image.digest }} +{{- else }} +{{- include "hyperpod-compute-configuration.webhookImageTag" . }} +{{- end }} +{{- end }} + +{{/* +Workload kinds the webhook handles: the webhook name prefix, the API group and resource, and the +path suffix shared by the mutating ("/mutate-") and validating ("/validate-") +handlers. +A kind marked "blocked: true" is temporarily unsupported. It keeps its webhook entries (dropping +them would leave cert-manager's caBundle behind in an entry Helm no longer manages, failing the +upgrade), but the admission policies skip it, so the unsupported-kinds policy rejects a labelled +object of that kind in every namespace. +*/}} +{{- define "hyperpod-compute-configuration.webhookKinds" -}} +- id: rayjobs + group: ray.io + resource: rayjobs + path: ray-io-v1-rayjob + # Container resources, the instance-type nodeSelector, and the affinity (which can rule out the + # instance type) in the head or any worker group's pod template + computeChanged: >- + object.?spec.?rayClusterSpec.?headGroupSpec.?template.?spec.?containers.orValue([]).map(c, c.?resources.orValue({})) + != oldObject.?spec.?rayClusterSpec.?headGroupSpec.?template.?spec.?containers.orValue([]).map(c, c.?resources.orValue({})) + || object.?spec.?rayClusterSpec.?workerGroupSpecs.orValue([]).map(g, g.?template.?spec.?containers.orValue([]).map(c, c.?resources.orValue({}))) + != oldObject.?spec.?rayClusterSpec.?workerGroupSpecs.orValue([]).map(g, g.?template.?spec.?containers.orValue([]).map(c, c.?resources.orValue({}))) + || object.?spec.?rayClusterSpec.?headGroupSpec.?template.?spec.?nodeSelector[?'node.kubernetes.io/instance-type'].orValue('') + != oldObject.?spec.?rayClusterSpec.?headGroupSpec.?template.?spec.?nodeSelector[?'node.kubernetes.io/instance-type'].orValue('') + || object.?spec.?rayClusterSpec.?workerGroupSpecs.orValue([]).map(g, g.?template.?spec.?nodeSelector[?'node.kubernetes.io/instance-type'].orValue('')) + != oldObject.?spec.?rayClusterSpec.?workerGroupSpecs.orValue([]).map(g, g.?template.?spec.?nodeSelector[?'node.kubernetes.io/instance-type'].orValue('')) + || object.?spec.?rayClusterSpec.?headGroupSpec.?template.?spec.?affinity.orValue({}) + != oldObject.?spec.?rayClusterSpec.?headGroupSpec.?template.?spec.?affinity.orValue({}) + || object.?spec.?rayClusterSpec.?workerGroupSpecs.orValue([]).map(g, g.?template.?spec.?affinity.orValue({})) + != oldObject.?spec.?rayClusterSpec.?workerGroupSpecs.orValue([]).map(g, g.?template.?spec.?affinity.orValue({})) + # A worker group the old object doesn't have, by name + groupsAdded: >- + object.?spec.?rayClusterSpec.?workerGroupSpecs.orValue([]).exists(g, + !oldObject.?spec.?rayClusterSpec.?workerGroupSpecs.orValue([]).exists(o, o.?groupName.orValue('') == g.?groupName.orValue(''))) +- id: pytorchjobs + group: kubeflow.org + resource: pytorchjobs + path: kubeflow-org-v1-pytorchjob + # TEMPORARILY BLOCKED: the admission policies treat Kubeflow PyTorchJob as unsupported, so a + # labelled one is rejected in every namespace. Its webhook entries stay, because removing them + # leaves cert-manager's caBundle behind in a half-removed entry and the upgrade fails. Remove + # this line to re-enable the kind. + blocked: true + # Container resources, the instance-type nodeSelector, and the affinity in any replica type's pod + # template (Master, Worker) + computeChanged: >- + size(object.?spec.?pytorchReplicaSpecs.orValue({})) != size(oldObject.?spec.?pytorchReplicaSpecs.orValue({})) + || object.?spec.?pytorchReplicaSpecs.orValue({}).exists(k, + !(k in oldObject.?spec.?pytorchReplicaSpecs.orValue({})) + || object.spec.pytorchReplicaSpecs[k].?template.?spec.?containers.orValue([]).map(c, c.?resources.orValue({})) + != oldObject.spec.pytorchReplicaSpecs[k].?template.?spec.?containers.orValue([]).map(c, c.?resources.orValue({})) + || object.spec.pytorchReplicaSpecs[k].?template.?spec.?nodeSelector[?'node.kubernetes.io/instance-type'].orValue('') + != oldObject.spec.pytorchReplicaSpecs[k].?template.?spec.?nodeSelector[?'node.kubernetes.io/instance-type'].orValue('') + || object.spec.pytorchReplicaSpecs[k].?template.?spec.?affinity.orValue({}) + != oldObject.spec.pytorchReplicaSpecs[k].?template.?spec.?affinity.orValue({})) + # A replica type the old object doesn't have + groupsAdded: >- + object.?spec.?pytorchReplicaSpecs.orValue({}).exists(k, !(k in oldObject.?spec.?pytorchReplicaSpecs.orValue({}))) +- id: hyperpodpytorchjobs + group: sagemaker.amazonaws.com + resource: hyperpodpytorchjobs + path: sagemaker-amazonaws-com-v1-hyperpodpytorchjob + # Container resources, the instance-type nodeSelector, and the affinity in any replica spec's pod + # template + computeChanged: >- + object.?spec.?replicaSpecs.orValue([]).map(r, r.?template.?spec.?containers.orValue([]).map(c, c.?resources.orValue({}))) + != oldObject.?spec.?replicaSpecs.orValue([]).map(r, r.?template.?spec.?containers.orValue([]).map(c, c.?resources.orValue({}))) + || object.?spec.?replicaSpecs.orValue([]).map(r, r.?template.?spec.?nodeSelector[?'node.kubernetes.io/instance-type'].orValue('')) + != oldObject.?spec.?replicaSpecs.orValue([]).map(r, r.?template.?spec.?nodeSelector[?'node.kubernetes.io/instance-type'].orValue('')) + || object.?spec.?replicaSpecs.orValue([]).map(r, r.?template.?spec.?affinity.orValue({})) + != oldObject.?spec.?replicaSpecs.orValue([]).map(r, r.?template.?spec.?affinity.orValue({})) + # A replica name the old object doesn't have + groupsAdded: >- + object.?spec.?replicaSpecs.orValue([]).exists(r, + !oldObject.?spec.?replicaSpecs.orValue([]).exists(o, o.?name.orValue('') == r.?name.orValue(''))) +- id: inferenceendpointconfigs + group: inference.sagemaker.aws.amazon.com + resource: inferenceendpointconfigs + path: inference-sagemaker-aws-amazon-com-v1-inferenceendpointconfig + # Instance type, worker resources, and instanceTypes and nodeAffinity (which can't be used with + # a compute configuration) + computeChanged: >- + object.?spec.?instanceType.orValue('') != oldObject.?spec.?instanceType.orValue('') + || object.?spec.?instanceTypes.orValue([]) != oldObject.?spec.?instanceTypes.orValue([]) + || object.?spec.?nodeAffinity.orValue({}) != oldObject.?spec.?nodeAffinity.orValue({}) + || object.?spec.?worker.?resources.orValue({}) != oldObject.?spec.?worker.?resources.orValue({}) + # Only one group, which can't be added + groupsAdded: "false" +{{- end }} + +{{/* +Namespace label that turns on enforcement when set to "enabled". The key is part of the +feature's API (Studio and admins set it), so it isn't a value. +*/}} +{{- define "hyperpod-compute-configuration.enforcementLabel" -}} +compute.configuration.sagemaker.amazonaws.com/enforcement +{{- end }} + +{{/* +Entries for a MutatingWebhookConfiguration or ValidatingWebhookConfiguration, one per kind. +- enforced false: every namespace except kube-system, with failurePolicy Ignore, so an outage + never blocks anyone (the mutating webhook). +- enforced true: only namespaces labelled =enabled, with failurePolicy Fail, + so nothing gets through unchecked (the validating webhook). The webhook's own namespace is + never enforced, so an outage can't stop the webhook from restarting. +Only workloads that reference a compute configuration are sent to the webhook. +Arguments: "context" (the root context), "type" ("mutate" or "validate"), "operations" and +"enforced". +*/}} +{{- define "hyperpod-compute-configuration.webhookEntries" -}} +{{- $ctx := .context }} +{{- $enforced := .enforced | default false }} +{{- range $kind := fromYamlArray (include "hyperpod-compute-configuration.webhookKinds" $ctx) }} +- name: {{ $kind.id }}.compute.configuration.sagemaker.amazonaws.com + admissionReviewVersions: [v1] + clientConfig: + service: + name: {{ include "hyperpod-compute-configuration.webhookName" $ctx }} + namespace: {{ include "hyperpod-compute-configuration.namespaceName" $ctx }} + path: /{{ $.type }}-{{ $kind.path }} + port: 443 + rules: + - apiGroups: [{{ $kind.group | quote }}] + apiVersions: [v1] + operations: {{ toJson $.operations }} + resources: [{{ $kind.resource }}] + scope: Namespaced + failurePolicy: {{ ternary "Fail" "Ignore" $enforced }} + timeoutSeconds: {{ $ctx.Values.webhook.timeoutSeconds }} + sideEffects: None + matchPolicy: Exact + {{- if eq $.type "mutate" }} + # If a later mutating webhook changes the object, call this one once more. It runs at most + # once more and doesn't guarantee our values end up last; the validating webhook catches that. + reinvocationPolicy: IfNeeded + {{- end }} + {{- if has "UPDATE" $.operations }} + # Updates reach the webhook only when they can matter: the configuration label changed, + # apply-latest is set, (mutating only) a group was added, or (validating only) compute or the + # applied-uid, applied-generation or applied-snapshot stamp changed (the mutating webhook + # manages the stamp, so the validating webhook must see edits to it). Kueue, autoscaler and other + # controller updates are filtered out, so a webhook outage can't block them. + matchConditions: + - name: create-or-relevant-update + expression: >- + request.operation != 'UPDATE' + || object.metadata.?labels[?'compute.configuration.sagemaker.amazonaws.com/name'].orValue('') + != oldObject.metadata.?labels[?'compute.configuration.sagemaker.amazonaws.com/name'].orValue('') + || object.metadata.?annotations[?'compute.configuration.sagemaker.amazonaws.com/apply-latest'].orValue('') == 'true' + {{- if eq $.type "mutate" }} + || ({{ $kind.groupsAdded }}) + {{- end }} + {{- if eq $.type "validate" }} + || ({{ $kind.computeChanged }}) + {{- range $a := list "applied-uid" "applied-generation" "applied-snapshot" }} + || object.metadata.?annotations[?'compute.configuration.sagemaker.amazonaws.com/{{ $a }}'].orValue('') + != oldObject.metadata.?annotations[?'compute.configuration.sagemaker.amazonaws.com/{{ $a }}'].orValue('') + {{- end }} + {{- end }} + {{- end }} + namespaceSelector: + matchExpressions: + {{- if $enforced }} + - key: {{ include "hyperpod-compute-configuration.enforcementLabel" $ctx }} + operator: In + values: [enabled] + {{- end }} + - key: kubernetes.io/metadata.name + operator: NotIn + values: [kube-system{{ if $enforced }}, {{ include "hyperpod-compute-configuration.namespaceName" $ctx }}{{ end }}] + # Only workloads that reference a compute configuration (on updates, before or after the change). + objectSelector: + matchExpressions: + - key: compute.configuration.sagemaker.amazonaws.com/name + operator: Exists +{{- end }} +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/cert-manager/certificate.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/cert-manager/certificate.yaml new file mode 100644 index 00000000..1f50a455 --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/cert-manager/certificate.yaml @@ -0,0 +1,17 @@ +{{- if and .Values.webhook.enable .Values.certManager.enable }} +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: {{ include "hyperpod-compute-configuration.webhookName" . }}-cert + namespace: {{ include "hyperpod-compute-configuration.namespaceName" . }} + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 4 }} +spec: + secretName: {{ include "hyperpod-compute-configuration.webhookName" . }}-tls + dnsNames: + - {{ include "hyperpod-compute-configuration.webhookName" . }}.{{ include "hyperpod-compute-configuration.namespaceName" . }}.svc + - {{ include "hyperpod-compute-configuration.webhookName" . }}.{{ include "hyperpod-compute-configuration.namespaceName" . }}.svc.cluster.local + issuerRef: + kind: Issuer + name: {{ include "hyperpod-compute-configuration.webhookName" . }}-selfsigned +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/cert-manager/issuer.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/cert-manager/issuer.yaml new file mode 100644 index 00000000..99f56ef9 --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/cert-manager/issuer.yaml @@ -0,0 +1,11 @@ +{{- if and .Values.webhook.enable .Values.certManager.enable }} +apiVersion: cert-manager.io/v1 +kind: Issuer +metadata: + name: {{ include "hyperpod-compute-configuration.webhookName" . }}-selfsigned + namespace: {{ include "hyperpod-compute-configuration.namespaceName" . }} + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 4 }} +spec: + selfSigned: {} +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/crds/computeconfigurations.compute.configuration.sagemaker.amazonaws.com.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/crds/computeconfigurations.compute.configuration.sagemaker.amazonaws.com.yaml new file mode 100644 index 00000000..15d98bbc --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/crds/computeconfigurations.compute.configuration.sagemaker.amazonaws.com.yaml @@ -0,0 +1,241 @@ +{{- /* +Generated by HyperPodComputeConfigurationWebhook (make manifests) from its api/v1alpha1 Go types. +Do not edit by hand: change the Go types, run make manifests there, and commit both packages. +*/}} +{{- if (.Values.crd | default dict).enable }} +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + {{- if (.Values.crd | default dict).keep }} + "helm.sh/resource-policy": keep + {{- end }} + labels: + app.kubernetes.io/component: compute-configurations + name: computeconfigurations.compute.configuration.sagemaker.amazonaws.com +spec: + group: compute.configuration.sagemaker.amazonaws.com + names: + kind: ComputeConfiguration + listKind: ComputeConfigurationList + plural: computeconfigurations + shortNames: + - computeconfig + singular: computeconfiguration + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .spec.targetKinds + name: Targets + type: string + - jsonPath: .spec.resources.gpus + name: GPUs + type: integer + - jsonPath: .spec.resources.vcpus + name: vCPUs + type: string + - jsonPath: .spec.resources.memory + name: Memory + type: string + - jsonPath: .spec.resources.efa + name: EFA + type: integer + - jsonPath: .spec.resources.worker.gpus + name: Worker GPUs + type: integer + - jsonPath: .spec.resources.worker.vcpus + name: Worker vCPUs + type: string + - jsonPath: .spec.resources.worker.memory + name: Worker Memory + type: string + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1alpha1 + schema: + openAPIV3Schema: + description: |- + ComputeConfiguration is an admin-defined, named compute shape + that workloads of the target kind can reference. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: |- + ComputeConfigurationSpec defines the compute shape and + the workload kind it applies to. + properties: + description: + description: |- + Description is a human-readable description of this + configuration. + maxLength: 1024 + type: string + instanceType: + description: |- + InstanceType is the instance type this configuration + targets, for example ml.p5.48xlarge. Studio (and later the admission + webhook) applies it as the node.kubernetes.io/instance-type node selector. + maxLength: 64 + pattern: ^ml\.[a-z0-9-]+\.[a-z0-9]+$ + type: string + resources: + description: |- + Resources is the compute shape applied to the workload. + Set either vcpus and memory (one shape for every pod), or head and + worker (Ray only, a shape per role), not both. + properties: + efa: + description: EFA is the number of EFA devices. Omitted means 0. + format: int32 + minimum: 0 + type: integer + gpus: + description: |- + GPUs is the number of accelerator devices (NVIDIA GPUs + or Neuron devices, per the workload's instance type). Omitted means 0. + format: int32 + minimum: 0 + type: integer + head: + description: Head is the Ray head pod's compute shape. + properties: + efa: + default: 0 + description: EFA is the number of EFA devices. + format: int32 + minimum: 0 + type: integer + gpus: + default: 0 + description: |- + GPUs is the number of accelerator devices + (NVIDIA GPUs or Neuron devices, per the workload's instance type). + format: int32 + minimum: 0 + type: integer + memory: + description: |- + Memory is the memory quantity, for example 64Gi. + Must be greater than 0. + pattern: ^([1-9][0-9]*(\.[0-9]+)?|0\.[0-9]*[1-9][0-9]*)(k|M|G|T|P|Ki|Mi|Gi|Ti|Pi)?$ + type: string + vcpus: + description: |- + VCPUs is the CPU quantity, for example 8 or 500m. + Must be greater than 0. + pattern: ^([1-9][0-9]*(\.[0-9]+)?|0\.[0-9]*[1-9][0-9]*)m?$ + type: string + required: + - memory + - vcpus + type: object + memory: + description: |- + Memory is the memory quantity, for example 64Gi. + Must be greater than 0. + pattern: ^([1-9][0-9]*(\.[0-9]+)?|0\.[0-9]*[1-9][0-9]*)(k|M|G|T|P|Ki|Mi|Gi|Ti|Pi)?$ + type: string + vcpus: + description: |- + VCPUs is the CPU quantity, for example 8 or 500m. + Must be greater than 0. + pattern: ^([1-9][0-9]*(\.[0-9]+)?|0\.[0-9]*[1-9][0-9]*)m?$ + type: string + worker: + description: Worker is the Ray worker pods' compute shape. + properties: + efa: + default: 0 + description: EFA is the number of EFA devices. + format: int32 + minimum: 0 + type: integer + gpus: + default: 0 + description: |- + GPUs is the number of accelerator devices + (NVIDIA GPUs or Neuron devices, per the workload's instance type). + format: int32 + minimum: 0 + type: integer + memory: + description: |- + Memory is the memory quantity, for example 64Gi. + Must be greater than 0. + pattern: ^([1-9][0-9]*(\.[0-9]+)?|0\.[0-9]*[1-9][0-9]*)(k|M|G|T|P|Ki|Mi|Gi|Ti|Pi)?$ + type: string + vcpus: + description: |- + VCPUs is the CPU quantity, for example 8 or 500m. + Must be greater than 0. + pattern: ^([1-9][0-9]*(\.[0-9]+)?|0\.[0-9]*[1-9][0-9]*)m?$ + type: string + required: + - memory + - vcpus + type: object + type: object + x-kubernetes-validations: + - message: vcpus and memory are required (for Ray, set head and worker + instead) + rule: has(self.head) || has(self.worker) || (has(self.vcpus) && + has(self.memory)) + - message: head and worker must be set together + rule: has(self.head) == has(self.worker) + - message: head and worker can't be combined with vcpus, memory, gpus + or efa; set those inside head and worker instead + rule: '!(has(self.head) || has(self.worker)) || !(has(self.vcpus) + || has(self.memory) || has(self.gpus) || has(self.efa))' + targetKinds: + description: |- + TargetKinds are the workload kinds this configuration + applies to, each as / (for example ray.io/RayJob). + items: + pattern: ^[a-z0-9.-]+/[A-Za-z][A-Za-z0-9]*$ + type: string + maxItems: 16 + minItems: 1 + type: array + x-kubernetes-list-type: set + required: + - resources + - targetKinds + type: object + x-kubernetes-validations: + - message: head and worker resources are only supported when every target + kind is a Ray kind (ray.io/...) + rule: '!has(self.resources.head) || self.targetKinds.all(k, k.startsWith(''ray.io/''))' + status: + description: |- + ComputeConfigurationStatus is reserved for the admission + webhook; nothing writes it today. + type: object + required: + - spec + type: object + x-kubernetes-validations: + - message: name must be at most 63 characters (it is used as a label value + on workloads) + rule: self.metadata.name.size() <= 63 + served: true + storage: true + subresources: + status: {} +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/rbac/computeconfiguration-admin.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/rbac/computeconfiguration-admin.yaml new file mode 100644 index 00000000..0b8e3f68 --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/rbac/computeconfiguration-admin.yaml @@ -0,0 +1,27 @@ +{{- if ((.Values.rbac | default dict).helpers | default dict).enable }} +# Full access to ComputeConfigurations. +# Not bound to anyone: bind it with a RoleBinding (one namespace) or ClusterRoleBinding (all). +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/component: compute-configurations + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/name: {{ .Chart.Name }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + name: {{ .Chart.Name }}-computeconfiguration-admin +rules: +- apiGroups: + - compute.configuration.sagemaker.amazonaws.com + resources: + - computeconfigurations + verbs: + - '*' +- apiGroups: + - compute.configuration.sagemaker.amazonaws.com + resources: + - computeconfigurations/status + verbs: + - get +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/rbac/computeconfiguration-editor.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/rbac/computeconfiguration-editor.yaml new file mode 100644 index 00000000..e18f11e0 --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/rbac/computeconfiguration-editor.yaml @@ -0,0 +1,33 @@ +{{- if ((.Values.rbac | default dict).helpers | default dict).enable }} +# Create, update and delete ComputeConfigurations. +# Not bound to anyone: bind it with a RoleBinding (one namespace) or ClusterRoleBinding (all). +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/component: compute-configurations + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/name: {{ .Chart.Name }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + name: {{ .Chart.Name }}-computeconfiguration-editor +rules: +- apiGroups: + - compute.configuration.sagemaker.amazonaws.com + resources: + - computeconfigurations + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - compute.configuration.sagemaker.amazonaws.com + resources: + - computeconfigurations/status + verbs: + - get +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/rbac/computeconfiguration-viewer.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/rbac/computeconfiguration-viewer.yaml new file mode 100644 index 00000000..4491bf44 --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/rbac/computeconfiguration-viewer.yaml @@ -0,0 +1,29 @@ +{{- if ((.Values.rbac | default dict).helpers | default dict).enable }} +# Read-only access to ComputeConfigurations. +# Not bound to anyone: bind it with a RoleBinding (one namespace) or ClusterRoleBinding (all). +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/component: compute-configurations + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/name: {{ .Chart.Name }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + name: {{ .Chart.Name }}-computeconfiguration-viewer +rules: +- apiGroups: + - compute.configuration.sagemaker.amazonaws.com + resources: + - computeconfigurations + verbs: + - get + - list + - watch +- apiGroups: + - compute.configuration.sagemaker.amazonaws.com + resources: + - computeconfigurations/status + verbs: + - get +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/deployment.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/deployment.yaml new file mode 100644 index 00000000..b03b9f75 --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/deployment.yaml @@ -0,0 +1,101 @@ +{{- if .Values.webhook.enable }} +{{- if not .Values.certManager.enable }} +{{- fail "webhook.enable=true requires certManager.enable=true: the webhook's TLS certificate and CA bundle come from cert-manager" }} +{{- end }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "hyperpod-compute-configuration.webhookName" . }} + namespace: {{ include "hyperpod-compute-configuration.namespaceName" . }} + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 4 }} +spec: + replicas: {{ .Values.webhook.replicas }} + selector: + matchLabels: + {{- include "hyperpod-compute-configuration.webhookSelectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 8 }} + annotations: + kubectl.kubernetes.io/default-container: webhook + spec: + serviceAccountName: {{ include "hyperpod-compute-configuration.webhookName" . }} + {{- with .Values.webhook.priorityClassName }} + priorityClassName: {{ . }} + {{- end }} + securityContext: + runAsNonRoot: true + runAsUser: 65532 + runAsGroup: 65532 + seccompProfile: + type: RuntimeDefault + # Spread the pods over nodes so one node failure doesn't take every replica down. + topologySpreadConstraints: + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + whenUnsatisfiable: ScheduleAnyway + labelSelector: + matchLabels: + {{- include "hyperpod-compute-configuration.webhookSelectorLabels" . | nindent 12 }} + containers: + - name: webhook + image: {{ include "hyperpod-compute-configuration.webhookImage" . }} + imagePullPolicy: {{ .Values.webhook.image.pullPolicy }} + args: + - --webhook-port={{ .Values.webhook.port }} + - --webhook-cert-path=/tmp/k8s-webhook-server/serving-certs + - --health-probe-bind-address=:{{ .Values.webhook.healthProbePort }} + - --zap-log-level={{ .Values.webhook.logLevel }} + env: + - name: WEBHOOK_VERSION + value: {{ include "hyperpod-compute-configuration.webhookImageVersion" . | quote }} + ports: + - name: webhook + containerPort: {{ .Values.webhook.port }} + protocol: TCP + - name: health + containerPort: {{ .Values.webhook.healthProbePort }} + protocol: TCP + readinessProbe: + httpGet: + path: /readyz + port: health + initialDelaySeconds: 5 + periodSeconds: 10 + livenessProbe: + httpGet: + path: /healthz + port: health + initialDelaySeconds: 15 + periodSeconds: 20 + resources: + {{- toYaml .Values.webhook.resources | nindent 10 }} + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: + - ALL + volumeMounts: + - name: serving-certs + mountPath: /tmp/k8s-webhook-server/serving-certs + readOnly: true + volumes: + - name: serving-certs + secret: + secretName: {{ include "hyperpod-compute-configuration.webhookName" . }}-tls + {{- with .Values.webhook.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.webhook.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.webhook.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/mutating-webhook-configuration.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/mutating-webhook-configuration.yaml new file mode 100644 index 00000000..e618e331 --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/mutating-webhook-configuration.yaml @@ -0,0 +1,17 @@ +{{- if .Values.webhook.enable }} +{{- $name := include "hyperpod-compute-configuration.webhookName" . }} +apiVersion: admissionregistration.k8s.io/v1 +kind: MutatingWebhookConfiguration +metadata: + name: {{ $name }} + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 4 }} + {{- if .Values.certManager.enable }} + annotations: + cert-manager.io/inject-ca-from: {{ include "hyperpod-compute-configuration.namespaceName" . }}/{{ $name }}-cert + {{- end }} +# Fills in compute from the referenced configuration. It never denies a workload; the +# ValidatingWebhookConfiguration does all denying. +webhooks: +{{- include "hyperpod-compute-configuration.webhookEntries" (dict "context" . "type" "mutate" "operations" (list "CREATE" "UPDATE")) }} +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/poddisruptionbudget.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/poddisruptionbudget.yaml new file mode 100644 index 00000000..9751beb6 --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/poddisruptionbudget.yaml @@ -0,0 +1,14 @@ +{{- if .Values.webhook.enable }} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: {{ include "hyperpod-compute-configuration.webhookName" . }} + namespace: {{ include "hyperpod-compute-configuration.namespaceName" . }} + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 4 }} +spec: + minAvailable: {{ .Values.webhook.podDisruptionBudget.minAvailable }} + selector: + matchLabels: + {{- include "hyperpod-compute-configuration.webhookSelectorLabels" . | nindent 6 }} +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/rbac.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/rbac.yaml new file mode 100644 index 00000000..28ac30ca --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/rbac.yaml @@ -0,0 +1,35 @@ +{{- if .Values.webhook.enable }} +{{- $name := include "hyperpod-compute-configuration.webhookName" . }} +# Lets the webhook read compute configurations, to fill in and check workloads' compute, and +# namespaces, to see which ones enforce compute configurations (their +# compute.configuration.sagemaker.amazonaws.com/enforcement label). list and watch are for its +# in-memory cache, so admission never waits on the API server. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ $name }} + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 4 }} +rules: +- apiGroups: ["compute.configuration.sagemaker.amazonaws.com"] + resources: ["computeconfigurations"] + verbs: ["get", "list", "watch"] +- apiGroups: [""] + resources: ["namespaces"] + verbs: ["get", "list", "watch"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ $name }} + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ $name }} +subjects: +- kind: ServiceAccount + name: {{ $name }} + namespace: {{ include "hyperpod-compute-configuration.namespaceName" . }} +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/service.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/service.yaml new file mode 100644 index 00000000..a97527b9 --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/service.yaml @@ -0,0 +1,18 @@ +{{- if .Values.webhook.enable }} +apiVersion: v1 +kind: Service +metadata: + name: {{ include "hyperpod-compute-configuration.webhookName" . }} + namespace: {{ include "hyperpod-compute-configuration.namespaceName" . }} + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 4 }} +spec: + type: ClusterIP + selector: + {{- include "hyperpod-compute-configuration.webhookSelectorLabels" . | nindent 4 }} + ports: + - name: webhook + port: 443 + targetPort: webhook + protocol: TCP +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/serviceaccount.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/serviceaccount.yaml new file mode 100644 index 00000000..0612a4be --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/serviceaccount.yaml @@ -0,0 +1,9 @@ +{{- if .Values.webhook.enable }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "hyperpod-compute-configuration.webhookName" . }} + namespace: {{ include "hyperpod-compute-configuration.namespaceName" . }} + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 4 }} +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/unsupported-kinds-policy.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/unsupported-kinds-policy.yaml new file mode 100644 index 00000000..177c227b --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/unsupported-kinds-policy.yaml @@ -0,0 +1,76 @@ +{{- if .Values.webhook.enable }} +{{- $name := printf "%s-unsupported-kinds" (include "hyperpod-compute-configuration.webhookName" .) }} +# Rejects, in every namespace, a workload that references a compute configuration but is a kind +# the webhook doesn't support, so the reference is never silently ignored. It runs in +# the API server, so it works even when the webhook is down. +apiVersion: admissionregistration.k8s.io/v1 +kind: ValidatingAdmissionPolicy +metadata: + name: {{ $name }} + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 4 }} +spec: + failurePolicy: Fail + matchConstraints: + resourceRules: + - apiGroups: ["*"] + apiVersions: ["*"] + operations: ["CREATE", "UPDATE"] + resources: ["*"] + scope: Namespaced + # The supported kinds (the webhook checks them) and compute configurations themselves. A + # blocked kind is deliberately not excluded, so this policy rejects it. + excludeResourceRules: + {{- range fromYamlArray (include "hyperpod-compute-configuration.webhookKinds" .) }} + {{- if not .blocked }} + - apiGroups: [{{ .group | quote }}] + apiVersions: ["*"] + operations: ["CREATE", "UPDATE"] + resources: [{{ .resource }}] + {{- end }} + {{- end }} + - apiGroups: ["compute.configuration.sagemaker.amazonaws.com"] + apiVersions: ["*"] + operations: ["CREATE", "UPDATE"] + resources: [computeconfigurations] + namespaceSelector: + matchExpressions: + - key: kubernetes.io/metadata.name + operator: NotIn + values: [kube-system, {{ include "hyperpod-compute-configuration.namespaceName" . }}] + objectSelector: + matchExpressions: + - key: compute.configuration.sagemaker.amazonaws.com/name + operator: Exists + matchConditions: + # Objects a controller creates from a supported workload (a RayJob's RayCluster, Pods) inherit + # the label but have an owner, so only objects a user created directly are checked. + - name: user-created + expression: "size(object.metadata.?ownerReferences.orValue([])) == 0" + # The listed controllers create objects from supported workloads without an owner (the HyperPod + # inference operator's Deployment for an InferenceEndpointConfig), so they aren't checked either. + - name: not-a-controller + expression: >- + !(request.userInfo.username in {{ .Values.webhook.workloadControllers | default list | toJson }}) + # Removing the label from an unsupported object must stay possible. + - name: still-labelled + expression: "'compute.configuration.sagemaker.amazonaws.com/name' in object.metadata.?labels.orValue({})" + validations: + - expression: "false" + messageExpression: >- + request.kind.kind + " doesn't support compute configurations: remove the + compute.configuration.sagemaker.amazonaws.com/name label. Supported kinds: RayJob (ray.io), + HyperPodPyTorchJob (sagemaker.amazonaws.com) and InferenceEndpointConfig + (inference.sagemaker.aws.amazon.com)." + reason: Invalid +--- +apiVersion: admissionregistration.k8s.io/v1 +kind: ValidatingAdmissionPolicyBinding +metadata: + name: {{ $name }} + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 4 }} +spec: + policyName: {{ $name }} + validationActions: [Deny] +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/validating-webhook-configuration.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/validating-webhook-configuration.yaml new file mode 100644 index 00000000..1487fd58 --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/validating-webhook-configuration.yaml @@ -0,0 +1,18 @@ +{{- if .Values.webhook.enable }} +{{- $name := include "hyperpod-compute-configuration.webhookName" . }} +apiVersion: admissionregistration.k8s.io/v1 +kind: ValidatingWebhookConfiguration +metadata: + name: {{ $name }} + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 4 }} + {{- if .Values.certManager.enable }} + annotations: + cert-manager.io/inject-ca-from: {{ include "hyperpod-compute-configuration.namespaceName" . }}/{{ $name }}-cert + {{- end }} +# Denies, in enforced namespaces only, workloads whose compute wasn't filled in from their +# configuration or no longer matches it. It runs after every mutating webhook, so it sees the +# final object. +webhooks: +{{- include "hyperpod-compute-configuration.webhookEntries" (dict "context" . "type" "validate" "operations" (list "CREATE" "UPDATE") "enforced" true) }} +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/workloads-policy.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/workloads-policy.yaml new file mode 100644 index 00000000..19f6b042 --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/templates/webhook/workloads-policy.yaml @@ -0,0 +1,81 @@ +{{- if .Values.webhook.enable }} +{{- $name := printf "%s-workloads" (include "hyperpod-compute-configuration.webhookName" .) }} +{{- $label := "compute.configuration.sagemaker.amazonaws.com/name" }} +# Rules for the supported workload kinds that don't need the webhook. It runs in the API server, +# so it works even when the webhook is down. +# - In enforced namespaces, every workload a user creates must use a compute configuration, which +# can then be switched but not removed. +# - A workload is only accepted in API version v1, the version the webhooks handle (matchPolicy +# Exact): in enforced namespaces always, elsewhere when it uses a compute configuration. +# Otherwise it would skip the webhooks and its configuration would be silently ignored. +apiVersion: admissionregistration.k8s.io/v1 +kind: ValidatingAdmissionPolicy +metadata: + name: {{ $name }} + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 4 }} +spec: + failurePolicy: Fail + matchConstraints: + matchPolicy: Exact + resourceRules: + {{- range fromYamlArray (include "hyperpod-compute-configuration.webhookKinds" .) }} + {{- if not .blocked }} + - apiGroups: [{{ .group | quote }}] + apiVersions: ["*"] + operations: ["CREATE", "UPDATE"] + resources: [{{ .resource }}] + {{- end }} + {{- end }} + namespaceSelector: + matchExpressions: + - key: kubernetes.io/metadata.name + operator: NotIn + values: [kube-system, {{ include "hyperpod-compute-configuration.namespaceName" . }}] + variables: + # matchConditions can't see the namespace, so the rules below check it through these variables. + - name: enforced + expression: >- + namespaceObject.?metadata.?labels[?'{{ include "hyperpod-compute-configuration.enforcementLabel" . }}'].orValue('') == 'enabled' + - name: configured + expression: "object.metadata.?labels[?'{{ $label }}'].orValue('') != ''" + matchConditions: + # Workloads a controller creates (for example the HyperPod inference operator's + # InferenceEndpointConfigs for a JumpStartModel) aren't checked. The exemption goes by who sends + # the request, not by ownerReferences, which any user can set on their own object. + - name: not-a-controller + expression: >- + !(request.userInfo.username in {{ .Values.webhook.workloadControllers | default list | toJson }}) + validations: + # Outside enforced namespaces, workloads that don't use a compute configuration are never + # affected. + - expression: >- + !(variables.enforced || variables.configured) || request.kind.version == 'v1' + messageExpression: >- + request.kind.kind + ' ' + request.kind.group + '/' + request.kind.version + + " isn't supported with compute configurations. Use " + request.kind.group + '/v1.' + reason: Invalid + - expression: >- + !variables.enforced || request.operation != 'CREATE' || variables.configured + message: >- + Every workload in this namespace must use a compute configuration: set the + {{ $label }} label. + reason: Invalid + - expression: >- + !variables.enforced || request.operation != 'UPDATE' || variables.configured + || oldObject.metadata.?labels[?'{{ $label }}'].orValue('') == '' + message: >- + This workload's compute configuration can't be removed in this namespace. Switch to a + different configuration instead. + reason: Invalid +--- +apiVersion: admissionregistration.k8s.io/v1 +kind: ValidatingAdmissionPolicyBinding +metadata: + name: {{ $name }} + labels: + {{- include "hyperpod-compute-configuration.webhookLabels" . | nindent 4 }} +spec: + policyName: {{ $name }} + validationActions: [Deny] +{{- end }} diff --git a/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/values.yaml b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/values.yaml new file mode 100644 index 00000000..5419ad67 --- /dev/null +++ b/helm_chart/HyperPodHelmChart/charts/hyperpod-compute-configuration/values.yaml @@ -0,0 +1,119 @@ +## Namespace the webhook is installed into (the parent chart's release namespace is kube-system). +namespace: aws-hyperpod + +## AWS region for resolving regional ECR image registries. +## Required when webhook.image.override is not explicitly set. +## +## Region detection priority: +## 1. This explicit region setting (highest priority) +## 2. Global region setting (global.region from parent chart) +## +## Supported regions: ap-northeast-1, ap-south-1, ap-south-2, ap-southeast-1, ap-southeast-2, +## eu-central-1, eu-north-1, eu-west-1, eu-west-2, sa-east-1, us-east-1, us-east-2, us-west-1, +## us-west-2 +region: "" + +## Custom Resource Definitions +## +crd: + # Install CRDs with the chart + enable: true + # Keep CRDs when uninstalling + keep: true + +## RBAC helper roles +## +rbac: + helpers: + # Install viewer / editor / admin ClusterRoles for ComputeConfigurations. They aren't bound to + # anyone; bind them to users or groups yourself. Access is normally granted through the EKS + # access policies AmazonSagemakerHyperpodComputeConfigurationPolicy (read) and + # AmazonSagemakerHyperpodComputeConfigurationAdminPolicy (write) instead. + enable: false + +## Admission webhook +## +webhook: + # Install the admission webhook: the server Deployment, Service, PodDisruptionBudget, + # ServiceAccount, cert-manager certificate, and the Mutating and Validating + # WebhookConfigurations. Set it to false to install only the CRD: compute configurations can + # then be created and read, but nothing applies them to workloads. + enable: true + + # Number of webhook server pods. Keep at least 2 so a node drain or pod restart doesn't + # leave workload creates without a webhook. + replicas: 2 + + ## Container image configuration. The repository is resolved from the region: see + ## hyperpod-compute-configuration.webhookImage in templates/_helpers.tpl. + image: + ## Image tag override. + ## If not specified, defaults to the published tag this chart version is tested with. + ## Ignored when digest is set. + ## + # tag: "" + + ## Image digest, "sha256:<64 hex>". Pins the webhook to one image, which a tag does not. + ## + digest: "" + + ## Override the full image URI, pinned by digest ("@sha256:<64 hex>"; a tag isn't + ## accepted). If specified, this overrides the automatic region-based URI selection. + ## Example: "945058679767.dkr.ecr.us-east-2.amazonaws.com/hyperpod-compute-configuration-webhook@sha256:" + ## + override: "" + pullPolicy: IfNotPresent + + # Port the webhook server listens on inside the pod (the Service exposes it on 443) + port: 9443 + # Port for the /healthz and /readyz endpoints + healthProbePort: 8081 + + # How long the API server waits for the webhook before applying its failurePolicy (1-30) + timeoutSeconds: 5 + + # Log level (debug, info, error) + logLevel: info + + resources: + requests: + cpu: 10m + memory: 64Mi + limits: + cpu: 500m + memory: 256Mi + + # Run on HyperPod-managed amd64 nodes, as the Ray endpoint operator does + nodeSelector: + kubernetes.io/arch: amd64 + sagemaker.amazonaws.com/compute-type: hyperpod + tolerations: [] + affinity: {} + # Optional priority class, so the webhook isn't evicted before workloads under node pressure + priorityClassName: "" + + # Controllers that create workloads on users' behalf. In enforced namespaces the "workloads" + # admission policy doesn't require them to use a compute configuration. In every namespace the + # "unsupported-kinds" policy lets them create labelled objects without an owner (such as the + # inference operator's Deployment for an InferenceEndpointConfig). Each is the requester's + # username, system:serviceaccount::; add your own installs' names. + workloadControllers: + # HyperPod inference operator (Helm and EKS add-on installs): InferenceEndpointConfigs for + # JumpStartModels + - system:serviceaccount:hyperpod-inference-system:hyperpod-inference-operator-controller-manager + - system:serviceaccount:hyperpod-inference-system:hyperpod-inference-controller-manager + # KubeRay: RayJobs for RayCronJobs + - system:serviceaccount:kuberay-system:kuberay-operator + + podDisruptionBudget: + # Minimum webhook pods kept running during voluntary disruptions (node drains) + minAvailable: 1 + +## cert-manager integration +## +certManager: + # Create a self-signed cert-manager Issuer and Certificate for the webhook's TLS, and have + # cert-manager inject the CA into both webhook configurations. Requires cert-manager in the + # cluster (HyperPod installs it as an EKS add-on). Must stay true when webhook.enable is true: + # the webhook has no other source of certificates, so the chart refuses to render without it. + enable: true diff --git a/helm_chart/HyperPodHelmChart/values.yaml b/helm_chart/HyperPodHelmChart/values.yaml index f97ed432..79553f51 100644 --- a/helm_chart/HyperPodHelmChart/values.yaml +++ b/helm_chart/HyperPodHelmChart/values.yaml @@ -318,3 +318,26 @@ hyperpod-ray-endpoint-operator: # node label, and the image then comes from us-east-1. hyperpod-kubernetes-resource-monitor: enabled: true + +# HyperPod compute configurations: named compute shapes (the ComputeConfiguration CRD) that an +# admin defines per namespace and users reference from a RayJob, HyperPodPyTorchJob or +# InferenceEndpointConfig, with an admission webhook that fills in and checks their compute. Off by +# default. Requires cert-manager (cert-manager.enabled) and Kubernetes 1.30+. The webhook image is +# picked by region (or global.region). +hyperpod-compute-configuration: + enabled: false + # Namespace for the webhook (default: aws-hyperpod, created by deep-health-check) + namespace: "aws-hyperpod" + # AWS region for resolving regional ECR image registries + region: "" + webhook: + # Install the admission webhook as well as the CRD + enable: true + # Container image configuration + image: + # Image tag override (defaults to the tested published tag) + # tag: "" + # Image digest, "sha256:<64 hex>"; pins one image and takes precedence over tag + digest: "" + # Override the full image URI, pinned by digest (skips region-based resolution) + override: "" diff --git a/helm_chart/readme.md b/helm_chart/readme.md index 7a174f3a..2c45ecdf 100644 --- a/helm_chart/readme.md +++ b/helm_chart/readme.md @@ -33,6 +33,7 @@ More information about orchestration features for cluster admins [here](https:// | [Kubeflow Training Operator](https://www.kubeflow.org/docs/components/trainer/legacy-v1/overview/) | Installs operators for managing various machine learning training jobs, such as TensorFlow, PyTorch, and MXNet, providing native Kubernetes support for distributed training workloads. | | Yes | | HyperPod patching | Deploys the RBAC and controller resources needed for orchestrating rolling updates and patching workflows in SageMaker HyperPod clusters. Includes pod eviction and node monitoring. | HyperPod Resiliency | Yes | | HyperPod Kubernetes resource monitor | Deploys a report-only agent that watches nodes, pods, DaemonSets and training jobs, and reports HyperPod component health as Kubernetes events. It does not change workloads. Deploys into the `aws-hyperpod` namespace, which Deep health check creates. | HyperPod Resiliency | Yes | +| HyperPod compute configurations | Installs the ComputeConfiguration CRD and its admission webhook: an admin defines named compute shapes in a namespace, and a RayJob, HyperPodPyTorchJob or InferenceEndpointConfig that references one gets its compute filled in and checked. Requires cert-manager and Kubernetes 1.30+. | | No | | hyperpod-inference-operator | Installs the HyperPod Inference Operator and its dependencies to the cluster, allowing cluster deployment and inferencing of JumpStart, s3-hosted, and FSx-hosted models | No | | [cert-manager](https://github.com/cert-manager/cert-manager) | Automatically provisions and manages TLS certificates in Kubernetes clusters. Provides certificate lifecycle management including issuance, renewal, and revocation for secure communications. | [Hyperpod training operator](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-eks-operator.html) | No |