Skip to content

Commit

Permalink
Merge pull request #24 from whylabs/dev/aberg/guardrails-#86b07jmrb
Browse files Browse the repository at this point in the history
Guardrails Helm chart
  • Loading branch information
AnchorArray authored May 9, 2024
2 parents 3e3f47c + 4ffd17c commit e21a5c0
Show file tree
Hide file tree
Showing 22 changed files with 925 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ jobs:
ghcr_chart="ghcr.io/${{ github.repository_owner }}/${{ github.repository }}/${chart_name}:${chart_version}"
helm push "$chart" oci://ghcr.io/${{ github.repository_owner }}
done
shell: bash
shell: bash

7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/norwoodj/helm-docs
rev: v1.2.0
hooks:
- id: helm-docs
args:
- --chart-search-root=charts
23 changes: 23 additions & 0 deletions charts/guardrails/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
13 changes: 13 additions & 0 deletions charts/guardrails/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog

All notable changes to this project will be documented in this file.

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.1.0] - 2024-05-08

### Added

- Initial release of `guardrails` Helm chart
6 changes: 6 additions & 0 deletions charts/guardrails/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: guardrails
description: A Helm chart for WhyLabs Guardrails
type: application
version: 0.1.0
appVersion: "1.0.19"
72 changes: 72 additions & 0 deletions charts/guardrails/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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)

A Helm chart for WhyLabs Guardrails

## Installing the Chart

```shell
# Downloads a .tgz file to the working directory or --destination path
helm pull \
oci://ghcr.io/whylabs/guardrails \
--version 0.1.0

helm diff upgrade \
--allow-unreleased \
--namespace <target-namespace> \
`# Specify the .tgz file as the chart` \
guardrails
guardrails-0.1.0.tgz
```

After you've installed the repo you can install the chart.

```shell
helm upgrade --install \
--create-namespace \
--namespace <target-namespace> \
guardrails
guardrails-0.1.0.tgz
```

## 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. |
| 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. |
| extraVolumes | list | `[]` | Extra [volumes](https://kubernetes.io/docs/concepts/storage/volumes/) for the `Pod`. |
| fullnameOverride | string | `""` | Override the full name of the chart. |
| image.pullPolicy | string | `"IfNotPresent"` | Image pull policy for the `guardrails` container. |
| image.repository | string | `"registry.gitlab.com/whylabs/langkit-container"` | Image repository for the `guardrails` container. |
| image.tag | string | `""` | Image tag for the `guardrails` container, this will default to `.Chart.AppVersion` if not set. |
| imagePullSecrets[0] | list | `{"name":""}` | Image pull secrets for the `guardrails` container. Defaults to `whylabs-{{ .Release.Name }}-registry-credentials`. |
| ingress | object | `{"annotations":{},"className":"","enabled":false,"hosts":[{"host":"chart-example.local","paths":[{"path":"/","pathType":"ImplementationSpecific"}]}],"tls":[]}` | [Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/) configuration for the `guardrails` container. |
| livenessProbe | object | `{"failureThreshold":3,"httpGet":{"path":"/health","port":8000},"initialDelaySeconds":30,"periodSeconds":30}` | [Liveness probe](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/) configuration for the `guardrails` container. |
| nameOverride | string | `""` | Override the name of the chart. |
| nodeSelector | object | `{}` | Node labels to match for `Pod` [scheduling](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/). |
| podAnnotations | object | `{}` | Annotations to add to the `Pod`. |
| 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. |
| 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. |
| service.targetPort | int | `8000` | The port on which the application container is listening. |
| service.type | string | `"ClusterIP"` | Service Type, i.e. ClusterIp, LoadBalancer, etc. |
| serviceAccount.annotations | object | `{}` | Annotations to add to the service account. |
| serviceAccount.automount | bool | `true` | Set this to `false` to [opt out of API credential automounting](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#opt-out-of-api-credential-automounting) for the `ServiceAccount`. |
| serviceAccount.create | bool | `true` | If `true`, create a new `ServiceAccount`. |
| serviceAccount.labels | object | `{}` | Labels to add to the service account. |
| serviceAccount.name | string | `""` | If this is set and `serviceAccount.create` is `true` this will be used for the created `ServiceAccount` name, if set and `serviceAccount.create` is `false` then this will define an existing `ServiceAccount` to use. |
| tolerations | list | `[]` | Node taints which will be tolerated for `Pod` [scheduling](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/). |

----------------------------------------------

Autogenerated from chart metadata using [helm-docs](https://github.com/norwoodj/helm-docs/).
46 changes: 46 additions & 0 deletions charts/guardrails/README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{ template "chart.header" . }}
{{ template "chart.deprecationWarning" . }}

{{ template "chart.badgesSection" . }}

{{ template "chart.description" . }}

{{ template "chart.homepageLine" . }}

{{ template "chart.maintainersSection" . }}

{{ template "chart.sourcesSection" . }}

## Installing the Chart

```shell
# Downloads a .tgz file to the working directory or --destination path
helm pull \
oci://ghcr.io/whylabs/{{ template "chart.name" . }} \
--version {{ template "chart.version" . }}

helm diff upgrade \
--allow-unreleased \
--namespace <target-namespace> \
`# Specify the .tgz file as the chart` \
{{ template "chart.name" . }}
{{ template "chart.name" . }}-{{ template "chart.version" . }}.tgz
```

After you've installed the repo you can install the chart.

```shell
helm upgrade --install \
--create-namespace \
--namespace <target-namespace> \
{{ template "chart.name" . }}
{{ template "chart.name" . }}-{{ template "chart.version" . }}.tgz
```

{{ template "chart.requirementsSection" . }}

{{ template "chart.valuesSection" . }}

----------------------------------------------

Autogenerated from chart metadata using [helm-docs](https://github.com/norwoodj/helm-docs/).
55 changes: 55 additions & 0 deletions charts/guardrails/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "guardrails.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "guardrails.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "guardrails.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "guardrails.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}

2. Ensure the necessary secrets are created. Your application requires specific secrets to function properly:

- Secret for API Key: `whylabs-{{ .Release.Name }}-api-key`
- Secret for API Secret: `whylabs-{{ .Release.Name }}-api-secret`
- Secret for pulling private image: `whylabs-{{ .Release.Name }}-registry-credentials`

You can create these secrets with the following commands:
```
kubectl create secret generic whylabs-{{ .Release.Name }}-api-key \
--namespace {{ .Release.Namespace }} \
--from-literal=WHYLABS_API_KEY='<your-api-key>'

kubectl create secret generic whylabs-{{ .Release.Name }}-api-secret \
--namespace {{ .Release.Namespace }} \
--from-literal=CONTAINER_PASSWORD='<your-api-secret>'

kubectl create secret docker-registry whylabs-{{ .Release.Name }}-registry-credentials \
--namespace {{ .Release.Namespace }} \
--docker-server="registry.gitlab.com" \
--docker-username="<whylabs-provided-username>" \
--docker-password="<whylabs-provided-token>" \
--docker-email="<whylabs-provided-email>"
```

Replace `<your-api-key>` and other values with the actual values you need to use.

3. After creating the secrets, verify that they are correctly set up by running:

```
kubectl get secrets --namespace {{ .Release.Namespace }}
```

65 changes: 65 additions & 0 deletions charts/guardrails/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "guardrails.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "guardrails.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "guardrails.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "guardrails.labels" -}}
helm.sh/chart: {{ include "guardrails.chart" . }}
{{ include "guardrails.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- with .Values.commonLabels }}
{{ toYaml . }}
{{- end }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "guardrails.selectorLabels" -}}
app.kubernetes.io/name: {{ include "guardrails.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "guardrails.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "guardrails.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
Loading

0 comments on commit e21a5c0

Please sign in to comment.