From dc044838113e632ad5036abc82a4553ef691ce96 Mon Sep 17 00:00:00 2001 From: AnchorArray Date: Tue, 14 May 2024 08:16:18 -0700 Subject: [PATCH 1/3] Update resources, app version, and docs --- charts/guardrails/CHANGELOG.md | 6 +++ charts/guardrails/Chart.yaml | 4 +- charts/guardrails/README.md | 44 +++++++++++++++++---- charts/guardrails/README.md.gotmpl | 30 ++++++++++++++ charts/guardrails/templates/deployment.yaml | 1 + charts/guardrails/values.yaml | 12 +++--- charts/langkit/README.md | 6 +-- 7 files changed, 86 insertions(+), 17 deletions(-) diff --git a/charts/guardrails/CHANGELOG.md b/charts/guardrails/CHANGELOG.md index d99e6a0..d021491 100644 --- a/charts/guardrails/CHANGELOG.md +++ b/charts/guardrails/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning] (https://semver.org/spec/v2.0.0.html). +## [0.2.0] - 2024-05-14 + +### Updated + +- Default image tag from `1.0.19` to `1.0.20-dev2` + ## [0.1.0] - 2024-05-08 ### Added diff --git a/charts/guardrails/Chart.yaml b/charts/guardrails/Chart.yaml index 187875a..209f25e 100644 --- a/charts/guardrails/Chart.yaml +++ b/charts/guardrails/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 name: guardrails description: A Helm chart for WhyLabs Guardrails type: application -version: 0.1.0 -appVersion: "1.0.19" +version: 0.2.0 +appVersion: "1.0.20-dev2" diff --git a/charts/guardrails/README.md b/charts/guardrails/README.md index 44b7967..1a7a14c 100644 --- a/charts/guardrails/README.md +++ b/charts/guardrails/README.md @@ -1,6 +1,6 @@ # guardrails -![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.0.19](https://img.shields.io/badge/AppVersion-1.0.19-informational?style=flat-square) +![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.0.20-dev2](https://img.shields.io/badge/AppVersion-1.0.20--dev2-informational?style=flat-square) A Helm chart for WhyLabs Guardrails @@ -10,14 +10,14 @@ A Helm chart for WhyLabs Guardrails # Downloads a .tgz file to the working directory or --destination path helm pull \ oci://ghcr.io/whylabs/guardrails \ - --version 0.1.0 + --version 0.2.0 helm diff upgrade \ --allow-unreleased \ --namespace \ `# Specify the .tgz file as the chart` \ guardrails - guardrails-0.1.0.tgz + guardrails-0.2.0.tgz ``` After you've installed the repo you can install the chart. @@ -27,15 +27,45 @@ helm upgrade --install \ --create-namespace \ --namespace \ guardrails - guardrails-0.1.0.tgz + guardrails-0.2.0.tgz ``` +## Horizontal Pod Autoscaling (HPA) + +The Horizontal Pod Autoscaler automatically scales the number of pods in a +replication controller, deployment, replica set or stateful set based on +observed CPU utilization (or, with custom metrics support, on some other +application-provided metrics). The Horizontal Pod Autoscaler uses the following +formula to calculate the desired number of pods: + +```text +Desired Replicas = [ (Current Utilization / Target Utilization) * Current Replicas ] +``` + +For example, if an HPA is configured with a target CPU utilization of 50%, there +are currently 3 pods, and the current average CPU utilization is 90%, the number +of replicas will be scaled to 6: + +```text +Desired Replicas = ⌈ (90% / 50%) * 3 ⌉ + = ⌈ 1.8 * 3 ⌉ + = ⌈ 5.4 ⌉ + = 6 +``` + +HPA uses the same formula for both increasing and decreasing the number of pods. +Horizontal pod scaling is disabled by default. To enable it, set the +`hpa.enabled` key to `true`. The pods QoS class will impact HPA behavior as a +deployment that is allowed to burst CPU usage will cause more aggressive HPA +scaling than a deployment with a `Guaranteed` QoS that does not go above 100% +utilization. + ## Values | Key | Type | Default | Description | |-----|------|---------|-------------| | affinity | object | `{}` | Affinity settings for `Pod` [scheduling](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/). If an explicit label selector is not provided for pod affinity or pod anti-affinity one will be created from the pod selector labels. | -| autoscaling | object | `{"enabled":false,"maxReplicas":100,"minReplicas":1,"targetCPUUtilizationPercentage":80}` | [Horizontal Pod Autoscaler](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/) configuration for the `guardrails` container. | +| autoscaling | object | `{"enabled":false,"maxReplicas":100,"minReplicas":1,"targetCPUUtilizationPercentage":70}` | [Horizontal Pod Autoscaler](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/) configuration for the `guardrails` container. | | commonLabels | object | `{}` | Labels to add to all chart resources. | | env | object | `{}` | [Environment variables](https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/) for the `guardrails` container. | | extraVolumeMounts | list | `[]` | Extra [volume mounts](https://kubernetes.io/docs/concepts/storage/volumes/) for the `guardrails` container. | @@ -53,8 +83,8 @@ helm upgrade --install \ | podLabels | object | `{}` | Labels to add to the `Pod`. | | podSecurityContext | object | `{"runAsNonRoot":true}` | [Pod security context](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#podsecuritycontext-v1-core), this supports full customisation. | | readinessProbe | object | `{"failureThreshold":10,"httpGet":{"path":"/health","port":8000},"initialDelaySeconds":30,"periodSeconds":30}` | [Readiness probe](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/) configuration for the `guardrails` container. | -| replicaCount | int | `2` | Number of replicas for the service. | -| resources | object | `{"limits":{"cpu":"4","memory":"6Gi"},"requests":{"cpu":"4","memory":"6Gi"}}` | [Resources](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) for the `guardrails` container. | +| replicaCount | int | `4` | Number of replicas for the service. | +| resources | object | `{"limits":{"cpu":"4","ephemeral-storage":"250Mi","memory":"4Gi"},"requests":{"cpu":"4","ephemeral-storage":"250Mi","memory":"4Gi"}}` | [Resources](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/) for the `guardrails` container. | | securityContext | object | `{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"privileged":false,"readOnlyRootFilesystem":true,"runAsNonRoot":true,"runAsUser":1000}` | [Security context](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container) for the `guardrails` container. | | service.annotations | object | `{}` | Service annotations. | | service.port | int | `80` | Service HTTP port. | diff --git a/charts/guardrails/README.md.gotmpl b/charts/guardrails/README.md.gotmpl index 43d2f88..64cf9d8 100644 --- a/charts/guardrails/README.md.gotmpl +++ b/charts/guardrails/README.md.gotmpl @@ -37,6 +37,36 @@ helm upgrade --install \ {{ template "chart.name" . }}-{{ template "chart.version" . }}.tgz ``` +## Horizontal Pod Autoscaling (HPA) + +The Horizontal Pod Autoscaler automatically scales the number of pods in a +replication controller, deployment, replica set or stateful set based on +observed CPU utilization (or, with custom metrics support, on some other +application-provided metrics). The Horizontal Pod Autoscaler uses the following +formula to calculate the desired number of pods: + +```text +Desired Replicas = [ (Current Utilization / Target Utilization) * Current Replicas ] +``` + +For example, if an HPA is configured with a target CPU utilization of 50%, there +are currently 3 pods, and the current average CPU utilization is 90%, the number +of replicas will be scaled to 6: + +```text +Desired Replicas = ⌈ (90% / 50%) * 3 ⌉ + = ⌈ 1.8 * 3 ⌉ + = ⌈ 5.4 ⌉ + = 6 +``` + +HPA uses the same formula for both increasing and decreasing the number of pods. +Horizontal pod scaling is disabled by default. To enable it, set the +`hpa.enabled` key to `true`. The pods QoS class will impact HPA behavior as a +deployment that is allowed to burst CPU usage will cause more aggressive HPA +scaling than a deployment with a `Guaranteed` QoS that does not go above 100% +utilization. + {{ template "chart.requirementsSection" . }} {{ template "chart.valuesSection" . }} diff --git a/charts/guardrails/templates/deployment.yaml b/charts/guardrails/templates/deployment.yaml index 07cba1a..580033c 100644 --- a/charts/guardrails/templates/deployment.yaml +++ b/charts/guardrails/templates/deployment.yaml @@ -5,6 +5,7 @@ metadata: labels: {{- include "guardrails.labels" . | nindent 4 }} spec: + revisionHistoryLimit: 1 {{- if not .Values.autoscaling.enabled }} replicas: {{ .Values.replicaCount }} {{- end }} diff --git a/charts/guardrails/values.yaml b/charts/guardrails/values.yaml index 5863c28..3edb82a 100644 --- a/charts/guardrails/values.yaml +++ b/charts/guardrails/values.yaml @@ -1,5 +1,5 @@ # -- Number of replicas for the service. -replicaCount: 2 +replicaCount: 4 image: # -- Image repository for the `guardrails` container. @@ -89,10 +89,12 @@ ingress: resources: requests: cpu: "4" - memory: 6Gi + memory: 4Gi + ephemeral-storage: 250Mi limits: cpu: "4" - memory: 6Gi + memory: 4Gi + ephemeral-storage: 250Mi # -- [Liveness probe](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/) configuration for the `guardrails` container. livenessProbe: @@ -117,8 +119,8 @@ autoscaling: enabled: false minReplicas: 1 maxReplicas: 100 - targetCPUUtilizationPercentage: 80 - # targetMemoryUtilizationPercentage: 80 + targetCPUUtilizationPercentage: 70 + # targetMemoryUtilizationPercentage: 70 # -- Extra [volumes](https://kubernetes.io/docs/concepts/storage/volumes/) for the `Pod`. extraVolumes: [] diff --git a/charts/langkit/README.md b/charts/langkit/README.md index f2712b2..fd02e3a 100644 --- a/charts/langkit/README.md +++ b/charts/langkit/README.md @@ -1,7 +1,7 @@ -# **:exclamation: This Helm Chart is deprecated! Please use the [GuardRails Chart](https://github.com/whylabs/charts/tree/mainline/charts/guardrails) instead** - # langkit +> **:exclamation: This Helm Chart is deprecated!** + ![Version: 0.16.0](https://img.shields.io/badge/Version-0.16.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.0.13](https://img.shields.io/badge/AppVersion-1.0.13-informational?style=flat-square) A Helm chart for LangKit container deployment @@ -141,4 +141,4 @@ helm uninstall \ ---------------------------------------------- -Autogenerated from chart metadata using [helm-docs](https://github.com/norwoodj/helm-docs/). +Autogenerated from chart metadata using [helm-docs](https://github.com/norwoodj/helm-docs/). \ No newline at end of file From fa0ca6adb24b3500b9ad8ee803184741787531d5 Mon Sep 17 00:00:00 2001 From: AnchorArray Date: Tue, 14 May 2024 08:53:52 -0700 Subject: [PATCH 2/3] publish dev chart on push to pr --- .github/workflows/main.yaml | 49 +++++++++++++++++++++++++++++++------ .gitignore | 1 + .pre-commit-config.yaml | 30 ++++++++++++++++++++++- README.md | 13 ++++++++++ 4 files changed, 84 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 15ddd71..f888e72 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -24,8 +24,43 @@ jobs: with: version: v3.14.0 + # - name: YAML Lint + # if: github.event_name == 'pull_request' + # uses: actionshub/yaml-lint@v1 + # with: + # directory: . + + # - name: Helm Lint + # if: github.event_name == 'pull_request' + # working-directory: ${{ github.workspace }}/charts + # run: | + # for dir in */ ; do + # if [ -f "$dir/Chart.yaml" ]; then + # helm lint "$dir" + # fi + # done + # shell: bash + + # - name: Markdown Lint + # if: github.event_name == 'pull_request' + # uses: github/super-linter@v4 + # env: + # DEFAULT_BRANCH: mainline + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # VALIDATE_MARKDOWN: true + + - name: Update Chart Version for PRs + if: github.event_name == 'pull_request' + working-directory: ${{ github.workspace }}/charts + run: | + for dir in */ ; do + if [ -f "$dir/Chart.yaml" ]; then + yq eval '.version += "-dev"' -i "$dir/Chart.yaml" + fi + done + shell: bash + - name: Package All Helm Charts - if: github.event_name == 'push' working-directory: ${{ github.workspace }}/charts run: | for dir in */ ; do @@ -36,21 +71,19 @@ jobs: shell: bash - name: Login to GHCR - if: github.event_name == 'push' run: | - docker login ghcr.io \ - -u ${{ github.repository_owner }} \ - --password-stdin < <(echo "${{ secrets.GITHUB_TOKEN }}") + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin - name: Publish Helm Charts to GHCR - if: github.event_name == 'push' working-directory: ${{ github.workspace }}/charts run: | for chart in *.tgz ; do chart_name=$(basename "$chart" .tgz) chart_version=$(echo "$chart_name" | sed 's/.*-//') + if [ "${{ github.event_name }}" == "pull_request" ]; then + chart_version="${chart_version}-dev" + fi ghcr_chart="ghcr.io/${{ github.repository_owner }}/${{ github.repository }}/${chart_name}:${chart_version}" - helm push "$chart" oci://ghcr.io/${{ github.repository_owner }} + helm push "$chart" oci://ghcr.io/${{ github.repository_owner }}" done shell: bash - \ No newline at end of file diff --git a/.gitignore b/.gitignore index 94f1119..b40938e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store .vscode +.ruby-version diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3a26d9f..20bc40f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,35 @@ repos: - repo: https://github.com/norwoodj/helm-docs - rev: v1.2.0 + rev: v1.13.1 hooks: - id: helm-docs args: - --chart-search-root=charts + + # - repo: https://github.com/pre-commit/pre-commit-hooks + # rev: v4.6.0 + # hooks: + # - id: trailing-whitespace + # - id: end-of-file-fixer + # - id: check-yaml + # - id: check-json + + # - repo: https://github.com/pre-commit/pre-commit-hooks + # rev: v4.6.0 + # hooks: + # - id: check-yaml + # files: \.(yml|yaml)$ + + # - repo: https://github.com/markdownlint/markdownlint + # rev: v0.12.0 + # hooks: + # - id: markdownlint + + # - repo: local + # hooks: + # - id: helm-lint + # name: Helm Lint + # entry: helm lint + # language: system + # files: ^charts/ + # types: [file] diff --git a/README.md b/README.md index 14c52ee..6a88a59 100644 --- a/README.md +++ b/README.md @@ -76,3 +76,16 @@ helm uninstall \ --namespace "${namespace}" \ "${release}" ``` + +## Development + +### Pre-Commit + +#### Troubleshooting + +Try executing `pre-commit` manually if it fails on commit: + +```shell +git add . +pre-commit run --all-files +``` From da46e2ed537ea526f98b7b2959d498d5ab1c97f0 Mon Sep 17 00:00:00 2001 From: AnchorArray Date: Tue, 14 May 2024 08:55:54 -0700 Subject: [PATCH 3/3] fix quote --- .github/workflows/main.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index f888e72..2aecfbb 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -84,6 +84,7 @@ jobs: chart_version="${chart_version}-dev" fi ghcr_chart="ghcr.io/${{ github.repository_owner }}/${{ github.repository }}/${chart_name}:${chart_version}" - helm push "$chart" oci://ghcr.io/${{ github.repository_owner }}" + helm push "$chart" "oci://ghcr.io/${{ github.repository_owner }}" done shell: bash +